Class: MQTT::Homie::Device
- Inherits:
-
HomieObject
- Object
- HomieObject
- MQTT::Homie::Device
- Extended by:
- Network
- Defined in:
- lib/mqtt/homie/device.rb
Defined Under Namespace
Classes: Firmware, Statistics
Constant Summary collapse
- HOMIE_VERSION =
"3.0.1"
- DEFAULT_STAT_REFRESH =
seconds
60
- DEFAULT_IMPLEMENTATION =
"mqtt-homie-#{VERSION}"
Instance Attribute Summary collapse
-
#fw ⇒ Object
readonly
Returns the value of attribute fw.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
-
#use_fw ⇒ Object
Returns the value of attribute use_fw.
-
#use_stats ⇒ Object
Returns the value of attribute use_stats.
Instance Method Summary collapse
-
#homie_attributes ⇒ Object
device attributes must be sent when connection to broker is established or re-established homie/device_id/.
-
#initialize(options = {}) ⇒ Device
constructor
A new instance of Device.
- #node(id) ⇒ Object
Methods included from Network
default_interface, default_localip, default_mac, interfaces, usable_address?
Methods inherited from HomieObject
Methods included from HomieAttribute
Constructor Details
#initialize(options = {}) ⇒ Device
Returns a new instance of Device.
62 63 64 65 66 67 68 69 |
# File 'lib/mqtt/homie/device.rb', line 62 def initialize( = {}) super() @stats = Statistics.new() @fw = Firmware.new(subhash(, "fw_")) @use_stats = .include?(:use_stats) ? [:use_stats] : true @use_fw = .include?(:use_fw) ? [:use_fw] : true end |
Instance Attribute Details
#fw ⇒ Object (readonly)
Returns the value of attribute fw.
51 52 53 |
# File 'lib/mqtt/homie/device.rb', line 51 def fw @fw end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
51 52 53 |
# File 'lib/mqtt/homie/device.rb', line 51 def stats @stats end |
#use_fw ⇒ Object
Returns the value of attribute use_fw.
52 53 54 |
# File 'lib/mqtt/homie/device.rb', line 52 def use_fw @use_fw end |
#use_stats ⇒ Object
Returns the value of attribute use_stats.
52 53 54 |
# File 'lib/mqtt/homie/device.rb', line 52 def use_stats @use_stats end |
Instance Method Details
#homie_attributes ⇒ Object
device attributes must be sent when connection to broker is established or re-established homie/device_id/
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# 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) ⇒ Object
71 72 73 |
# File 'lib/mqtt/homie/device.rb', line 71 def node(id) @nodes.find { |i| i.id == id } end |