Skip to content

Commit

Permalink
Add new stream filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Mar 18, 2024
1 parent f5056ae commit 110e544
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions config/configuration.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# https://www.home-assistant.io/integrations/default_config/
default_config:

ffmpeg:

# https://www.home-assistant.io/integrations/logger/
logger:
default: info
Expand Down
14 changes: 9 additions & 5 deletions custom_components/teslemetry/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ async def async_added_to_hass(self) -> None:
await super().async_added_to_hass()
if self.stream.server:
self.async_on_remove(
self.stream.async_add_listener(self._handle_stream_update)
self.stream.async_add_listener(
self._handle_stream_update,
{"vin": self.vin, "data": {self.streaming_key: None}},
)
)

def _handle_stream_update(self, data: dict[str, Any]) -> None:
Expand Down Expand Up @@ -179,13 +182,14 @@ async def async_added_to_hass(self) -> None:
await super().async_added_to_hass()
if self.stream.server and self.streaming_key:
self.async_on_remove(
self.stream.async_add_listener(self._handle_stream_update)
self.stream.async_add_listener(
self._handle_stream_update,
{"vin": self.vin, "data": {self.streaming_key: None}},
)
)

def _handle_stream_update(self, data: dict[str, Any]) -> None:
"""Handle updated data from the stream."""
if (value := data["data"].get(self.streaming_key)) is None:
return
if data["timestamp"] < self._last_update:
LOGGER.warning(
"Streaming data of %s was %s seconds older than polling data",
Expand All @@ -194,7 +198,7 @@ def _handle_stream_update(self, data: dict[str, Any]) -> None:
)
return
self._last_update = data["timestamp"]
self._async_value_from_stream(value)
self._async_value_from_stream(data["data"][self.streaming_key])
self.async_write_ha_state()

def _handle_coordinator_update(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/teslemetry/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
],
"requirements": [
"tesla-fleet-api==0.4.9",
"teslemetry-stream==0.1.5"
"teslemetry-stream==0.2.0"
],
"version": "1.5.6"
}

0 comments on commit 110e544

Please sign in to comment.