From 8cdf7fb7c032c6b87510e635e08744c29b0b6bc6 Mon Sep 17 00:00:00 2001 From: Matt Rayner Date: Mon, 8 Apr 2024 15:10:11 +0100 Subject: [PATCH] Add connectivity_status to Pod (#17) --- podpointclient/pod.py | 5 ++++- podpointclient/version.py | 2 +- tests/test_pod.py | 4 ++-- tests/test_user.py | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/podpointclient/pod.py b/podpointclient/pod.py index 59f4bc6..27cd5d2 100644 --- a/podpointclient/pod.py +++ b/podpointclient/pod.py @@ -11,6 +11,7 @@ from .charge import Charge from .charge_mode import ChargeMode from .charge_override import ChargeOverride +from .connectivity_status import ConnectivityStatus class StatusName(StrEnum): @@ -165,6 +166,7 @@ def __init__(self, data: Dict[str, Any]): self.offering_energy: bool = False self.last_message_at: datetime = None self.charging_state: str = None + self.connectivity_status: ConnectivityStatus = None self.firmware: Union(Firmware, None) = None @@ -288,7 +290,8 @@ def dict(self) -> Dict[str, Any]: "charge_override": None, "offering_energy": self.offering_energy, "last_message_at": lazy_iso_format_datetime(self.last_message_at), - "charging_state": self.charging_state if self.charging_state is not None else "Unknown" + "charging_state": self.charging_state if self.charging_state is not None else "Unknown", + "connectivity_status": self.connectivity_status.dict if self.connectivity_status is not None else None, } for status in self.statuses: diff --git a/podpointclient/version.py b/podpointclient/version.py index 92a3818..093e107 100644 --- a/podpointclient/version.py +++ b/podpointclient/version.py @@ -1,3 +1,3 @@ """Version for the podpointclient library""" -__version__ = "1.6.0" +__version__ = "1.6.1" diff --git a/tests/test_pod.py b/tests/test_pod.py index a4e1482..e992095 100644 --- a/tests/test_pod.py +++ b/tests/test_pod.py @@ -220,11 +220,11 @@ def test_serialisation(): pod = Pod(data=complete_pod_fixture()) pod.firmware = Firmware(data=complete_firmware_fixture()) - expected = {'id': 113113, 'name': 'Foo Pod', 'ppid': 'PSL-254321', 'offering_energy': False, 'payg': False, 'home': True, 'public': False, 'evZone': False, 'location': {'lat': 51.4995, 'lng': 0.1248}, 'address_id': 987, 'description': 'My pod description', 'charging_state': 'Unknown', 'commissioned_at': '2022-01-01T09:00:00+00:00', 'created_at': '2022-02-01T10:00:00+00:00', 'last_contact_at': '2022-01-11T02:15:59+01:00', 'last_message_at': None, 'contactless_enabled': False, 'unit_id': 198765, 'timezone': 'UTC', 'model': {'id': 123, 'name': 'S7-UC-03-ACA', 'vendor': 'Pod Point', 'supports_payg': False, 'supports_ocpp': False, 'supports_contactless': False, 'image_url': None}, 'price': None, 'statuses': [{'id': 2, 'name': 'Charging', 'key_name': 'charging', 'label': 'Charging', 'door': 'A', 'door_id': 1}], 'unit_connectors': [{'connector': {'id': 123, 'door': 'A', 'door_id': 1, 'power': 7, 'current': 32, 'voltage': 230, 'charge_method': 'Single Phase AC', 'has_cable': False, 'socket': {'type': 'IEC 62196-2 Type 2', 'description': 'Type 2 socket', 'ocpp_name': 'sType2', 'ocpp_code': 3}}}], 'charge_schedules': [ + expected = {'id': 113113, 'name': 'Foo Pod', 'ppid': 'PSL-254321', 'offering_energy': False, 'payg': False, 'home': True, 'public': False, 'evZone': False, 'location': {'lat': 51.4995, 'lng': 0.1248}, 'address_id': 987, 'description': 'My pod description', 'charging_state': 'Unknown', 'connectivity_status': None, 'commissioned_at': '2022-01-01T09:00:00+00:00', 'created_at': '2022-02-01T10:00:00+00:00', 'last_contact_at': '2022-01-11T02:15:59+01:00', 'last_message_at': None, 'contactless_enabled': False, 'unit_id': 198765, 'timezone': 'UTC', 'model': {'id': 123, 'name': 'S7-UC-03-ACA', 'vendor': 'Pod Point', 'supports_payg': False, 'supports_ocpp': False, 'supports_contactless': False, 'image_url': None}, 'price': None, 'statuses': [{'id': 2, 'name': 'Charging', 'key_name': 'charging', 'label': 'Charging', 'door': 'A', 'door_id': 1}], 'unit_connectors': [{'connector': {'id': 123, 'door': 'A', 'door_id': 1, 'power': 7, 'current': 32, 'voltage': 230, 'charge_method': 'Single Phase AC', 'has_cable': False, 'socket': {'type': 'IEC 62196-2 Type 2', 'description': 'Type 2 socket', 'ocpp_name': 'sType2', 'ocpp_code': 3}}}], 'charge_schedules': [ {'uid': 'a18eb318-f84b-48a8-9f84-e5cb44e32b16', 'start_day': 1, 'start_time': '00:00:00', 'end_day': 1, 'end_time': '00:00:01', 'status': {'is_active': True}}, {'uid': 'ec1a9a6c-bb4e-4435-a676-06eea8fd8f1a', 'start_day': 2, 'start_time': '00:00:00', 'end_day': 2, 'end_time': '00:00:01', 'status': {'is_active': True}}, {'uid': 'c5447a64-0aeb-4e1e-9af1-c5e13b7acf0c', 'start_day': 3, 'start_time': '00:00:00', 'end_day': 3, 'end_time': '00:00:01', 'status': {'is_active': True}}, {'uid': '8de14592-47f8-4102-a2a8-ef0638a97eb8', 'start_day': 4, 'start_time': '00:00:00', 'end_day': 4, 'end_time': '00:00:01', 'status': {'is_active': True}}, {'uid': '8e7ff42e-d1a4-4fa1-985f-7a5768d16852', 'start_day': 5, 'start_time': '00:00:00', 'end_day': 5, 'end_time': '00:00:01', 'status': {'is_active': False}}, {'uid': 'dfa4d6e5-fb69-43d1-85b1-41c818f6940e', 'start_day': 6, 'start_time': '00:00:00', 'end_day': 6, 'end_time': '00:00:01', 'status': {'is_active': False}}, {'uid': 'fd378f0b-c91a-4377-ab02-7d668a505b5b', 'start_day': 7, 'start_time': '00:00:00', 'end_day': 7, 'end_time': '00:00:01', 'status': {'is_active': False}}], "current_kwh": 0.0, "total_kwh": 0.0, "total_charge_seconds": 0, "total_cost": 0, "firmware": {'serial_number': '123456789', 'update_status': {'is_update_available': False}, 'version_info': {'manifest_id': 'A30P-3.1.22-00001'}}, 'charge_override': None } assert pod.dict == expected - assert pod.to_json() == '{"id": 113113, "name": "Foo Pod", "ppid": "PSL-254321", "payg": false, "home": true, "public": false, "evZone": false, "location": {"lat": 51.4995, "lng": 0.1248}, "address_id": 987, "description": "My pod description", "commissioned_at": "2022-01-01T09:00:00+00:00", "created_at": "2022-02-01T10:00:00+00:00", "last_contact_at": "2022-01-11T02:15:59+01:00", "contactless_enabled": false, "unit_id": 198765, "timezone": "UTC", "model": {"id": 123, "name": "S7-UC-03-ACA", "vendor": "Pod Point", "supports_payg": false, "supports_ocpp": false, "supports_contactless": false, "image_url": null}, "price": null, "statuses": [{"id": 2, "name": "Charging", "key_name": "charging", "label": "Charging", "door": "A", "door_id": 1}], "unit_connectors": [{"connector": {"id": 123, "door": "A", "door_id": 1, "power": 7, "current": 32, "voltage": 230, "charge_method": "Single Phase AC", "has_cable": false, "socket": {"type": "IEC 62196-2 Type 2", "description": "Type 2 socket", "ocpp_name": "sType2", "ocpp_code": 3}}}], "charge_schedules": [{"uid": "a18eb318-f84b-48a8-9f84-e5cb44e32b16", "start_day": 1, "start_time": "00:00:00", "end_day": 1, "end_time": "00:00:01", "status": {"is_active": true}}, {"uid": "ec1a9a6c-bb4e-4435-a676-06eea8fd8f1a", "start_day": 2, "start_time": "00:00:00", "end_day": 2, "end_time": "00:00:01", "status": {"is_active": true}}, {"uid": "c5447a64-0aeb-4e1e-9af1-c5e13b7acf0c", "start_day": 3, "start_time": "00:00:00", "end_day": 3, "end_time": "00:00:01", "status": {"is_active": true}}, {"uid": "8de14592-47f8-4102-a2a8-ef0638a97eb8", "start_day": 4, "start_time": "00:00:00", "end_day": 4, "end_time": "00:00:01", "status": {"is_active": true}}, {"uid": "8e7ff42e-d1a4-4fa1-985f-7a5768d16852", "start_day": 5, "start_time": "00:00:00", "end_day": 5, "end_time": "00:00:01", "status": {"is_active": false}}, {"uid": "dfa4d6e5-fb69-43d1-85b1-41c818f6940e", "start_day": 6, "start_time": "00:00:00", "end_day": 6, "end_time": "00:00:01", "status": {"is_active": false}}, {"uid": "fd378f0b-c91a-4377-ab02-7d668a505b5b", "start_day": 7, "start_time": "00:00:00", "end_day": 7, "end_time": "00:00:01", "status": {"is_active": false}}], "total_kwh": 0.0, "total_charge_seconds": 0, "current_kwh": 0.0, "total_cost": 0, "firmware": {"serial_number": "123456789", "version_info": {"manifest_id": "A30P-3.1.22-00001"}, "update_status": {"is_update_available": false}}, "charge_override": null, "offering_energy": false, "last_message_at": null, "charging_state": "Unknown"}' + assert pod.to_json() == '{"id": 113113, "name": "Foo Pod", "ppid": "PSL-254321", "payg": false, "home": true, "public": false, "evZone": false, "location": {"lat": 51.4995, "lng": 0.1248}, "address_id": 987, "description": "My pod description", "commissioned_at": "2022-01-01T09:00:00+00:00", "created_at": "2022-02-01T10:00:00+00:00", "last_contact_at": "2022-01-11T02:15:59+01:00", "contactless_enabled": false, "unit_id": 198765, "timezone": "UTC", "model": {"id": 123, "name": "S7-UC-03-ACA", "vendor": "Pod Point", "supports_payg": false, "supports_ocpp": false, "supports_contactless": false, "image_url": null}, "price": null, "statuses": [{"id": 2, "name": "Charging", "key_name": "charging", "label": "Charging", "door": "A", "door_id": 1}], "unit_connectors": [{"connector": {"id": 123, "door": "A", "door_id": 1, "power": 7, "current": 32, "voltage": 230, "charge_method": "Single Phase AC", "has_cable": false, "socket": {"type": "IEC 62196-2 Type 2", "description": "Type 2 socket", "ocpp_name": "sType2", "ocpp_code": 3}}}], "charge_schedules": [{"uid": "a18eb318-f84b-48a8-9f84-e5cb44e32b16", "start_day": 1, "start_time": "00:00:00", "end_day": 1, "end_time": "00:00:01", "status": {"is_active": true}}, {"uid": "ec1a9a6c-bb4e-4435-a676-06eea8fd8f1a", "start_day": 2, "start_time": "00:00:00", "end_day": 2, "end_time": "00:00:01", "status": {"is_active": true}}, {"uid": "c5447a64-0aeb-4e1e-9af1-c5e13b7acf0c", "start_day": 3, "start_time": "00:00:00", "end_day": 3, "end_time": "00:00:01", "status": {"is_active": true}}, {"uid": "8de14592-47f8-4102-a2a8-ef0638a97eb8", "start_day": 4, "start_time": "00:00:00", "end_day": 4, "end_time": "00:00:01", "status": {"is_active": true}}, {"uid": "8e7ff42e-d1a4-4fa1-985f-7a5768d16852", "start_day": 5, "start_time": "00:00:00", "end_day": 5, "end_time": "00:00:01", "status": {"is_active": false}}, {"uid": "dfa4d6e5-fb69-43d1-85b1-41c818f6940e", "start_day": 6, "start_time": "00:00:00", "end_day": 6, "end_time": "00:00:01", "status": {"is_active": false}}, {"uid": "fd378f0b-c91a-4377-ab02-7d668a505b5b", "start_day": 7, "start_time": "00:00:00", "end_day": 7, "end_time": "00:00:01", "status": {"is_active": false}}], "total_kwh": 0.0, "total_charge_seconds": 0, "current_kwh": 0.0, "total_cost": 0, "firmware": {"serial_number": "123456789", "version_info": {"manifest_id": "A30P-3.1.22-00001"}, "update_status": {"is_update_available": false}}, "charge_override": null, "offering_energy": false, "last_message_at": null, "charging_state": "Unknown", "connectivity_status": null}' assert pod.unit_connectors[0].to_json() == '{"id": 123, "door": "A", "door_id": 1, "power": 7, "current": 32, "voltage": 230, "charge_method": "Single Phase AC", "has_cable": false, "socket": {"type": "IEC 62196-2 Type 2", "description": "Type 2 socket", "ocpp_name": "sType2", "ocpp_code": 3}}' assert pod.unit_connectors[0].socket.to_json() == '{"type": "IEC 62196-2 Type 2", "description": "Type 2 socket", "ocpp_name": "sType2", "ocpp_code": 3}' diff --git a/tests/test_user.py b/tests/test_user.py index 2f65293..839ccdc 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -169,6 +169,7 @@ def test_complete_user(): 'uid': 'f79028be-00e9-4a86-a6c4-d474b7aaab37'}], 'charge_override': None, 'charging_state': 'Unknown', + 'connectivity_status': None, 'commissioned_at': '2022-01-25T09:00:00+00:00', 'contactless_enabled': False, 'created_at': '2022-02-13T10:39:05+00:00', @@ -241,4 +242,4 @@ def test_complete_user(): 'name': 'C5 Aircross Plug-in Hybrid', 'startYear': None, 'uuid': 'citroenC5AircrossPlugInHybrid'}} - assert user.to_json() == '{"id": 123456, "email": "podpoint@example.com", "first_name": "Example", "last_name": "User", "role": "user", "hasHomeCharge": 1, "locale": "en", "preferences": [{"unitOfDistance": "mi"}], "account": {"user_id": 123456, "uid": "1a756c9b-dfac-4c2a-ba13-9cdcc2399366", "balance": 173, "currency": "GBP", "billing_address": {"business_name": "", "address1": "", "address2": "", "town": "", "postcode": "", "country": ""}, "phone": "", "mobile": null}, "vehicle": {"id": 129, "uuid": "citroenC5AircrossPlugInHybrid", "name": "C5 Aircross Plug-in Hybrid", "capacity": 7, "batteryCapacity": 13.2, "startYear": null, "endYear": null, "image": {"@1x": "https://pod-point-admin-images-prod.imgix.net/vehicle-model-images/8eb13aeaf566eaedbe648bab8a5c14c0.png?w=0.5&h=0.5", "@2x": "https://pod-point-admin-images-prod.imgix.net/vehicle-model-images/8eb13aeaf566eaedbe648bab8a5c14c0.png?w=0.75&h=0.75", "@3x": "https://pod-point-admin-images-prod.imgix.net/vehicle-model-images/8eb13aeaf566eaedbe648bab8a5c14c0.png"}, "make": {"id": 22, "name": "Citroen", "logo": {"@1x": "https://pod-point-admin-images-prod.imgix.net/vehicle-make-logos/315261a80a1287b6d1b70f5c0fa8ccde.png?w=0.5&h=0.5", "@2x": "https://pod-point-admin-images-prod.imgix.net/vehicle-make-logos/315261a80a1287b6d1b70f5c0fa8ccde.png?w=0.75&h=0.75", "@3x": "https://pod-point-admin-images-prod.imgix.net/vehicle-make-logos/315261a80a1287b6d1b70f5c0fa8ccde.png"}}}, "unit": {"id": 123456, "ppid": "211092", "name": null, "status": "Available", "architecture": "soloArch3", "pod": {"id": 123456, "name": null, "ppid": "PSL-211092", "payg": false, "home": true, "public": false, "evZone": false, "location": {"lat": 23.543643, "lng": 7.2434543}, "address_id": 12345, "description": "", "commissioned_at": "2022-01-25T09:00:00+00:00", "created_at": "2022-02-13T10:39:05+00:00", "last_contact_at": "2023-01-10T19:17:12+00:00", "contactless_enabled": false, "unit_id": 123456, "timezone": "UTC", "model": {"id": 256, "name": "S7-UC-03-ACA", "vendor": "Pod Point", "supports_payg": false, "supports_ocpp": false, "supports_contactless": false, "image_url": null}, "price": null, "statuses": [{"id": 1, "name": "Available", "key_name": "available", "label": "Available", "door": "A", "door_id": 1}], "unit_connectors": [{"connector": {"id": 303, "door": "A", "door_id": 1, "power": 7, "current": 32, "voltage": 230, "charge_method": "Single Phase AC", "has_cable": false, "socket": {"type": "IEC 62196-2 Type 2", "description": "Type 2 socket", "ocpp_name": "sType2", "ocpp_code": 3}}}], "charge_schedules": [{"uid": "2e47721e-cdb2-49d7-ba47-f956975b7ed5", "start_day": 1, "start_time": "00:00:00", "end_day": 1, "end_time": "00:00:01", "status": {"is_active": false}}, {"uid": "bf3188eb-745e-4fbd-baa9-8a141eb708ed", "start_day": 2, "start_time": "00:00:00", "end_day": 2, "end_time": "00:00:01", "status": {"is_active": false}}, {"uid": "80eeba4b-2e69-4e04-a1e9-6e7dfc88528e", "start_day": 3, "start_time": "00:00:00", "end_day": 3, "end_time": "00:00:01", "status": {"is_active": false}}, {"uid": "3fddde7d-0809-43b3-8d16-64faf8a84e97", "start_day": 4, "start_time": "00:00:00", "end_day": 4, "end_time": "00:00:01", "status": {"is_active": false}}, {"uid": "79e69a06-2c3a-442b-a65f-5766140d8874", "start_day": 5, "start_time": "00:00:00", "end_day": 5, "end_time": "00:00:01", "status": {"is_active": false}}, {"uid": "0d2e6fdc-2a3d-4808-84e1-22e1d9d10be8", "start_day": 6, "start_time": "00:00:00", "end_day": 6, "end_time": "00:00:01", "status": {"is_active": false}}, {"uid": "f79028be-00e9-4a86-a6c4-d474b7aaab37", "start_day": 7, "start_time": "00:00:00", "end_day": 7, "end_time": "00:00:01", "status": {"is_active": false}}], "total_kwh": 0.0, "total_charge_seconds": 0, "current_kwh": 0.0, "total_cost": 0, "firmware": null, "charge_override": null, "offering_energy": false, "last_message_at": null, "charging_state": "Unknown"}}}' + assert user.to_json() == '{"id": 123456, "email": "podpoint@example.com", "first_name": "Example", "last_name": "User", "role": "user", "hasHomeCharge": 1, "locale": "en", "preferences": [{"unitOfDistance": "mi"}], "account": {"user_id": 123456, "uid": "1a756c9b-dfac-4c2a-ba13-9cdcc2399366", "balance": 173, "currency": "GBP", "billing_address": {"business_name": "", "address1": "", "address2": "", "town": "", "postcode": "", "country": ""}, "phone": "", "mobile": null}, "vehicle": {"id": 129, "uuid": "citroenC5AircrossPlugInHybrid", "name": "C5 Aircross Plug-in Hybrid", "capacity": 7, "batteryCapacity": 13.2, "startYear": null, "endYear": null, "image": {"@1x": "https://pod-point-admin-images-prod.imgix.net/vehicle-model-images/8eb13aeaf566eaedbe648bab8a5c14c0.png?w=0.5&h=0.5", "@2x": "https://pod-point-admin-images-prod.imgix.net/vehicle-model-images/8eb13aeaf566eaedbe648bab8a5c14c0.png?w=0.75&h=0.75", "@3x": "https://pod-point-admin-images-prod.imgix.net/vehicle-model-images/8eb13aeaf566eaedbe648bab8a5c14c0.png"}, "make": {"id": 22, "name": "Citroen", "logo": {"@1x": "https://pod-point-admin-images-prod.imgix.net/vehicle-make-logos/315261a80a1287b6d1b70f5c0fa8ccde.png?w=0.5&h=0.5", "@2x": "https://pod-point-admin-images-prod.imgix.net/vehicle-make-logos/315261a80a1287b6d1b70f5c0fa8ccde.png?w=0.75&h=0.75", "@3x": "https://pod-point-admin-images-prod.imgix.net/vehicle-make-logos/315261a80a1287b6d1b70f5c0fa8ccde.png"}}}, "unit": {"id": 123456, "ppid": "211092", "name": null, "status": "Available", "architecture": "soloArch3", "pod": {"id": 123456, "name": null, "ppid": "PSL-211092", "payg": false, "home": true, "public": false, "evZone": false, "location": {"lat": 23.543643, "lng": 7.2434543}, "address_id": 12345, "description": "", "commissioned_at": "2022-01-25T09:00:00+00:00", "created_at": "2022-02-13T10:39:05+00:00", "last_contact_at": "2023-01-10T19:17:12+00:00", "contactless_enabled": false, "unit_id": 123456, "timezone": "UTC", "model": {"id": 256, "name": "S7-UC-03-ACA", "vendor": "Pod Point", "supports_payg": false, "supports_ocpp": false, "supports_contactless": false, "image_url": null}, "price": null, "statuses": [{"id": 1, "name": "Available", "key_name": "available", "label": "Available", "door": "A", "door_id": 1}], "unit_connectors": [{"connector": {"id": 303, "door": "A", "door_id": 1, "power": 7, "current": 32, "voltage": 230, "charge_method": "Single Phase AC", "has_cable": false, "socket": {"type": "IEC 62196-2 Type 2", "description": "Type 2 socket", "ocpp_name": "sType2", "ocpp_code": 3}}}], "charge_schedules": [{"uid": "2e47721e-cdb2-49d7-ba47-f956975b7ed5", "start_day": 1, "start_time": "00:00:00", "end_day": 1, "end_time": "00:00:01", "status": {"is_active": false}}, {"uid": "bf3188eb-745e-4fbd-baa9-8a141eb708ed", "start_day": 2, "start_time": "00:00:00", "end_day": 2, "end_time": "00:00:01", "status": {"is_active": false}}, {"uid": "80eeba4b-2e69-4e04-a1e9-6e7dfc88528e", "start_day": 3, "start_time": "00:00:00", "end_day": 3, "end_time": "00:00:01", "status": {"is_active": false}}, {"uid": "3fddde7d-0809-43b3-8d16-64faf8a84e97", "start_day": 4, "start_time": "00:00:00", "end_day": 4, "end_time": "00:00:01", "status": {"is_active": false}}, {"uid": "79e69a06-2c3a-442b-a65f-5766140d8874", "start_day": 5, "start_time": "00:00:00", "end_day": 5, "end_time": "00:00:01", "status": {"is_active": false}}, {"uid": "0d2e6fdc-2a3d-4808-84e1-22e1d9d10be8", "start_day": 6, "start_time": "00:00:00", "end_day": 6, "end_time": "00:00:01", "status": {"is_active": false}}, {"uid": "f79028be-00e9-4a86-a6c4-d474b7aaab37", "start_day": 7, "start_time": "00:00:00", "end_day": 7, "end_time": "00:00:01", "status": {"is_active": false}}], "total_kwh": 0.0, "total_charge_seconds": 0, "current_kwh": 0.0, "total_cost": 0, "firmware": null, "charge_override": null, "offering_energy": false, "last_message_at": null, "charging_state": "Unknown", "connectivity_status": null}}}'