Skip to content

Commit

Permalink
fix(target temperature): get last good value if value returns error
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkaldheim committed Oct 17, 2023
1 parent 4d0e3d3 commit 5b8e858
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
10 changes: 4 additions & 6 deletions custom_components/fujitsu_airstage/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,8 @@ def __init__(self, instance: AirstageData, ac_key: str) -> None:
@property
def target_temperature(self) -> float | None:
"""Return the current target temperature."""
if self.hvac_mode == HVACMode.FAN_ONLY:
return self._ac.get_display_temperature()
if int(self._ac.get_target_temperature()) >= 6553:
return self._ac.get_display_temperature()
if self.hvac_mode == HVACMode.FAN_ONLY or int(self._ac.get_target_temperature()) >= 6000:
return self.current_temperature()
return self._ac.get_target_temperature()

async def async_set_temperature(self, **kwargs: Any) -> None:
Expand Down Expand Up @@ -228,8 +226,8 @@ def supported_features(self) -> ClimateEntityFeature:
"""Return the list of supported features."""
supported_features = ClimateEntityFeature.FAN_MODE

if self.hvac_mode != HVACMode.FAN_ONLY and int(self._ac.get_target_temperature()) < 6553:
supported_features |= ClimateEntityFeature.TARGET_TEMPERATURE
# if self.hvac_mode != HVACMode.FAN_ONLY and int(self._ac.get_target_temperature()) < 6553:
# supported_features |= ClimateEntityFeature.TARGET_TEMPERATURE

if self.swing_mode:
supported_features |= ClimateEntityFeature.SWING_MODE
Expand Down
4 changes: 2 additions & 2 deletions custom_components/fujitsu_airstage/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/danielkaldheim/ha_airstage/issues",
"requirements": [
"pyairstage>=1.1.0"
"pyairstage>=1.1.1"
],
"version": "1.1.0"
"version": "1.1.4"
}
37 changes: 36 additions & 1 deletion custom_components/fujitsu_airstage/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async def async_setup_entry(
entities: list[SwitchEntity] = []
if devices := instance.coordinator.data:
for ac_key in devices:
entities.append(AirstagePowerSwitch(instance, ac_key))
data = {x["name"]: x for x in devices[ac_key]["parameters"]}
if data["iu_economy"]["value"] != constants.CAPABILITY_NOT_AVAILABLE:
entities.append(AirstageEcoSwitch(instance, ac_key))
Expand Down Expand Up @@ -203,7 +204,7 @@ def is_on(self) -> bool:

@property
def icon(self) -> str:
"""Return a representative icon of the timer."""
"""Return a representative icon of the switch."""
if self.is_on:
return "mdi:led-on"
return "mdi:led-variant-off"
Expand All @@ -217,3 +218,37 @@ async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn energy saving fan off."""
await self._ac.set_indoor_led(constants.BooleanProperty.OFF)
await self.instance.coordinator.async_refresh() # TODO: see if we can update entity


class AirstagePowerSwitch(AirstageAcEntity, SwitchEntity):
"""Representation of Airstage power switch."""

_attr_name = "Power"
_attr_device_class = SwitchDeviceClass.SWITCH

def __init__(self, instance: AirstageData, ac_key: str) -> None:
"""Initialize an Airstage power control."""
super().__init__(instance, ac_key)
self._attr_unique_id += "-power"

@property
def is_on(self) -> bool:
"""Return the power status."""
return self._ac.get_device_on_off_state() == constants.BooleanDescriptors.ON

@property
def icon(self) -> str:
"""Return a representative icon of the switch."""
if self.is_on:
return "mdi:power"
return "mdi:power-off"

async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn power on."""
await self._ac.turn_on()
await self.instance.coordinator.async_refresh() # TODO: see if we can update entity

async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn power off."""
await self._ac.turn_off()
await self.instance.coordinator.async_refresh() # TODO: see if we can update entity

0 comments on commit 5b8e858

Please sign in to comment.