From c0883db29507e6190b77bca406907dc459ec7e17 Mon Sep 17 00:00:00 2001 From: formatBCE Date: Sun, 24 Jul 2022 11:40:43 -0700 Subject: [PATCH] Fixed: expiration slider doesn't update UI state --- custom_components/format_ble_tracker/README.md | 2 -- custom_components/format_ble_tracker/number.py | 14 +++++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) delete mode 100644 custom_components/format_ble_tracker/README.md diff --git a/custom_components/format_ble_tracker/README.md b/custom_components/format_ble_tracker/README.md deleted file mode 100644 index d73b7d7..0000000 --- a/custom_components/format_ble_tracker/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# Format-BLE-Tracker -BLE tracker integration, which works with ESP32 firmware https://github.com/formatBCE/ESP32_BLE_presense diff --git a/custom_components/format_ble_tracker/number.py b/custom_components/format_ble_tracker/number.py index 8abb5f5..641a1f1 100644 --- a/custom_components/format_ble_tracker/number.py +++ b/custom_components/format_ble_tracker/number.py @@ -40,13 +40,17 @@ async def async_added_to_hass(self): """Entity has been added to hass, restoring state""" restored = await self.async_get_last_number_data() native_value = 2 if restored is None else restored.native_value - self._attr_native_value = native_value - await self.coordinator.on_expiration_time_changed(native_value) - self.async_write_ha_state() + await self.update_value(native_value) async def async_set_native_value(self, value: float) -> None: """Update the current value.""" val = min(10, max(1, int(value))) - self._attr_native_value = val - await self.coordinator.on_expiration_time_changed(val) + await self.update_value(val) + + + async def update_value(self, value: int): + """Set value to HA and coordinator""" + self._attr_native_value = value + await self.coordinator.on_expiration_time_changed(value) + self.async_write_ha_state()