dji_mqtt_connect 0.1.4.1 → 0.1.5

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: fbb1f6a5cee41059ec3528a88ec50e9d0c558c41280024d45556fcab092d6508
4
- data.tar.gz: d7b5bd0c3e7d06e098b0c384d40175d1e284290ee12a4de1a316c91da01157e6
3
+ metadata.gz: b81ef7e12ef07f8f3d42d5bae091f2f5d3e99c4afe3bea10cf1b5bacf8592a83
4
+ data.tar.gz: b374963480351bdbb3de7418d3fbcbd8bf6a6c8785b7e107051c3fcddf870676
5
5
  SHA512:
6
- metadata.gz: 931690b396410a56c174dc004a64c466e843d9f48d6cb6467a74d3e02116c68bc97390791d586f65db2a8cafa00263e8eff420481ffe52ff3e61d8b20bd403f2
7
- data.tar.gz: 4356a30715205936278d0a1ef01e997b9551131ae1e581dd094008b1129f80de93aa2d8713fc843bb4d5bc5074140a769447d7ff4214ed8af5a1f2bfc44a2f43
6
+ metadata.gz: e97c71486c48d8c475b212e804c1ad8e12e5e32dc9769dd2332465b34a86c9ff5429e37727000cc606704eba10916d62226f1ebc3ebbef2b23382292ab5274b5
7
+ data.tar.gz: 6f35209caa9a35bbf8ca3e82fa24d103b6387d026334e7ecb4f3454c0327c03b598ed67b1e614f40742d26ff87f78c5391e9d8e1c947c58ff1d7a076f3d02588
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dji_mqtt_connect (0.1.4.1)
4
+ dji_mqtt_connect (0.1.5)
5
5
  activesupport (>= 6.0, <= 8)
6
6
  dry-struct (~> 1.6)
7
7
  dry-transformer (~> 1.0)
@@ -13,10 +13,8 @@ module DjiMqttConnect
13
13
  import Dry::Transformer::HashTransformations
14
14
 
15
15
  define! do
16
- symbolize_keys
17
-
18
- copy_keys data: :_data
19
- rename_keys method: :_method
16
+ copy_keys "data" => "_data"
17
+ rename_keys "method" => "_method"
20
18
  end
21
19
  end
22
20
 
@@ -27,9 +25,10 @@ module DjiMqttConnect
27
25
 
28
26
  # Transform the message
29
27
  transformed_message = attribute_transformer.call(parsed_message)
28
+ message_method = transformed_message["_method"]
30
29
 
31
30
  # Build an instance of the class, or a generic message from the current class
32
- message_class = message_class_from_method_value(parsed_message, StatusMessage)
31
+ message_class = message_class_from_message_method(message_method, StatusMessage)
33
32
  message_class.new transformed_message
34
33
  rescue JSON::ParserError => e
35
34
  raise ParseError.new(e, "Unable to parse message as JSON")
@@ -11,13 +11,41 @@ module DjiMqttConnect
11
11
 
12
12
  # Rename pesky `method` argument to `_method` and makes a copy of the raw data
13
13
  class AttributeTransformer < Dry::Transformer::Pipe
14
+ import Dry::Transformer::Conditional
15
+ import Dry::Transformer::ArrayTransformations
14
16
  import Dry::Transformer::HashTransformations
15
17
 
16
18
  define! do
17
- symbolize_keys
19
+ # Keep a copy of the original data hash
20
+ copy_keys "data" => "_data"
18
21
 
19
- copy_keys data: :_data
20
- rename_keys method: :_method
22
+ # Fix the legacy hms message
23
+ guard ->(message) { message.dig("data", "method") == "hms" } do
24
+ map_value "data" do
25
+ reject_keys ["event"]
26
+
27
+ map_value "output" do
28
+ map_value "codes" do
29
+ map_array do
30
+ nest "args", ["component_index", "sensor_index"]
31
+
32
+ map_value "id", ->(id) { "0x#{id}" }
33
+ rename_keys "id" => "code"
34
+
35
+ deep_merge({"module" => 3}) # hardcoded to hms module
36
+ end
37
+ end
38
+ end
39
+
40
+ unwrap "output", ["codes"]
41
+
42
+ rename_keys "codes" => "list"
43
+ end
44
+
45
+ unwrap "data", ["method"]
46
+ end
47
+
48
+ rename_keys "method" => "_method"
21
49
  end
22
50
  end
23
51
 
@@ -28,9 +56,10 @@ module DjiMqttConnect
28
56
 
29
57
  # Transform the message
30
58
  transformed_message = attribute_transformer.call(parsed_message)
59
+ message_method = transformed_message["_method"]
31
60
 
32
61
  # Build an instance of the class, or a generic message from the current class
33
- message_class = message_class_from_method_value(parsed_message, EventsMessage)
62
+ message_class = message_class_from_message_method(message_method, EventsMessage)
34
63
  message_class.new transformed_message
35
64
  rescue JSON::ParserError => e
36
65
  raise ParseError.new(e, "Unable to parse message as JSON")
@@ -14,10 +14,8 @@ module DjiMqttConnect
14
14
  import Dry::Transformer::HashTransformations
15
15
 
16
16
  define! do
17
- symbolize_keys
18
-
19
- copy_keys data: :_data
20
- rename_keys method: :_method
17
+ copy_keys "data" => "_data"
18
+ rename_keys "method" => "_method"
21
19
  end
22
20
  end
23
21
 
@@ -28,9 +26,10 @@ module DjiMqttConnect
28
26
 
29
27
  # Transform the message
30
28
  transformed_message = attribute_transformer.call(parsed_message)
29
+ message_method = transformed_message["_method"]
31
30
 
32
31
  # Build an instance of the class, or a generic message from the current class
33
- message_class = message_class_from_method_value(parsed_message, RequestsMessage)
32
+ message_class = message_class_from_message_method(message_method, RequestsMessage)
34
33
  message_class.new transformed_message
35
34
  rescue JSON::ParserError => e
36
35
  raise ParseError.new(e, "Unable to parse message as JSON")
@@ -14,12 +14,12 @@ module DjiMqttConnect
14
14
  attribute :module, Types::Integer.enum(0, 1, 2, 3)
15
15
 
16
16
  # {"0":"on the ground","1":"in the sky"}
17
- attribute :in_the_sky, Types::Integer.enum(0, 1)
17
+ attribute? :in_the_sky, Types::Integer.enum(0, 1)
18
18
 
19
19
  attribute :code, Types::String
20
20
 
21
21
  # {"0":"No","1":"Yes"}
22
- attribute :imminent, Types::Integer.enum(0, 1)
22
+ attribute? :imminent, Types::Integer.enum(0, 1)
23
23
 
24
24
  attribute :args do
25
25
  attribute :component_index, Types::Integer
@@ -5,8 +5,7 @@ module DjiMqttConnect
5
5
  module MessageParsing
6
6
  private
7
7
 
8
- def message_class_from_method_value(parsed_message, generic_class)
9
- message_method = parsed_message["method"]
8
+ def message_class_from_message_method(message_method, generic_class)
10
9
  return generic_class if message_method.blank?
11
10
 
12
11
  # update_topo => UpdateTopo
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DjiMqttConnect
4
- VERSION = "0.1.4.1"
4
+ VERSION = "0.1.5"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dji_mqtt_connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4.1
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sphere Drones