dji_mqtt_connect 0.1.21 → 0.1.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c7dcc1c840ccf9aaee09ac40525e54250b00543951b3adf3fc2535fead82529
4
- data.tar.gz: 768cbfdd365db52896838434a319742e55dbd82ad021d0a3aa6c76f07d94f8ac
3
+ metadata.gz: 7027ac9b38e9e7b0a0927e4fd9b6419c910d8c6fb3b531fdf70f5384a8f924b1
4
+ data.tar.gz: e8ebff861fe60c9f97d6ab1123c557c606d9ff1c7fac4585b119d8810de334ae
5
5
  SHA512:
6
- metadata.gz: 530a33ad82c122710f9a8421553768cd7eff877099722d2ce34918d434703c7fa429fdad587030db3fca04953c5c26411d3665d9bd61e468d4e6ddfc4feafee5
7
- data.tar.gz: 01df1da7273ba9b2492cd799c6eb08d8d20bb022c90f3860acd528abc32af4e2d759f6d8ec4a0ed922035db58bd0e7ef9cf68e2f668d68aaa97d00d4532282a7
6
+ metadata.gz: '0508e79e10728091f78602a32b4c5af879952c042f6ca2c9feb82f9141fb63ee2184f1d43e0ff484108139b8e0f3e591d8d60b29338732732b83a401ed6a5e4c'
7
+ data.tar.gz: 913b5ea242a5f96f3f5e0331fe55cc123632d5baa7db91016cb932233fc3322e0ae1b8a88e8fda32f7b6ed21aca6e26cf9e38e8dc9b599a811c7672246ce6fe1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dji_mqtt_connect (0.1.21)
4
+ dji_mqtt_connect (0.1.22)
5
5
  activesupport (>= 6.0, <= 8)
6
6
  dry-struct (~> 1.6)
7
7
  dry-transformer (~> 1.0)
@@ -144,6 +144,7 @@ GEM
144
144
 
145
145
  PLATFORMS
146
146
  arm64-darwin-22
147
+ arm64-darwin-23
147
148
  x86_64-darwin-21
148
149
  x86_64-linux
149
150
 
@@ -644,6 +644,29 @@ module DjiMqttConnect
644
644
  )
645
645
  end
646
646
 
647
+ def build_thing_product_offline_map_get_requests_message
648
+ message_data = {}
649
+
650
+ Thing::Product::OfflineMapGetRequestsMessage.new(
651
+ _method: "offline_map_get",
652
+ _data: message_data,
653
+ tid: Message.generate_tid,
654
+ bid: Message.generate_bid,
655
+ timestamp: Message.current_timestamp,
656
+ gateway: "gatewaysn",
657
+ data: message_data
658
+ )
659
+ end
660
+
661
+ def build_thing_product_offline_map_get_requests_reply_message
662
+ request_message = build_thing_product_offline_map_get_requests_message
663
+
664
+ Thing::Product::OfflineMapGetRequestsReplyMessage.build_for(
665
+ request_message,
666
+ result: 0
667
+ )
668
+ end
669
+
647
670
  def build_thing_product_storage_config_get_requests_message
648
671
  message_data = {
649
672
  module: 0
@@ -21,7 +21,7 @@ module DjiMqttConnect
21
21
  # Attempts to look a the method attribute, and builds a specific Message class for the message
22
22
  def load(raw_message)
23
23
  # Parse the message from JSON
24
- parsed_message = JSON.parse(raw_message)
24
+ parsed_message = parse_json(raw_message)
25
25
 
26
26
  # Transform the message
27
27
  transformed_message = attribute_transformer.call(parsed_message)
@@ -29,11 +29,7 @@ module DjiMqttConnect
29
29
 
30
30
  # Build an instance of the class, or a generic message from the current class
31
31
  message_class = message_class_from_message_method(message_method, StatusMessage)
32
- message_class.new transformed_message
33
- rescue JSON::ParserError => e
34
- raise ParseError.new(e, "Unable to parse message as JSON")
35
- rescue Dry::Struct::Error => e
36
- raise ParseError.new(e, "Unexpected #{message_class} payload")
32
+ build_message(message_class, transformed_message)
37
33
  end
38
34
 
39
35
  private
@@ -62,7 +62,7 @@ module DjiMqttConnect
62
62
  # Attempts to look a the method attribute, and builds a specific Message class for the message
63
63
  def load(raw_message)
64
64
  # Parse the message from JSON
65
- parsed_message = JSON.parse(raw_message)
65
+ parsed_message = parse_json(raw_message)
66
66
 
67
67
  # Transform the message
68
68
  transformed_message = attribute_transformer.call(parsed_message)
@@ -70,11 +70,7 @@ module DjiMqttConnect
70
70
 
71
71
  # Build an instance of the class, or a generic message from the current class
72
72
  message_class = message_class_from_message_method(message_method, EventsMessage)
73
- message_class.new transformed_message
74
- rescue JSON::ParserError => e
75
- raise ParseError.new(e, "Unable to parse message as JSON")
76
- rescue Dry::Struct::Error => e
77
- raise ParseError.new(e, "Unexpected #{message_class} payload")
73
+ build_message(message_class, transformed_message)
78
74
  end
79
75
 
80
76
  private
@@ -6,6 +6,8 @@ require "json"
6
6
  module DjiMqttConnect
7
7
  module Thing::Product
8
8
  class OsdMarshal < MessageMarshal
9
+ include Utils::MessageParsing
10
+
9
11
  # Make a copy of the raw data
10
12
  class AttributeTransformer < Dry::Transformer::Pipe
11
13
  import Dry::Transformer::Conditional
@@ -36,7 +38,7 @@ module DjiMqttConnect
36
38
 
37
39
  # Parse message from Device > Cloud Server
38
40
  def load(raw_message)
39
- parsed_message = JSON.parse(raw_message)
41
+ parsed_message = parse_json(raw_message)
40
42
 
41
43
  message_data = parsed_message.fetch("data", {})
42
44
 
@@ -53,11 +55,7 @@ module DjiMqttConnect
53
55
 
54
56
  transformed_message = attribute_transformer.call(parsed_message)
55
57
 
56
- message_class.new(transformed_message)
57
- rescue JSON::ParserError => e
58
- raise ParseError.new(e, "Unable to parse message as JSON")
59
- rescue Dry::Struct::Error => e
60
- raise ParseError.new(e, "Invalid #{message_class} payload")
58
+ build_message(message_class, transformed_message)
61
59
  end
62
60
 
63
61
  private
@@ -22,7 +22,7 @@ module DjiMqttConnect
22
22
  # Attempts to look a the method attribute, and builds a specific Message class for the message
23
23
  def load(raw_message)
24
24
  # Parse the message from JSON
25
- parsed_message = JSON.parse(raw_message)
25
+ parsed_message = parse_json(raw_message)
26
26
 
27
27
  # Transform the message
28
28
  transformed_message = attribute_transformer.call(parsed_message)
@@ -30,11 +30,7 @@ module DjiMqttConnect
30
30
 
31
31
  # Build an instance of the class, or a generic message from the current class
32
32
  message_class = message_class_from_message_method(message_method, RequestsMessage)
33
- message_class.new transformed_message
34
- rescue JSON::ParserError => e
35
- raise ParseError.new(e, "Unable to parse message as JSON")
36
- rescue Dry::Struct::Error => e
37
- raise ParseError.new(e, "Unexpected #{message_class} payload")
33
+ build_message(message_class, transformed_message)
38
34
  end
39
35
 
40
36
  private
@@ -22,7 +22,7 @@ module DjiMqttConnect
22
22
  # Attempts to look a the method attribute, and builds a specific Message class for the message
23
23
  def load(raw_message)
24
24
  # Parse the message from JSON
25
- parsed_message = JSON.parse(raw_message)
25
+ parsed_message = parse_json(raw_message)
26
26
 
27
27
  # Transform the message
28
28
  transformed_message = attribute_transformer.call(parsed_message)
@@ -30,11 +30,7 @@ module DjiMqttConnect
30
30
 
31
31
  # Build an instance of the class, or a generic message from the current class
32
32
  message_class = message_class_from_message_method(message_method, ServicesReplyMessage)
33
- message_class.new transformed_message
34
- rescue JSON::ParserError => e
35
- raise ParseError.new(e, "Unable to parse message as JSON")
36
- rescue Dry::Struct::Error => e
37
- raise ParseError.new(e, "Unexpected #{message_class} payload")
33
+ build_message(message_class, transformed_message)
38
34
  end
39
35
 
40
36
  private
@@ -21,17 +21,13 @@ module DjiMqttConnect
21
21
  # Attempts to look a the method attribute, and builds a specific Message class for the message
22
22
  def load(raw_message)
23
23
  # Parse the message from JSON
24
- parsed_message = JSON.parse(raw_message)
24
+ parsed_message = parse_json(raw_message)
25
25
 
26
26
  # Transform the message
27
27
  transformed_message = attribute_transformer.call(parsed_message)
28
28
 
29
29
  # Build an instance of the class, or a generic message from the current class
30
- StateMessage.new transformed_message
31
- rescue JSON::ParserError => e
32
- raise ParseError.new(e, "Unable to parse message as JSON")
33
- rescue Dry::Struct::Error => e
34
- raise ParseError.new(e, "Unexpected #{StateMessage} payload")
30
+ build_message(StateMessage, transformed_message)
35
31
  end
36
32
 
37
33
  private
@@ -13,7 +13,7 @@ module DjiMqttConnect
13
13
  attribute :file do
14
14
  attribute :object_key, Types::String
15
15
 
16
- attribute :path, Types::String
16
+ attribute :path, Types::String | Types::Nil
17
17
 
18
18
  attribute :name, Types::String
19
19
 
@@ -35,7 +35,7 @@ module DjiMqttConnect
35
35
 
36
36
  attribute :relative_altitude, Types::JSON::Decimal
37
37
 
38
- attribute :created_time, Types::JSON::DateTime
38
+ attribute :created_time, Types::JSON::DateTime | Types::Nil
39
39
 
40
40
  attribute :shoot_position do
41
41
  include Mixins::LatitudeConditional
@@ -16,7 +16,7 @@ module DjiMqttConnect
16
16
  attribute :ext do
17
17
  attribute :current_waypoint_index, Types::Integer
18
18
  attribute? :media_count, Types::Integer
19
- attribute :track_id, Types::String
19
+ attribute :track_id, Types::String | Types::Nil
20
20
  attribute :flight_id, Types::String
21
21
 
22
22
  attribute? :break_point do
@@ -32,11 +32,11 @@ module DjiMqttConnect
32
32
  include Mixins::TemperatureConditional
33
33
 
34
34
  attribute :capacity_percent, Types::Integer
35
- attribute :firmware_version, Types::String
35
+ attribute :firmware_version, Types::String | Types::Nil
36
36
  attribute? :high_voltage_storage_days, Types::Integer
37
37
  attribute :index, Types::Integer
38
38
  attribute :loop_times, Types::Integer
39
- attribute :sn, Types::String
39
+ attribute :sn, Types::String | Types::Nil
40
40
  attribute :sub_type, Types::DeviceSubType
41
41
  attribute :temperature, Types::Temperature
42
42
  attribute :type, Types::DeviceType
@@ -58,7 +58,7 @@ module DjiMqttConnect
58
58
  end
59
59
  attribute :elevation, Types::JSON::Decimal
60
60
 
61
- attribute? :firmware_version, Types::String
61
+ attribute? :firmware_version, Types::String | Types::Nil
62
62
  attribute :gear, Types::Integer
63
63
  attribute :height, Types::JSON::Decimal
64
64
  attribute? :height_limit, Types::JSON::Decimal
@@ -79,7 +79,7 @@ module DjiMqttConnect
79
79
  end
80
80
  attribute :total_flight_distance, Types::JSON::Decimal
81
81
  attribute :total_flight_time, Types::JSON::Decimal
82
- attribute? :track_id, Types::String
82
+ attribute? :track_id, Types::String | Types::Nil
83
83
  attribute :vertical_speed, Types::JSON::Decimal
84
84
  attribute :wind_direction, Types::JSON::Decimal
85
85
  attribute :wind_speed, Types::JSON::Decimal
@@ -15,7 +15,7 @@ module DjiMqttConnect
15
15
  attribute? :live_status do
16
16
  attribute :live_time, Types::Integer
17
17
  attribute :live_trendline, Types::Integer
18
- attribute :video_id, Types::String
18
+ attribute :video_id, Types::String | Types::Nil
19
19
  attribute :video_quality, Types::Integer
20
20
  end
21
21
  attribute? :transmission_signal_quality, Types::Integer
@@ -8,9 +8,9 @@ module DjiMqttConnect
8
8
 
9
9
  attribute :data do
10
10
  attribute :bind_devices, Types::Array do
11
- attribute :device_binding_code, Types::String
12
- attribute :organization_id, Types::String
13
- attribute :device_callsign, Types::String
11
+ attribute :device_binding_code, Types::String | Types::Nil
12
+ attribute :organization_id, Types::String | Types::Nil
13
+ attribute :device_callsign, Types::String | Types::Nil
14
14
  attribute :sn, Types::String
15
15
  attribute :device_model_key, Types::String
16
16
  attribute :device_nonce, Types::String
@@ -7,8 +7,8 @@ module DjiMqttConnect
7
7
  attribute :_method, Types::String.enum("airport_organization_get")
8
8
 
9
9
  attribute :data do
10
- attribute :device_binding_code, Types::String
11
- attribute :organization_id, Types::String
10
+ attribute :device_binding_code, Types::String | Types::Nil
11
+ attribute :organization_id, Types::String | Types::Nil
12
12
  end
13
13
  end
14
14
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DjiMqttConnect
4
+ module Thing::Product
5
+ # Get the offline map data
6
+ # https://developer.dji.com/doc/cloud-api-tutorial/en/faq.html#why-does-the-third-party-platform-experience-prolonged-wait-time-when-executing-one-key-takeoff-or-wayline-missions-on-the-dock
7
+ class OfflineMapGetRequestsMessage < RequestsMessage
8
+ attribute :_method, Types::String.enum("offline_map_get")
9
+
10
+ attribute :data, Types::Hash
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DjiMqttConnect
4
+ module Thing::Product
5
+ # https://developer.dji.com/doc/cloud-api-tutorial/en/faq.html#why-does-the-third-party-platform-experience-prolonged-wait-time-when-executing-one-key-takeoff-or-wayline-missions-on-the-dock
6
+ class OfflineMapGetRequestsReplyMessage < Message
7
+ def self.build_for(offline_map_get, result: 0)
8
+ new(
9
+ _method: offline_map_get._method,
10
+ data: {
11
+ result: result
12
+ },
13
+ tid: offline_map_get.tid,
14
+ bid: offline_map_get.bid,
15
+ timestamp: current_timestamp
16
+ )
17
+ end
18
+
19
+ attribute :tid, Types::UUID
20
+ attribute :bid, Types::UUID
21
+ attribute :timestamp, Types::Timestamp
22
+
23
+ attribute :_method, Types::String.enum("offline_map_get")
24
+ attribute :data do
25
+ attribute :result, Types::ResultCode
26
+ end
27
+ end
28
+ end
29
+ end
@@ -5,6 +5,47 @@ module DjiMqttConnect
5
5
  module MessageParsing
6
6
  private
7
7
 
8
+ def parse_json(raw_message)
9
+ parsed_message = JSON.parse(raw_message)
10
+ strip_blank_strings(parsed_message)
11
+ rescue JSON::ParserError => e
12
+ raise ParseError.new(e, "Unable to parse message as JSON (#{e.message})")
13
+ end
14
+
15
+ def strip_blank_strings(object)
16
+ case object
17
+ when Hash
18
+ object.transform_values(&method(:strip_blank_strings))
19
+ when Array
20
+ object.map(&method(:strip_blank_strings))
21
+ when String
22
+ object.strip.presence
23
+ else
24
+ object
25
+ end
26
+ end
27
+
28
+ def build_message(message_class, transformed_message)
29
+ message_class.new transformed_message
30
+ rescue Dry::Struct::Error => e
31
+ # Get the source of the error and the error message (without the source)
32
+ source = e.message.include?(".new] ") ? e.message.split(".new] ").first.sub(/\A\[/, "") : message_class.name
33
+ error_message = e.message.split(".new] ").last
34
+
35
+ case e.cause
36
+ when Dry::Types::SchemaError
37
+ # Clean up the error message to be more developer-friendly
38
+ # e.message: [DjiMqttConnect::Sys::Product::StatusMessage.new] nil (NilClass) has invalid type for :_data violates constraints (type?(Hash, nil) failed)
39
+ # e.cause.message: nil (NilClass) has invalid type for :_data violates constraints (type?(Hash, nil) failed)
40
+ cause_key = e.cause.key.to_s.sub("_data", "data")
41
+ cause_message = "#{e.cause.value.inspect} (#{e.cause.value.class.name}) is invalid type for :#{cause_key}"
42
+ # cause_message: nil (NilClass) is invalid type for :data
43
+ raise ParseError.new(e, "Unexpected #{source} payload (#{cause_message})")
44
+ else
45
+ raise ParseError.new(e, "Unexpected #{source} payload (#{error_message})")
46
+ end
47
+ end
48
+
8
49
  def message_class_from_message_method(message_method, generic_class)
9
50
  return generic_class if message_method.blank?
10
51
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DjiMqttConnect
4
- VERSION = "0.1.21"
4
+ VERSION = "0.1.22"
5
5
  end
@@ -66,6 +66,7 @@ module DjiMqttConnect
66
66
  autoload :ConfigRequestsMessage, "dji_mqtt_connect/messages/thing/product/requests/config"
67
67
  autoload :FlightAreasGetRequestsMessage, "dji_mqtt_connect/messages/thing/product/requests/flight_areas_get"
68
68
  autoload :FlighttaskResourceGetRequestsMessage, "dji_mqtt_connect/messages/thing/product/requests/flighttask_resource_get"
69
+ autoload :OfflineMapGetRequestsMessage, "dji_mqtt_connect/messages/thing/product/requests/offline_map_get"
69
70
  autoload :StorageConfigGetRequestsMessage, "dji_mqtt_connect/messages/thing/product/requests/storage_config_get"
70
71
  autoload :RequestsMessage, "dji_mqtt_connect/messages/thing/product/requests_message"
71
72
 
@@ -75,6 +76,7 @@ module DjiMqttConnect
75
76
  autoload :FlightAreasGetRequestsReplyMessage, "dji_mqtt_connect/messages/thing/product/requests_reply/flight_areas_get"
76
77
  autoload :ConfigRequestsReplyMessage, "dji_mqtt_connect/messages/thing/product/requests_reply/config"
77
78
  autoload :FlighttaskResourceGetRequestsReplyMessage, "dji_mqtt_connect/messages/thing/product/requests_reply/flighttask_resource_get"
79
+ autoload :OfflineMapGetRequestsReplyMessage, "dji_mqtt_connect/messages/thing/product/requests_reply/offline_map_get"
78
80
  autoload :StorageConfigGetRequestsReplyMessage, "dji_mqtt_connect/messages/thing/product/requests_reply/storage_config_get"
79
81
 
80
82
  autoload :ServicesMessage, "dji_mqtt_connect/messages/thing/product/services_message"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dji_mqtt_connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sphere Drones
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-12 00:00:00.000000000 Z
11
+ date: 2024-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -157,6 +157,7 @@ files:
157
157
  - lib/dji_mqtt_connect/messages/thing/product/requests/config.rb
158
158
  - lib/dji_mqtt_connect/messages/thing/product/requests/flight_areas_get.rb
159
159
  - lib/dji_mqtt_connect/messages/thing/product/requests/flighttask_resource_get.rb
160
+ - lib/dji_mqtt_connect/messages/thing/product/requests/offline_map_get.rb
160
161
  - lib/dji_mqtt_connect/messages/thing/product/requests/storage_config_get.rb
161
162
  - lib/dji_mqtt_connect/messages/thing/product/requests_message.rb
162
163
  - lib/dji_mqtt_connect/messages/thing/product/requests_reply/airport_bind_status.rb
@@ -165,6 +166,7 @@ files:
165
166
  - lib/dji_mqtt_connect/messages/thing/product/requests_reply/config.rb
166
167
  - lib/dji_mqtt_connect/messages/thing/product/requests_reply/flight_areas_get.rb
167
168
  - lib/dji_mqtt_connect/messages/thing/product/requests_reply/flighttask_resource_get.rb
169
+ - lib/dji_mqtt_connect/messages/thing/product/requests_reply/offline_map_get.rb
168
170
  - lib/dji_mqtt_connect/messages/thing/product/requests_reply/storage_config_get.rb
169
171
  - lib/dji_mqtt_connect/messages/thing/product/services/alarm_state_switch.rb
170
172
  - lib/dji_mqtt_connect/messages/thing/product/services/cover_close.rb
@@ -251,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
253
  - !ruby/object:Gem::Version
252
254
  version: '0'
253
255
  requirements: []
254
- rubygems_version: 3.5.4
256
+ rubygems_version: 3.5.15
255
257
  signing_key:
256
258
  specification_version: 4
257
259
  summary: Manages MQTT Connections with DJI Drones