FIX: Unnecessary flash writes by ModbusSwitch component (#3648)

This commit is contained in:
Javier Peletier
2022-11-29 22:05:40 +01:00
committed by GitHub
parent a59ce7bfa2
commit c55e01ff3f
11 changed files with 114 additions and 144 deletions
+1 -16
View File
@@ -2,20 +2,10 @@ import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.components import switch
from esphome.const import CONF_INTERLOCK, CONF_PIN, CONF_RESTORE_MODE
from esphome.const import CONF_INTERLOCK, CONF_PIN
from .. import gpio_ns
GPIOSwitch = gpio_ns.class_("GPIOSwitch", switch.Switch, cg.Component)
GPIOSwitchRestoreMode = gpio_ns.enum("GPIOSwitchRestoreMode")
RESTORE_MODES = {
"RESTORE_DEFAULT_OFF": GPIOSwitchRestoreMode.GPIO_SWITCH_RESTORE_DEFAULT_OFF,
"RESTORE_DEFAULT_ON": GPIOSwitchRestoreMode.GPIO_SWITCH_RESTORE_DEFAULT_ON,
"ALWAYS_OFF": GPIOSwitchRestoreMode.GPIO_SWITCH_ALWAYS_OFF,
"ALWAYS_ON": GPIOSwitchRestoreMode.GPIO_SWITCH_ALWAYS_ON,
"RESTORE_INVERTED_DEFAULT_OFF": GPIOSwitchRestoreMode.GPIO_SWITCH_RESTORE_INVERTED_DEFAULT_OFF,
"RESTORE_INVERTED_DEFAULT_ON": GPIOSwitchRestoreMode.GPIO_SWITCH_RESTORE_INVERTED_DEFAULT_ON,
}
CONF_INTERLOCK_WAIT_TIME = "interlock_wait_time"
CONFIG_SCHEMA = (
@@ -23,9 +13,6 @@ CONFIG_SCHEMA = (
.extend(
{
cv.Required(CONF_PIN): pins.gpio_output_pin_schema,
cv.Optional(CONF_RESTORE_MODE, default="RESTORE_DEFAULT_OFF"): cv.enum(
RESTORE_MODES, upper=True, space="_"
),
cv.Optional(CONF_INTERLOCK): cv.ensure_list(cv.use_id(switch.Switch)),
cv.Optional(
CONF_INTERLOCK_WAIT_TIME, default="0ms"
@@ -43,8 +30,6 @@ async def to_code(config):
pin = await cg.gpio_pin_expression(config[CONF_PIN])
cg.add(var.set_pin(pin))
cg.add(var.set_restore_mode(config[CONF_RESTORE_MODE]))
if CONF_INTERLOCK in config:
interlock = []
for it in config[CONF_INTERLOCK]: