class MQTT::Homie::Device
def publish
def publish return if @published mqtt.batch_publish do mqtt.publish("#{topic}/$homie", VERSION, retain: true, qos: 1) mqtt.publish("#{topic}/$name", name, retain: true, qos: 1) mqtt.publish("#{topic}/$state", @state.to_s, retain: true, qos: 1) @subscription_thread = Thread.new do # you'll get the exception when you call `join` Thread.current.report_on_exception = false mqtt.get do |packet| logger&.debug("received packet at #{packet.topic} with payload #{packet.payload.inspect}") match = packet.topic.match(topic_regex) node = @nodes[match[:node]] if match property = node[match[:property]] if node unless property&.settable? @out_of_band_topic_proc&.call(packet.topic, packet.payload) next end property.set(packet.payload) end end mqtt.publish("#{topic}/$nodes", @nodes.keys.join(","), retain: true, qos: 1) @nodes.each_value(&:publish) yield if block_given? mqtt.publish("#{topic}/$state", (@state = :ready).to_s, retain: true, qos: 1) end @published = true end