solarlog-cli 0.3.2__tar.gz → 0.4.0__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.
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/.coverage +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/PKG-INFO +1 -2
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/pyproject.toml +1 -1
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/src/solarlog_cli/solarlog_client.py +13 -11
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/src/solarlog_cli/solarlog_connector.py +4 -1
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/test_solarlog_cli.py +21 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/.devcontainer/devcontainer.json +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/.github/workflows/pylint.yml +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/.github/workflows/python-publish.yml +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/.github/workflows/ruff.yml +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/.github/workflows/tests.yml +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/.github/workflows/typing.yml +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/.gitignore +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/.vscode/settings.json +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/.vscode/tasks.json +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/LICENSE +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/README.md +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/pytest.ini +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/requirements.txt +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/src/solarlog_cli/__init__.py +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/src/solarlog_cli/py.typed +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/src/solarlog_cli/solarlog_exceptions.py +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/src/solarlog_cli/solarlog_models.py +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/__init__.py +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/__snapshots__/test_solarlog_cli.ambr +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/conftest.py +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/fixtures/basic_data.json +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/fixtures/basic_data_during_update.json +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/fixtures/basic_data_no_power.json +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/fixtures/device_data_1.json +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/fixtures/device_data_2.json +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/fixtures/device_data_3.json +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/fixtures/device_data_4.json +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/fixtures/device_list.json +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/fixtures/device_list_access_denied.json +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/fixtures/energy_per_inverter.json +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/fixtures/extended_data.json +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/fixtures/power_per_inverter.json +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/ruff.toml +0 -0
- {solarlog_cli-0.3.2 → solarlog_cli-0.4.0}/tests/syrupy.py +0 -0
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: solarlog_cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Python library to access the Solar-Log
|
|
5
5
|
Project-URL: Repository, https://github.com/dontinelli/solarlog_cli.git
|
|
6
6
|
Project-URL: Issues, https://github.com/dontinelli/solarlog_cli/issues
|
|
@@ -8,7 +8,6 @@ Project-URL: Changelog, https://github.com/dontinelli/solarlog_cli/blob/master/C
|
|
|
8
8
|
Project-URL: Solar-Log homepage, https://www.solar-log.com/
|
|
9
9
|
Project-URL: API Documentation (inofficial), https://github.com/iobroker-community-adapters/ioBroker.solarlog/blob/master/docs/solarlog_dataobjects.md
|
|
10
10
|
Author-email: dontinelli <73341522+dontinelli@users.noreply.github.com>
|
|
11
|
-
License-File: LICENSE
|
|
12
11
|
Keywords: IoT,hass,home assistant,sensor,smart home,solar
|
|
13
12
|
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
|
14
13
|
Classifier: Operating System :: OS Independent
|
|
@@ -26,15 +26,17 @@ class Client:
|
|
|
26
26
|
|
|
27
27
|
# pylint: disable=too-many-positional-arguments
|
|
28
28
|
|
|
29
|
-
def __init__(self, host: str, password: str = "") -> None:
|
|
29
|
+
def __init__(self, host: str, session: ClientSession | None, password: str = "") -> None:
|
|
30
30
|
self.host: str = host
|
|
31
31
|
self.password: str = password
|
|
32
32
|
self.token: str = ""
|
|
33
33
|
|
|
34
34
|
self.request_timeout = 30
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
|
|
36
|
+
if not session:
|
|
37
|
+
self.session = ClientSession()
|
|
38
|
+
else:
|
|
39
|
+
self.session = session
|
|
38
40
|
|
|
39
41
|
self._close_session: bool = True
|
|
40
42
|
|
|
@@ -42,14 +44,15 @@ class Client:
|
|
|
42
44
|
async def test_connection(self) -> bool:
|
|
43
45
|
"""Test the connection to Solar-Log."""
|
|
44
46
|
if self.session is None:
|
|
45
|
-
self.session = ClientSession(
|
|
46
|
-
timeout=ClientTimeout(total=self.request_timeout)
|
|
47
|
-
)
|
|
47
|
+
self.session = ClientSession()
|
|
48
48
|
self._close_session = True
|
|
49
49
|
|
|
50
50
|
url = f"{self.host}/getjp"
|
|
51
51
|
|
|
52
|
-
response = await self.session.post(
|
|
52
|
+
response = await self.session.post(
|
|
53
|
+
url, json=SOLARLOG_REQUEST_PAYLOAD,
|
|
54
|
+
timeout=ClientTimeout(total=self.request_timeout)
|
|
55
|
+
)
|
|
53
56
|
|
|
54
57
|
if response.status == 200:
|
|
55
58
|
return True
|
|
@@ -85,9 +88,7 @@ class Client:
|
|
|
85
88
|
async def execute_http_request(self, body: str, path: str = "getjp") -> ClientResponse:
|
|
86
89
|
"""Helper function to process the HTTP Get call."""
|
|
87
90
|
if self.session is None:
|
|
88
|
-
self.session = ClientSession(
|
|
89
|
-
timeout=ClientTimeout(total=self.request_timeout)
|
|
90
|
-
)
|
|
91
|
+
self.session = ClientSession()
|
|
91
92
|
self._close_session = True
|
|
92
93
|
|
|
93
94
|
url = f"{self.host}/{path}"
|
|
@@ -105,6 +106,7 @@ class Client:
|
|
|
105
106
|
url=url,
|
|
106
107
|
headers=header,
|
|
107
108
|
data=body,
|
|
109
|
+
timeout=ClientTimeout(total=self.request_timeout),
|
|
108
110
|
)
|
|
109
111
|
except asyncio.TimeoutError as exception:
|
|
110
112
|
msg = f"Timeout occurred while connecting to Solar-Log at {self.host}"
|
|
@@ -4,6 +4,8 @@ from datetime import timezone, tzinfo
|
|
|
4
4
|
import logging
|
|
5
5
|
from zoneinfo import ZoneInfo
|
|
6
6
|
|
|
7
|
+
from aiohttp import ClientSession
|
|
8
|
+
|
|
7
9
|
from .solarlog_client import Client
|
|
8
10
|
from .solarlog_exceptions import(
|
|
9
11
|
SolarLogAuthenticationError,
|
|
@@ -28,8 +30,9 @@ class SolarLogConnector:
|
|
|
28
30
|
tz: str = "",
|
|
29
31
|
device_enabled: dict[int, bool] | None = None,
|
|
30
32
|
password: str = "",
|
|
33
|
+
session: ClientSession | None = None,
|
|
31
34
|
):
|
|
32
|
-
self.client = Client(host, password)
|
|
35
|
+
self.client = Client(host, session, password)
|
|
33
36
|
self.extended_data: bool = extended_data
|
|
34
37
|
|
|
35
38
|
self._device_list: dict[int, InverterData] = {}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Tests for solarlog_cli."""
|
|
2
2
|
|
|
3
3
|
from aioresponses import aioresponses
|
|
4
|
+
from aiohttp import ClientSession
|
|
4
5
|
|
|
5
6
|
import pytest
|
|
6
7
|
from syrupy.assertion import SnapshotAssertion
|
|
@@ -48,6 +49,26 @@ async def test_connection(
|
|
|
48
49
|
assert solarlog_connector.client.session.closed
|
|
49
50
|
|
|
50
51
|
|
|
52
|
+
async def test_existing_session(
|
|
53
|
+
responses: aioresponses,
|
|
54
|
+
) -> None:
|
|
55
|
+
"""Test connection."""
|
|
56
|
+
responses.post(
|
|
57
|
+
"localhost/getjp",
|
|
58
|
+
status=200,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
solarlog_connector = SolarLogConnector("localhost", session=ClientSession())
|
|
62
|
+
|
|
63
|
+
assert await solarlog_connector.test_connection()
|
|
64
|
+
|
|
65
|
+
assert solarlog_connector.host == "localhost"
|
|
66
|
+
|
|
67
|
+
assert solarlog_connector.client.session is not None
|
|
68
|
+
assert not solarlog_connector.client.session.closed
|
|
69
|
+
await solarlog_connector.client.close()
|
|
70
|
+
assert solarlog_connector.client.session.closed
|
|
71
|
+
|
|
51
72
|
async def test_extended_data_available(
|
|
52
73
|
responses: aioresponses,
|
|
53
74
|
) -> None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|