Skip to content

Commit 4116c9a

Browse files
authored
Merge pull request #24 from redwirelabs/shadow-readme
Update readme with device shadow desired to reported transformation
2 parents 61c7a46 + 74a05a9 commit 4116c9a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,17 +254,26 @@ The new, unknown fields will be filtered out of `message` during the validation
254254
Using `meta`, the unknown fields can be selected with a filter, and they can be merged into the `reported` map to send to the shadow.
255255

256256
```elixir
257-
reported = %{
258-
# Real data to report to the shadow ...
257+
shadow = %{
258+
state: %{
259+
reported: %{
260+
# Real data to report to the shadow ...
261+
}
262+
}
259263
}
260264

261265
meta
262266
|> Attribute.list
263267
|> Enum.filter(fn
264-
{_path, :unknown, _value} -> true
268+
# Only capture the device shadow state, not the metadata.
269+
{["state" | _rest], :unknown, _value} -> true
265270
{_path, _status, _value} -> false
266271
end)
267-
|> Attribute.merge(reported)
272+
|> Enum.map(fn
273+
{["state" | rest], status, value} ->
274+
{["state", "reported"] ++ rest, status, value}
275+
)
276+
|> Attribute.merge(shadow)
268277
```
269278

270279
### Fields as actions

0 commit comments

Comments
 (0)