Sha256: 0116f3a720f8fe67604d78b1f81502db2fc8737f6def1e6f0499ad53f49860a3

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module DjiMqttConnect
  module Thing::Product
    # https://developer.dji.com/doc/cloud-api-tutorial/en/server-api-reference/mqtt/topic-definition.html#events-reply-struct-example
    class EventsReplyMessage < DjiMqttConnect::Message
      # a result of 0 means we approve of this action
      def self.build_for(events_message, result: 0)
        new(
          _method: events_message._method,
          tid: events_message.tid,
          bid: events_message.bid,
          timestamp: current_timestamp,
          data: {
            result: result
          }
        )
      end

      # Ensure all values are accepted
      schema schema.strict

      attribute :bid, Types::UUID
      attribute :tid, Types::UUID
      attribute :timestamp, Types::Timestamp

      attribute :_method, Types::String

      attribute :data do
        include Mixins::ResultMessage

        attribute :result, Types::ResultCode
      end

      def humanized_summary
        Translations.thing_product_events_reply_summary(_method, **humanized_summary_interpolation)
      end

      def humanized_summary_interpolation
        data.to_h.merge(method: _method)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dji_mqtt_connect-0.1.25.1 lib/dji_mqtt_connect/messages/thing/product/events_reply_message.rb
dji_mqtt_connect-0.1.25 lib/dji_mqtt_connect/messages/thing/product/events_reply_message.rb