Skip to content

Commit

Permalink
Add available_fn to vehicle sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Jan 31, 2024
1 parent 0f80305 commit bacf5f9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion custom_components/teslemetry/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class TeslemetrySensorEntityDescription(SensorEntityDescription):
device_class=SensorDeviceClass.TIMESTAMP,
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda value: dt_util.now() + timedelta(minutes=cast(float, value)),
available_fn=lambda value: value is not None and value > 0,
),
TeslemetrySensorEntityDescription(
key="charge_state_battery_range",
Expand Down Expand Up @@ -399,7 +400,7 @@ def native_value(self) -> StateType | datetime:
@property
def available(self) -> bool:
"""Return if sensor is available."""
return super().available and self.get() is not None
return super().available and self.entity_description.available_fn(self.get())


class TeslemetryEnergySensorEntity(TeslemetryEnergyEntity, SensorEntity):
Expand Down

0 comments on commit bacf5f9

Please sign in to comment.