Skip to content

Commit

Permalink
maint: Add url to api error
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed Nov 7, 2023
1 parent 27a80ef commit 11f5729
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
26 changes: 13 additions & 13 deletions pyhomelink/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, auth: AbstractAuth) -> None:
async def async_get_properties(self) -> List[Property]:
"""Return the Properties."""
resp = await self.auth.request("get", HomeLINKEndpoint.PROPERTIES)
check_status(resp.status)
check_status(resp)
return [
Property(property_data, self.auth)
for property_data in (await resp.json())[ATTR_RESULTS]
Expand All @@ -33,7 +33,7 @@ async def async_get_property(self, propertyreference) -> Property:
"get",
HomeLINKEndpoint.PROPERTY.format(propertyreference=propertyreference),
)
check_status(resp.status)
check_status(resp)
return Property(await resp.json(), self.auth)

async def async_get_property_devices(self, propertyreference) -> List[Device]:
Expand All @@ -44,7 +44,7 @@ async def async_get_property_devices(self, propertyreference) -> List[Device]:
propertyreference=propertyreference
),
)
check_status(resp.status)
check_status(resp)
return [
Device(device_data, self.auth)
for device_data in (await resp.json())[ATTR_RESULTS]
Expand All @@ -58,7 +58,7 @@ async def async_get_property_alerts(self, propertyreference) -> List[Alert]:
propertyreference=propertyreference
),
)
check_status(resp.status)
check_status(resp)
return [Alert(alert_data) for alert_data in (await resp.json())[ATTR_RESULTS]]

async def async_add_property_tags(self, propertyreference, tags) -> List[str]:
Expand All @@ -68,7 +68,7 @@ async def async_add_property_tags(self, propertyreference, tags) -> List[str]:
HomeLINKEndpoint.PROPERTY_TAGS.format(propertyreference=propertyreference),
json={"tagIds": tags},
)
check_status(resp.status)
check_status(resp)
return await resp.json()

async def async_delete_property_tags(self, propertyreference, tags) -> List[str]:
Expand All @@ -78,13 +78,13 @@ async def async_delete_property_tags(self, propertyreference, tags) -> List[str]
HomeLINKEndpoint.PROPERTY_TAGS.format(propertyreference=propertyreference),
json={"tagIds": tags},
)
check_status(resp.status)
check_status(resp)
return await resp.json()

async def async_get_devices(self) -> List[Device]:
"""Return the Properties."""
resp = await self.auth.request("get", HomeLINKEndpoint.DEVICES)
check_status(resp.status)
check_status(resp)
return [
Device(device_data, self.auth)
for device_data in (await resp.json())[ATTR_RESULTS]
Expand All @@ -95,7 +95,7 @@ async def async_get_device(self, serialnumber) -> Device:
resp = await self.auth.request(
"get", HomeLINKEndpoint.DEVICE.format(serialnumber=serialnumber)
)
check_status(resp.status)
check_status(resp)
return Device(await resp.json(), self.auth)

async def async_get_device_alerts(self, serialnumber) -> List[Alert]:
Expand All @@ -104,13 +104,13 @@ async def async_get_device_alerts(self, serialnumber) -> List[Alert]:
"get",
HomeLINKEndpoint.DEVICES_ALERTS.format(serialnumber=serialnumber),
)
check_status(resp.status)
check_status(resp)
return [Alert(alert_data) for alert_data in (await resp.json())[ATTR_RESULTS]]

async def async_get_insights(self) -> List[Insight]:
"""Return the Properties."""
resp = await self.auth.request("get", HomeLINKEndpoint.INSIGHTS)
check_status(resp.status)
check_status(resp)
return [
Insight(insight_data) for insight_data in (await resp.json())[ATTR_RESULTS]
]
Expand All @@ -120,15 +120,15 @@ async def async_get_insight(self, insightid) -> Insight:
resp = await self.auth.request(
"get", HomeLINKEndpoint.INSIGHT.format(insightid=insightid)
)
check_status(resp.status)
check_status(resp)
return Insight(await resp.json())

async def async_get_lookups(self, lookuptype) -> List:
"""Return the Lookups for lookuptype"""
resp = await self.auth.request(
"get", HomeLINKEndpoint.LOOKUPS.format(lookuptype=lookuptype)
)
check_status(resp.status)
check_status(resp)
return [
self._process_lookup(lookuptype, lookup_data)
for lookup_data in await resp.json()
Expand All @@ -140,7 +140,7 @@ async def async_get_lookup(self, lookuptype, lookupid):
"get",
HomeLINKEndpoint.LOOKUP.format(lookuptype=lookuptype, lookupid=lookupid),
)
check_status(resp.status)
check_status(resp)
return self._process_lookup(lookuptype, await resp.json())

def _process_lookup(self, lookuptype, data):
Expand Down
2 changes: 1 addition & 1 deletion pyhomelink/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,5 @@ def alerts(self) -> str:
async def async_get_alerts(self) -> List[Alert]:
"""Return the Alerts."""
resp = await self._auth.request("get", f"{self.rel.alerts}")
check_status(resp.status)
check_status(resp)
return [Alert(alert_data) for alert_data in (await resp.json())[ATTR_RESULTS]]
10 changes: 5 additions & 5 deletions pyhomelink/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def insights(self) -> str:
async def async_get_devices(self) -> List[Device]:
"""Return the Devices."""
resp = await self._auth.request("get", f"{self.rel.devices}")
check_status(resp.status)
check_status(resp)
return [
Device(device_data, self._auth)
for device_data in (await resp.json())[ATTR_RESULTS]
Expand All @@ -107,15 +107,15 @@ async def async_get_devices(self) -> List[Device]:
async def async_get_insights(self) -> List[Insight]:
"""Return the Insights."""
resp = await self._auth.request("get", f"{self.rel.insights}")
check_status(resp.status)
check_status(resp)
return [
Insight(insight_data) for insight_data in (await resp.json())[ATTR_RESULTS]
]

async def async_get_alerts(self) -> List[Alert]:
"""Return the Alerts."""
resp = await self._auth.request("get", f"{self.rel.alerts}")
check_status(resp.status)
check_status(resp)
return [Alert(alert_data) for alert_data in (await resp.json())[ATTR_RESULTS]]

async def async_add_tags(self, tags) -> List[str]:
Expand All @@ -125,7 +125,7 @@ async def async_add_tags(self, tags) -> List[str]:
HomeLINKEndpoint.PROPERTY_TAGS.format(propertyreference=self.reference),
json={"tagIds": tags},
)
check_status(resp.status)
check_status(resp)
return await resp.json()

async def async_delete_tags(self, tags) -> List[str]:
Expand All @@ -135,5 +135,5 @@ async def async_delete_tags(self, tags) -> List[str]:
HomeLINKEndpoint.PROPERTY_TAGS.format(propertyreference=self.reference),
json={"tagIds": tags},
)
check_status(resp.status)
check_status(resp)
return await resp.json()
10 changes: 5 additions & 5 deletions pyhomelink/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from .exceptions import ApiException, AuthException


def check_status(status):
def check_status(resp):
"""Check status of the call."""
if status == 401:
raise AuthException(f"Authorization failed: {status}")
if status != 200:
raise ApiException(f"Error request failed: {status}")
if resp.status == 401:
raise AuthException(f"Authorization failed: {resp.status}")
if resp.status != 200:
raise ApiException(f"Error request failed: {resp.status}, url: {resp.url}")


def parse_date(in_date):
Expand Down

0 comments on commit 11f5729

Please sign in to comment.