Skip to content

Commit

Permalink
Merge pull request #115 from gjohansson-ST/204_response
Browse files Browse the repository at this point in the history
Fix 204 no response json
  • Loading branch information
gjohansson-ST authored Oct 2, 2022
2 parents 7d72735 + 16990d8 commit b29138b
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions custom_components/sector/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ async def triggerlock(
if command == "lock":
await self._request(API_URL + "/Panel/Lock", json_data=message_json)
except (UpdateFailed, ConfigEntryAuthFailed) as error:
raise HomeAssistantError from error
raise HomeAssistantError(
f"Could not lock {lock} on error {str(error)}"
) from error
await self.async_request_refresh()

async def triggerswitch(self, identity: str, command: str, panel_id: str) -> None:
Expand All @@ -88,7 +90,9 @@ async def triggerswitch(self, identity: str, command: str, panel_id: str) -> Non
json_data=message_json,
)
except (UpdateFailed, ConfigEntryAuthFailed) as error:
raise HomeAssistantError from error
raise HomeAssistantError(
f"Could not change switch {identity} on error {str(error)}"
) from error

await self.async_request_refresh()

Expand All @@ -111,7 +115,9 @@ async def triggeralarm(self, command: str, code: str, panel_id: str) -> None:
if command == "disarm":
await self._request(API_URL + "/Panel/Disarm", json_data=message_json)
except (UpdateFailed, ConfigEntryAuthFailed) as error:
raise HomeAssistantError from error
raise HomeAssistantError(
f"Could not arm/disarm {panel_id} on error {str(error)}"
) from error

await self.async_request_refresh()

Expand Down Expand Up @@ -358,7 +364,7 @@ async def _request(
if retry > 0:
return await self._request(url, json_data, retry=retry - 1)

if response.status in (200, 204):
if response.status == 200:
LOGGER.debug("Info retrieved successfully URL: %s", url)
LOGGER.debug("request status: %s", response.status)

Expand All @@ -367,10 +373,15 @@ async def _request(
except aiohttp.ContentTypeError as error:
LOGGER.debug("ContentTypeError on ok status: %s", error.message)
response_text = await response.text()
LOGGER.debug("Response text is: %s", response_text)
LOGGER.debug("Response (200) text is: %s", response_text)
raise UpdateFailed from error
return output

if response.status == 204:
LOGGER.debug("Info retrieved successfully URL: %s", url)
LOGGER.debug("request status: %s", response.status)
return None

LOGGER.debug("Did not retrieve information properly")
LOGGER.debug("request status: %s", response.status)
response_text = await response.text()
Expand Down Expand Up @@ -405,7 +416,7 @@ async def _login(self) -> None:
LOGGER.debug("Response status 401: %s", response_text)
self._access_token = None

if response.status in (200, 204):
if response.status == 200:
token_data = await response.json()
LOGGER.debug("Response status ok: %s", token_data)
self._access_token = token_data.get("AuthorizationToken")
Expand Down

0 comments on commit b29138b

Please sign in to comment.