src/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
21 / 21
100.0%
Branches:
28 / 28
100.0%
Functions:
3 / 3
100.0%

ShadeChanges.cpp
Line Branch Exec Source
1 #include "ShadeChanges.h"
2
3 7 static bool flag(const shade_snapshot_t &shade, somfy_flags_t f) { return (shade.flags & static_cast<uint8_t>(f)) != 0; }
4
5 10 void publishShadeTopics(uint16_t changed, const shade_snapshot_t &shade, topic_sink_t sink, void *ctx) {
6 // Where the shade is and is going are kept by the broker so a client that
7 // connects later gets them; the rest are passing news.
8
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7 times.
10 if(changed & SHADE_CHANGED_POSITION) sink("position", shade.position, true, ctx);
9
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7 times.
10 if(changed & SHADE_CHANGED_DIRECTION) sink("direction", shade.direction, true, ctx);
10
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7 times.
10 if(changed & SHADE_CHANGED_TARGET) sink("target", shade.target, true, ctx);
11
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7 times.
10 if(changed & SHADE_CHANGED_ROLLING_CODE) sink("lastRollingCode", shade.lastRollingCode, false, ctx);
12
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7 times.
10 if(changed & SHADE_CHANGED_MY_POS) sink("mypos", shade.myPos, true, ctx);
13
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7 times.
10 if(changed & SHADE_CHANGED_MY_TILT_POS) sink("myTiltPos", shade.myTiltPos, true, ctx);
14
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
10 if(changed & SHADE_CHANGED_TILT_DIRECTION) sink("tiltDirection", shade.tiltDirection, true, ctx);
15
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
10 if(changed & SHADE_CHANGED_TILT_POSITION) sink("tiltPosition", shade.tiltPosition, true, ctx);
16
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
10 if(changed & SHADE_CHANGED_TILT_TARGET) sink("tiltTarget", shade.tiltTarget, true, ctx);
17
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
10 if(changed & SHADE_CHANGED_SUN_FLAG) sink("sunFlag", flag(shade, somfy_flags_t::SunFlag), false, ctx);
18
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
10 if(changed & SHADE_CHANGED_SUNNY) sink("sunny", flag(shade, somfy_flags_t::Sunny), false, ctx);
19
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7 times.
10 if(changed & SHADE_CHANGED_WINDY) sink("windy", flag(shade, somfy_flags_t::Windy), false, ctx);
20 10 }
21 2 uint16_t shadeStateTopics(const shade_snapshot_t &shade) {
22 2 uint16_t topics = SHADE_CHANGED_POSITION | SHADE_CHANGED_DIRECTION | SHADE_CHANGED_TARGET | SHADE_CHANGED_ROLLING_CODE |
23 SHADE_CHANGED_MY_POS | SHADE_CHANGED_MY_TILT_POS | SHADE_CHANGED_WINDY;
24
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 if(shade.tiltType != static_cast<uint8_t>(tilt_types::none))
25 1 topics |= SHADE_CHANGED_TILT_DIRECTION | SHADE_CHANGED_TILT_POSITION | SHADE_CHANGED_TILT_TARGET;
26
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 if(shade.sunSensor) topics |= SHADE_CHANGED_SUN_FLAG | SHADE_CHANGED_SUNNY;
27 2 return topics;
28 }
29