Allow storing other items than untyped dict in StorageCollection (#90932)

Allow storing other items than untyped dict in StorageCollection
This commit is contained in:
Erik Montnemery
2023-04-06 10:57:00 -04:00
committed by GitHub
parent 8025fbf398
commit 59a02cd08c
18 changed files with 134 additions and 91 deletions
@@ -231,7 +231,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
return True
class InputSelectStorageCollection(collection.StorageCollection):
class InputSelectStorageCollection(collection.DictStorageCollection):
"""Input storage based collection."""
CREATE_UPDATE_SCHEMA = vol.Schema(vol.All(STORAGE_FIELDS, _cv_input_select))
@@ -246,11 +246,11 @@ class InputSelectStorageCollection(collection.StorageCollection):
return cast(str, info[CONF_NAME])
async def _update_data(
self, data: dict[str, Any], update_data: dict[str, Any]
self, item: dict[str, Any], update_data: dict[str, Any]
) -> dict[str, Any]:
"""Return a new updated data object."""
update_data = self.CREATE_UPDATE_SCHEMA(update_data)
return {CONF_ID: data[CONF_ID]} | update_data
return {CONF_ID: item[CONF_ID]} | update_data
class InputSelect(collection.CollectionEntity, SelectEntity, RestoreEntity):