From d8204a17c096c66113a9932b5a7d7a921fe1b826 Mon Sep 17 00:00:00 2001 From: Josias Montag Date: Thu, 4 May 2023 12:54:02 +0200 Subject: [PATCH 1/2] Add charging timer sensor --- custom_components/porscheconnect/__init__.py | 12 +++++++++++- custom_components/porscheconnect/const.py | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) mode change 100644 => 100755 custom_components/porscheconnect/__init__.py diff --git a/custom_components/porscheconnect/__init__.py b/custom_components/porscheconnect/__init__.py old mode 100644 new mode 100755 index c2deb53..84d90a1 --- a/custom_components/porscheconnect/__init__.py +++ b/custom_components/porscheconnect/__init__.py @@ -172,6 +172,16 @@ async def _update_data_for_vehicle(self, vehicle): for item in vdata["chargingProfiles"]["profiles"] } ) + + + vdata["timersDict"] = {} + vdata["currentTimerId"] = None + for item in vdata.get("timers", []): + if item.get("active", False) and vdata["currentTimerId"] is None: + vdata["currentTimerId"] = item["timerID"] + vdata["timersDict"].update({item["timerID"]: item}) + + if vdata["services"]["vehicleServiceEnabledMap"]["CF"] == "ENABLED": vdata.update(await self.controller.getPosition(vin)) return vdata @@ -225,7 +235,7 @@ async def _async_update_data(self): sensor_meta, sensor_data, ) - if sensor_data is not None: + if sensor_data is not None or len(sensor_meta.attributes) > 0: ha_type = "sensor" if isinstance(sensor_meta, SwitchMeta): ha_type = "switch" diff --git a/custom_components/porscheconnect/const.py b/custom_components/porscheconnect/const.py index 6f9709b..f490f9d 100644 --- a/custom_components/porscheconnect/const.py +++ b/custom_components/porscheconnect/const.py @@ -125,6 +125,12 @@ class SensorAttr: "mdi:battery-charging", attributes=[SensorAttr("profiles", "chargingProfilesDict")], ), + SensorMeta( + "charging timer", + "currentTimerId", + "mdi:car-clock", + attributes=[SensorAttr("timers", "timersDict")], + ), SwitchMeta( "climate", "directClimatisation.climatisationState", @@ -176,6 +182,7 @@ class SensorAttr: "remainingRanges.electricalRange.distance": "range", "chargingStatus": "charger", "chargingProfiles.currentProfileId": "charging profile", + "currentTimerId": "charging timer", "directClimatisation.climatisationState": "climatisation", "directCharge.isActive": "direct charge", "doors.overallLockStatus": "door lock", From 9805b6d40e0b6da469d15e49acc7beba7e3d84f4 Mon Sep 17 00:00:00 2001 From: Josias Montag Date: Thu, 4 May 2023 13:03:10 +0200 Subject: [PATCH 2/2] linting --- custom_components/porscheconnect/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/custom_components/porscheconnect/__init__.py b/custom_components/porscheconnect/__init__.py index 84d90a1..404cd61 100755 --- a/custom_components/porscheconnect/__init__.py +++ b/custom_components/porscheconnect/__init__.py @@ -172,7 +172,6 @@ async def _update_data_for_vehicle(self, vehicle): for item in vdata["chargingProfiles"]["profiles"] } ) - vdata["timersDict"] = {} vdata["currentTimerId"] = None @@ -181,7 +180,6 @@ async def _update_data_for_vehicle(self, vehicle): vdata["currentTimerId"] = item["timerID"] vdata["timersDict"].update({item["timerID"]: item}) - if vdata["services"]["vehicleServiceEnabledMap"]["CF"] == "ENABLED": vdata.update(await self.controller.getPosition(vin)) return vdata