From e323bd364761f9866dbb2adb6055bef394853d99 Mon Sep 17 00:00:00 2001 From: Remus Lazar Date: Mon, 1 Jul 2024 17:34:13 +0000 Subject: [PATCH] feat: Add availability property to DrivingAnalysisSensor The `DrivingAnalysisSensor` now includes an `available` property to indicate the sensor's availability. This property returns `True` if the data for driving analysis is available, and `False` otherwise. This change improves the overall functionality of the sensor. --- custom_components/nissan_carwings/sensor.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/custom_components/nissan_carwings/sensor.py b/custom_components/nissan_carwings/sensor.py index 6ba15a3..8277e62 100644 --- a/custom_components/nissan_carwings/sensor.py +++ b/custom_components/nissan_carwings/sensor.py @@ -182,6 +182,11 @@ def native_value(self) -> float | None: da: pycarwings3.responses.CarwingsDrivingAnalysisResponse = self.coordinator.data[DATA_DRIVING_ANALYSIS_KEY] return float(da.electric_mileage) + @property + def available(self) -> bool: + """Sensor availability.""" + return self.coordinator.data[DATA_DRIVING_ANALYSIS_KEY] is not None + @property def extra_state_attributes(self) -> dict[str, Any]: """Return default attributes for Nissan leaf entities."""