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 | 10 | if(changed & SHADE_CHANGED_POSITION) sink("position", shade.position, true, ctx); | |
| 9 | 10 | if(changed & SHADE_CHANGED_DIRECTION) sink("direction", shade.direction, true, ctx); | |
| 10 | 10 | if(changed & SHADE_CHANGED_TARGET) sink("target", shade.target, true, ctx); | |
| 11 | 10 | if(changed & SHADE_CHANGED_ROLLING_CODE) sink("lastRollingCode", shade.lastRollingCode, false, ctx); | |
| 12 | 10 | if(changed & SHADE_CHANGED_MY_POS) sink("mypos", shade.myPos, true, ctx); | |
| 13 | 10 | if(changed & SHADE_CHANGED_MY_TILT_POS) sink("myTiltPos", shade.myTiltPos, true, ctx); | |
| 14 | 10 | if(changed & SHADE_CHANGED_TILT_DIRECTION) sink("tiltDirection", shade.tiltDirection, true, ctx); | |
| 15 | 10 | if(changed & SHADE_CHANGED_TILT_POSITION) sink("tiltPosition", shade.tiltPosition, true, ctx); | |
| 16 | 10 | if(changed & SHADE_CHANGED_TILT_TARGET) sink("tiltTarget", shade.tiltTarget, true, ctx); | |
| 17 | 10 | if(changed & SHADE_CHANGED_SUN_FLAG) sink("sunFlag", flag(shade, somfy_flags_t::SunFlag), false, ctx); | |
| 18 | 10 | if(changed & SHADE_CHANGED_SUNNY) sink("sunny", flag(shade, somfy_flags_t::Sunny), false, ctx); | |
| 19 | 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 | 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 | if(shade.sunSensor) topics |= SHADE_CHANGED_SUN_FLAG | SHADE_CHANGED_SUNNY; | |
| 27 | 2 | return topics; | |
| 28 | } | ||
| 29 |