Skip to content

Commit d95cf4a

Browse files
authored
Merge pull request #60 from pyalarmdotcom/fix-arm_stay
Fix arm stay
2 parents 747dc24 + f703056 commit d95cf4a

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

pyalarmdotcomajax/__init__.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
from .extensions import ConfigurationOption
3838
from .extensions import ExtendedProperties
3939

40-
__version__ = "0.4.5"
41-
40+
__version__ = "0.4.6"
4241

4342
log = logging.getLogger(__name__)
4443

@@ -390,7 +389,7 @@ async def async_send_command(
390389
and (msg_body.get("forceBypass") is True)
391390
):
392391
# 422 sometimes occurs when forceBypass is True but there's nothing to bypass.
393-
log.warning(
392+
log.debug(
394393
"Error executing %s, trying again without force bypass...",
395394
event.value,
396395
)
@@ -872,7 +871,10 @@ async def _async_get_trouble_conditions(self) -> None:
872871

873872
# Takes EITHER url (without base) or device_type.
874873
async def _async_get_items_and_subordinates(
875-
self, device_type: DeviceType | None = None, url: str | None = None
874+
self,
875+
device_type: DeviceType | None = None,
876+
url: str | None = None,
877+
retry_on_failure: bool = True,
876878
) -> list:
877879
"""Get attributes, metadata, and child devices for an ADC device class."""
878880

@@ -936,13 +938,27 @@ async def _async_get_items_and_subordinates(
936938
# All requests for those device types will return 403.
937939
#
938940
# On some providers, 403 may mean that the user has been logged out.
939-
# For now, we'll ignore this case.
941+
# Try logging in again, then give up by pretending that we couldn't find any devices of this type.
940942

941-
log.debug(
942-
"Got 403 status when fetching data for device type %s.", device_type
943-
)
943+
log.error("Error fetching data from Alarm.com.")
944+
945+
if not retry_on_failure:
946+
log.debug(
947+
"Got 403 status when fetching data for device type %s. Logging"
948+
" in again didn't help.",
949+
device_type,
950+
)
951+
952+
return list([])
953+
954+
log.error("Trying to refresh auth tokens by logging in again.")
944955

945-
return list([])
956+
await self.async_login()
957+
958+
return await self._async_get_items_and_subordinates(
959+
device_type=device_type,
960+
retry_on_failure=False,
961+
)
946962

947963
if (
948964
rsp_errors[0].get("status") == "409"

0 commit comments

Comments
 (0)