diff --git a/changelog b/changelog index 17e1ee5..f317399 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +0.8.0b8: + Ping wired doorbell. + Try proper device id for cloud flare 0.8.0b7: Allow more MQTT config. Fix headers. diff --git a/pyaarlo/__init__.py b/pyaarlo/__init__.py index 558d982..1418b98 100644 --- a/pyaarlo/__init__.py +++ b/pyaarlo/__init__.py @@ -45,7 +45,7 @@ _LOGGER = logging.getLogger("pyaarlo") -__version__ = "0.8.0b7" +__version__ = "0.8.0b8" class PyArlo(object): diff --git a/pyaarlo/backend.py b/pyaarlo/backend.py index ac9b7e8..2e810a9 100644 --- a/pyaarlo/backend.py +++ b/pyaarlo/backend.py @@ -48,6 +48,7 @@ class ArloBackEnd(object): _session_lock = threading.Lock() _session_info = {} _multi_location = False + _user_device_id = None def __init__(self, arlo): @@ -63,6 +64,7 @@ def __init__(self, arlo): self._resource_types = DEFAULT_RESOURCES self._load_session() + self._user_device_id = str(uuid.uuid4()) # event thread stuff self._event_thread = None @@ -149,6 +151,7 @@ def _request( raw=False, timeout=None, host=None, + authpost=False, ): if params is None: params = {} @@ -160,9 +163,13 @@ def _request( with self._req_lock: if host is None: host = self._arlo.cfg.host - tid = self._transaction_id() - url = self._build_url(host + path, tid) - headers['x-transaction-id'] = tid + if authpost: + url = host + path + else: + tid = self._transaction_id() + url = self._build_url(host + path, tid) + headers['x-transaction-id'] = tid + self.vdebug("request-url={}".format(url)) self.vdebug("request-params=\n{}".format(pprint.pformat(params))) self.vdebug("request-headers=\n{}".format(pprint.pformat(headers))) @@ -675,7 +682,7 @@ def _auth(self): "Referer": REFERER_HOST, "Source": "arloCamWeb", "User-Agent": self._user_agent, - "x-user-device-id": self._user_id, + "x-user-device-id": self._user_device_id, "x-user-device-automation-name": "QlJPV1NFUg==", "x-user-device-type": "BROWSER", } @@ -756,7 +763,12 @@ def _auth(self): self.debug( "starting auth with {}".format(self._arlo.cfg.tfa_type) ) - body = self.auth_post(AUTH_START_PATH, {"factorId": factor_id}, headers) + payload = { + "factorId": factor_id, + "factorType": "BROWSER", + "userId": self._user_id + } + body = self.auth_post(AUTH_START_PATH, payload, headers) if body is None: self._arlo.error("2fa startAuth failed") return False @@ -826,7 +838,7 @@ def _validate(self): "Referer": REFERER_HOST, "User-Agent": self._user_agent, "Source": "arloCamWeb", - "x-user-device-id": self._user_id, + "x-user-device-id": self._user_device_id, "x-user-device-automation-name": "QlJPV1NFUg==", "x-user-device-type": "BROWSER", } @@ -1076,14 +1088,14 @@ def post( def auth_post(self, path, params=None, headers=None, raw=False, timeout=None): return self._request( - path, "POST", params, headers, False, raw, timeout, self._arlo.cfg.auth_host + path, "POST", params, headers, False, raw, timeout, self._arlo.cfg.auth_host, authpost=True ) def auth_get( self, path, params=None, headers=None, stream=False, raw=False, timeout=None ): return self._request( - path, "GET", params, headers, stream, raw, timeout, self._arlo.cfg.auth_host + path, "GET", params, headers, stream, raw, timeout, self._arlo.cfg.auth_host, authpost=True ) @property diff --git a/pyaarlo/base.py b/pyaarlo/base.py index 5a84506..ef7c0b3 100644 --- a/pyaarlo/base.py +++ b/pyaarlo/base.py @@ -23,6 +23,7 @@ MODEL_HUB, MODEL_PRO_3_FLOODLIGHT, MODEL_PRO_4, + MODEL_WIRED_VIDEO_DOORBELL, MODEL_WIREFREE_VIDEO_DOORBELL, PING_CAPABILITY, RESOURCE_CAPABILITY, @@ -553,8 +554,18 @@ def has_capability(self, cap): return True if cap in (PING_CAPABILITY,): + + # Always true for these devices. if self.model_id.startswith(MODEL_BABY): return True + if self.model_id.startswith(MODEL_WIRED_VIDEO_DOORBELL): + return True + + # Don't ping these devices ever. + if self.model_id.startswith( + (MODEL_WIREFREE_VIDEO_DOORBELL, MODEL_ESSENTIAL, MODEL_PRO_3_FLOODLIGHT, MODEL_PRO_4) + ): + return False # We have to be careful pinging some base stations because it can rapidly # drain the battery power. Don't ping if: @@ -566,12 +577,6 @@ def has_capability(self, cap): if self.using_wifi: return False - # Don't ping these devices ever. - if self.model_id.startswith( - (MODEL_WIREFREE_VIDEO_DOORBELL, MODEL_ESSENTIAL, MODEL_PRO_3_FLOODLIGHT, MODEL_PRO_4) - ): - return False - # All others, then ping. return True diff --git a/setup.py b/setup.py index 6624741..0ba15fe 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ def readme(): setup( name='pyaarlo', - version='0.8.0b7', + version='0.8.0b8', packages=['pyaarlo'], python_requires='>=3.6',