Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
*.whl

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"python.formatting.provider": "black",
"python.sortImports.args": ["--profile", "black"],
"editor.codeActionsOnSave": {
"source.organizeImports": true
"source.organizeImports": "explicit"
}
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# pyuhoo

[![PyPi version](https://img.shields.io/pypi/v/pyuhoo.svg)](https://pypi.python.org/pypi/pyuhoo/)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/csacca/pyuhoo/master.svg)](https://results.pre-commit.ci/latest/github/csacca/pyuhoo/master)
![ci workflow](https://github.com/csacca/pyuhoo/actions/workflows/ci.yaml/badge.svg)

Python API for talking to uHoo consumer API

Please note that this is a non-public API that has been reverse-engineered from mobile
apps. It is likely to break unexpectedly when uHoo changes the API.

Original project by [@csacca](https://github.com/csacca/pyuhoo)

Currently maintained fork by [@andrewleech](https://github.com/andrewleech/pyuhoo)
1,488 changes: 876 additions & 612 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[tool.poetry]
name = "pyuhoo"
version = "0.0.5"
version = "0.0.6"
description = "Python API for talking to uHoo consumer API"
authors = ["Christopher Sacca <csacca@csacca.net>"]
repository = "https://github.com/csacca/pyuhoo"
authors = ["Christopher Sacca <csacca@csacca.net>", "Andrew Leech", "Simone Rescio"]
repository = "https://github.com/andrewleech/pyuhoo"
license = "MIT"
readme = "README.md"

Expand All @@ -15,6 +15,8 @@ python = "^3.8"
aiohttp = "^3.7.4"
click = "^8.0.1"
pycryptodome = "^3.10.1"
pyyaml = "^6.0"
yarl = "^1.8.1"

[tool.poetry.dev-dependencies]
flake8 = "^3.9.2"
Expand Down
12 changes: 11 additions & 1 deletion pyuhoo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ async def refresh_token(self) -> None:
)
await self.login()

def get_user_settings_temp(self, data_latest):
if "userSettings" in data_latest and "temp" in data_latest["userSettings"]:
return data_latest["userSettings"]["temp"]
if "devices" in data_latest:
temp_data = data_latest["devices"][0]["threshold"]["temp"]
aMax = temp_data.get("aMax")
if aMax is None:
return None
return "f" if aMax == 104 else "c"

async def get_latest_data(self) -> None:
try:
data_latest: dict = await self._api.data_latest()
Expand All @@ -118,7 +128,7 @@ async def get_latest_data(self) -> None:

# self._log.debug(f"[data_latest] returned\n{json_pp(data_latest)}")

self.user_settings_temp = data_latest["userSettings"]["temp"]
self.user_settings_temp = self.get_user_settings_temp(data_latest)

device: dict
for device in data_latest["devices"]:
Expand Down
79 changes: 63 additions & 16 deletions tests/test_api_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from aiohttp import ClientSession

from pyuhoo.api import API
from pyuhoo.client import Client
from pyuhoo.util import encrypted_hash, salted_hash

#
Expand All @@ -31,18 +32,34 @@
"companyName",
"clientName",
"paymentStatus",
"paymentExpires",
"trialPeriod",
"productType",
"smartAlert",
"paymentRenewStatus",
"systemTime",
"paymentName",
"billingRetry",
]

USER_REFRESH_TOKEN_KEYS = [
"refreshToken",
"token",
"billingRetry",
"smartAlert",
"gdpr",
"language",
"Role",
"paymentStatus",
"passwordLastUpdate",
"systemTime",
"paymentName",
"trialPeriod",
"paymentRenewStatus",
"productType",
]

DATA_LATEST_KEYS = ["devices", "data", "userSettings", "offline", "systemTime"]
DATA_LATEST_KEYS = ["devices", "userSettings", "systemTime"]

DATA_LATEST_DATA_KEYS = [
"serialNumber",
Expand All @@ -59,21 +76,26 @@
"virusScore",
]
DATA_LATEST_DEVICES_KEYS = [
"name",
"serialNumber",
"macAddress",
"status",
"latitude",
"home",
"ssid",
"longitude",
"createdAt",
"server",
"calibration",
"location",
"city",
"city_ios",
"createdAt",
"home",
"latitude",
"location",
"longitude",
"macAddress",
"name",
"RoomType",
"thresholdName",
"thresholdType",
"offline",
"serialNumber",
"server",
"ssid",
"status",
"data",
"offline_timestamp",
"threshold",
]

Expand Down Expand Up @@ -123,7 +145,6 @@ async def websession():

@pytest.fixture(scope="module")
async def results(websession, username, password):

_results = {}

# Create API client
Expand Down Expand Up @@ -207,10 +228,10 @@ def test_data_latest(results):
def test_data_latest_data(results):
data_latest: dict = results["data_latest"]

assert "data" in data_latest.keys()
assert "devices" in data_latest.keys()

if len(data_latest["data"]) > 0:
data = data_latest["data"][0]
if len(data_latest["devices"]) > 0:
data = data_latest["devices"][0]["data"]
verify_keys(DATA_LATEST_DATA_KEYS, data)
else:
pytest.skip('Skipping: No data to test in data_latest["data"]')
Expand All @@ -226,3 +247,29 @@ def test_data_latest_devices(results):
verify_keys(DATA_LATEST_DEVICES_KEYS, devices)
else:
pytest.skip('Skipping: No devices to test in data_latest["devices"]')


def test_get_user_settings_temp():
client = Client("username", "password", None)

# Case userSettings.temp is defined
data_latest = {
"devices": [{"threshold": {"temp": {"aMax": 104}}}],
"userSettings": {"temp": "c"},
}
assert client.get_user_settings_temp(data_latest) == "c"
# Case userSettings.temp is undefined, aMax is 104
data_latest = {"devices": [{"threshold": {"temp": {"aMax": 104}}}]}
assert client.get_user_settings_temp(data_latest) == "f"

# Case userSettings.temp is undefined, aMax is not 104
data_latest = {"devices": [{"threshold": {"temp": {"aMax": 40}}}]}
assert client.get_user_settings_temp(data_latest) == "c"

# Case userSettings.temp is undefined, aMax is undefined
data_latest = {"devices": [{"threshold": {"temp": {}}}]}
assert client.get_user_settings_temp(data_latest) is None

# Case userSettings.temp is undefined, devices is undefined
data_latest = {}
assert client.get_user_settings_temp(data_latest) is None