With implemn in thermostat_switch (not finished)
This commit is contained in:
@@ -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_AC_MODE, default=False): cv.boolean,
|
||||||
vol.Optional(CONF_INVERSE_SWITCH, default=False): cv.boolean,
|
vol.Optional(CONF_INVERSE_SWITCH, default=False): cv.boolean,
|
||||||
vol.Optional("on_command_text", default=False): vol.In([]),
|
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("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)),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -127,8 +127,8 @@ CONF_OPENING_DEGREE_LIST = "opening_degree_entity_ids"
|
|||||||
CONF_CLOSING_DEGREE_LIST = "closing_degree_entity_ids"
|
CONF_CLOSING_DEGREE_LIST = "closing_degree_entity_ids"
|
||||||
CONF_MIN_OPENING_DEGREES = "min_opening_degrees"
|
CONF_MIN_OPENING_DEGREES = "min_opening_degrees"
|
||||||
|
|
||||||
CONF_VSWITCH_ON_COMMAND = "vswitch_on_command"
|
CONF_VSWITCH_ON_CMD_LIST = "vswitch_on_command"
|
||||||
CONF_VSWITCH_OFF_COMMAND = "vswitch_off_command"
|
CONF_VSWITCH_OFF_CMD_LIST = "vswitch_off_command"
|
||||||
|
|
||||||
# Deprecated
|
# Deprecated
|
||||||
CONF_HEATER = "heater_entity_id"
|
CONF_HEATER = "heater_entity_id"
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ from .const import (
|
|||||||
CONF_UNDERLYING_LIST,
|
CONF_UNDERLYING_LIST,
|
||||||
CONF_HEATER_KEEP_ALIVE,
|
CONF_HEATER_KEEP_ALIVE,
|
||||||
CONF_INVERSE_SWITCH,
|
CONF_INVERSE_SWITCH,
|
||||||
|
CONF_VSWITCH_ON_CMD_LIST,
|
||||||
|
CONF_VSWITCH_OFF_CMD_LIST,
|
||||||
overrides,
|
overrides,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -40,6 +42,8 @@ class ThermostatOverSwitch(BaseThermostat[UnderlyingSwitch]):
|
|||||||
"tpi_coef_ext",
|
"tpi_coef_ext",
|
||||||
"power_percent",
|
"power_percent",
|
||||||
"calculated_on_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:
|
def __init__(self, hass: HomeAssistant, unique_id, name, config_entry) -> None:
|
||||||
"""Initialize the thermostat over switch."""
|
"""Initialize the thermostat over switch."""
|
||||||
self._is_inversed: bool | None = None
|
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)
|
super().__init__(hass, unique_id, name, config_entry)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -76,9 +82,13 @@ class ThermostatOverSwitch(BaseThermostat[UnderlyingSwitch]):
|
|||||||
)
|
)
|
||||||
|
|
||||||
lst_switches = config_entry.get(CONF_UNDERLYING_LIST)
|
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)
|
delta_cycle = self._cycle_min * 60 / len(lst_switches)
|
||||||
for idx, switch in enumerate(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(
|
self._underlyings.append(
|
||||||
UnderlyingSwitch(
|
UnderlyingSwitch(
|
||||||
hass=self._hass,
|
hass=self._hass,
|
||||||
@@ -86,6 +96,8 @@ class ThermostatOverSwitch(BaseThermostat[UnderlyingSwitch]):
|
|||||||
switch_entity_id=switch,
|
switch_entity_id=switch,
|
||||||
initial_delay_sec=idx * delta_cycle,
|
initial_delay_sec=idx * delta_cycle,
|
||||||
keep_alive_sec=config_entry.get(CONF_HEATER_KEEP_ALIVE, 0),
|
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"
|
"calculated_on_percent"
|
||||||
] = self._prop_algorithm.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()
|
self.async_write_ha_state()
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"%s - Calling update_custom_attributes: %s",
|
"%s - Calling update_custom_attributes: %s",
|
||||||
|
|||||||
@@ -209,17 +209,8 @@ class UnderlyingEntity:
|
|||||||
class UnderlyingSwitch(UnderlyingEntity):
|
class UnderlyingSwitch(UnderlyingEntity):
|
||||||
"""Represent a underlying switch"""
|
"""Represent a underlying switch"""
|
||||||
|
|
||||||
_initialDelaySec: int
|
|
||||||
_on_time_sec: int
|
|
||||||
_off_time_sec: int
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
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
|
||||||
hass: HomeAssistant,
|
|
||||||
thermostat: Any,
|
|
||||||
switch_entity_id: str,
|
|
||||||
initial_delay_sec: int,
|
|
||||||
keep_alive_sec: float,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the underlying switch"""
|
"""Initialize the underlying switch"""
|
||||||
|
|
||||||
@@ -235,6 +226,8 @@ class UnderlyingSwitch(UnderlyingEntity):
|
|||||||
self._on_time_sec = 0
|
self._on_time_sec = 0
|
||||||
self._off_time_sec = 0
|
self._off_time_sec = 0
|
||||||
self._keep_alive = IntervalCaller(hass, keep_alive_sec)
|
self._keep_alive = IntervalCaller(hass, keep_alive_sec)
|
||||||
|
self._vswitch_on = vswitch_on
|
||||||
|
self._vswitch_off = vswitch_off
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def initial_delay_sec(self):
|
def initial_delay_sec(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user