Method: MQTT::Homie::Property#initialize
- Defined in:
- lib/mqtt/homie/property.rb
#initialize(node, id, name, datatype, value = nil, format: nil, retained: true, unit: nil, non_standard_value_check: nil, &block) ⇒ Property
Returns a new instance of Property.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mqtt/homie/property.rb', line 10 def initialize(node, id, name, datatype, value = nil, format: nil, retained: true, unit: nil, non_standard_value_check: nil, &block) raise ArgumentError, "Invalid Homie datatype" unless %i[string integer float boolean enum color datetime duration].include?(datatype) raise ArgumentError, "retained must be boolean" unless [true, false].include?(retained) raise ArgumentError, "unit must be nil or a string" unless unit.nil? || unit.is_a?(String) if !value.nil? && !retained raise ArgumentError, "an initial value cannot be provided for a non-retained property" end super(id, name) @node = node @datatype = datatype self.format = format @retained = retained @unit = unit @value = value @published = false @non_standard_value_check = non_standard_value_check @block = block end |