Skip to content
Open
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
16 changes: 0 additions & 16 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.194.0/containers/python-3
{
"name": "Python 3",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
// Update 'VARIANT' to pick a Python version: 3, 3.6, 3.7, 3.8, 3.9
"VARIANT": "3.9",
// Options
"NODE_VERSION": "lts/*"
}
},

// Set *default* container specific settings.json values on container create.
"settings": {
"python.pythonPath": "/usr/local/bin/python",
"python.languageServer": "Pylance",
Expand All @@ -29,16 +23,6 @@
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": ["ms-python.python", "ms-python.vscode-pylance"],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
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)
Empty file added __init__.py
Empty file.
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 <[email protected]>"]
repository = "https://github.com/csacca/pyuhoo"
authors = ["Christopher Sacca <[email protected]>", "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
2 changes: 1 addition & 1 deletion pyuhoo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import click
from aiohttp import ClientSession

from pyuhoo import Client
from .client import Client


async def init_client(username, password, websession) -> Client:
Expand Down
22 changes: 16 additions & 6 deletions pyuhoo/client.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import logging
import uuid
from typing import Dict, Optional

from aiohttp import ClientSession

from pyuhoo.errors import ForbiddenError, UhooError, UnauthorizedError
from .errors import ForbiddenError, UhooError, UnauthorizedError

from .api import API
from .consts import APP_VERSION, CLIENT_ID
from .consts import APP_VERSION
from .device import Device
from .util import encrypted_hash, json_pp, salted_hash

Expand All @@ -26,7 +27,7 @@ def __init__(
)

self._app_version: int = APP_VERSION
self._client_id: str = CLIENT_ID
self._client_id: str = (uuid.uuid1().hex * 2)[0:48]
self._device_id: Optional[str] = None
self._devices: Dict[str, Device] = {}
self._username: str = username
Expand Down Expand Up @@ -95,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 @@ -117,16 +128,15 @@ 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"]:
serial_number: str = device["serialNumber"]
if serial_number not in self._devices:
self._devices[serial_number] = Device(device)

for data in data_latest["data"]:
serial_number = data["serialNumber"]
data: dict = device["data"]
device_obj: Device = self._devices[serial_number]
if device_obj.timestamp < data["timestamp"]:
device_obj.update_data(data)
Expand Down
1 change: 0 additions & 1 deletion pyuhoo/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
USER_AGENT_SYSTEM_INFORMATION: str = "iPhone;13.3; iOS 14.7.1; Scale/3.00"

APP_VERSION: int = 93
CLIENT_ID: str = "0000000000000000000|0000000000000000000"
2 changes: 1 addition & 1 deletion pyuhoo/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
DEVICE_TIMEZONES: str = "gettimezones"
DEVICE_ROOMS: str = "getlocationtypes"
DEVICE_TRANSFER_OWNER: str = "transferowner"
DATA_LATEST: str = "getalllatestdata"
DATA_LATEST: str = "allconsumerdata"
DATA_HOUR: str = "wtvsRh/gethourcolor"
DATA_DAY: str = "wtvsRh/getdaycolor"
DATA_WEEK: str = "wtvsRh/getweekcolor"
Expand Down
83 changes: 65 additions & 18 deletions tests/test_api_live.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import asyncio
import os
import uuid
from typing import List

import pytest
from aiohttp import ClientSession

from pyuhoo.api import API
from pyuhoo.consts import CLIENT_ID
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 All @@ -136,7 +157,7 @@ async def results(websession, username, password):
u_id = user_config["uId"]

# do user_verify_email()
client_id = CLIENT_ID
client_id: str = (uuid.uuid1().hex * 2)[0:48]
user_verify_email: dict = await api.user_verify_email(username, client_id)
_results["user_verify_email"] = user_verify_email

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