Skip to content

Commit

Permalink
Fix streaming charge current max
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Jan 6, 2025
1 parent 86d6119 commit b66b0ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions custom_components/teslemetry/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/Teslemetry/hass-teslemetry/issues",
"loggers": ["tesla_fleet_api", "teslemetry_stream"],
"requirements": ["tesla-fleet-api==0.9.3", "teslemetry-stream==0.5.7"],
"version": "3.0.3"
"requirements": ["tesla-fleet-api==0.9.4", "teslemetry-stream==0.5.7"],
"version": "3.0.4"
}
28 changes: 21 additions & 7 deletions custom_components/teslemetry/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from homeassistant.helpers.restore_state import RestoreEntity

from .entity import (
TeslemetryVehicleComplexStreamEntity,
TeslemetryVehicleEntity,
TeslemetryEnergyInfoEntity,
TeslemetryVehicleStreamEntity,
Expand All @@ -47,6 +48,7 @@ class TeslemetryNumberEntityDescription(NumberEntityDescription):
scopes: list[Scope] | None = None
requires: str | None = None
streaming_key: Signal | None = None
streaming_max_key: Signal | None = None


VEHICLE_DESCRIPTIONS: tuple[TeslemetryNumberEntityDescription, ...] = (
Expand All @@ -60,6 +62,7 @@ class TeslemetryNumberEntityDescription(NumberEntityDescription):
device_class=NumberDeviceClass.CURRENT,
mode=NumberMode.AUTO,
max_key="charge_state_charge_current_request_max",
streaming_max_key=Signal.CHARGE_CURRENT_REQUEST_MAX,
func=lambda api, value: api.set_charging_amps(value),
scopes=[Scope.VEHICLE_CHARGING_CMDS],
),
Expand Down Expand Up @@ -229,7 +232,7 @@ def _async_update_attrs(self) -> None:
)


class TeslemetryStreamingNumberEntity(TeslemetryVehicleStreamEntity, TeslemetryVehicleNumberEntity, RestoreEntity):
class TeslemetryStreamingNumberEntity(TeslemetryVehicleComplexStreamEntity, TeslemetryVehicleNumberEntity, RestoreEntity):
"""Number entity for current charge."""

entity_description: TeslemetryNumberEntityDescription
Expand All @@ -244,8 +247,11 @@ def __init__(
self.scoped = any(scope in scopes for scope in description.scopes)
self.entity_description = description
assert description.streaming_key
keys = [description.streaming_key]
if description.streaming_max_key:
keys.append(description.streaming_max_key)
super().__init__(
data, description.key, description.streaming_key
data, description.key, keys
)

async def async_added_to_hass(self) -> None:
Expand All @@ -255,12 +261,20 @@ async def async_added_to_hass(self) -> None:
if (state.state.isdigit()):
self._attr_native_value = float(state.state)

def _async_value_from_stream(self, value) -> None:
def _async_data_from_stream(self, data) -> None:
"""Update the value of the entity."""
if isinstance(value, float | int):
self._attr_native_value = float(value)
else:
self._attr_native_value = None
if self.entity_description.streaming_key in data:
value = data[self.entity_description.streaming_key]
if isinstance(value, float | int):
self._attr_native_value = float(value)
else:
self._attr_native_value = None
if self.entity_description.streaming_max_key in data:
value = data[self.entity_description.streaming_max_key]
if isinstance(value, float | int):
self._attr_native_max_value = float(value)
else:
self._attr_native_max_value = self.entity_description.native_max_value


class TeslemetryImperialSpeedNumberEntity(TeslemetryVehicleEntity, NumberEntity):
Expand Down

0 comments on commit b66b0ba

Please sign in to comment.