| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#include "MqttDisco.h" |
| 2 |
|
|
|
| 3 |
4/4
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 21 times.
|
24 |
bool isDiscoSwitch(shade_types type) { return type == shade_types::drycontact || type == shade_types::drycontact2; } |
| 4 |
|
24 |
void shadeDiscoTopic(const char *discoTopic, uint8_t shadeId, bool isSwitch, char *topic, size_t len) { |
| 5 |
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 21 times.
|
24 |
snprintf(topic, len, "%s/%s/%d/config", discoTopic, isSwitch ? "switch" : "cover", shadeId); |
| 6 |
|
24 |
} |
| 7 |
|
20 |
static const char *deviceClass(shade_types type) { |
| 8 |
6/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 6 times.
|
20 |
switch(type) { |
| 9 |
|
3 |
case shade_types::blind: |
| 10 |
|
3 |
return "blind"; |
| 11 |
|
5 |
case shade_types::lgate: |
| 12 |
|
|
case shade_types::cgate: |
| 13 |
|
|
case shade_types::rgate: |
| 14 |
|
|
case shade_types::lgate1: |
| 15 |
|
|
case shade_types::cgate1: |
| 16 |
|
|
case shade_types::rgate1: |
| 17 |
|
|
case shade_types::ldrapery: |
| 18 |
|
|
case shade_types::rdrapery: |
| 19 |
|
|
case shade_types::cdrapery: |
| 20 |
|
5 |
return "curtain"; |
| 21 |
|
2 |
case shade_types::garage1: |
| 22 |
|
|
case shade_types::garage3: |
| 23 |
|
2 |
return "garage"; |
| 24 |
|
3 |
case shade_types::awning: |
| 25 |
|
3 |
return "awning"; |
| 26 |
|
1 |
case shade_types::shutter: |
| 27 |
|
1 |
return "shutter"; |
| 28 |
|
6 |
default: |
| 29 |
|
6 |
return "shade"; |
| 30 |
|
|
} |
| 31 |
|
|
} |
| 32 |
|
22 |
void shadeDisco(const shade_disco_t &shade, JsonObject obj, char *topic, size_t len) { |
| 33 |
|
22 |
snprintf(topic, len, "%s/shades/%d", shade.rootTopic, shade.shadeId); |
| 34 |
2/4
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
|
22 |
obj["~"] = topic; |
| 35 |
2/4
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
|
22 |
JsonObject dobj = obj["device"].to<JsonObject>(); |
| 36 |
2/4
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
|
22 |
dobj["hw_version"] = shade.fwVersion; |
| 37 |
2/4
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
|
22 |
dobj["name"] = shade.hostname; |
| 38 |
2/4
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
|
22 |
dobj["mf"] = "cjkas"; |
| 39 |
2/4
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
|
22 |
JsonArray arrids = dobj["identifiers"].to<JsonArray>(); |
| 40 |
|
22 |
snprintf(topic, len, "mqtt_espsomfyrts_%s", shade.serverId); |
| 41 |
1/2
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
|
22 |
arrids.add(topic); |
| 42 |
2/4
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
|
22 |
dobj["model"] = "ESPSomfy-RTS MQTT"; |
| 43 |
|
22 |
snprintf(topic, len, "%s/status", shade.rootTopic); |
| 44 |
2/4
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
|
22 |
obj["availability_topic"] = topic; |
| 45 |
2/4
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
|
22 |
obj["payload_available"] = "online"; |
| 46 |
2/4
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
|
22 |
obj["payload_not_available"] = "offline"; |
| 47 |
2/4
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
|
22 |
obj["name"] = shade.name; |
| 48 |
|
22 |
snprintf(topic, len, "mqtt_%s_shade%d", shade.serverId, shade.shadeId); |
| 49 |
2/4
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
|
22 |
obj["unique_id"] = topic; |
| 50 |
|
22 |
const bool isSwitch = isDiscoSwitch(shade.shadeType); |
| 51 |
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 2 times.
|
22 |
if(!isSwitch) { |
| 52 |
2/4
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
|
20 |
obj["device_class"] = deviceClass(shade.shadeType); |
| 53 |
|
|
// Positions count down from open: 0 is open and 100 closed, so an |
| 54 |
|
|
// upward move (-1) opens. An awning, which opens downward, and a |
| 55 |
|
|
// flipped position turn that around. |
| 56 |
|
20 |
const bool reversed = shade.flipPosition != (shade.shadeType == shade_types::awning); |
| 57 |
4/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 17 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 7 not taken.
|
20 |
obj["payload_close"] = reversed ? "-1" : "1"; |
| 58 |
4/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 17 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 7 not taken.
|
20 |
obj["payload_open"] = reversed ? "1" : "-1"; |
| 59 |
4/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 17 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 7 not taken.
|
20 |
obj["position_open"] = reversed ? 100 : 0; |
| 60 |
4/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 17 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 7 not taken.
|
20 |
obj["position_closed"] = reversed ? 0 : 100; |
| 61 |
4/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 17 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 7 not taken.
|
20 |
obj["state_closing"] = reversed ? "-1" : "1"; |
| 62 |
4/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 17 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 7 not taken.
|
20 |
obj["state_opening"] = reversed ? "1" : "-1"; |
| 63 |
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 1 time.
|
20 |
if(shade.tiltType != tilt_types::tiltonly) { |
| 64 |
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
|
19 |
obj["command_topic"] = "~/direction/set"; |
| 65 |
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
|
19 |
obj["position_topic"] = "~/position"; |
| 66 |
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
|
19 |
obj["set_position_topic"] = "~/target/set"; |
| 67 |
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
|
19 |
obj["state_topic"] = "~/direction"; |
| 68 |
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
|
19 |
obj["payload_stop"] = "0"; |
| 69 |
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
|
19 |
obj["state_stopped"] = "0"; |
| 70 |
|
|
} |
| 71 |
|
|
else { |
| 72 |
2/4
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
|
1 |
obj["payload_close"] = nullptr; |
| 73 |
2/4
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
|
1 |
obj["payload_open"] = nullptr; |
| 74 |
2/4
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
|
1 |
obj["payload_stop"] = nullptr; |
| 75 |
|
|
} |
| 76 |
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 18 times.
|
20 |
if(shade.tiltType != tilt_types::none) { |
| 77 |
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 |
obj["tilt_command_topic"] = "~/tiltTarget/set"; |
| 78 |
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 |
obj["tilt_status_topic"] = "~/tiltPosition"; |
| 79 |
|
|
} |
| 80 |
|
|
} |
| 81 |
|
|
else { |
| 82 |
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 |
obj["payload_on"] = 100; |
| 83 |
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 |
obj["payload_off"] = 0; |
| 84 |
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 |
obj["state_off"] = 0; |
| 85 |
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 |
obj["state_on"] = 100; |
| 86 |
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 |
obj["state_topic"] = "~/position"; |
| 87 |
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 |
obj["command_topic"] = "~/target/set"; |
| 88 |
|
|
} |
| 89 |
2/4
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
|
22 |
obj["enabled_by_default"] = true; |
| 90 |
|
22 |
shadeDiscoTopic(shade.discoTopic, shade.shadeId, isSwitch, topic, len); |
| 91 |
|
22 |
} |
| 92 |
|
|
|