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

change the exception name to HomeAssistantError #124

Merged
merged 1 commit into from
Jan 5, 2023
Merged
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
20 changes: 10 additions & 10 deletions custom_components/nuki_ng/nuki.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(
async def async_json(self, cb):
response = await self.hass.async_add_executor_job(lambda: cb(requests))
if not response.ok:
raise ConnectionError(f"Http response for {response.request.url}: {response.status_code} {response.reason}")
raise HomeAssistantError(f"Http response for {response.request.url}: {response.status_code} {response.reason}")
if response.status_code > 200:
_LOGGER.debug(f"async_json: http status: {response.status_code} - {response.text}")
return dict()
Expand Down Expand Up @@ -146,7 +146,7 @@ async def bridge_remove_callback(self, callback: str):
)
)
if not result.get("success", True):
raise ConnectionError(result.get("message"))
raise HomeAssistantError(result.get("message"))
return True
return False

Expand All @@ -170,7 +170,7 @@ async def bridge_check_callback(self, callback: str):
lambda r: r.get(self.bridge_url("/callback/add", {"url": callback_url}), timeout=BRIDGE_TIMEOUT)
)
if not result.get("success", True):
raise ConnectionError(result.get("message"))
raise HomeAssistantError(result.get("message"))
_LOGGER.debug("Callback is set - re-added")
callbacks = await self.async_json(
lambda r: r.get(self.bridge_url("/callback/list"), timeout=BRIDGE_TIMEOUT)
Expand Down Expand Up @@ -401,27 +401,27 @@ def web_id_for_item(item):
if self.api.can_web():
try:
web_list = await self.api.web_list()
except ConnectionError:
except HomeAssistantError:
_LOGGER.warning("Despite being configured, Web API request has failed")
_LOGGER.exception("Error while fetching list of devices via web API:")
if not device_list:
device_list = web_list
result = dict(devices={}, bridge_info=bridge_info)
if not device_list:
raise ConnectionError("No available device data")
raise HomeAssistantError("No available device data")
for key, item in device_list.items():
dev_id = item["nukiId"]
if self.api.can_web():
web_id = web_id_for_item(item)
item["webId"] = web_id
try:
item["web_auth"] = await self.api.web_list_all_auths(web_id)
except ConnectionError:
except HomeAssistantError:
_LOGGER.warning("Despite being configured, Web API request has failed")
_LOGGER.exception("Error while fetching auth:")
try:
item["last_log"] = await self.api.web_get_last_unlock_log(web_id)
except ConnectionError:
except HomeAssistantError:
_LOGGER.warning("Despite being configured, Web API request has failed")
_LOGGER.exception("Error while fetching last log entry")
if web_list:
Expand Down Expand Up @@ -474,19 +474,19 @@ async def do_reboot(self):
if self.api.can_bridge():
await self.api.bridge_reboot()
else:
raise ConnectionError("Not supported")
raise HomeAssistantError("Not supported")

async def do_fwupdate(self):
if self.api.can_bridge():
await self.api.bridge_fwupdate()
else:
raise ConnectionError("Not supported")
raise HomeAssistantError("Not supported")

async def do_delete_callback(self, callback):
if self.api.can_bridge():
await self.api.bridge_remove_callback(callback)
else:
raise ConnectionError("Not supported")
raise HomeAssistantError("Not supported")

def device_data(self, dev_id: str):
return self.data.get("devices", {}).get(dev_id, {})
Expand Down