Skip to content

Commit

Permalink
Fix avaliable
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Dec 19, 2024
1 parent c0cf8d1 commit a0e632e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
11 changes: 5 additions & 6 deletions custom_components/teslemetry/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,8 @@ def __init__(
def _async_update_attrs(self) -> None:
"""Update the attributes of the binary sensor."""

if self._value is None:
self._attr_available = False
self._attr_is_on = None
else:
self._attr_available = True
self._attr_available = self._value is not None
if self._attr_available:
self._attr_is_on = self.entity_description.polling_value_fn(self._value)


Expand Down Expand Up @@ -429,7 +426,9 @@ async def async_added_to_hass(self) -> None:

def _async_value_from_stream(self, value) -> None:
"""Update the value of the entity."""
self._attr_is_on = self.entity_description.streaming_value_fn(value)
self._attr_avaliable = value is not None
if self._attr_avaliable:
self._attr_is_on = self.entity_description.streaming_value_fn(value)


class TeslemetryEnergyLiveBinarySensorEntity(
Expand Down
3 changes: 1 addition & 2 deletions custom_components/teslemetry/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ async def async_added_to_hass(self) -> None:

def _handle_stream_update(self, data: dict[str, Any]) -> None:
"""Handle updated data from the stream."""

try:
self._async_value_from_stream(data["data"][self.streaming_key])
except Exception as e:
Expand All @@ -93,7 +92,7 @@ async def wake_up_if_asleep(self) -> None:
@cached_property
def available(self) -> bool:
"""Return True if entity is available."""
return self.stream.connected
return self.stream.connected and self._attr_available

class TeslemetryVehicleComplexStreamEntity(TeslemetryEntity):
"""Parent class for Teslemetry Vehicle Stream entities with multiple keys."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/teslemetry/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,7 @@ def _async_update_attrs(self) -> None:
if seconds == self._last_value:
return
self._last_value = seconds
self._attr_native_value = self._time_value(seconds)
self._attr_native_value = self._time_value(value)


class TeslemetryVehicleTimeStreamSensorEntity(TeslemetryVehicleStreamEntity, SensorEntity):
Expand Down

0 comments on commit a0e632e

Please sign in to comment.