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_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_I2C_DRIVERS = 96; // Max number of allowed i2c drivers
const uint8_t MAX_SHUTTERS = 4; // Max number of shutters 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_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_PCF8574 = 4; // Max number of PCF8574 devices
const uint8_t MAX_RULE_SETS = 3; // Max number of rule sets of size 512 characters 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 #ifdef USE_SHUTTER
if (Settings->flag3.shutter_mode) { if (Settings->flag3.shutter_mode) {
for (uint32_t k = 0; k < MAX_SHUTTERS; k++) { for (uint32_t k = 0; k < MAX_SHUTTERS; k++) {
if (0 == Settings->shutter_startrelay[k]) { if (Settings->shutter_startrelay[k] > 0) {
break;
} 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; Shutter[Settings->shutter_startrelay[k]-1] = Shutter[Settings->shutter_startrelay[k]] = 1;
} } else {
// terminate loop at first INVALID Settings->shutter_startrelay[i].
break;
} }
} }
} }

View File

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