Sha256: a6ab7e96418c8147c724b95662ab77e864b8f0e159bdadc29e249da29b321b89
Contents?: true
Size: 976 Bytes
Versions: 8
Compression:
Stored size: 976 Bytes
Contents
# frozen_string_literal: true module DjiMqttConnect module Thing::Product class StateTopicRepository < TopicRepository STATE_TOPIC_REGEX = /\Athing\/product\/(?<device_sn>.+)\/state\z/ def listen! listen_to_topic("thing/product/+/state") do |topic, raw_message| logger.debug(raw_message) matched_topic = STATE_TOPIC_REGEX.match(topic) raise Error, "Unknown topic: #{topic}" unless matched_topic device_sn = matched_topic[:device_sn] message = state_marshal.load(raw_message) logger.info("Received #{message} from #{device_sn}") # Broadcast a generic received state message event broadcast(:received_state_message, device_sn, message) rescue ParseError => error broadcast(:parse_error, error, topic, raw_message) end end private def state_marshal @state_marshal ||= StateMarshal.new end end end end
Version data entries
8 entries across 8 versions & 1 rubygems