Skip to content

Commit c78bc26

Browse files
farmiofrenck
authored andcommitted
Fix KNX BinarySensor config_store data (home-assistant#151808)
1 parent 0c09364 commit c78bc26

File tree

6 files changed

+65
-6
lines changed

6 files changed

+65
-6
lines changed

homeassistant/components/knx/storage/config_store.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313

1414
from ..const import DOMAIN
1515
from .const import CONF_DATA
16-
from .migration import migrate_1_to_2
16+
from .migration import migrate_1_to_2, migrate_2_1_to_2_2
1717

1818
_LOGGER = logging.getLogger(__name__)
1919

2020
STORAGE_VERSION: Final = 2
21+
STORAGE_VERSION_MINOR: Final = 2
2122
STORAGE_KEY: Final = f"{DOMAIN}/config_store.json"
2223

2324
type KNXPlatformStoreModel = dict[str, dict[str, Any]] # unique_id: configuration
@@ -54,9 +55,13 @@ async def _async_migrate_func(
5455
) -> dict[str, Any]:
5556
"""Migrate to the new version."""
5657
if old_major_version == 1:
57-
# version 2 introduced in 2025.8
58+
# version 2.1 introduced in 2025.8
5859
migrate_1_to_2(old_data)
5960

61+
if old_major_version <= 2 and old_minor_version < 2:
62+
# version 2.2 introduced in 2025.9.2
63+
migrate_2_1_to_2_2(old_data)
64+
6065
return old_data
6166

6267

@@ -71,7 +76,9 @@ def __init__(
7176
"""Initialize config store."""
7277
self.hass = hass
7378
self.config_entry = config_entry
74-
self._store = _KNXConfigStoreStorage(hass, STORAGE_VERSION, STORAGE_KEY)
79+
self._store = _KNXConfigStoreStorage(
80+
hass, STORAGE_VERSION, STORAGE_KEY, minor_version=STORAGE_VERSION_MINOR
81+
)
7582
self.data = KNXConfigStoreModel(entities={})
7683
self._platform_controllers: dict[Platform, PlatformControllerBase] = {}
7784

homeassistant/components/knx/storage/migration.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from homeassistant.const import Platform
66

7+
from ..const import CONF_RESPOND_TO_READ
78
from . import const as store_const
89

910

@@ -40,3 +41,12 @@ def _migrate_light_schema_1_to_2(light_knx_data: dict[str, Any]) -> None:
4041

4142
if color:
4243
light_knx_data[store_const.CONF_COLOR] = color
44+
45+
46+
def migrate_2_1_to_2_2(data: dict[str, Any]) -> None:
47+
"""Migrate from schema 2.1 to schema 2.2."""
48+
if b_sensors := data.get("entities", {}).get(Platform.BINARY_SENSOR):
49+
for b_sensor in b_sensors.values():
50+
# "respond_to_read" was never used for binary_sensor and is not valid
51+
# in the new schema. It was set as default in Store schema v1 and v2.1
52+
b_sensor["knx"].pop(CONF_RESPOND_TO_READ, None)

tests/components/knx/fixtures/config_store_binarysensor.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"version": 2,
3-
"minor_version": 1,
3+
"minor_version": 2,
44
"key": "knx/config_store.json",
55
"data": {
66
"entities": {
@@ -17,7 +17,6 @@
1717
"state": "3/2/21",
1818
"passive": []
1919
},
20-
"respond_to_read": false,
2120
"sync_state": true
2221
}
2322
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"version": 2,
3+
"minor_version": 1,
4+
"key": "knx/config_store.json",
5+
"data": {
6+
"entities": {
7+
"light": {},
8+
"binary_sensor": {
9+
"knx_es_01JJP1XDQRXB0W6YYGXW6Y1X10": {
10+
"entity": {
11+
"name": "test",
12+
"device_info": null,
13+
"entity_category": null
14+
},
15+
"knx": {
16+
"ga_sensor": {
17+
"state": "3/2/21",
18+
"passive": []
19+
},
20+
"respond_to_read": false,
21+
"sync_state": true
22+
}
23+
}
24+
}
25+
}
26+
}
27+
}

tests/components/knx/fixtures/config_store_light.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"version": 2,
3-
"minor_version": 1,
3+
"minor_version": 2,
44
"key": "knx/config_store.json",
55
"data": {
66
"entities": {

tests/components/knx/test_config_store.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,3 +458,19 @@ async def test_migration_1_to_2(
458458
hass, "config_store_light.json", "knx"
459459
)
460460
assert hass_storage[KNX_CONFIG_STORAGE_KEY] == new_data
461+
462+
463+
async def test_migration_2_1_to_2_2(
464+
hass: HomeAssistant,
465+
knx: KNXTestKit,
466+
hass_storage: dict[str, Any],
467+
) -> None:
468+
"""Test migration from schema 2.1 to schema 2.2."""
469+
await knx.setup_integration(
470+
config_store_fixture="config_store_binarysensor_v2_1.json",
471+
state_updater=False,
472+
)
473+
new_data = await async_load_json_object_fixture(
474+
hass, "config_store_binarysensor.json", "knx"
475+
)
476+
assert hass_storage[KNX_CONFIG_STORAGE_KEY] == new_data

0 commit comments

Comments
 (0)