diff --git a/psa_car_controller/psacc/application/psa_client.py b/psa_car_controller/psacc/application/psa_client.py index 25b6030..bef30ce 100644 --- a/psa_car_controller/psacc/application/psa_client.py +++ b/psa_car_controller/psacc/application/psa_client.py @@ -182,7 +182,10 @@ class PSAClient: mileage = car.status.timed_odometer.mileage level = car.status.get_energy('Electric').level level_fuel = car.status.get_energy('Fuel').level - charge_date = car.status.get_energy('Electric').updated_at + if car.is_thermal(): + charge_date = car.status.get_energy('Fuel').updated_at + else: + charge_date = car.status.get_energy('Electric').updated_at moving = car.status.kinetic.moving longitude = car.status.last_position.geometry.coordinates[0] diff --git a/tests/data/car_status.py b/tests/data/car_status.py index 6c806a7..b63d880 100644 --- a/tests/data/car_status.py +++ b/tests/data/car_status.py @@ -5,8 +5,8 @@ FUEL_CAR_STATUS = { 'airConditioning': {'updatedAt': '2021-04-01T16:17:01Z', 'status': 'Disabled', 'programs': [ {'enabled': False, 'slot': 1, 'recurrence': 'Daily', 'start': 'PT21H40M', 'occurence': {'day': ['Sat']}}]}}, - 'energy': [{'createdAt': '2021-02-23T22:29:03Z', 'type': 'Fuel', 'level': 0}, - {'createdAt': '2021-04-01T16:17:01Z', 'type': 'Electric', 'level': 70, 'autonomy': 192, + 'energy': [{'updatedAt': '2021-02-23T22:29:03Z', 'type': 'Fuel', 'level': 42}, + {'updatedAt': '2021-04-01T16:17:01Z', 'type': 'Electric', 'level': 70, 'autonomy': 192, 'charging': {'plugged': True, 'status': 'InProgress', 'remainingTime': 'PT0S', 'chargingRate': 20, 'chargingMode': 'Slow', 'nextDelayedTime': 'PT21H30M'}}], 'createdAt': '2021-04-01T16:17:01Z', @@ -24,8 +24,8 @@ ELECTRIC_CAR_STATUS = { "lastPosition": {"type": "Feature", "geometry": {"type": "Point", "coordinates": [-1.59008, 47.274, 30]}, "properties": {"updatedAt": "2021-03-29T06:22:51Z", "type": "Acquire", "signalQuality": 9}}, "preconditionning": {"airConditioning": {"updatedAt": "2022-03-26T10:52:11Z", "status": "Disabled"}}, - "energy": [{"createdAt": "2021-09-14T20:39:06Z", "type": "Fuel", "level": 0}, - {"createdAt": "2022-03-26T11:02:54Z", "type": "Electric", "level": 59, "autonomy": 122, + "energy": [{"updatedAt": "2021-09-14T20:39:06Z", "type": "Fuel", "level": 0}, + {"updatedAt": "2022-03-26T11:02:54Z", "type": "Electric", "level": 59, "autonomy": 122, "charging": {"plugged": False, "status": "Disconnected", "remainingTime": "PT0S", "chargingRate": 0, "chargingMode": "No", "nextDelayedTime": "PT22H31M"}}], "createdAt": "2022-03-26T11:02:54Z", @@ -42,7 +42,7 @@ ELECTRIC_CAR_STATUS_V2 = { "properties": {"updatedAt": "2021-03-29T06:22:51Z", "type": "Acquire", "signalQuality": 9}}, "preconditionning": {"airConditioning": {"updatedAt": "2022-03-26T10:52:11Z", "status": "Disabled"}}, "energy": [{"createdAt": "2021-09-14T20:39:06Z", "type": "Fuel", "level": 0}, - {"createdAt": "2022-03-26T11:02:54Z", "type": "Electric", "level": 59, "autonomy": 122, + {"updatedAt": "2022-03-26T11:02:54Z", "type": "Electric", "level": 59, "autonomy": 122, "charging": {"plugged": False, "status": "Disconnected", "remainingTime": "PT0S", "chargingRate": 0, "chargingMode": "No", "nextDelayedTime": "PT22H31M"}, "battery": {"health": {"resistance": 90}}}],