Skip to content

Commit

Permalink
Merge pull request #579 from MTrab:Fix-raindelay-mapping-error
Browse files Browse the repository at this point in the history
Fixing input_number not updating
  • Loading branch information
MTrab committed Apr 15, 2024
2 parents 38ea975 + 3e41b1b commit 0006d45
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
20 changes: 6 additions & 14 deletions custom_components/landroid_cloud/device_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,8 +1122,6 @@ def __init__(
self._api = api
self._config = config

self._value = None

self._attr_name = self.entity_description.name

_LOGGER.debug(
Expand Down Expand Up @@ -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}"),
Expand All @@ -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'",
Expand Down
4 changes: 2 additions & 2 deletions custom_components/landroid_cloud/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}})
),
Expand All @@ -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})
),
Expand Down

0 comments on commit 0006d45

Please sign in to comment.