mirror of
https://github.com/home-assistant/core.git
synced 2025-11-13 21:10:25 +00:00
Use BSH keys as unique ID's suffix at Home Connect (#126143)
* Use BSH keys as as unique id suffix instead of the simple description * Update tests/components/home_connect/test_init.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
committed by
GitHub
parent
3e8bc98f23
commit
0d795aad16
@@ -2,18 +2,31 @@
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, Mock
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
from requests import HTTPError
|
||||
import requests_mock
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.components.home_connect import SCAN_INTERVAL
|
||||
from homeassistant.components.home_connect.const import DOMAIN, OAUTH2_TOKEN
|
||||
from homeassistant.components.home_connect.const import (
|
||||
BSH_CHILD_LOCK_STATE,
|
||||
BSH_OPERATION_STATE,
|
||||
BSH_POWER_STATE,
|
||||
BSH_REMOTE_START_ALLOWANCE_STATE,
|
||||
COOKING_LIGHTING,
|
||||
DOMAIN,
|
||||
OAUTH2_TOKEN,
|
||||
)
|
||||
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
from .conftest import (
|
||||
CLIENT_ID,
|
||||
@@ -294,3 +307,68 @@ async def test_services_exception(
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
await hass.services.async_call(**service_call)
|
||||
|
||||
|
||||
async def test_entity_migration(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
config_entry_v1_1: MockConfigEntry,
|
||||
appliance: Mock,
|
||||
platforms: list[Platform],
|
||||
) -> None:
|
||||
"""Test entity migration."""
|
||||
|
||||
config_entry_v1_1.add_to_hass(hass)
|
||||
|
||||
device_entry = device_registry.async_get_or_create(
|
||||
config_entry_id=config_entry_v1_1.entry_id,
|
||||
identifiers={(DOMAIN, appliance.haId)},
|
||||
)
|
||||
|
||||
test_entities = [
|
||||
(
|
||||
SENSOR_DOMAIN,
|
||||
"Operation State",
|
||||
BSH_OPERATION_STATE,
|
||||
),
|
||||
(
|
||||
SWITCH_DOMAIN,
|
||||
"ChildLock",
|
||||
BSH_CHILD_LOCK_STATE,
|
||||
),
|
||||
(
|
||||
SWITCH_DOMAIN,
|
||||
"Power",
|
||||
BSH_POWER_STATE,
|
||||
),
|
||||
(
|
||||
BINARY_SENSOR_DOMAIN,
|
||||
"Remote Start",
|
||||
BSH_REMOTE_START_ALLOWANCE_STATE,
|
||||
),
|
||||
(
|
||||
LIGHT_DOMAIN,
|
||||
"Light",
|
||||
COOKING_LIGHTING,
|
||||
),
|
||||
]
|
||||
|
||||
for domain, old_unique_id_suffix, _ in test_entities:
|
||||
entity_registry.async_get_or_create(
|
||||
domain,
|
||||
DOMAIN,
|
||||
f"{appliance.haId}-{old_unique_id_suffix}",
|
||||
device_id=device_entry.id,
|
||||
config_entry=config_entry_v1_1,
|
||||
)
|
||||
|
||||
with patch("homeassistant.components.home_connect.PLATFORMS", platforms):
|
||||
await hass.config_entries.async_setup(config_entry_v1_1.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
for domain, _, expected_unique_id_suffix in test_entities:
|
||||
assert entity_registry.async_get_entity_id(
|
||||
domain, DOMAIN, f"{appliance.haId}-{expected_unique_id_suffix}"
|
||||
)
|
||||
assert config_entry_v1_1.minor_version == 2
|
||||
|
||||
Reference in New Issue
Block a user