lib/mqtt/homie/node.rb in mqtt-homie-0.1.0 vs lib/mqtt/homie/node.rb in mqtt-homie-0.1.1
- old
+ new
@@ -1,26 +1,18 @@
module MQTT
module Homie
class Node < HomieObject
- attr_reader :name, :properties
+ homie_id
+ homie_attr :name, required: true
+ homie_attr :type, required: true
+ homie_attr :properties, datatype: Array, required: true, immutable: true
- def initialize(options = {})
- super(options)
- @name = set(options, :name, required: true)
- @type = set(options, :type, required: true)
- @properties = set(options, :properties, required: true, data_type: Array)
- end
-
def property(id)
@properties.find { |i| i.id == id }
end
def homie_attributes
- data = {
- "$name" => @name,
- "$type" => @type,
- "$properties" => @properties.collect { |i| i.id }.join(","),
- }
+ data = super
@properties.each do |p|
p.homie_attributes.each do |k, v|
data[p.topic + "/" + k] = v
end