1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Allow reconfiguration of integration sensor (#116740)

* Allow reconfiguration of integration sensor

* Adjust allowed options to not change unit
This commit is contained in:
Joakim Plate
2024-05-06 21:03:46 +02:00
committed by GitHub
parent ebd1efa53b
commit 2b6dd59cfc
3 changed files with 101 additions and 40 deletions

View File

@@ -8,6 +8,7 @@ from homeassistant import config_entries
from homeassistant.components.integration.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.helpers import selector
from tests.common import MockConfigEntry
@@ -95,21 +96,34 @@ async def test_options(hass: HomeAssistant, platform) -> None:
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
hass.states.async_set("sensor.input", 10, {"unit_of_measurement": "dog"})
hass.states.async_set("sensor.valid", 10, {"unit_of_measurement": "dog"})
hass.states.async_set("sensor.invalid", 10, {"unit_of_measurement": "cat"})
result = await hass.config_entries.options.async_init(config_entry.entry_id)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "init"
schema = result["data_schema"].schema
assert get_suggested(schema, "round") == 1.0
source = schema["source"]
assert isinstance(source, selector.EntitySelector)
assert source.config["include_entities"] == [
"sensor.input",
"sensor.valid",
]
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={
"method": "right",
"round": 2.0,
"source": "sensor.input",
},
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["data"] == {
"method": "left",
"method": "right",
"name": "My integration",
"round": 2.0,
"source": "sensor.input",
@@ -118,7 +132,7 @@ async def test_options(hass: HomeAssistant, platform) -> None:
}
assert config_entry.data == {}
assert config_entry.options == {
"method": "left",
"method": "right",
"name": "My integration",
"round": 2.0,
"source": "sensor.input",
@@ -131,7 +145,7 @@ async def test_options(hass: HomeAssistant, platform) -> None:
await hass.async_block_till_done()
# Check the entity was updated, no new entity was created
assert len(hass.states.async_all()) == 1
assert len(hass.states.async_all()) == 4
# Check the state of the entity has changed as expected
hass.states.async_set("sensor.input", 10, {"unit_of_measurement": "dog"})