Add HA lifecycle tests and CI
Tests / tests (push) Canceled after 0s

This commit is contained in:
buzera committed 2026-10-26 18:21:18 +02:00
1 parent cea79b6b48
commit c771bc360a
12 files changed
+378 -4

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
"""Validate actual HA form schemas, options and entry migration."""
from homeassistant.config_entries import SOURCE_USER
from homeassistant.data_entry_flow import FlowResultType
from pytest_homeassistant_custom_component.common import MockConfigEntry
from custom_components.heating_mpc.const import DOMAIN
async def test_config_flow(hass, inputs):
result = await hass.config_entries.flow.async_init(DOMAIN, context={"source": SOURCE_USER})
assert result["type"] is FlowResultType.FORM
main = {"climate_entity": "climate.reference", "heater_entity": "switch.boiler",
"room_entities": ["sensor.room"]}
validated = result["data_schema"](main)
assert validated["room_max_age_minutes"] == 30
assert validated["weather_max_age_minutes"] == 120
result = await hass.config_entries.flow.async_configure(result["flow_id"], validated)
assert result["step_id"] == "weather"
result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["data_schema"]({"outside_temperature_sources": ["sensor.outside"]}))
assert result["step_id"] == "weather_extra"
result = await hass.config_entries.flow.async_configure(result["flow_id"], result["data_schema"]({}))
assert result["step_id"] == "weights"
result = await hass.config_entries.flow.async_configure(result["flow_id"], {"weight__sensor.room": 2})
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["data"]["weights"] == {"sensor.room": 2}
await hass.async_block_till_done()
async def test_options_flow_keeps_settings(hass, entry, inputs):
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
result = await hass.config_entries.options.async_init(entry.entry_id)
main = result["data_schema"]({"climate_entity": "climate.reference",
"heater_entity": "switch.boiler", "room_entities": ["sensor.room"],
"room_max_age_minutes": 45})
result = await hass.config_entries.options.async_configure(result["flow_id"], main)
result = await hass.config_entries.options.async_configure(
result["flow_id"], result["data_schema"]({"outside_temperature_sources": ["sensor.outside"]}))
result = await hass.config_entries.options.async_configure(result["flow_id"], result["data_schema"]({}))
result = await hass.config_entries.options.async_configure(result["flow_id"], {"weight__sensor.room": 3})
assert result["type"] is FlowResultType.CREATE_ENTRY
await hass.async_block_till_done()
assert entry.options["room_max_age_minutes"] == 45
assert hass.data[DOMAIN][entry.entry_id].config["room_max_age_minutes"] == 45
async def test_v1_entry_migrates_on_setup(hass, inputs):
entry = MockConfigEntry(domain=DOMAIN, version=1, data={
"climate_entity": "climate.reference", "heater_entity": "switch.boiler",
"room_entities": ["sensor.room"], "outside_entity": "sensor.outside"})
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert entry.version == 2
assert entry.data["outside_temperature_sources"] == ["sensor.outside"]
assert "outside_entity" not in entry.data