Drop initial when loading input_number from storage (#78354)

This commit is contained in:
Erik Montnemery 2022-09-13 14:39:05 +02:00 committed by GitHub
parent a5fa34b4bb
commit 6256d07255
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -196,6 +196,22 @@ class NumberStorageCollection(collection.StorageCollection):
"""Suggest an ID based on the config."""
return info[CONF_NAME]
async def _async_load_data(self) -> dict | None:
"""Load the data.
A past bug caused frontend to add initial value to all input numbers.
This drops that.
"""
data = await super()._async_load_data()
if data is None:
return data
for number in data["items"]:
number.pop(CONF_INITIAL, None)
return data
async def _update_data(self, data: dict, update_data: dict) -> dict:
"""Return a new updated data object."""
update_data = self.UPDATE_SCHEMA(update_data)

View File

@ -416,7 +416,7 @@ async def test_load_from_storage(hass, storage_setup):
"""Test set up from storage."""
assert await storage_setup()
state = hass.states.get(f"{DOMAIN}.from_storage")
assert float(state.state) == 10
assert float(state.state) == 0 # initial is not supported when loading from storage
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "from storage"
assert state.attributes.get(ATTR_EDITABLE)
@ -438,7 +438,7 @@ async def test_editable_state_attribute(hass, storage_setup):
)
state = hass.states.get(f"{DOMAIN}.from_storage")
assert float(state.state) == 10
assert float(state.state) == 0
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "from storage"
assert state.attributes.get(ATTR_EDITABLE)