Update xdrv_12_home_assistant.ino

Fix problem on ESP32 and enhanced i2c GPIO boards with more than 8 relays and shutter defined on relay 9++
This commit is contained in:
stefanbode 2021-11-05 09:02:42 +01:00 committed by GitHub
parent 15990f2aa5
commit 540f6178da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 13 deletions

View File

@ -1,18 +1,14 @@
/*
xdrv_12_home_assistant.ino - home assistant support for Tasmota
Copyright (C) 2021 Erik Montnemery, Federico Leoni and Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -259,12 +255,11 @@ void HassDiscoverMessage(void) {
#ifdef USE_SHUTTER
if (Settings->flag3.shutter_mode) {
for (uint32_t k = 0; k < MAX_SHUTTERS; k++) {
if (0 == Settings->shutter_startrelay[k]) {
break;
if (Settings->shutter_startrelay[k] > 0) {
Shutter[Settings->shutter_startrelay[k]-1] = Shutter[Settings->shutter_startrelay[k]] = 1;
} else {
if (Settings->shutter_startrelay[k] > 0 && Settings->shutter_startrelay[k] <= MAX_SHUTTER_RELAYS) {
Shutter[Settings->shutter_startrelay[k]-1] = Shutter[Settings->shutter_startrelay[k]] = 1;
}
// terminate loop at first INVALID Settings->shutter_startrelay[i].
break;
}
}
}
@ -441,7 +436,7 @@ void HAssAnnounceRelayLight(void)
uint8_t TuyaRel = 0;
uint8_t TuyaRelInv = 0;
uint8_t TuyaDim = 0;
uint8_t shutter_mask = 0;
power_t shutter_mask = 0;
#ifdef ESP8266
if (PWM_DIMMER == TasmotaGlobal.module_type ) { PwmMod = true; } //
@ -463,9 +458,12 @@ void HAssAnnounceRelayLight(void)
#ifdef USE_SHUTTER
if (Settings->flag3.shutter_mode) {
for (uint32_t i = 0; i < MAX_SHUTTERS; i++) {
if (Settings->shutter_startrelay[i] > 0 && Settings->shutter_startrelay[i] <= MAX_SHUTTER_RELAYS) {
if (Settings->shutter_startrelay[i] > 0 ) {
bitSet(shutter_mask, Settings->shutter_startrelay[i] -1);
bitSet(shutter_mask, Settings->shutter_startrelay[i]);
} else {
// terminate loop at first INVALID Settings->shutter_startrelay[i].
break;
}
}
}
@ -503,7 +501,7 @@ void HAssAnnounceRelayLight(void)
if (bitRead(shutter_mask, i-1)) {
// suppress shutter relays
#ifdef USE_LIGHT
#ifdef USE_LIGHT
} else if ((i < Light.device) && !RelayX) {
err_flag = true;
AddLog(LOG_LEVEL_ERROR, PSTR("%s"), kHAssError2);
@ -1003,7 +1001,7 @@ void HAssAnnounceShutters(void)
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);
if (Settings->flag.hass_discovery && Settings->flag3.shutter_mode && Settings->shutter_startrelay[i] > 0 && Settings->shutter_startrelay[i] <= MAX_SHUTTER_RELAYS) {
if (Settings->flag.hass_discovery && Settings->flag3.shutter_mode && Settings->shutter_startrelay[i] > 0) {
ShowTopic = 0; // Show the new generated topic
if (i > MAX_FRIENDLYNAMES) {
snprintf_P(stemp1, sizeof(stemp1), PSTR("%s Shutter %d"), SettingsText(SET_DEVICENAME), i + 1);
@ -1025,6 +1023,9 @@ void HAssAnnounceShutters(void)
TryResponseAppend_P(HASS_DISCOVER_DEVICE_INFO_SHORT, unique_id, ESP_getChipId());
TryResponseAppend_P(PSTR("}"));
} else {
// terminate loop at first INVALID Settings->shutter_startrelay[i].
break;
}
TasmotaGlobal.masterlog_level = ShowTopic;