From 08f36722342a097c4560904f32028878405cbc18 Mon Sep 17 00:00:00 2001 From: ReneNulschDE Date: Sun, 2 Jun 2024 10:19:39 +0200 Subject: [PATCH] Fix LastParkevent NoneType check --- custom_components/mbapi2020/sensor.py | 32 +++------------------------ 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/custom_components/mbapi2020/sensor.py b/custom_components/mbapi2020/sensor.py index e9e95cbf..be8a444e 100644 --- a/custom_components/mbapi2020/sensor.py +++ b/custom_components/mbapi2020/sensor.py @@ -3,6 +3,7 @@ For more details about this component, please refer to the documentation at https://github.com/ReneNulschDE/mbapi2020/ """ + from __future__ import annotations from datetime import datetime @@ -97,22 +98,11 @@ def state(self): return "NOT_RECEIVED" if self._internal_name == "lastParkEvent": - # try: - return datetime.fromtimestamp(int(self._state)) - # finally: - # return None + if self._state: + return datetime.fromtimestamp(int(self._state)) return self._state - # async def async_added_to_hass(self) -> None: - # """Call when entity about to be added to Home Assistant.""" - # await super().async_added_to_hass() - # # __init__ will set self._state to self._initial, only override - # # if needed. - - # if (last_sensor_data := await self.async_get_last_sensor_data()) is not None: - # self._state = last_sensor_data.native_value - class MercedesMESensorPoll(MercedesMeEntity, RestoreSensor): """Representation of a Sensor.""" @@ -130,19 +120,3 @@ def state(self): return "NOT_RECEIVED" return self._state - - # async def async_added_to_hass(self) -> None: - # """Call when entity about to be added to Home Assistant.""" - # await super().async_added_to_hass() - # # __init__ will set self._state to self._initial, only override - # # if needed. - # if (last_sensor_data := await self.async_get_last_sensor_data()) is not None: - # self._state = last_sensor_data.native_value - - # async def async_update(self): - # """Get the latest data and updates the states.""" - # LOGGER.debug("Updating %s", self._internal_name) - - # await self._coordinator.client.update_poll_states(self._vin) - - # self._state = self._get_car_value(self._feature_name, self._object_name, self._attrib_name, "error")