Skip to content

Commit

Permalink
feat: Add availability property to DrivingAnalysisSensor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
remuslazar committed Jul 1, 2024
1 parent e825a02 commit e323bd3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions custom_components/nissan_carwings/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit e323bd3

Please sign in to comment.