class MQTT::Homie::Device
Constants
- DEFAULT_IMPLEMENTATION
- DEFAULT_STAT_REFRESH
- HOMIE_VERSION
Attributes
fw[R]
stats[R]
use_fw[RW]
use_stats[RW]
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
# File lib/mqtt/homie/device.rb, line 62 def initialize(options = {}) super(options) @stats = Statistics.new(options) @fw = Firmware.new(subhash(options, "fw_")) @use_stats = options.include?(:use_stats) ? options[:use_stats] : true @use_fw = options.include?(:use_fw) ? options[:use_fw] : true end
Public Instance Methods
homie_attributes()
click to toggle source
device attributes must be sent when connection to broker is established or re-established homie/device_id/
Calls superclass method
# File lib/mqtt/homie/device.rb, line 77 def homie_attributes data = super.merge({ "$homie" => HOMIE_VERSION, }) data.merge!({ "$fw/name" => @fw.name, "$fw/version" => @fw.version, }) if @use_fw @nodes.each do |node| node.homie_attributes.each do |k, v| data[node.topic + "/" + k] = v end end data end
node(id)
click to toggle source
# File lib/mqtt/homie/device.rb, line 71 def node(id) @nodes.find { |i| i.id == id } end
Private Instance Methods
subhash(data, prefix)
click to toggle source
# File lib/mqtt/homie/device.rb, line 97 def subhash(data, prefix) result = {} data.each do |key, value| next unless key.to_s.start_with?(prefix) key = key.to_s.sub(/^#{prefix}/, "") result[key.to_sym] = value end result end