Sha256: f4d555120378dff6b291e32735ae67a94458cb63c0c628e393054cdc30dd56ab
Contents?: true
Size: 1.16 KB
Versions: 32
Compression:
Stored size: 1.16 KB
Contents
# frozen_string_literal: true module DjiMqttConnect module Thing::Product class EventsTopicRepository < TopicRepository EVENTS_TOPIC_REGEX = /\Athing\/product\/(?<device_sn>.+)\/events\z/ def listen! listen_to_topic("thing/product/+/events") do |topic, raw_message| logger.debug(raw_message) matched_topic = EVENTS_TOPIC_REGEX.match(topic) raise Error, "Unknown topic: #{topic}" unless matched_topic device_sn = matched_topic[:device_sn] message = EventsMarshal.load(raw_message) logger.info("Received #{message} from #{device_sn}") if message.instance_of?(EventsMessage) # Broadcast an unsupported message event broadcast(:unsupported_message, topic, raw_message) else # Build event name and broadcast (i.e. ::HmsEventsMessage => hms_event) event_name = message.class.name.demodulize.sub(/sMessage\z/, "").underscore.to_sym broadcast(event_name, device_sn, message) end rescue ParseError => error broadcast(:parse_error, error, topic, raw_message) end end end end end
Version data entries
32 entries across 32 versions & 1 rubygems