Sha256: cb646584713ce2008681ec1c75007171af8a566d36e2e0a2e8168b96d41bf4ff
Contents?: true
Size: 1023 Bytes
Versions: 4
Compression:
Stored size: 1023 Bytes
Contents
# frozen_string_literal: true module DjiMqttConnect module Thing::Product class OsdTopicRepository < TopicRepository OSD_TOPIC_REGEX = /\Athing\/product\/(?<device_identifier>.+)\/osd\z/ def listen! listen_to_topic("thing/product/+/osd") do |topic, raw_message| logger.debug(raw_message) matched_topic = OSD_TOPIC_REGEX.match(topic) raise Error, "Unknown topic: #{topic}" unless matched_topic device_identifier = matched_topic[:device_identifier] message = OsdMarshal.load(raw_message) logger.info("Received #{message} from #{device_identifier}") # Build event name and broadcast (i.e. ::RemoteOsdMessage => remote_osd_update) event_name = message.class.name.demodulize.sub(/Message\z/, "Update").underscore.to_sym broadcast(event_name, device_identifier, message) rescue ParseError => error broadcast(:parse_error, error, topic, raw_message) end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems