Test migration

This commit is contained in:
farmio 2025-06-02 11:12:44 +02:00
parent fb04a1dc8f
commit f86fc5687b
5 changed files with 318 additions and 6 deletions

View File

@ -76,6 +76,7 @@ class KNXTestKit:
yaml_config: ConfigType | None = None,
config_store_fixture: str | None = None,
add_entry_to_hass: bool = True,
state_updater: bool = True,
) -> None:
"""Create the KNX integration."""
@ -107,6 +108,12 @@ class KNXTestKit:
self.xknx = args[0]
return DEFAULT
def state_update_register_mock(*args, **kwargs):
"""Mock the state updater registration."""
if state_updater:
return DEFAULT
return DEFAULT
if config_store_fixture:
self.hass_storage[
KNX_CONFIG_STORAGE_KEY
@ -118,14 +125,24 @@ class KNXTestKit:
self.mock_config_entry.add_to_hass(self.hass)
knx_config = {DOMAIN: yaml_config or {}}
with patch(
"xknx.xknx.knx_interface_factory",
return_value=knx_ip_interface_mock(),
side_effect=fish_xknx,
with (
patch(
"xknx.xknx.knx_interface_factory",
return_value=knx_ip_interface_mock(),
side_effect=fish_xknx,
),
):
state_updater_patcher = patch(
"xknx.xknx.StateUpdater.register_remote_value"
)
if not state_updater:
state_updater_patcher.start()
await async_setup_component(self.hass, DOMAIN, knx_config)
await self.hass.async_block_till_done()
state_updater_patcher.stop()
########################
# Telegram counter tests
########################

View File

@ -0,0 +1,142 @@
{
"version": 2,
"minor_version": 1,
"key": "knx/config_store.json",
"data": {
"entities": {
"light": {
"knx_es_01JWDFHP1ZG6NT62BX6ENR3MG7": {
"entity": {
"name": "rgbw",
"device_info": null,
"entity_category": null
},
"knx": {
"ga_switch": {
"write": "1/0/1",
"state": "1/0/0",
"passive": []
},
"ga_brightness": {
"write": "1/1/1",
"state": "1/1/0",
"passive": []
},
"sync_state": true,
"color_temp_min": 2700,
"color_temp_max": 6000,
"color": {
"ga_color": {
"write": "1/2/1",
"dpt": "251.600",
"state": "1/2/0",
"passive": []
}
}
}
},
"knx_es_01JWDFKBG3PYPPRQDJZ3N3PMCB": {
"entity": {
"name": "individual colors",
"device_info": null,
"entity_category": null
},
"knx": {
"sync_state": true,
"color_temp_min": 2700,
"color_temp_max": 6000,
"color": {
"ga_red_brightness": {
"write": "2/1/2",
"state": null,
"passive": []
},
"ga_red_switch": {
"write": "2/1/1",
"state": null,
"passive": []
},
"ga_green_brightness": {
"write": "2/2/2",
"state": null,
"passive": []
},
"ga_green_switch": {
"write": "2/2/1",
"state": null,
"passive": []
},
"ga_blue_brightness": {
"write": "2/3/2",
"state": null,
"passive": []
},
"ga_blue_switch": {
"write": "2/3/1",
"state": null,
"passive": []
}
}
}
},
"knx_es_01JWDFMSYYRDBDJYJR1K29ABEE": {
"entity": {
"name": "hsv",
"device_info": null,
"entity_category": null
},
"knx": {
"ga_switch": {
"write": "3/0/1",
"state": null,
"passive": []
},
"ga_brightness": {
"write": "3/1/1",
"state": null,
"passive": []
},
"sync_state": true,
"color_temp_min": 2700,
"color_temp_max": 6000,
"color": {
"ga_hue": {
"write": "3/2/1",
"state": "3/2/0",
"passive": []
},
"ga_saturation": {
"write": "3/3/1",
"state": "3/3/0",
"passive": []
}
}
}
},
"knx_es_01JWDFP1RH50JXP5D2SSSRKWWT": {
"entity": {
"name": "ct",
"device_info": null,
"entity_category": null
},
"knx": {
"ga_switch": {
"write": "4/0/1",
"state": "4/0/0",
"passive": []
},
"ga_color_temp": {
"write": "4/1/1",
"dpt": "7.600",
"state": "4/1/0",
"passive": []
},
"color_temp_max": 4788,
"sync_state": true,
"color_temp_min": 2700
}
}
}
}
}
}

View File

@ -1,5 +1,5 @@
{
"version": 1,
"version": 2,
"minor_version": 1,
"key": "knx/config_store.json",
"data": {
@ -33,7 +33,6 @@
"knx": {
"color_temp_min": 2700,
"color_temp_max": 6000,
"_light_color_mode_schema": "default",
"ga_switch": {
"write": "1/1/21",
"state": "1/0/21",

View File

@ -0,0 +1,140 @@
{
"version": 1,
"minor_version": 1,
"key": "knx/config_store.json",
"data": {
"entities": {
"light": {
"knx_es_01JWDFHP1ZG6NT62BX6ENR3MG7": {
"entity": {
"name": "rgbw",
"device_info": null,
"entity_category": null
},
"knx": {
"_light_color_mode_schema": "default",
"ga_switch": {
"write": "1/0/1",
"state": "1/0/0",
"passive": []
},
"ga_brightness": {
"write": "1/1/1",
"state": "1/1/0",
"passive": []
},
"ga_color": {
"write": "1/2/1",
"dpt": "251.600",
"state": "1/2/0",
"passive": []
},
"sync_state": true,
"color_temp_min": 2700,
"color_temp_max": 6000
}
},
"knx_es_01JWDFKBG3PYPPRQDJZ3N3PMCB": {
"entity": {
"name": "individual colors",
"device_info": null,
"entity_category": null
},
"knx": {
"_light_color_mode_schema": "individual",
"ga_red_switch": {
"write": "2/1/1",
"state": null,
"passive": []
},
"ga_red_brightness": {
"write": "2/1/2",
"state": null,
"passive": []
},
"ga_green_switch": {
"write": "2/2/1",
"state": null,
"passive": []
},
"ga_green_brightness": {
"write": "2/2/2",
"state": null,
"passive": []
},
"ga_blue_switch": {
"write": "2/3/1",
"state": null,
"passive": []
},
"ga_blue_brightness": {
"write": "2/3/2",
"state": null,
"passive": []
},
"sync_state": true,
"color_temp_min": 2700,
"color_temp_max": 6000
}
},
"knx_es_01JWDFMSYYRDBDJYJR1K29ABEE": {
"entity": {
"name": "hsv",
"device_info": null,
"entity_category": null
},
"knx": {
"_light_color_mode_schema": "hsv",
"ga_switch": {
"write": "3/0/1",
"state": null,
"passive": []
},
"ga_brightness": {
"write": "3/1/1",
"state": null,
"passive": []
},
"ga_hue": {
"write": "3/2/1",
"state": "3/2/0",
"passive": []
},
"ga_saturation": {
"write": "3/3/1",
"state": "3/3/0",
"passive": []
},
"sync_state": true,
"color_temp_min": 2700,
"color_temp_max": 6000
}
},
"knx_es_01JWDFP1RH50JXP5D2SSSRKWWT": {
"entity": {
"name": "ct",
"device_info": null,
"entity_category": null
},
"knx": {
"_light_color_mode_schema": "default",
"ga_switch": {
"write": "4/0/1",
"state": "4/0/0",
"passive": []
},
"ga_color_temp": {
"write": "4/1/1",
"dpt": "7.600",
"state": "4/1/0",
"passive": []
},
"color_temp_max": 4788,
"sync_state": true,
"color_temp_min": 2700
}
}
}
}
}
}

View File

@ -14,6 +14,7 @@ from homeassistant.helpers import entity_registry as er
from . import KnxEntityGenerator
from .conftest import KNXTestKit
from tests.common import load_json_object_fixture
from tests.typing import WebSocketGenerator
@ -410,3 +411,16 @@ async def test_validate_entity(
assert res["result"]["errors"][0]["path"] == ["data", "knx", "ga_switch", "write"]
assert res["result"]["errors"][0]["error_message"] == "required key not provided"
assert res["result"]["error_base"].startswith("required key not provided")
async def test_migration_1_to_2(
hass: HomeAssistant,
knx: KNXTestKit,
hass_storage: dict[str, Any],
) -> None:
"""Test migration from schema 1 to schema 2."""
await knx.setup_integration(
config_store_fixture="config_store_light_v1.json", state_updater=False
)
new_data = load_json_object_fixture("config_store_light.json", "knx")
assert hass_storage[KNX_CONFIG_STORAGE_KEY] == new_data