From 3e41b1ba0045a1ca118671f026b5a7a6a3267259 Mon Sep 17 00:00:00 2001 From: Malene Trab Date: Mon, 15 Apr 2024 08:31:58 +0000 Subject: [PATCH] Fixing input_number not updating --- .../landroid_cloud/device_base.py | 20 ++++++------------- custom_components/landroid_cloud/number.py | 4 ++-- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/custom_components/landroid_cloud/device_base.py b/custom_components/landroid_cloud/device_base.py index f18521a..17a370a 100644 --- a/custom_components/landroid_cloud/device_base.py +++ b/custom_components/landroid_cloud/device_base.py @@ -1122,8 +1122,6 @@ def __init__( self._api = api self._config = config - self._value = None - self._attr_name = self.entity_description.name _LOGGER.debug( @@ -1157,6 +1155,8 @@ def __init__( _connections = {(dr.CONNECTION_NETWORK_MAC, self.device.mac_address)} self._attr_device_info.update({"connections": _connections}) + self._value = None #self.entity_description.value_fn(self._api) + async_dispatcher_connect( self.hass, util_slugify(f"{UPDATE_SIGNAL}_{self._api.device.name}"), @@ -1171,27 +1171,19 @@ def available(self) -> bool: @property def native_value(self) -> float | None: """Return the entity value to represent the entity state.""" - val = self.entity_description.value_fn(self._api) - _LOGGER.debug( - "(%s, Show Value) Returning number '%s' with value '%s'", - self._api.friendly_name, - self._attr_name, - val, - ) - - return val + return self._value async def async_added_to_hass(self) -> None: """Set state on adding to home assistant.""" - # await self.handle_update() + await self.handle_update() return await super().async_added_to_hass() async def handle_update(self) -> None: """Handle the updates when recieving an update signal.""" try: - self._value = self.entity_description.value_fn(self.device) + self._value = self.entity_description.value_fn(self._api) except AttributeError: - return + pass _LOGGER.debug( "(%s, Update signal) Updating number '%s'", diff --git a/custom_components/landroid_cloud/number.py b/custom_components/landroid_cloud/number.py index 42ea63e..3496267 100644 --- a/custom_components/landroid_cloud/number.py +++ b/custom_components/landroid_cloud/number.py @@ -26,7 +26,7 @@ native_max_value=100, native_step=1, mode=NumberMode.SLIDER, - value_fn=lambda api: api.cloud.device.schedules["time_extension"], + value_fn=lambda api: api.cloud.devices[api.device_name].schedules["time_extension"], command_fn=lambda api, value: api.cloud.send( api.device.serial_number, json.dumps({"sc": {"p": value}}) ), @@ -43,7 +43,7 @@ native_max_value=50, native_step=1, mode=NumberMode.SLIDER, - value_fn=lambda api: api.device.torque, + value_fn=lambda api: api.cloud.devices[api.device_name].torque, command_fn=lambda api, value: api.cloud.send( api.device.serial_number, json.dumps({"tq": value}) ),