Class: DjiMqttConnect::Thing::Product::StateTopicRepository
- Inherits:
-
DjiMqttConnect::TopicRepository
- Object
- DjiMqttConnect::TopicRepository
- DjiMqttConnect::Thing::Product::StateTopicRepository
- Defined in:
- lib/dji_mqtt_connect/topics/thing/product/state.rb
Constant Summary collapse
- STATE_TOPIC_REGEX =
/\Athing\/product\/(?<device_sn>.+)\/state\z/
Instance Method Summary collapse
Methods inherited from DjiMqttConnect::TopicRepository
Constructor Details
This class inherits a constructor from DjiMqttConnect::TopicRepository
Instance Method Details
#listen! ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dji_mqtt_connect/topics/thing/product/state.rb', line 8 def listen! listen_to_topic("thing/product/+/state") do |topic, | logger.debug() matched_topic = STATE_TOPIC_REGEX.match(topic) raise Error, "Unknown topic: #{topic}" unless matched_topic device_sn = matched_topic[:device_sn] = state_marshal.load() logger.info("Received #{} from #{device_sn}") # Broadcast a generic received state message event broadcast(:received_state_message, device_sn, ) rescue ParseError => error broadcast(:parse_error, error, topic, ) end end |