Skip to content

Commit

Permalink
OBK_FLAG_DISCOVERY_DONT_MERGE_LIGHTS
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Dec 23, 2023
1 parent 0acb820 commit b27c3a9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 43 deletions.
86 changes: 44 additions & 42 deletions src/httpserver/http_fns.c
Original file line number Diff line number Diff line change
Expand Up @@ -1595,52 +1595,54 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) {
// try to pair toggles with dimmers. This is needed only for TuyaMCU,
// where custom channel types are used. This is NOT used for simple
// CW/RGB/RGBCW/etc lights.
while (true) {
// find first dimmer
dimmer = -1;
for (i = 0; i < CHANNEL_MAX; i++) {
type = g_cfg.pins.channelTypes[i];
if (BIT_CHECK(flagsChannelPublished, i)) {
continue;
}
if (type == ChType_Dimmer) {
brightness_scale = 100;
dimmer = i;
break;
}
if (type == ChType_Dimmer1000) {
brightness_scale = 1000;
dimmer = i;
break;
}
if (type == ChType_Dimmer256) {
brightness_scale = 256;
dimmer = i;
break;
if (CFG_HasFlag(OBK_FLAG_DISCOVERY_DONT_MERGE_LIGHTS) == false) {
while (true) {
// find first dimmer
dimmer = -1;
for (i = 0; i < CHANNEL_MAX; i++) {
type = g_cfg.pins.channelTypes[i];
if (BIT_CHECK(flagsChannelPublished, i)) {
continue;
}
if (type == ChType_Dimmer) {
brightness_scale = 100;
dimmer = i;
break;
}
if (type == ChType_Dimmer1000) {
brightness_scale = 1000;
dimmer = i;
break;
}
if (type == ChType_Dimmer256) {
brightness_scale = 256;
dimmer = i;
break;
}
}
}
// find first togle
toggle = -1;
for (i = 0; i < CHANNEL_MAX; i++) {
type = g_cfg.pins.channelTypes[i];
if (BIT_CHECK(flagsChannelPublished, i)) {
continue;
// find first togle
toggle = -1;
for (i = 0; i < CHANNEL_MAX; i++) {
type = g_cfg.pins.channelTypes[i];
if (BIT_CHECK(flagsChannelPublished, i)) {
continue;
}
if (type == ChType_Toggle) {
toggle = i;
break;
}
}
if (type == ChType_Toggle) {
toggle = i;
// if nothing found, stop
if (toggle == -1 || dimmer == -1) {
break;
}
}
// if nothing found, stop
if (toggle == -1 || dimmer == -1) {
break;
}

BIT_SET(flagsChannelPublished, toggle);
BIT_SET(flagsChannelPublished, dimmer);
dev_info = hass_init_light_singleColor_onChannels(toggle, dimmer, brightness_scale);
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
hass_free_device_info(dev_info);
BIT_SET(flagsChannelPublished, toggle);
BIT_SET(flagsChannelPublished, dimmer);
dev_info = hass_init_light_singleColor_onChannels(toggle, dimmer, brightness_scale);
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
hass_free_device_info(dev_info);
}
}
#endif
//if (relayCount > 0) {
Expand Down Expand Up @@ -2547,7 +2549,7 @@ const char* g_obk_flagNames[] = {
"[DoorSensor] Invert state",
"[TuyaMCU] Use queue",
"[HTTP] Disable authentication in safe mode (not recommended)",
"error",
"[MQTT Discovery] Don't merge toggles and dimmers into lights",
"error",
};
int http_fn_cfg_generic(http_request_t* request) {
Expand Down
3 changes: 2 additions & 1 deletion src/new_pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -1035,8 +1035,9 @@ typedef struct pinsState_s {
#define OBK_FLAG_DOORSENSOR_INVERT_STATE 42
#define OBK_FLAG_TUYAMCU_USE_QUEUE 43
#define OBK_FLAG_HTTP_DISABLE_AUTH_IN_SAFE_MODE 44
#define OBK_FLAG_DISCOVERY_DONT_MERGE_LIGHTS 45

#define OBK_TOTAL_FLAGS 45
#define OBK_TOTAL_FLAGS 46

#define LOGGER_FLAG_MQTT_DEDUPER 1
#define LOGGER_FLAG_POWER_SAVE 2
Expand Down

0 comments on commit b27c3a9

Please sign in to comment.