Move lock and devicelock attributes into sensors for all AVM Fritz!Smarthome entities (#60426)
This commit is contained in:
parent
b3f3e7259e
commit
9deebaa65f
11 changed files with 140 additions and 73 deletions
|
@ -4,8 +4,10 @@ from __future__ import annotations
|
|||
from unittest.mock import Mock, call, patch
|
||||
|
||||
from pyfritzhome import LoginError
|
||||
import pytest
|
||||
from requests.exceptions import ConnectionError, HTTPError
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.components.fritzbox.const import DOMAIN as FB_DOMAIN
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
|
@ -42,7 +44,37 @@ async def test_setup(hass: HomeAssistant, fritz: Mock):
|
|||
]
|
||||
|
||||
|
||||
async def test_update_unique_id(hass: HomeAssistant, fritz: Mock):
|
||||
@pytest.mark.parametrize(
|
||||
"entitydata,old_unique_id,new_unique_id",
|
||||
[
|
||||
(
|
||||
{
|
||||
"domain": SENSOR_DOMAIN,
|
||||
"platform": FB_DOMAIN,
|
||||
"unique_id": CONF_FAKE_AIN,
|
||||
"unit_of_measurement": TEMP_CELSIUS,
|
||||
},
|
||||
CONF_FAKE_AIN,
|
||||
f"{CONF_FAKE_AIN}_temperature",
|
||||
),
|
||||
(
|
||||
{
|
||||
"domain": BINARY_SENSOR_DOMAIN,
|
||||
"platform": FB_DOMAIN,
|
||||
"unique_id": CONF_FAKE_AIN,
|
||||
},
|
||||
CONF_FAKE_AIN,
|
||||
f"{CONF_FAKE_AIN}_alarm",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_update_unique_id(
|
||||
hass: HomeAssistant,
|
||||
fritz: Mock,
|
||||
entitydata: dict,
|
||||
old_unique_id: str,
|
||||
new_unique_id: str,
|
||||
):
|
||||
"""Test unique_id update of integration."""
|
||||
entry = MockConfigEntry(
|
||||
domain=FB_DOMAIN,
|
||||
|
@ -52,23 +84,55 @@ async def test_update_unique_id(hass: HomeAssistant, fritz: Mock):
|
|||
entry.add_to_hass(hass)
|
||||
|
||||
entity_registry = er.async_get(hass)
|
||||
entity = entity_registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
FB_DOMAIN,
|
||||
CONF_FAKE_AIN,
|
||||
unit_of_measurement=TEMP_CELSIUS,
|
||||
entity: er.RegistryEntry = entity_registry.async_get_or_create(
|
||||
**entitydata,
|
||||
config_entry=entry,
|
||||
)
|
||||
assert entity.unique_id == CONF_FAKE_AIN
|
||||
assert entity.unique_id == old_unique_id
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity_migrated = entity_registry.async_get(entity.entity_id)
|
||||
assert entity_migrated
|
||||
assert entity_migrated.unique_id == f"{CONF_FAKE_AIN}_temperature"
|
||||
assert entity_migrated.unique_id == new_unique_id
|
||||
|
||||
|
||||
async def test_update_unique_id_no_change(hass: HomeAssistant, fritz: Mock):
|
||||
@pytest.mark.parametrize(
|
||||
"entitydata,unique_id",
|
||||
[
|
||||
(
|
||||
{
|
||||
"domain": SENSOR_DOMAIN,
|
||||
"platform": FB_DOMAIN,
|
||||
"unique_id": f"{CONF_FAKE_AIN}_temperature",
|
||||
"unit_of_measurement": TEMP_CELSIUS,
|
||||
},
|
||||
f"{CONF_FAKE_AIN}_temperature",
|
||||
),
|
||||
(
|
||||
{
|
||||
"domain": BINARY_SENSOR_DOMAIN,
|
||||
"platform": FB_DOMAIN,
|
||||
"unique_id": f"{CONF_FAKE_AIN}_alarm",
|
||||
},
|
||||
f"{CONF_FAKE_AIN}_alarm",
|
||||
),
|
||||
(
|
||||
{
|
||||
"domain": BINARY_SENSOR_DOMAIN,
|
||||
"platform": FB_DOMAIN,
|
||||
"unique_id": f"{CONF_FAKE_AIN}_other",
|
||||
},
|
||||
f"{CONF_FAKE_AIN}_other",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_update_unique_id_no_change(
|
||||
hass: HomeAssistant,
|
||||
fritz: Mock,
|
||||
entitydata: dict,
|
||||
unique_id: str,
|
||||
):
|
||||
"""Test unique_id is not updated of integration."""
|
||||
entry = MockConfigEntry(
|
||||
domain=FB_DOMAIN,
|
||||
|
@ -79,19 +143,16 @@ async def test_update_unique_id_no_change(hass: HomeAssistant, fritz: Mock):
|
|||
|
||||
entity_registry = er.async_get(hass)
|
||||
entity = entity_registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
FB_DOMAIN,
|
||||
f"{CONF_FAKE_AIN}_temperature",
|
||||
unit_of_measurement=TEMP_CELSIUS,
|
||||
**entitydata,
|
||||
config_entry=entry,
|
||||
)
|
||||
assert entity.unique_id == f"{CONF_FAKE_AIN}_temperature"
|
||||
assert entity.unique_id == unique_id
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity_migrated = entity_registry.async_get(entity.entity_id)
|
||||
assert entity_migrated
|
||||
assert entity_migrated.unique_id == f"{CONF_FAKE_AIN}_temperature"
|
||||
assert entity_migrated.unique_id == unique_id
|
||||
|
||||
|
||||
async def test_coordinator_update_after_reboot(hass: HomeAssistant, fritz: Mock):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue