Skip to content

Commit

Permalink
Fixed issues with Preset not setting and reflecting correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
sockless-coding committed Jan 6, 2025
1 parent e3e5051 commit 8d53461
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
30 changes: 21 additions & 9 deletions custom_components/panasonic_cc/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,21 @@ def _update_attributes(self, builder: ChangeRequestBuilder) -> None:
"""Update attributes."""
if builder.power_mode == constants.Power.Off:
self._attr_hvac_mode = HVACMode.OFF
default_preset = PRESET_NONE
if builder.target_temperature:
self._attr_target_temperature = builder.target_temperature
if builder.target_temperature > 15 and self._attr_preset_mode == PRESET_8_15:
self._attr_preset_mode = PRESET_NONE
self._attr_preset_mode = default_preset
elif builder.target_temperature < 15 and self._attr_preset_mode != PRESET_8_15:
self._attr_preset_mode = PRESET_8_15
self._attr_preset_mode = default_preset = PRESET_8_15

if builder.eco_mode:
if builder.eco_mode.name in (PRESET_QUIET, PRESET_ECO):
self._attr_preset_mode = self._quiet_preset
elif builder.eco_mode.name in (PRESET_POWERFUL, PRESET_BOOST):
self._attr_preset_mode = self._powerful_preset
else:
self._attr_preset_mode = PRESET_NONE
self._attr_preset_mode = default_preset

if builder.fan_speed:
self._attr_fan_mode = builder.fan_speed.name
Expand All @@ -228,10 +229,10 @@ async def _async_enter_summer_house_mode(self, builder: ChangeRequestBuilder):
device = self.coordinator.device
stored_data = await self.coordinator.async_get_stored_data()

stored_data['mode'] = device.parameters.mode
stored_data['ecoMode'] = device.parameters.eco_mode
stored_data['mode'] = device.parameters.mode.value
stored_data['ecoMode'] = device.parameters.eco_mode.value
stored_data['targetTemperature'] = device.parameters.target_temperature
stored_data['fanSpeed'] = device.parameters.fan_speed
stored_data['fanSpeed'] = device.parameters.fan_speed.value
await self.coordinator.async_store_data(stored_data)

builder.set_hvac_mode(constants.OperationMode.Heat)
Expand All @@ -249,10 +250,20 @@ async def _async_exit_summer_house_mode(self, builder: ChangeRequestBuilder) ->
if not self.coordinator.device.in_summer_house_mode:
return
stored_data = await self.coordinator.async_get_stored_data()
hvac_mode = stored_data['mode'] if 'mode' in stored_data else constants.OperationMode.Heat
eco_mode = stored_data['ecoMode'] if 'ecoMode' in stored_data else constants.EcoMode.Auto
try:
hvac_mode = constants.OperationMode(stored_data['mode']) if 'mode' in stored_data else constants.OperationMode.Heat
except:
hvac_mode = constants.OperationMode.Heat
try:
eco_mode = constants.EcoMode(stored_data['ecoMode']) if 'ecoMode' in stored_data else constants.EcoMode.Auto
except:
eco_mode = constants.EcoMode.Auto
target_temperature = stored_data['targetTemperature'] if 'targetTemperature' in stored_data else 20
fan_speed = stored_data['fanSpeed'] if 'fanSpeed' in stored_data else constants.FanSpeed.Auto
try:
fan_speed = constants.FanSpeed(stored_data['fanSpeed']) if 'fanSpeed' in stored_data else constants.FanSpeed.Auto
except:
fan_speed = constants.FanSpeed.Auto

builder.set_hvac_mode(hvac_mode)
builder.set_eco_mode(eco_mode)
builder.set_target_temperature(target_temperature)
Expand Down Expand Up @@ -317,6 +328,7 @@ async def async_set_preset_mode(self, preset_mode: str) -> None:
await self._async_enter_summer_house_mode(builder)
await self.coordinator.async_apply_changes(builder)
self._update_attributes(builder)
await self.coordinator.async_request_refresh()

async def async_set_fan_mode(self, fan_mode: str) -> None:
"""Set new target fan mode."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def has_iauto_x(self):
@property
def in_summer_house_mode(self):
temp = self._parameters.target_temperature
i = 1 if temp - 8 > 0 else (0 if temp -8 else -1)
i = 1 if temp - 8 > 0 else (0 if temp -8 == 0 else -1)
match self._features.summer_house:
case 1:
return i == 0 or temp == 10
Expand Down

0 comments on commit 8d53461

Please sign in to comment.