From b9a0ae98dfe3a7f2a77b8d69ccab80fba3356dbc Mon Sep 17 00:00:00 2001 From: stefanbode Date: Sat, 6 Apr 2024 17:21:54 +0200 Subject: [PATCH] Bugfix: power0 if power_lock is used (#21102) * Bug Fix: power_lock with Power0 command Power0 changed power regardless of the new lock state of power. New implementation respect the LOCK also on global change * simplify * readded the all_on filter to power_lock change readded the all_on to ensure new defined relays always start with power off ass intended. --- tasmota/tasmota_support/support_tasmota.ino | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tasmota/tasmota_support/support_tasmota.ino b/tasmota/tasmota_support/support_tasmota.ino index f7e7f6498..a8b0ba755 100644 --- a/tasmota/tasmota_support/support_tasmota.ino +++ b/tasmota/tasmota_support/support_tasmota.ino @@ -392,13 +392,17 @@ void SetAllPower(uint32_t state, uint32_t source) power_t all_on = POWER_MASK >> (POWER_SIZE - TasmotaGlobal.devices_present); switch (state) { case POWER_OFF: - TasmotaGlobal.power = 0; - break; + // keep loocked bits and set all other to 0 + TasmotaGlobal.power &= Settings->power_lock; + break; case POWER_ON: - TasmotaGlobal.power = all_on; - break; + // Keep locked bits and set all other to 1 + TasmotaGlobal.power = (TasmotaGlobal.power & Settings->power_lock) | (all_on & ~Settings->power_lock); + break; case POWER_TOGGLE: - TasmotaGlobal.power ^= all_on; // Complement current state + // Keep locked bits and toggle all other + TasmotaGlobal.power ^= ~Settings->power_lock & all_on; + break; } SetDevicePower(TasmotaGlobal.power, source); }