Merge pull request #13572 from stefanbode/patch-2

Add ability to discover shutters on relay 9++
This commit is contained in:
Theo Arends 2021-11-05 09:51:25 +01:00 committed by GitHub
commit f22ec011b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 20 deletions

View File

@ -73,7 +73,6 @@ const uint8_t MAX_XDRV_DRIVERS = 96; // Max number of allowed driver driv
const uint8_t MAX_XSNS_DRIVERS = 128; // Max number of allowed sensor drivers
const uint8_t MAX_I2C_DRIVERS = 96; // Max number of allowed i2c drivers
const uint8_t MAX_SHUTTERS = 4; // Max number of shutters
const uint8_t MAX_SHUTTER_RELAYS = 8; // Max number of shutter relays
const uint8_t MAX_SHUTTER_KEYS = 4; // Max number of shutter keys or buttons
const uint8_t MAX_PCF8574 = 4; // Max number of PCF8574 devices
const uint8_t MAX_RULE_SETS = 3; // Max number of rule sets of size 512 characters

View File

@ -106,12 +106,11 @@ void TasDiscoverMessage(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;
}
}
}
@ -300,4 +299,4 @@ bool Xdrv12(uint8_t function) {
return result;
}
#endif // USE_TASMOTA_DISCOVERY
#endif // USE_TASMOTA_DISCOVERY

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;