Skip to content

Commit 2435755

Browse files
committed
Updates
1 parent ee7c532 commit 2435755

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

custom_components/plugwise/climate.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from dataclasses import asdict, dataclass
5+
from dataclasses import dataclass
66
from typing import Any
77

88
from homeassistant.components.climate import (
@@ -21,8 +21,6 @@
2121
ATTR_TEMPERATURE,
2222
STATE_OFF,
2323
STATE_ON,
24-
STATE_UNAVAILABLE,
25-
STATE_UNKNOWN,
2624
UnitOfTemperature,
2725
)
2826
from homeassistant.core import HomeAssistant, callback
@@ -111,7 +109,10 @@ class PlugwiseClimateExtraStoredData(ExtraStoredData):
111109

112110
def as_dict(self) -> dict[str, Any]:
113111
"""Return a dict representation of the text data."""
114-
return asdict(self)
112+
return {
113+
"last_active_schedule": self.last_active_schedule,
114+
"previous_action_mode": self.previous_action_mode,
115+
}
115116

116117

117118
class PlugwiseClimateEntity(PlugwiseEntity, ClimateEntity, RestoreEntity):
@@ -124,27 +125,17 @@ class PlugwiseClimateEntity(PlugwiseEntity, ClimateEntity, RestoreEntity):
124125
_enable_turn_on_off_backwards_compatibility = False
125126

126127
_last_active_schedule: str | None = None
127-
_previous_action_mode: str = HVACAction.HEATING # Upstream
128+
_previous_action_mode = HVACAction.HEATING # Upstream
128129
_homekit_mode: HVACMode | None = None # pw-beta homekit emulation + intentional unsort
129130

130131
async def async_added_to_hass(self) -> None:
131132
"""Run when entity about to be added."""
132133
await super().async_added_to_hass()
133-
if not (
134-
last_state := await self.async_get_last_state()
135-
) or last_state.state in (
136-
STATE_UNAVAILABLE,
137-
STATE_UNKNOWN,
138-
):
139-
return
140134

141-
LOGGER.debug("Last state: %s", last_state)
142-
LOGGER.debug("Last state attributes: %s", last_state.attributes)
143-
last_extra_data = await self.async_get_last_extra_data()
144-
if last_extra_data is not None:
145-
LOGGER.debug("Last extra data: %s", last_extra_data)
146-
self._last_active_schedule = last_extra_data.as_dict()["last_active_schedule"]
147-
self._previous_action_mode = last_extra_data.as_dict()["previous_action_mode"]
135+
if (extra_data := await self.async_get_last_extra_data()):
136+
LOGGER.debug("Extra data: %s", extra_data)
137+
self._last_active_schedule = extra_data.as_dict()["last_active_schedule"]
138+
self._previous_action_mode = extra_data.as_dict()["previous_action_mode"]
148139

149140
def __init__(
150141
self,
@@ -195,7 +186,10 @@ def current_temperature(self) -> float | None:
195186
@property
196187
def extra_restore_state_data(self) -> PlugwiseClimateExtraStoredData:
197188
"""Return text specific state data to be restored."""
198-
return PlugwiseClimateExtraStoredData(self._last_active_schedule)
189+
return PlugwiseClimateExtraStoredData(
190+
last_active_schedule=self._last_active_schedule,
191+
previous_action_mode=self._previous_action_mode,
192+
)
199193

200194
@property
201195
def target_temperature(self) -> float | None:
@@ -278,7 +272,7 @@ def hvac_action(self) -> HVACAction: # pw-beta add to Core
278272
):
279273
mode = self._gateway_data[SELECT_REGULATION_MODE]
280274
if mode in (HVACAction.COOLING, HVACAction.HEATING):
281-
self._previous_action_mode = mode
275+
self._previous_action_mode = HVACAction(mode)
282276

283277
if (action := self.device.get(CONTROL_STATE)) is not None:
284278
return HVACAction(action)
@@ -344,4 +338,4 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
344338
@plugwise_command
345339
async def async_set_preset_mode(self, preset_mode: str) -> None:
346340
"""Set the preset mode."""
347-
await self.coordinator.api.set_preset(self._location, preset_mode)
341+
await self.coordinator.api.set_preset(self._location, preset_mode)

0 commit comments

Comments
 (0)