Skip to content

Commit

Permalink
Fix streaming values
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Jun 30, 2024
1 parent a00781f commit 7a22bc4
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 7 deletions.
6 changes: 6 additions & 0 deletions custom_components/teslemetry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
LOGGER.error("Invalid response from Teslemetry", e)
raise ConfigEntryNotReady from e


print(teslemetry.server)
teslemetry.server = "https://temp.teslemetry.com"
print(teslemetry.server)

if entry.unique_id is None:
LOGGER.debug("Setting unique_id to %s", uid)
hass.config_entries.async_update_entry(entry, unique_id=uid)
Expand Down Expand Up @@ -167,6 +172,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

# Enrich devices
for energysite in energysites:
models = []
for gateway in energysite.info_coordinator.data.get("components_gateways", []):
if gateway.get("part_name"):
models.add(gateway["part_name"])
Expand Down
2 changes: 1 addition & 1 deletion custom_components/teslemetry/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def __init__(

def _async_value_from_stream(self, value) -> None:
"""Update the value of the entity."""
self._attr_native_value = self.entity_description.value_fn(value)
self._attr_native_value = self.entity_description.value_fn(auto_type(value))


class TeslemetryEnergyLiveBinarySensorEntity(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/teslemetry/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _async_update_attrs(self) -> None:

def _async_value_from_stream(self, value) -> None:
"""Update the value from the stream."""
self._attr_current_temperature = value
self._attr_current_temperature = float(value)

async def async_turn_on(self) -> None:
"""Set the climate state to on."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/teslemetry/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _async_update_attrs(self) -> None:

def _async_value_from_stream(self, value) -> None:
"""Update the value of the entity."""
self._attr_is_closed = not value
self._attr_is_closed = not auto_type(value)

async def async_open_cover(self, **kwargs: Any) -> None:
"""Open windows."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/teslemetry/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _async_update_attrs(self) -> None:

def _async_value_from_stream(self, value) -> None:
"""Update entity value from stream."""
self._attr_is_locked = value
self._attr_is_locked = value == "true"

async def async_lock(self, **kwargs: Any) -> None:
"""Lock the doors."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/teslemetry/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def _async_update_attrs(self) -> None:

def _async_value_from_stream(self, value) -> None:
"""Update the value of the entity."""
self._attr_native_value = value
self._attr_native_value = float(value)

async def async_set_native_value(self, value: float) -> None:
"""Set new value."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/teslemetry/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def _async_update_attrs(self) -> None:

def _async_value_from_stream(self, value) -> None:
"""Update the value of the entity."""
self._attr_is_on = value
self._attr_is_on = value == "true"

async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the Switch."""
Expand Down
3 changes: 2 additions & 1 deletion custom_components/teslemetry/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def _async_update_attrs(self) -> None:

def _async_value_from_stream(self, value) -> None:
"""Update the value of the entity."""
self._attr_installed_version = value
if (value != " "):
self._attr_installed_version = value

async def async_install(
self, version: str | None, backup: bool, **kwargs: Any
Expand Down

0 comments on commit 7a22bc4

Please sign in to comment.