Add power_percent in over_switch for UI

This commit is contained in:
Jean-Marc Collin
2023-11-07 00:09:34 +00:00
parent a40f976fd1
commit 71aad211c6

View File

@@ -12,7 +12,7 @@ from .const import (
CONF_HEATER_3, CONF_HEATER_3,
CONF_HEATER_4, CONF_HEATER_4,
CONF_INVERSE_SWITCH, CONF_INVERSE_SWITCH,
overrides overrides,
) )
from .base_thermostat import BaseThermostat from .base_thermostat import BaseThermostat
@@ -21,15 +21,29 @@ from .prop_algorithm import PropAlgorithm
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
class ThermostatOverSwitch(BaseThermostat): class ThermostatOverSwitch(BaseThermostat):
"""Representation of a base class for a Versatile Thermostat over a switch.""" """Representation of a base class for a Versatile Thermostat over a switch."""
_entity_component_unrecorded_attributes = BaseThermostat._entity_component_unrecorded_attributes.union(frozenset( _entity_component_unrecorded_attributes = (
BaseThermostat._entity_component_unrecorded_attributes.union(
frozenset(
{ {
"is_over_switch", "underlying_switch_0", "underlying_switch_1", "is_over_switch",
"underlying_switch_2", "underlying_switch_3", "on_time_sec", "off_time_sec", "underlying_switch_0",
"cycle_min", "function", "tpi_coef_int", "tpi_coef_ext" "underlying_switch_1",
})) "underlying_switch_2",
"underlying_switch_3",
"on_time_sec",
"off_time_sec",
"cycle_min",
"function",
"tpi_coef_int",
"tpi_coef_ext",
}
)
)
)
# useless for now # useless for now
# def __init__(self, hass: HomeAssistant, unique_id, name, entry_infos) -> None: # def __init__(self, hass: HomeAssistant, unique_id, name, entry_infos) -> None:
@@ -47,6 +61,14 @@ class ThermostatOverSwitch(BaseThermostat):
"""True if the switch is inversed (for pilot wire and diode)""" """True if the switch is inversed (for pilot wire and diode)"""
return self._is_inversed is True return self._is_inversed is True
@property
def power_percent(self) -> float | None:
"""Get the current on_percent value"""
if self._prop_algorithm:
return round(self._prop_algorithm.on_percent * 100, 0)
else:
return None
@overrides @overrides
def post_init(self, entry_infos): def post_init(self, entry_infos):
"""Initialize the Thermostat""" """Initialize the Thermostat"""
@@ -106,8 +128,9 @@ class ThermostatOverSwitch(BaseThermostat):
super().update_custom_attributes() super().update_custom_attributes()
self._attr_extra_state_attributes["is_over_switch"] = self.is_over_switch self._attr_extra_state_attributes["is_over_switch"] = self.is_over_switch
self._attr_extra_state_attributes["underlying_switch_0"] = ( self._attr_extra_state_attributes["underlying_switch_0"] = self._underlyings[
self._underlyings[0].entity_id) 0
].entity_id
self._attr_extra_state_attributes["underlying_switch_1"] = ( self._attr_extra_state_attributes["underlying_switch_1"] = (
self._underlyings[1].entity_id if len(self._underlyings) > 1 else None self._underlyings[1].entity_id if len(self._underlyings) > 1 else None
) )