-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathexample_profile_write.ex
52 lines (46 loc) · 1.12 KB
/
example_profile_write.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
defmodule Parser do
use Platform.Parsing.Behaviour
require Logger
# Example parser for writing values to device profile
#
# A profile has a "technical name" and each field has its own "technical name".
# These are needed here, NOT the display name!
#
# Name: Example parser for writing profile fields of a device
# Changelog:
# 2019-09-30 [jb]: Initial implementation
# Not needed to preload a profile when writing to it.
def parse(<<value::16>>, %{meta: %{frame_port: 42}}) do
{
%{
value: value
},
[
fields: %{
my_profile: %{
my_field: "new_value"
}
}
]
}
end
def parse(payload, meta) do
Logger.warn(
"Could not parse payload #{inspect(payload)} with frame_port #{
inspect(get_in(meta, [:meta, :frame_port]))
}"
)
[]
end
def tests() do
[
{
# No profile given, default factor =1 will be used.
:parse_hex,
"1337",
%{meta: %{frame_port: 42}},
{%{value: 4919}, [fields: %{my_profile: %{my_field: "new_value"}}]}
}
]
end
end