Skip to content

Commit

Permalink
Raise an error if the device is offline.
Browse files Browse the repository at this point in the history
  • Loading branch information
crevetor committed Aug 30, 2024
1 parent 9a0d0d2 commit 8f8e0f4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/ayla_iot_unofficial/fujitsu_hvac.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class DeviceNotSupportedError(Exception):
class SettingNotSupportedError(Exception):
pass

class DeviceOffline(Exception):
pass

def _convert_sensed_temp_to_celsius(value: int) -> float:
source_span = MAX_SENSED_TEMP - MIN_SENSED_TEMP
Expand All @@ -50,6 +52,15 @@ def _convert_sensed_temp_to_celsius(value: int) -> float:

return MIN_SENSED_CELSIUS + (value_scaled * celsius_span)

def check_online(func):
def wrapped(self, *args, **kwargs):
if not self.is_online():
raise DeviceOffline

return func(self, *args, **kwargs)

return wrapped

class FujitsuHVAC(Device):
@staticmethod
def supports(device: Dict) -> bool:
Expand All @@ -76,6 +87,12 @@ def __init__(self, ayla_api: "AylaApi", device_dct: Dict, europe: bool = False):
if not self.model:
raise DeviceNotSupportedError("This device is not supported by FujitsuHVAC.")

self._connection_status = device_dct["connection_status"]

def is_online(self):
return self._connection_status != 'Offline'

@check_online
def set_property_value(self, property_name: PropertyName, value: PropertyValue, poll=False, keep_polling_value=None):
"""Update a property"""
if isinstance(property_name, Enum):
Expand All @@ -100,6 +117,7 @@ def set_property_value(self, property_name: PropertyName, value: PropertyValue,
else:
self.properties_full[property_name].update(resp)

@check_online
async def async_set_property_value(self, property_name: PropertyName, value: PropertyValue, poll=False, keep_polling_value=None):
"""Update a property async. Override the parent version since it adds SET_ in front of the property name."""
if isinstance(property_name, Enum):
Expand Down Expand Up @@ -127,6 +145,11 @@ async def async_set_property_value(self, property_name: PropertyName, value: Pro
self.properties_full[property_name].update(resp_data)


@check_online
def update(self, props: list[str] | None=None):
super().update(props)

@check_online
async def async_update(self, props: list[str] | None=None):
await super().async_update(props)
await self.refresh_sensed_temp()
Expand Down

0 comments on commit 8f8e0f4

Please sign in to comment.