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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/dji_mqtt_connect/marshals/sys/product/status_marshal.rb +4 -5
- data/lib/dji_mqtt_connect/marshals/thing/product/events_marshal.rb +33 -4
- data/lib/dji_mqtt_connect/marshals/thing/product/requests_marshal.rb +4 -5
- data/lib/dji_mqtt_connect/messages/thing/product/hms_events_message.rb +2 -2
- data/lib/dji_mqtt_connect/utils/message_parsing.rb +1 -2
- data/lib/dji_mqtt_connect/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b81ef7e12ef07f8f3d42d5bae091f2f5d3e99c4afe3bea10cf1b5bacf8592a83
|
4
|
+
data.tar.gz: b374963480351bdbb3de7418d3fbcbd8bf6a6c8785b7e107051c3fcddf870676
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e97c71486c48d8c475b212e804c1ad8e12e5e32dc9769dd2332465b34a86c9ff5429e37727000cc606704eba10916d62226f1ebc3ebbef2b23382292ab5274b5
|
7
|
+
data.tar.gz: 6f35209caa9a35bbf8ca3e82fa24d103b6387d026334e7ecb4f3454c0327c03b598ed67b1e614f40742d26ff87f78c5391e9d8e1c947c58ff1d7a076f3d02588
|
data/Gemfile.lock
CHANGED
@@ -13,10 +13,8 @@ module DjiMqttConnect
|
|
13
13
|
import Dry::Transformer::HashTransformations
|
14
14
|
|
15
15
|
define! do
|
16
|
-
|
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 =
|
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
|
-
|
19
|
+
# Keep a copy of the original data hash
|
20
|
+
copy_keys "data" => "_data"
|
18
21
|
|
19
|
-
|
20
|
-
|
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 =
|
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
|
-
|
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 =
|
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
|
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
|