Skip to content

Commit

Permalink
Arlo back end (#123)
Browse files Browse the repository at this point in the history
* Always ping wired doorbell.

* Improve Arlo headers.

* Bumep revision...
  • Loading branch information
twrecked committed May 31, 2023
1 parent 3eead47 commit d8a05cb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
3 changes: 3 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pyaarlo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

_LOGGER = logging.getLogger("pyaarlo")

__version__ = "0.8.0b7"
__version__ = "0.8.0b8"


class PyArlo(object):
Expand Down
28 changes: 20 additions & 8 deletions pyaarlo/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ArloBackEnd(object):
_session_lock = threading.Lock()
_session_info = {}
_multi_location = False
_user_device_id = None

def __init__(self, arlo):

Expand All @@ -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
Expand Down Expand Up @@ -149,6 +151,7 @@ def _request(
raw=False,
timeout=None,
host=None,
authpost=False,
):
if params is None:
params = {}
Expand All @@ -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)))
Expand Down Expand Up @@ -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",
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
}
Expand Down Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions pyaarlo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def readme():
setup(

name='pyaarlo',
version='0.8.0b7',
version='0.8.0b8',
packages=['pyaarlo'],

python_requires='>=3.6',
Expand Down

0 comments on commit d8a05cb

Please sign in to comment.