From f794dd37ca54ec0752aa4f0c884eb4a39b54a3f3 Mon Sep 17 00:00:00 2001 From: Jean-Marc Collin Date: Mon, 27 Jan 2025 19:47:42 +0000 Subject: [PATCH] With implemn in thermostat_switch (not finished) --- .../versatile_thermostat/config_schema.py | 4 ++-- custom_components/versatile_thermostat/const.py | 4 ++-- .../versatile_thermostat/thermostat_switch.py | 15 +++++++++++++++ .../versatile_thermostat/underlyings.py | 13 +++---------- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/custom_components/versatile_thermostat/config_schema.py b/custom_components/versatile_thermostat/config_schema.py index a3fbdef..f745b1e 100644 --- a/custom_components/versatile_thermostat/config_schema.py +++ b/custom_components/versatile_thermostat/config_schema.py @@ -135,9 +135,9 @@ STEP_THERMOSTAT_SWITCH = vol.Schema( # pylint: disable=invalid-name vol.Optional(CONF_AC_MODE, default=False): cv.boolean, vol.Optional(CONF_INVERSE_SWITCH, default=False): cv.boolean, vol.Optional("on_command_text", default=False): vol.In([]), - vol.Optional(CONF_VSWITCH_ON_COMMAND): selector.TextSelector(selector.TextSelectorConfig(type=selector.TextSelectorType.TEXT, multiple=True)), + vol.Optional(CONF_VSWITCH_ON_CMD_LIST): selector.TextSelector(selector.TextSelectorConfig(type=selector.TextSelectorType.TEXT, multiple=True)), vol.Optional("off_command_text", default=False): vol.In([]), - vol.Optional(CONF_VSWITCH_OFF_COMMAND): selector.TextSelector(selector.TextSelectorConfig(type=selector.TextSelectorType.TEXT, multiple=True)), + vol.Optional(CONF_VSWITCH_OFF_CMD_LIST): selector.TextSelector(selector.TextSelectorConfig(type=selector.TextSelectorType.TEXT, multiple=True)), } ) diff --git a/custom_components/versatile_thermostat/const.py b/custom_components/versatile_thermostat/const.py index d27035b..5d44768 100644 --- a/custom_components/versatile_thermostat/const.py +++ b/custom_components/versatile_thermostat/const.py @@ -127,8 +127,8 @@ CONF_OPENING_DEGREE_LIST = "opening_degree_entity_ids" CONF_CLOSING_DEGREE_LIST = "closing_degree_entity_ids" CONF_MIN_OPENING_DEGREES = "min_opening_degrees" -CONF_VSWITCH_ON_COMMAND = "vswitch_on_command" -CONF_VSWITCH_OFF_COMMAND = "vswitch_off_command" +CONF_VSWITCH_ON_CMD_LIST = "vswitch_on_command" +CONF_VSWITCH_OFF_CMD_LIST = "vswitch_off_command" # Deprecated CONF_HEATER = "heater_entity_id" diff --git a/custom_components/versatile_thermostat/thermostat_switch.py b/custom_components/versatile_thermostat/thermostat_switch.py index 9fef124..f007ea9 100644 --- a/custom_components/versatile_thermostat/thermostat_switch.py +++ b/custom_components/versatile_thermostat/thermostat_switch.py @@ -14,6 +14,8 @@ from .const import ( CONF_UNDERLYING_LIST, CONF_HEATER_KEEP_ALIVE, CONF_INVERSE_SWITCH, + CONF_VSWITCH_ON_CMD_LIST, + CONF_VSWITCH_OFF_CMD_LIST, overrides, ) @@ -40,6 +42,8 @@ class ThermostatOverSwitch(BaseThermostat[UnderlyingSwitch]): "tpi_coef_ext", "power_percent", "calculated_on_percent", + "vswitch_on_commands", + "vswitch_off_commands", } ) ) @@ -47,6 +51,8 @@ class ThermostatOverSwitch(BaseThermostat[UnderlyingSwitch]): def __init__(self, hass: HomeAssistant, unique_id, name, config_entry) -> None: """Initialize the thermostat over switch.""" self._is_inversed: bool | None = None + self._lst_vswitch_on: list[str] = [] + self._lst_vswitch_off: list[str] = [] super().__init__(hass, unique_id, name, config_entry) @property @@ -76,9 +82,13 @@ class ThermostatOverSwitch(BaseThermostat[UnderlyingSwitch]): ) lst_switches = config_entry.get(CONF_UNDERLYING_LIST) + self._lst_vswitch_on = config_entry.get(CONF_VSWITCH_ON_CMD_LIST, []) + self._lst_vswitch_off = config_entry.get(CONF_VSWITCH_OFF_CMD_LIST, []) delta_cycle = self._cycle_min * 60 / len(lst_switches) for idx, switch in enumerate(lst_switches): + vswitch_on = self._lst_vswitch_on[idx] if idx < len(self._lst_vswitch_on) else None + vswitch_off = self._lst_vswitch_off[idx] if idx < len(self._lst_vswitch_off) else None self._underlyings.append( UnderlyingSwitch( hass=self._hass, @@ -86,6 +96,8 @@ class ThermostatOverSwitch(BaseThermostat[UnderlyingSwitch]): switch_entity_id=switch, initial_delay_sec=idx * delta_cycle, keep_alive_sec=config_entry.get(CONF_HEATER_KEEP_ALIVE, 0), + vswitch_on=vswitch_on, + vswitch_off=vswitch_off, ) ) @@ -142,6 +154,9 @@ class ThermostatOverSwitch(BaseThermostat[UnderlyingSwitch]): "calculated_on_percent" ] = self._prop_algorithm.calculated_on_percent + self._attr_extra_state_attributes["vswitch_on_commands"] = self._lst_vswitch_on + self._attr_extra_state_attributes["vswitch_off_commands"] = self._lst_vswitch_off + self.async_write_ha_state() _LOGGER.debug( "%s - Calling update_custom_attributes: %s", diff --git a/custom_components/versatile_thermostat/underlyings.py b/custom_components/versatile_thermostat/underlyings.py index 9f1e559..bd3f606 100644 --- a/custom_components/versatile_thermostat/underlyings.py +++ b/custom_components/versatile_thermostat/underlyings.py @@ -209,17 +209,8 @@ class UnderlyingEntity: class UnderlyingSwitch(UnderlyingEntity): """Represent a underlying switch""" - _initialDelaySec: int - _on_time_sec: int - _off_time_sec: int - def __init__( - self, - hass: HomeAssistant, - thermostat: Any, - switch_entity_id: str, - initial_delay_sec: int, - keep_alive_sec: float, + self, hass: HomeAssistant, thermostat: Any, switch_entity_id: str, initial_delay_sec: int, keep_alive_sec: float, vswitch_on: str = None, vswitch_off: str = None ) -> None: """Initialize the underlying switch""" @@ -235,6 +226,8 @@ class UnderlyingSwitch(UnderlyingEntity): self._on_time_sec = 0 self._off_time_sec = 0 self._keep_alive = IntervalCaller(hass, keep_alive_sec) + self._vswitch_on = vswitch_on + self._vswitch_off = vswitch_off @property def initial_delay_sec(self):