From 42b93670fdcfbb0f153ce4fa0827e2d3aece6306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Strandberg?= Date: Fri, 23 Feb 2024 20:29:39 +0000 Subject: [PATCH 1/2] Add some imports to __init__ --- src/myuplink/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/myuplink/__init__.py b/src/myuplink/__init__.py index 627b4ff..f052246 100644 --- a/src/myuplink/__init__.py +++ b/src/myuplink/__init__.py @@ -2,5 +2,15 @@ from .api import MyUplinkAPI # noqa: F401 from .auth import Auth # noqa: F401 from .auth_abstract import AbstractAuth # noqa: F401 -from .models import System, SystemDevice, Device, DevicePoint, EnumValue # noqa: F401 +from .models import ( # noqa: F401 + Device, + DeviceConnectionState, + DevicePoint, + EnumValue, + Paging, + System, + SystemDevice, + SystemNotification, + SystemNotificationStatus, +) from .names import get_model, get_manufacturer, get_series, get_system_name # noqa:F401 From dc13d2fdf6afd0aecc66083cbbd2d5b47547899e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Strandberg?= Date: Fri, 8 Mar 2024 11:46:50 +0000 Subject: [PATCH 2/2] Enable cherry-picking of device points --- examples/example_specific_points.py | 48 +++++++++++++++++++++++++++++ src/myuplink/api.py | 13 +++++--- 2 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 examples/example_specific_points.py diff --git a/examples/example_specific_points.py b/examples/example_specific_points.py new file mode 100644 index 0000000..8d86bed --- /dev/null +++ b/examples/example_specific_points.py @@ -0,0 +1,48 @@ +"""List defined zones.""" +import asyncio +import aiohttp + +from my_token import MY_TOKEN + +from myuplink.auth import Auth +from myuplink import MyUplinkAPI + +PARAMETERS = ["40004", "40940", "40005"] + + +async def main(): + """Connect and print test data.""" + async with aiohttp.ClientSession() as session: + auth = Auth( + session, + "https://api.myuplink.com", + MY_TOKEN, + ) + api = MyUplinkAPI(auth) + + systems = await api.async_get_systems() + for system in systems: + print(f"System id: {system.id}") + print(f"System name: {system.name}") + + print(f"No of devices in system: {len(system.devices)}") + for sys_device in system.devices: + device = await api.async_get_device(sys_device.deviceId) + print(device.id) + print(device.productName) + print(device.productSerialNumber) + print(device.firmwareCurrent) + print(device.firmwareDesired) + print(device.connectionState) + + points = await api.async_get_device_points( + sys_device.deviceId, points=PARAMETERS + ) + for point in points: + print( + f"{point.parameter_id} | {point.parameter_name} | {point.value}" + ) + print() + + +asyncio.run(main()) diff --git a/src/myuplink/api.py b/src/myuplink/api.py index 05145cf..9c76e90 100644 --- a/src/myuplink/api.py +++ b/src/myuplink/api.py @@ -55,19 +55,24 @@ async def async_get_device_json(self, device_id) -> dict: return await resp.json() async def async_get_device_points( - self, device_id, language: str = "en-GB" + self, device_id, language: str = "en-GB", points: list[str] | None = None ) -> list[DevicePoint]: """Return device points.""" - array = await self.async_get_device_points_json(device_id, language) + array = await self.async_get_device_points_json(device_id, language, points) return [DevicePoint(point_data) for point_data in array] async def async_get_device_points_json( - self, device_id, language: str = "en-GB" + self, device_id, language: str = "en-GB", points: list[str] | None = None ) -> dict: """Return device points as json.""" headers = {"Accept-Language": language} + if points is None: + points = [] + params = "" + if len(points) > 0: + params = "?parameters=" + ",".join(points) resp = await self.auth.request( - "get", f"v2/devices/{device_id}/points", headers=headers + "get", f"v2/devices/{device_id}/points{params}", headers=headers ) resp.raise_for_status() return await resp.json()