diff --git a/homepilot/api.py b/homepilot/api.py index 971a846..e36fe4e 100644 --- a/homepilot/api.py +++ b/homepilot/api.py @@ -107,6 +107,8 @@ async def async_get_fw_status(self): f"http://{self.host}/service/system-update-image/status" ) as response: response = await response.json() + if response.status == 401: + raise AuthError() return response async def async_get_interfaces(self): @@ -125,6 +127,8 @@ async def async_get_fw_version(self): f"http://{self.host}/service/system-update-image/version" ) as response: response = await response.json() + if response.status == 401: + raise AuthError() return response async def async_get_nodename(self): @@ -143,6 +147,8 @@ async def async_get_led_status(self): f"http://{self.host}/service/system/leds/status" ) as response: response = await response.json() + if response.status == 401: + raise AuthError() return response async def async_get_device_state(self, did): @@ -168,6 +174,8 @@ async def async_get_devices_state(self): f"http://{self.host}/v4/devices?devtype=Actuator" ) as response: response = await response.json() + if response.status == 401: + raise AuthError() if response["response"] != "get_visible_devices": actuators = {} else: @@ -180,6 +188,8 @@ async def async_get_devices_state(self): f"http://{self.host}/v4/devices?devtype=Sensor" ) as response: response = await response.json() + if response.status == 401: + raise AuthError() if response["response"] != "get_meters": sensors = {} else: diff --git a/homepilot/manager.py b/homepilot/manager.py index 22b9f3c..73bd009 100644 --- a/homepilot/manager.py +++ b/homepilot/manager.py @@ -8,7 +8,7 @@ from .cover import HomePilotCover from .thermostat import HomePilotThermostat from .actuator import HomePilotActuator -from .api import HomePilotApi +from .api import HomePilotApi, AuthError from .device import HomePilotDevice @@ -89,6 +89,8 @@ async def update_states(self): try: states = await self.api.async_get_devices_state() states["-1"] = await self.get_hub_state() + except AuthError: + raise except Exception: for did in self.devices: device: HomePilotDevice = self.devices[did]