Skip to content

Commit

Permalink
Add Pod serialisation for cost properties
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrayner committed Nov 12, 2022
1 parent 34ee28a commit 3d24b80
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion podpointclient/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ def dict(self) -> Dict[str, Any]:
"charge_schedules": [],
"total_kwh": self.total_kwh,
"total_charge_seconds": self.total_charge_seconds,
"current_kwh": self.current_kwh
"current_kwh": self.current_kwh,
"total_cost": self.total_cost,
"current_cost": self.current_cost
}

for status in self.statuses:
Expand Down
2 changes: 1 addition & 1 deletion podpointclient/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version for the podpointclient library"""

__version__ = "0.3.0-beta5"
__version__ = "0.3.0-beta6"
6 changes: 3 additions & 3 deletions tests/test_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ def test_happy_path():
def test_serialisation():
pod = Pod(data=complete_pod_fixture())

expected = {'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': 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}
expected = {'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', 'current_cost': 0, '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': 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 }

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}'
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, "current_cost": 0}'

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}'
Expand Down

0 comments on commit 3d24b80

Please sign in to comment.