Add options flow to File (#120269)

* Add options flow to File

* Review comments
This commit is contained in:
G Johansson 2024-08-15 18:21:07 +02:00 committed by GitHub
parent e39bfeac08
commit 24a20c75eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 307 additions and 38 deletions

View file

@ -60,14 +60,15 @@ async def async_setup_entry(
) -> None:
"""Set up the file sensor."""
config = dict(entry.data)
options = dict(entry.options)
file_path: str = config[CONF_FILE_PATH]
unique_id: str = entry.entry_id
name: str = config.get(CONF_NAME, DEFAULT_NAME)
unit: str | None = config.get(CONF_UNIT_OF_MEASUREMENT)
unit: str | None = options.get(CONF_UNIT_OF_MEASUREMENT)
value_template: Template | None = None
if CONF_VALUE_TEMPLATE in config:
value_template = Template(config[CONF_VALUE_TEMPLATE], hass)
if CONF_VALUE_TEMPLATE in options:
value_template = Template(options[CONF_VALUE_TEMPLATE], hass)
async_add_entities(
[FileSensor(unique_id, name, file_path, unit, value_template)], True