Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add raise AuthError #36

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions homepilot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion homepilot/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down