Skip to content

Commit 21648b8

Browse files
authored
Merge pull request #3874 from reubenmiller/tests-fix-te-to-c8y-example
tests: update flow for measurement unit transformation to always output c8y compatible measurements
2 parents f5a9a33 + 329b377 commit 21648b8

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

tests/RobotFramework/tests/tedge_flows/flows/measurements.samples

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The default is to have no units
2-
INPUT: [te/device/main///m/] {"temperature": 25, "time":"2025-06-27T13:33:53.493Z"}
3-
OUTPUT: [c8y/measurement/measurements/create] {"type":"ThinEdgeMeasurement","temperature":{"temperature":25},"time":"2025-06-27T13:33:53.493Z"}
2+
INPUT: [te/device/main///m/] {"temperature": 25,"outside":{"humidity":85}, "time":"2025-06-27T13:33:53.493Z"}
3+
OUTPUT: [c8y/measurement/measurements/create] {"type":"ThinEdgeMeasurement","temperature":{"temperature":{"value":25}},"outside":{"humidity":{"value":85}},"time":"2025-06-27T13:33:53.493Z"}
44

55
# Units can be set using the meta topic
66
INPUT: [te/device/main///m//meta] {"temperature": { "unit": "°C" }}
@@ -17,7 +17,7 @@ OUTPUT: [c8y/measurement/measurements/create] {"type":"ThinEdgeMeasurement","tem
1717
# Units can be set to across measurement types
1818
INPUT: [te/device/main///m/environment/meta] { "temperature": { "unit": "°C" }, "location": { "altitude": { "unit": "m" } }, "pressure": { "unit": "pascal" } }
1919
INPUT: [te/device/main///m/environment] {"time":"2025-06-27T08:11:05.301804125Z", "temperature": 25, "location": {"latitude": 32.54, "longitude": -117.67, "altitude": 98.6 }, "pressure": 98}
20-
OUTPUT: [c8y/measurement/measurements/create] {"type":"environment","time":"2025-06-27T08:11:05.301804125Z","temperature":{"temperature":{"value":25,"unit":"°C"}},"location":{"latitude":32.54,"longitude":-117.67,"altitude":{"value":98.6,"unit":"m"}},"pressure":{"pressure":{"value":98,"unit":"pascal"}}}
20+
OUTPUT: [c8y/measurement/measurements/create] {"type":"environment","time":"2025-06-27T08:11:05.301804125Z","temperature":{"temperature":{"value":25,"unit":"°C"}},"location":{"latitude":{"value":32.54},"longitude":{"value":-117.67},"altitude":{"value":98.6,"unit":"m"}},"pressure":{"pressure":{"value":98,"unit":"pascal"}}}
2121

2222
# For the default type °F are still used, while changed to °C for environment measurements
2323
INPUT: [te/device/main///m/] {"temperature": 77, "time":"2025-06-27T12:40:24.122Z"}

tests/RobotFramework/tests/tedge_flows/flows/te_to_c8y.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ export function onMessage(message, config) {
6666
else if (typeof(v) === "number") {
6767
if (Object.keys(k_meta).length>0) {
6868
v = { value: v, ...k_meta }
69+
} else {
70+
v = { value: v }
6971
}
7072
let fragment = { [k]: { [k]: v } }
7173
Object.assign(c8y_msg, fragment)
@@ -76,6 +78,8 @@ export function onMessage(message, config) {
7678
if (typeof(sub_v) === "number") {
7779
if (sub_k_meta) {
7880
sub_v = { value: sub_v, ...sub_k_meta }
81+
} else {
82+
sub_v = { value: sub_v }
7983
}
8084
let sub_fragment = { [sub_k]: sub_v }
8185
Object.assign(fragment, sub_fragment)

tests/RobotFramework/tests/tedge_flows/tedge_flows.robot

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Translate complex tedge json to c8y json
4747
... strip=True
4848
Should Be Equal
4949
... ${transformed_msg}
50-
... [c8y/measurement/measurements/create] {"type":"environment","time":"2025-06-27T08:11:05.301804125Z","temperature":{"temperature":258},"location":{"latitude":32.54,"longitude":-117.67,"altitude":98.6},"pressure":{"pressure":98}}
50+
... [c8y/measurement/measurements/create] {"type":"environment","time":"2025-06-27T08:11:05.301804125Z","temperature":{"temperature":{"value":258}},"location":{"latitude":{"value":32.54},"longitude":{"value":-117.67},"altitude":{"value":98.6}},"pressure":{"pressure":{"value":98}}}
5151

5252
Using base64 to encode tedge flows input
5353
${encoded_input} Execute Command
@@ -57,11 +57,11 @@ Using base64 to encode tedge flows input
5757
... strip=True
5858
Should Be Equal
5959
... ${transformed_msg}
60-
... [c8y/measurement/measurements/create] {"type":"env","time":"2025-06-27T08:11:05.301804125Z","temperature":{"temperature":258}}
60+
... [c8y/measurement/measurements/create] {"type":"env","time":"2025-06-27T08:11:05.301804125Z","temperature":{"temperature":{"value":258}}}
6161

6262
Using base64 to encode tedge flows output
6363
${encoded_output} Execute Command
64-
... echo -n '{"type":"env","time":"2025-06-27T08:11:05.301804125Z","temperature":{"temperature":258}}' | base64 --wrap\=0
64+
... echo -n '{"type":"env","time":"2025-06-27T08:11:05.301804125Z","temperature":{"temperature":{"value":258}}}' | base64 --wrap\=0
6565
${transformed_msg} Execute Command
6666
... tedge flows test --base64-output te/device/main///m/env '{"time":"2025-06-27T08:11:05.301804125Z", "temperature": 258}'
6767
... strip=True

0 commit comments

Comments
 (0)