smartbox 2.4.0__tar.gz → 2.5.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {smartbox-2.4.0 → smartbox-2.5.1}/.github/workflows/publish-to-pypi.yml +3 -3
- {smartbox-2.4.0 → smartbox-2.5.1}/.github/workflows/python-package.yml +7 -7
- {smartbox-2.4.0 → smartbox-2.5.1}/.gitignore +3 -2
- {smartbox-2.4.0 → smartbox-2.5.1}/.pre-commit-config.yaml +2 -2
- {smartbox-2.4.0 → smartbox-2.5.1}/PKG-INFO +3 -3
- {smartbox-2.4.0 → smartbox-2.5.1}/pyproject.toml +18 -3
- {smartbox-2.4.0 → smartbox-2.5.1}/src/smartbox/models.py +4 -1
- {smartbox-2.4.0 → smartbox-2.5.1}/src/smartbox/session.py +101 -44
- {smartbox-2.4.0 → smartbox-2.5.1}/src/smartbox/socket.py +125 -44
- {smartbox-2.4.0 → smartbox-2.5.1}/src/smartbox/update_manager.py +6 -2
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/conftest.py +35 -3
- smartbox-2.5.1/tests/fixtures/devs/device1/acm/1/version.json +6 -0
- smartbox-2.5.1/tests/fixtures/devs/device1/htr/0/version.json +6 -0
- smartbox-2.5.1/tests/fixtures/devs/device1/pmo/3/version.json +6 -0
- smartbox-2.5.1/tests/fixtures/devs/device2/htr_mod/0/version.json +6 -0
- smartbox-2.5.1/tests/fixtures/devs/device2/htr_mod/1/version.json +6 -0
- smartbox-2.5.1/tests/fixtures/devs/device2/htr_mod/2/version.json +6 -0
- smartbox-2.5.1/tests/fixtures/devs/device2/htr_mod/3/version.json +6 -0
- smartbox-2.5.1/tests/fixtures/devs/device2/htr_mod/4/version.json +6 -0
- smartbox-2.5.1/tests/fixtures/devs/device2/htr_mod/5/version.json +6 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/test_session.py +196 -45
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/test_update_manager.py +0 -1
- smartbox-2.5.1/uv.lock +1144 -0
- smartbox-2.4.0/tox.ini +0 -14
- smartbox-2.4.0/uv.lock +0 -1293
- {smartbox-2.4.0 → smartbox-2.5.1}/.github/FUNDING.yml +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/.github/ISSUE_TEMPLATE/new-reseller.md +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/.github/dependabot.yml +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/.vscode/settings.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/CHANGELOG.md +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/CODEOWNERS +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/LICENSE +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/README.md +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/api-notes.md +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/codecov.yml +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/src/smartbox/__init__.py +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/src/smartbox/cmd.py +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/src/smartbox/error.py +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/src/smartbox/py.typed +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/src/smartbox/reseller.py +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/__init__.py +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/common.py +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device1/acm/1/samples.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device1/acm/1/setup.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device1/acm/1/status.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device1/connected.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device1/htr/0/samples.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device1/htr/0/setup.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device1/htr/0/status.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device1/htr_system/power_limit.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device1/mgr/away_status.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device1/mgr/nodes.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device1/pmo/3/samples.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device1/pmo/3/setup.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device1/pmo/3/status.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/connected.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/0/samples.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/0/setup.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/0/status.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/1/samples.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/1/setup.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/1/status.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/2/samples.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/2/setup.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/2/status.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/3/samples.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/3/setup.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/3/status.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/4/samples.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/4/setup.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/4/status.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/5/samples.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/5/setup.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_mod/5/status.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/htr_system/power_limit.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/mgr/away_status.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs/device2/mgr/nodes.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/devs.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/grouped_devs.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/groups/test_home/guest_users.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/fixtures/test_path.json +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/test_cmd.py +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/test_models.py +0 -0
- {smartbox-2.4.0 → smartbox-2.5.1}/tests/test_reseller.py +0 -0
|
@@ -5,7 +5,7 @@ on:
|
|
|
5
5
|
tags:
|
|
6
6
|
- "v*"
|
|
7
7
|
env:
|
|
8
|
-
PYTHON_VERSION: 3.
|
|
8
|
+
PYTHON_VERSION: 3.14
|
|
9
9
|
|
|
10
10
|
jobs:
|
|
11
11
|
build-n-publish:
|
|
@@ -22,10 +22,10 @@ jobs:
|
|
|
22
22
|
with:
|
|
23
23
|
python-version: ${{ env.PYTHON_VERSION }}
|
|
24
24
|
- name: Set up Python ${{ env.PYTHON_VERSION }}
|
|
25
|
-
uses: actions/setup-python@v6.
|
|
25
|
+
uses: actions/setup-python@v6.2.0
|
|
26
26
|
with:
|
|
27
27
|
python-version: ${{ env.PYTHON_VERSION }}
|
|
28
28
|
- name: Build a binary wheel and a source tarball
|
|
29
29
|
run: uv build
|
|
30
30
|
- name: Publish 📦 to PyPI
|
|
31
|
-
uses: pypa/gh-action-pypi-publish@release/v1.
|
|
31
|
+
uses: pypa/gh-action-pypi-publish@release/v1.14
|
|
@@ -16,7 +16,7 @@ jobs:
|
|
|
16
16
|
strategy:
|
|
17
17
|
max-parallel: 4
|
|
18
18
|
matrix:
|
|
19
|
-
python-version: [3.
|
|
19
|
+
python-version: [3.14]
|
|
20
20
|
steps:
|
|
21
21
|
- uses: actions/checkout@v6
|
|
22
22
|
- name: Install uv
|
|
@@ -24,7 +24,7 @@ jobs:
|
|
|
24
24
|
with:
|
|
25
25
|
python-version: ${{ matrix.python-version }}
|
|
26
26
|
- name: Set up Python ${{ matrix.python-version }}
|
|
27
|
-
uses: actions/setup-python@v6.
|
|
27
|
+
uses: actions/setup-python@v6.2.0
|
|
28
28
|
with:
|
|
29
29
|
python-version: ${{ matrix.python-version }}
|
|
30
30
|
- name: Install the project
|
|
@@ -37,7 +37,7 @@ jobs:
|
|
|
37
37
|
strategy:
|
|
38
38
|
max-parallel: 1
|
|
39
39
|
matrix:
|
|
40
|
-
python-version: [3.
|
|
40
|
+
python-version: [3.14]
|
|
41
41
|
|
|
42
42
|
steps:
|
|
43
43
|
- uses: actions/checkout@v6
|
|
@@ -46,7 +46,7 @@ jobs:
|
|
|
46
46
|
with:
|
|
47
47
|
python-version: ${{ matrix.python-version }}
|
|
48
48
|
- name: Set up Python ${{ matrix.python-version }}
|
|
49
|
-
uses: actions/setup-python@v6.
|
|
49
|
+
uses: actions/setup-python@v6.2.0
|
|
50
50
|
with:
|
|
51
51
|
python-version: ${{ matrix.python-version }}
|
|
52
52
|
- name: Install the project
|
|
@@ -59,7 +59,7 @@ jobs:
|
|
|
59
59
|
strategy:
|
|
60
60
|
max-parallel: 4
|
|
61
61
|
matrix:
|
|
62
|
-
python-version: [3.
|
|
62
|
+
python-version: [3.14]
|
|
63
63
|
|
|
64
64
|
steps:
|
|
65
65
|
- uses: actions/checkout@v6
|
|
@@ -69,7 +69,7 @@ jobs:
|
|
|
69
69
|
python-version: ${{ matrix.python-version }}
|
|
70
70
|
|
|
71
71
|
- name: Set up Python ${{ matrix.python-version }}
|
|
72
|
-
uses: actions/setup-python@v6.
|
|
72
|
+
uses: actions/setup-python@v6.2.0
|
|
73
73
|
with:
|
|
74
74
|
python-version: ${{ matrix.python-version }}
|
|
75
75
|
- name: Install the project
|
|
@@ -77,7 +77,7 @@ jobs:
|
|
|
77
77
|
uv sync --all-extras --dev
|
|
78
78
|
uv run tox -e py
|
|
79
79
|
- name: "Upload coverage to Codecov"
|
|
80
|
-
uses: codecov/codecov-action@
|
|
80
|
+
uses: codecov/codecov-action@v6.0.0
|
|
81
81
|
with:
|
|
82
82
|
token: ${{ secrets.CODECOV_TOKEN }}
|
|
83
83
|
fail_ci_if_error: true
|
|
@@ -30,6 +30,7 @@ share/python-wheels/
|
|
|
30
30
|
.installed.cfg
|
|
31
31
|
*.egg
|
|
32
32
|
MANIFEST
|
|
33
|
+
.sonar/
|
|
33
34
|
|
|
34
35
|
# PyInstaller
|
|
35
36
|
# Usually these files are written by a python script from a template
|
|
@@ -47,7 +48,7 @@ htmlcov/
|
|
|
47
48
|
.nox/
|
|
48
49
|
.coverage
|
|
49
50
|
.coverage.*
|
|
50
|
-
|
|
51
|
+
.*cache*
|
|
51
52
|
nosetests.xml
|
|
52
53
|
coverage.xml
|
|
53
54
|
*.cover
|
|
@@ -71,4 +72,4 @@ venv.bak/
|
|
|
71
72
|
junit.xml
|
|
72
73
|
.DS_Store
|
|
73
74
|
|
|
74
|
-
*.code-workspace
|
|
75
|
+
*.code-workspace
|
|
@@ -2,7 +2,7 @@ repos:
|
|
|
2
2
|
|
|
3
3
|
- repo: https://github.com/astral-sh/uv-pre-commit
|
|
4
4
|
# uv version.
|
|
5
|
-
rev: 0.
|
|
5
|
+
rev: 0.10.8
|
|
6
6
|
hooks:
|
|
7
7
|
# Update the uv lockfile
|
|
8
8
|
- id: uv-lock
|
|
@@ -22,7 +22,7 @@ repos:
|
|
|
22
22
|
- "--indent=4"
|
|
23
23
|
|
|
24
24
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
25
|
-
rev: v0.
|
|
25
|
+
rev: v0.15.4
|
|
26
26
|
hooks:
|
|
27
27
|
- id: ruff
|
|
28
28
|
args: [--fix, --exit-non-zero-on-fix]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: smartbox
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.5.1
|
|
4
4
|
Summary: Python API to control heating 'smart boxes'
|
|
5
5
|
Project-URL: Homepage, https://github.com/ajtudela/smartbox
|
|
6
6
|
Project-URL: Issues, https://github.com/ajtudela/smartbox/issues
|
|
@@ -10,11 +10,11 @@ License-File: LICENSE
|
|
|
10
10
|
Classifier: License :: OSI Approved :: MIT License
|
|
11
11
|
Classifier: Operating System :: OS Independent
|
|
12
12
|
Classifier: Programming Language :: Python :: 3
|
|
13
|
-
Requires-Python: >=3.
|
|
13
|
+
Requires-Python: >=3.14.2
|
|
14
14
|
Requires-Dist: aiohttp
|
|
15
15
|
Requires-Dist: asyncclick
|
|
16
16
|
Requires-Dist: jq
|
|
17
|
-
Requires-Dist: pydantic==2.
|
|
17
|
+
Requires-Dist: pydantic==2.13.2
|
|
18
18
|
Requires-Dist: python-socketio
|
|
19
19
|
Requires-Dist: requests
|
|
20
20
|
Requires-Dist: websocket-client
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "smartbox"
|
|
3
|
-
version = "2.
|
|
4
|
-
requires-python = ">=3.
|
|
3
|
+
version = "2.5.1"
|
|
4
|
+
requires-python = ">=3.14.2"
|
|
5
5
|
authors = [
|
|
6
6
|
{ name="Alberto Tudela", email="ajtudela@gmail.com" },
|
|
7
7
|
{ name="Delmael", email="delmael@outlook.com" },
|
|
@@ -21,7 +21,7 @@ dependencies = [
|
|
|
21
21
|
"aiohttp",
|
|
22
22
|
"asyncclick",
|
|
23
23
|
"jq",
|
|
24
|
-
"pydantic==2.
|
|
24
|
+
"pydantic==2.13.2",
|
|
25
25
|
"python-socketio",
|
|
26
26
|
"requests",
|
|
27
27
|
"websocket-client",
|
|
@@ -136,3 +136,18 @@ max-complexity = 25
|
|
|
136
136
|
|
|
137
137
|
[tool.setuptools.packages.find]
|
|
138
138
|
where = ["src"]
|
|
139
|
+
|
|
140
|
+
[tool.tox]
|
|
141
|
+
env_list = ["3.14"]
|
|
142
|
+
|
|
143
|
+
[tool.tox.env_run_base]
|
|
144
|
+
isolated_build = true
|
|
145
|
+
description = "Run test under {base_python}"
|
|
146
|
+
dependency_groups = ["dev"]
|
|
147
|
+
commands = [["python", "-m", "pytest", "--cov=smartbox", "--cov-append", "--cov-report=term", "--cov-report=xml", "--junitxml=junit.xml"]]
|
|
148
|
+
|
|
149
|
+
[tool.sonar]
|
|
150
|
+
"sonar.python.version" = "3.14"
|
|
151
|
+
"python.coverage.reportPaths" = "coverage.xml"
|
|
152
|
+
"sonar.tests" = "tests"
|
|
153
|
+
"python.xunit.reportPath" = "junit.xml"
|
|
@@ -83,14 +83,16 @@ class NodeSetup(RootModel[DefaultNodeSetup | PmoSetup]):
|
|
|
83
83
|
"""Get the root model directly."""
|
|
84
84
|
return getattr(self.root, name)
|
|
85
85
|
|
|
86
|
+
|
|
86
87
|
class NodeVersion(BaseModel):
|
|
87
88
|
"""NodeVersion model."""
|
|
88
|
-
|
|
89
|
+
|
|
89
90
|
hw_version: str
|
|
90
91
|
fw_version: str
|
|
91
92
|
uid: str
|
|
92
93
|
pid: str
|
|
93
94
|
|
|
95
|
+
|
|
94
96
|
class DefaultNodeStatus(BaseModel):
|
|
95
97
|
"""Default Node Status."""
|
|
96
98
|
|
|
@@ -173,6 +175,7 @@ class Node(BaseModel):
|
|
|
173
175
|
installed: bool
|
|
174
176
|
lost: bool | None = False
|
|
175
177
|
|
|
178
|
+
|
|
176
179
|
class Nodes(BaseModel):
|
|
177
180
|
"""Nodes model."""
|
|
178
181
|
|
|
@@ -5,7 +5,7 @@ import datetime
|
|
|
5
5
|
import json
|
|
6
6
|
import logging
|
|
7
7
|
import time
|
|
8
|
-
from typing import Any
|
|
8
|
+
from typing import Any, Self
|
|
9
9
|
|
|
10
10
|
import aiohttp
|
|
11
11
|
from aiohttp import ClientSession
|
|
@@ -27,6 +27,7 @@ from smartbox.models import (
|
|
|
27
27
|
Nodes,
|
|
28
28
|
NodeSetup,
|
|
29
29
|
NodeStatus,
|
|
30
|
+
NodeVersion,
|
|
30
31
|
Samples,
|
|
31
32
|
SmartboxNodeType,
|
|
32
33
|
Token,
|
|
@@ -72,6 +73,10 @@ class AsyncSession:
|
|
|
72
73
|
self._username: str = username
|
|
73
74
|
self._password: str = password
|
|
74
75
|
self._access_token: str = ""
|
|
76
|
+
self._refresh_token: str = ""
|
|
77
|
+
self._expires_at: datetime.datetime = datetime.datetime.now(
|
|
78
|
+
datetime.UTC
|
|
79
|
+
)
|
|
75
80
|
self._client_session: ClientSession | None = websession
|
|
76
81
|
self.raw_response: bool = raw_response
|
|
77
82
|
self._headers: dict[str, str] = {
|
|
@@ -83,6 +88,29 @@ class AsyncSession:
|
|
|
83
88
|
if self.reseller.web_url:
|
|
84
89
|
self._headers.update({"x-referer": self.reseller.web_url})
|
|
85
90
|
|
|
91
|
+
async def __aenter__(self) -> Self:
|
|
92
|
+
"""Async context manager entry."""
|
|
93
|
+
_LOGGER.debug(
|
|
94
|
+
"__aenter__ of AsyncSmartboxSession, authenticating and creating client session if not provided",
|
|
95
|
+
)
|
|
96
|
+
return self
|
|
97
|
+
|
|
98
|
+
async def __aexit__(
|
|
99
|
+
self,
|
|
100
|
+
exc_type: type[BaseException] | None,
|
|
101
|
+
exc_val: BaseException | None,
|
|
102
|
+
exc_tb: object,
|
|
103
|
+
) -> None:
|
|
104
|
+
"""Async context manager exit."""
|
|
105
|
+
_LOGGER.debug(
|
|
106
|
+
"Async context manager exit, closing client session and socket if exists"
|
|
107
|
+
)
|
|
108
|
+
if self._client_session:
|
|
109
|
+
await self._client_session.close()
|
|
110
|
+
# Cleanup socket if exists
|
|
111
|
+
if hasattr(self, "_socket") and self._socket:
|
|
112
|
+
await self._socket.disconnect()
|
|
113
|
+
|
|
86
114
|
@property
|
|
87
115
|
def reseller(self) -> SmartboxReseller:
|
|
88
116
|
"""Get the reseller."""
|
|
@@ -117,37 +145,39 @@ class AsyncSession:
|
|
|
117
145
|
def client(self) -> ClientSession:
|
|
118
146
|
"""Return the underlying http client."""
|
|
119
147
|
if not self._client_session:
|
|
120
|
-
|
|
148
|
+
self._client_session = ClientSession()
|
|
121
149
|
return self._client_session
|
|
122
150
|
|
|
123
151
|
async def health_check(self) -> dict[str, Any]:
|
|
124
152
|
"""Check if the API is alived."""
|
|
125
153
|
api_url = f"{self._api_host}/health_check"
|
|
126
154
|
try:
|
|
127
|
-
|
|
155
|
+
async with self.client.get(api_url) as response:
|
|
156
|
+
response.raise_for_status()
|
|
157
|
+
return await response.json()
|
|
128
158
|
except (
|
|
129
159
|
aiohttp.ClientConnectionError,
|
|
130
160
|
aiohttp.ClientConnectorError,
|
|
131
161
|
) as e:
|
|
132
162
|
raise APIUnavailableError(e) from e
|
|
133
|
-
return await response.json()
|
|
134
163
|
|
|
135
164
|
async def api_version(self) -> dict[str, str]:
|
|
136
165
|
"""Check if the API is alived."""
|
|
137
166
|
api_url = f"{self._api_host}/version"
|
|
138
167
|
try:
|
|
139
|
-
|
|
168
|
+
async with self.client.get(api_url) as response:
|
|
169
|
+
response.raise_for_status()
|
|
170
|
+
return await response.json()
|
|
140
171
|
except (
|
|
141
172
|
aiohttp.ClientConnectionError,
|
|
142
173
|
aiohttp.ClientConnectorError,
|
|
143
174
|
) as e:
|
|
144
175
|
raise APIUnavailableError(e) from e
|
|
145
|
-
return await response.json()
|
|
146
176
|
|
|
147
177
|
async def _authentication(self, credentials: dict[str, str]) -> None:
|
|
148
178
|
"""Do the authentication process to Smartbox. First one use login/mdp/basic_auth. Then the tokens."""
|
|
149
179
|
token_headers = self._headers.copy()
|
|
150
|
-
|
|
180
|
+
token_headers.pop("Authorization", None)
|
|
151
181
|
token_headers.update(
|
|
152
182
|
{
|
|
153
183
|
"authorization": f"Basic {self.reseller.basic_auth}",
|
|
@@ -157,11 +187,40 @@ class AsyncSession:
|
|
|
157
187
|
|
|
158
188
|
token_url = f"{self._api_host}/client/token"
|
|
159
189
|
try:
|
|
160
|
-
|
|
190
|
+
async with self.client.post(
|
|
161
191
|
url=token_url,
|
|
162
192
|
headers=token_headers,
|
|
163
193
|
data=credentials,
|
|
164
|
-
)
|
|
194
|
+
) as response:
|
|
195
|
+
response.raise_for_status()
|
|
196
|
+
response_json = await response.json()
|
|
197
|
+
try:
|
|
198
|
+
rtoken: Token = Token.model_validate(response_json)
|
|
199
|
+
self._access_token = rtoken.access_token
|
|
200
|
+
self._headers["Authorization"] = (
|
|
201
|
+
f"Bearer {self._access_token}"
|
|
202
|
+
)
|
|
203
|
+
self._refresh_token = rtoken.refresh_token
|
|
204
|
+
if rtoken.expires_in < _MIN_TOKEN_LIFETIME:
|
|
205
|
+
_LOGGER.warning(
|
|
206
|
+
"Token expires in %ss which is below minimum lifetime of %ss- will refresh again on next operation",
|
|
207
|
+
rtoken.expires_in,
|
|
208
|
+
_MIN_TOKEN_LIFETIME,
|
|
209
|
+
)
|
|
210
|
+
self._expires_at = datetime.datetime.now(
|
|
211
|
+
datetime.UTC
|
|
212
|
+
) + datetime.timedelta(
|
|
213
|
+
seconds=rtoken.expires_in,
|
|
214
|
+
)
|
|
215
|
+
_LOGGER.debug(
|
|
216
|
+
"Authenticated session (%s), access_token=%s, expires at %s",
|
|
217
|
+
credentials["grant_type"],
|
|
218
|
+
self.access_token,
|
|
219
|
+
self.expiry_time,
|
|
220
|
+
)
|
|
221
|
+
except ValidationError as e:
|
|
222
|
+
msg = f"Received invalid auth response {response.status} with msg: {response.reason}"
|
|
223
|
+
raise InvalidAuthError(msg) from e
|
|
165
224
|
except (
|
|
166
225
|
aiohttp.ClientConnectionError,
|
|
167
226
|
aiohttp.ClientConnectorError,
|
|
@@ -169,31 +228,6 @@ class AsyncSession:
|
|
|
169
228
|
raise APIUnavailableError(e) from e
|
|
170
229
|
except aiohttp.ClientResponseError as e:
|
|
171
230
|
raise InvalidAuthError(e) from e
|
|
172
|
-
try:
|
|
173
|
-
rtoken: Token = Token.model_validate(await response.json())
|
|
174
|
-
self._access_token = rtoken.access_token
|
|
175
|
-
self._headers["Authorization"] = f"Bearer {self._access_token}"
|
|
176
|
-
self._refresh_token = rtoken.refresh_token
|
|
177
|
-
if rtoken.expires_in < _MIN_TOKEN_LIFETIME:
|
|
178
|
-
_LOGGER.warning(
|
|
179
|
-
"Token expires in %ss which is below minimum lifetime of %ss- will refresh again on next operation",
|
|
180
|
-
rtoken.expires_in,
|
|
181
|
-
_MIN_TOKEN_LIFETIME,
|
|
182
|
-
)
|
|
183
|
-
self._expires_at = datetime.datetime.now(
|
|
184
|
-
datetime.UTC
|
|
185
|
-
) + datetime.timedelta(
|
|
186
|
-
seconds=rtoken.expires_in,
|
|
187
|
-
)
|
|
188
|
-
_LOGGER.debug(
|
|
189
|
-
"Authenticated session (%s), access_token=%s, expires at %s",
|
|
190
|
-
credentials["grant_type"],
|
|
191
|
-
self.access_token,
|
|
192
|
-
self.expiry_time,
|
|
193
|
-
)
|
|
194
|
-
except ValidationError as e:
|
|
195
|
-
msg = f"Received invalid auth response {response.status} with msg: {response.reason}"
|
|
196
|
-
raise InvalidAuthError(msg) from e
|
|
197
231
|
|
|
198
232
|
async def check_refresh_auth(self) -> None:
|
|
199
233
|
"""Do we have to refresh auth."""
|
|
@@ -221,8 +255,13 @@ class AsyncSession:
|
|
|
221
255
|
api_url = f"{self._api_host}/api/v2/{path}"
|
|
222
256
|
try:
|
|
223
257
|
_LOGGER.debug("Getting %s.", api_url)
|
|
224
|
-
|
|
225
|
-
|
|
258
|
+
async with self.client.get(
|
|
259
|
+
api_url, headers=self._headers
|
|
260
|
+
) as response:
|
|
261
|
+
response.raise_for_status()
|
|
262
|
+
data = await response.json()
|
|
263
|
+
_LOGGER.debug("Response %s.", data)
|
|
264
|
+
return data
|
|
226
265
|
except (
|
|
227
266
|
aiohttp.ClientConnectionError,
|
|
228
267
|
aiohttp.ClientConnectorError,
|
|
@@ -235,7 +274,6 @@ class AsyncSession:
|
|
|
235
274
|
e.status,
|
|
236
275
|
)
|
|
237
276
|
raise SmartboxError(e) from e
|
|
238
|
-
return await response.json()
|
|
239
277
|
|
|
240
278
|
async def _api_post(
|
|
241
279
|
self,
|
|
@@ -248,12 +286,13 @@ class AsyncSession:
|
|
|
248
286
|
try:
|
|
249
287
|
data_str = json.dumps(data)
|
|
250
288
|
_LOGGER.debug("Posting %s to %s.", data_str, api_url)
|
|
251
|
-
|
|
252
|
-
api_url,
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
289
|
+
async with self.client.post(
|
|
290
|
+
api_url, headers=self._headers, data=data_str
|
|
291
|
+
) as response:
|
|
292
|
+
response.raise_for_status()
|
|
293
|
+
data = await response.json()
|
|
294
|
+
_LOGGER.debug("Response %s.", data)
|
|
295
|
+
return data
|
|
257
296
|
except (
|
|
258
297
|
aiohttp.ClientConnectionError,
|
|
259
298
|
aiohttp.ClientConnectorError,
|
|
@@ -266,7 +305,6 @@ class AsyncSession:
|
|
|
266
305
|
e.status,
|
|
267
306
|
)
|
|
268
307
|
raise SmartboxError(e) from e
|
|
269
|
-
return await response.json()
|
|
270
308
|
|
|
271
309
|
|
|
272
310
|
class AsyncSmartboxSession(AsyncSession):
|
|
@@ -502,6 +540,25 @@ class AsyncSmartboxSession(AsyncSession):
|
|
|
502
540
|
path=f"devs/{device_id}/{_node.type}/{_node.addr}/setup",
|
|
503
541
|
)
|
|
504
542
|
|
|
543
|
+
async def get_node_version(
|
|
544
|
+
self,
|
|
545
|
+
device_id: str,
|
|
546
|
+
node: dict[str, Any],
|
|
547
|
+
) -> dict[str, Any] | NodeVersion:
|
|
548
|
+
"""Get a node setup."""
|
|
549
|
+
_node: Node = Node.model_validate(node)
|
|
550
|
+
response = await self._api_request(
|
|
551
|
+
f"devs/{device_id}/{_node.type}/{_node.addr}/version",
|
|
552
|
+
)
|
|
553
|
+
_LOGGER.debug("(%s) Version config data %s", _node.type, response)
|
|
554
|
+
if self.raw_response is True:
|
|
555
|
+
return response
|
|
556
|
+
try:
|
|
557
|
+
return NodeVersion.model_validate(response)
|
|
558
|
+
except ValidationError:
|
|
559
|
+
_LOGGER.exception("Version config validation error %s", response)
|
|
560
|
+
raise
|
|
561
|
+
|
|
505
562
|
|
|
506
563
|
class Session:
|
|
507
564
|
"""For retro compatibility, this class is a sync which called the async."""
|