Skip to content

Commit

Permalink
Add attributes for UI Card actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Marc Collin committed Dec 10, 2023
1 parent ac9a18e commit 1587514
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
14 changes: 12 additions & 2 deletions custom_components/versatile_thermostat/base_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
CONF_PRESENCE_SENSOR,
CONF_PRESET_POWER,
SUPPORT_FLAGS,
PRESET_FROST_PROTECTION,
PRESET_POWER,
PRESET_SECURITY,
PROPORTIONAL_FUNCTION_TPI,
Expand Down Expand Up @@ -148,9 +149,11 @@ class BaseThermostat(ClimateEntity, RestoreEntity):
{
"is_on",
"type",
"frost_temp",
"eco_temp",
"boost_temp",
"comfort_temp",
"frost_away_temp",
"eco_away_temp",
"boost_away_temp",
"comfort_away_temp",
Expand Down Expand Up @@ -1112,9 +1115,12 @@ async def async_set_hvac_mode(self, hvac_mode, need_control_heating=True):
await under.set_hvac_mode(hvac_mode) or need_control_heating
)

# If AC is on maybe we have to change the temperature in force mode
# If AC is on maybe we have to change the temperature in force mode, but not in frost mode (there is no Frost protection possible in AC mode)
if self._ac_mode:
await self._async_set_preset_mode_internal(self._attr_preset_mode, True)
if self.preset_mode != PRESET_FROST_PROTECTION:
await self._async_set_preset_mode_internal(self._attr_preset_mode, True)
else:
await self._async_set_preset_mode_internal(PRESET_ECO, True)

if need_control_heating and sub_need_control_heating:
await self.async_control_heating(force=True)
Expand Down Expand Up @@ -2172,9 +2178,13 @@ def update_custom_attributes(self):
"hvac_mode": self.hvac_mode,
"preset_mode": self.preset_mode,
"type": self._thermostat_type,
"frost_temp": self._presets[PRESET_FROST_PROTECTION],
"eco_temp": self._presets[PRESET_ECO],
"boost_temp": self._presets[PRESET_BOOST],
"comfort_temp": self._presets[PRESET_COMFORT],
"frost_away_temp": self._presets_away.get(
self.get_preset_away_name(PRESET_FROST_PROTECTION)
),
"eco_away_temp": self._presets_away.get(
self.get_preset_away_name(PRESET_ECO)
),
Expand Down
18 changes: 15 additions & 3 deletions custom_components/versatile_thermostat/thermostat_climate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pylint: disable=line-too-long
# pylint: disable=line-too-long, too-many-lines
""" A climate over switch classe """
import logging
from datetime import timedelta, datetime
Expand Down Expand Up @@ -65,7 +65,11 @@ class ThermostatOverClimate(BaseThermostat):
_auto_regulation_dtemp: float = None
_auto_regulation_period_min: int = None
_last_regulation_change: datetime = None
# The fan mode configured in configEntry
_auto_fan_mode: str = None
# The current fan mode (could be change by service call)
_current_auto_fan_mode: str = None
# The fan_mode name depending of the current_mode
_auto_activated_fan_mode: str = None
_auto_deactivated_fan_mode: str = None

Expand All @@ -82,6 +86,7 @@ class ThermostatOverClimate(BaseThermostat):
"regulation_accumulated_error",
"auto_regulation_mode",
"auto_fan_mode",
"current_auto_fan_mode",
"auto_activated_fan_mode",
"auto_deactivated_fan_mode",
}
Expand Down Expand Up @@ -350,6 +355,8 @@ def choose_auto_regulation_mode(self, auto_regulation_mode):
def choose_auto_fan_mode(self, auto_fan_mode):
"""Choose the correct fan mode depending of the underlying capacities and the configuration"""

self._current_auto_fan_mode = auto_fan_mode

# Get the supported feature of the first underlying. We suppose each underlying have the same fan attributes
fan_supported = self.supported_features & ClimateEntityFeature.FAN_MODE > 0

Expand Down Expand Up @@ -382,8 +389,9 @@ def find_fan_mode(fan_modes, fan_mode) -> str:
break

_LOGGER.info(
"%s - choose_auto_fan_mode founds auto_activated_fan_mode=%s and auto_deactivated_fan_mode=%s",
"%s - choose_auto_fan_mode founds current_auto_fan_mode=%s auto_activated_fan_mode=%s and auto_deactivated_fan_mode=%s",
self,
self._current_auto_fan_mode,
self._auto_activated_fan_mode,
self._auto_deactivated_fan_mode,
)
Expand Down Expand Up @@ -463,9 +471,14 @@ def update_custom_attributes(self):
] = self._regulation_algo.accumulated_error

self._attr_extra_state_attributes["auto_fan_mode"] = self.auto_fan_mode
self._attr_extra_state_attributes[
"current_auto_fan_mode"
] = self._current_auto_fan_mode

self._attr_extra_state_attributes[
"auto_activated_fan_mode"
] = self._auto_activated_fan_mode

self._attr_extra_state_attributes[
"auto_deactivated_fan_mode"
] = self._auto_deactivated_fan_mode
Expand Down Expand Up @@ -987,5 +1000,4 @@ async def service_set_auto_fan_mode(self, auto_fan_mode):
elif auto_fan_mode == "Turbo":
self.choose_auto_fan_mode(CONF_AUTO_FAN_TURBO)

await self._send_regulated_temperature()
self.update_custom_attributes()

0 comments on commit 1587514

Please sign in to comment.