Skip to content

Commit

Permalink
only get user profile if id is known
Browse files Browse the repository at this point in the history
  • Loading branch information
raman325 committed Sep 22, 2020
1 parent 8394a6f commit 6e71f3a
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions custom_components/zoom/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,28 +222,32 @@ async def async_added_to_hass(self) -> None:
_LOGGER.debug("ID not found, restoring state.")
await self._restore_state()

try:
contact = await self._api.async_get_contact_user_profile(self.id)
status = contact["presence_status"]
_LOGGER.debug("Retrieved initial Zoom status: %s", status)
self._set_state(status)
self.async_write_ha_state()
except HTTPUnauthorized:
_LOGGER.debug(
"User is unauthorized to query presence status, restoring state.",
exc_info=True,
)
await self._restore_state()
except:
_LOGGER.warning(
"Error retrieving initial zoom status, restoring state.", exc_info=True
)
if self.id:
try:
contact = await self._api.async_get_contact_user_profile(self.id)
status = contact["presence_status"]
_LOGGER.debug("Retrieved initial Zoom status: %s", status)
self._set_state(status)
self.async_write_ha_state()
except HTTPUnauthorized:
_LOGGER.debug(
"User is unauthorized to query presence status, restoring state.",
exc_info=True,
)
await self._restore_state()
except:
_LOGGER.warning(
"Error retrieving initial zoom status, restoring state.", exc_info=True
)
await self._restore_state()
else:
_LOGGER.debug("ID is unknown, restoring state.")
await self._restore_state()

@property
def assumed_state(self) -> bool:
"""Return True if unable to access real state of the entity."""
return True
return not self._profile

@property
def profile(self) -> Optional[Dict[str, str]]:
Expand Down

0 comments on commit 6e71f3a

Please sign in to comment.