haas: sync shutter discovery and fix for more than 4 shutter (#18694)

* discovery: hoist shutter computation out of loop

* haas: sync shutter discovery and fix for more than 4 shutter
This commit is contained in:
Bernhard Urban-Forster 2023-05-20 09:06:56 +02:00 committed by GitHub
parent 63a83c7289
commit d5ad79985b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 20 deletions

View File

@ -109,22 +109,23 @@ void TasDiscoverMessage(void) {
uint16_t Relay[MAX_RELAYS_SET] = { 0 }; // Base array to store the relay type uint16_t Relay[MAX_RELAYS_SET] = { 0 }; // Base array to store the relay type
uint16_t Shutter[MAX_RELAYS_SET] = { 0 }; // Array to store a temp list for shutters uint16_t Shutter[MAX_RELAYS_SET] = { 0 }; // Array to store a temp list for shutters
for (uint32_t i = 0; i < MAX_RELAYS_SET; i++) {
if (i < TasmotaGlobal.devices_present) {
#ifdef USE_SHUTTER #ifdef USE_SHUTTER
if (Settings->flag3.shutter_mode) { if (Settings->flag3.shutter_mode) {
for (uint32_t k = 0; k < TasmotaGlobal.shutters_present; k++) { for (uint32_t k = 0; k < TasmotaGlobal.shutters_present; k++) {
if (ShutterGetStartRelay(k) > 0) { uint8_t sr = ShutterGetStartRelay(k);
Shutter[ShutterGetStartRelay(k)-1] = Shutter[ShutterGetStartRelay(k)] = 1; if (sr > 0) {
} else { Shutter[sr-1] = Shutter[sr] = 1;
// terminate loop at first INVALID ShutterGetStartRelay(k). } else {
break; // terminate loop at first INVALID ShutterGetStartRelay(k).
} break;
}
} }
}
}
#endif // USE_SHUTTER #endif // USE_SHUTTER
for (uint32_t i = 0; i < MAX_RELAYS_SET; i++) {
if (i < TasmotaGlobal.devices_present) {
if (Shutter[i] != 0) { // Check if there are shutters present if (Shutter[i] != 0) { // Check if there are shutters present
Relay[i] = 3; // Relay is a shutter Relay[i] = 3; // Relay is a shutter
} else { } else {

View File

@ -393,7 +393,7 @@ void HassDiscoverMessage(void) {
light_controller_isCTRGBLinked, light_controller_isCTRGBLinked,
light_subtype); light_subtype);
for (uint32_t i = 0; i < tmax(TasmotaGlobal.shutters_present, MAX_SHUTTERS); i++) { for (uint32_t i = 0; i < tmin(TasmotaGlobal.shutters_present, MAX_SHUTTERS); i++) {
#ifdef USE_SHUTTER #ifdef USE_SHUTTER
ResponseAppend_P(PSTR("%s%d"), (i > 0 ? "," : ""), Settings->shutter_options[i]); ResponseAppend_P(PSTR("%s%d"), (i > 0 ? "," : ""), Settings->shutter_options[i]);
#else #else
@ -528,10 +528,11 @@ void HAssAnnounceRelayLight(void)
#ifdef USE_SHUTTER #ifdef USE_SHUTTER
if (Settings->flag3.shutter_mode) { if (Settings->flag3.shutter_mode) {
for (uint32_t i = 0; i < MAX_SHUTTERS; i++) { for (uint32_t i = 0; i < TasmotaGlobal.shutters_present; i++) {
if (Settings->shutter_startrelay[i] > 0 ) { uint8_t sr = ShutterGetStartRelay(i);
bitSet(shutter_mask, Settings->shutter_startrelay[i] -1); if (sr > 0) {
bitSet(shutter_mask, Settings->shutter_startrelay[i]); bitSet(shutter_mask, sr-1);
bitSet(shutter_mask, sr);
} else { } else {
// terminate loop at first INVALID Settings->shutter_startrelay[i]. // terminate loop at first INVALID Settings->shutter_startrelay[i].
break; break;
@ -1064,7 +1065,7 @@ void HAssAnnounceShutters(void)
char unique_id[30]; char unique_id[30];
uint8_t ShowTopic; // Used to hide/unhide a topic during Discovery to spare some cpu load uint8_t ShowTopic; // Used to hide/unhide a topic during Discovery to spare some cpu load
for (uint32_t i = 0; i < MAX_SHUTTERS; i++) { for (uint32_t i = 0; i < TasmotaGlobal.shutters_present; i++) {
ResponseClear(); // Clear retained message ResponseClear(); // Clear retained message
TasmotaGlobal.masterlog_level = ShowTopic = 4; // Hide topic on clean and remove use weblog 4 to see it TasmotaGlobal.masterlog_level = ShowTopic = 4; // Hide topic on clean and remove use weblog 4 to see it
@ -1072,7 +1073,7 @@ void HAssAnnounceShutters(void)
snprintf_P(unique_id, sizeof(unique_id), PSTR("%06X_SHT_%d"), ESP_getChipId(), i + 1); snprintf_P(unique_id, sizeof(unique_id), PSTR("%06X_SHT_%d"), ESP_getChipId(), i + 1);
snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/cover/%s/config"), unique_id); snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/cover/%s/config"), unique_id);
if (Settings->flag.hass_discovery && Settings->flag3.shutter_mode && Settings->shutter_startrelay[i] > 0) { if (Settings->flag.hass_discovery && Settings->flag3.shutter_mode && ShutterGetStartRelay(i) > 0) {
ShowTopic = 0; // Show the new generated topic ShowTopic = 0; // Show the new generated topic
if (i > MAX_FRIENDLYNAMES) { if (i > MAX_FRIENDLYNAMES) {
snprintf_P(stemp1, sizeof(stemp1), PSTR("%s Shutter %d"), SettingsText(SET_DEVICENAME), i + 1); snprintf_P(stemp1, sizeof(stemp1), PSTR("%s Shutter %d"), SettingsText(SET_DEVICENAME), i + 1);
@ -1091,9 +1092,9 @@ void HAssAnnounceShutters(void)
GetTopic_P(stemp2, CMND, TasmotaGlobal.mqtt_topic, PSTR("ShutterPosition")); GetTopic_P(stemp2, CMND, TasmotaGlobal.mqtt_topic, PSTR("ShutterPosition"));
TryResponseAppend_P(HASS_DISCOVER_SHUTTER_POS, stemp1, i + 1, stemp2, i + 1); TryResponseAppend_P(HASS_DISCOVER_SHUTTER_POS, stemp1, i + 1, stemp2, i + 1);
if (Settings->shutter_tilt_config[3][i] != Settings->shutter_tilt_config[4][i]) { if (ShutterGetTiltConfig(3,i) != ShutterGetTiltConfig(4,i)) {
GetTopic_P(stemp1, CMND, TasmotaGlobal.mqtt_topic, PSTR("ShutterTilt")); GetTopic_P(stemp1, CMND, TasmotaGlobal.mqtt_topic, PSTR("ShutterTilt"));
TryResponseAppend_P(HASS_DISCOVER_SHUTTER_TILT, stemp1, i + 1, Settings->shutter_tilt_config[3][i], Settings->shutter_tilt_config[4][i]); TryResponseAppend_P(HASS_DISCOVER_SHUTTER_TILT, stemp1, i + 1, ShutterGetTiltConfig(3,i), ShutterGetTiltConfig(4,i));
} }
TryResponseAppend_P(HASS_DISCOVER_DEVICE_INFO_SHORT, unique_id, ESP_getChipId()); TryResponseAppend_P(HASS_DISCOVER_DEVICE_INFO_SHORT, unique_id, ESP_getChipId());