mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Clean up unnecessary registry mocks from integration tests (#87763)
This commit is contained in:
@@ -5,16 +5,20 @@ from homeassistant.components.broadlink.const import DOMAIN
|
||||
from homeassistant.components.broadlink.updater import BroadlinkSP4UpdateManager
|
||||
from homeassistant.const import ATTR_FRIENDLY_NAME, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers.entity_component import async_update_entity
|
||||
from homeassistant.helpers.entity_registry import async_entries_for_device
|
||||
from homeassistant.util import dt
|
||||
|
||||
from . import get_device
|
||||
|
||||
from tests.common import async_fire_time_changed, mock_device_registry, mock_registry
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
|
||||
async def test_a1_sensor_setup(hass: HomeAssistant) -> None:
|
||||
async def test_a1_sensor_setup(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test a successful e-Sensor setup."""
|
||||
device = get_device("Bedroom")
|
||||
mock_api = device.get_mock_api()
|
||||
@@ -26,16 +30,13 @@ async def test_a1_sensor_setup(hass: HomeAssistant) -> None:
|
||||
"noise": 1,
|
||||
}
|
||||
|
||||
device_registry = mock_device_registry(hass)
|
||||
entity_registry = mock_registry(hass)
|
||||
|
||||
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
|
||||
|
||||
assert mock_api.check_sensors_raw.call_count == 1
|
||||
device_entry = device_registry.async_get_device(
|
||||
{(DOMAIN, mock_setup.entry.unique_id)}
|
||||
)
|
||||
entries = async_entries_for_device(entity_registry, device_entry.id)
|
||||
entries = er.async_entries_for_device(entity_registry, device_entry.id)
|
||||
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
|
||||
assert len(sensors) == 5
|
||||
|
||||
@@ -55,7 +56,11 @@ async def test_a1_sensor_setup(hass: HomeAssistant) -> None:
|
||||
}
|
||||
|
||||
|
||||
async def test_a1_sensor_update(hass: HomeAssistant) -> None:
|
||||
async def test_a1_sensor_update(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test a successful e-Sensor update."""
|
||||
device = get_device("Bedroom")
|
||||
mock_api = device.get_mock_api()
|
||||
@@ -67,15 +72,12 @@ async def test_a1_sensor_update(hass: HomeAssistant) -> None:
|
||||
"noise": 1,
|
||||
}
|
||||
|
||||
device_registry = mock_device_registry(hass)
|
||||
entity_registry = mock_registry(hass)
|
||||
|
||||
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
|
||||
|
||||
device_entry = device_registry.async_get_device(
|
||||
{(DOMAIN, mock_setup.entry.unique_id)}
|
||||
)
|
||||
entries = async_entries_for_device(entity_registry, device_entry.id)
|
||||
entries = er.async_entries_for_device(entity_registry, device_entry.id)
|
||||
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
|
||||
assert len(sensors) == 5
|
||||
|
||||
@@ -105,22 +107,23 @@ async def test_a1_sensor_update(hass: HomeAssistant) -> None:
|
||||
}
|
||||
|
||||
|
||||
async def test_rm_pro_sensor_setup(hass: HomeAssistant) -> None:
|
||||
async def test_rm_pro_sensor_setup(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test a successful RM pro sensor setup."""
|
||||
device = get_device("Office")
|
||||
mock_api = device.get_mock_api()
|
||||
mock_api.check_sensors.return_value = {"temperature": 18.2}
|
||||
|
||||
device_registry = mock_device_registry(hass)
|
||||
entity_registry = mock_registry(hass)
|
||||
|
||||
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
|
||||
|
||||
assert mock_api.check_sensors.call_count == 1
|
||||
device_entry = device_registry.async_get_device(
|
||||
{(DOMAIN, mock_setup.entry.unique_id)}
|
||||
)
|
||||
entries = async_entries_for_device(entity_registry, device_entry.id)
|
||||
entries = er.async_entries_for_device(entity_registry, device_entry.id)
|
||||
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
|
||||
assert len(sensors) == 1
|
||||
|
||||
@@ -134,21 +137,22 @@ async def test_rm_pro_sensor_setup(hass: HomeAssistant) -> None:
|
||||
assert sensors_and_states == {(f"{device.name} Temperature", "18.2")}
|
||||
|
||||
|
||||
async def test_rm_pro_sensor_update(hass: HomeAssistant) -> None:
|
||||
async def test_rm_pro_sensor_update(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test a successful RM pro sensor update."""
|
||||
device = get_device("Office")
|
||||
mock_api = device.get_mock_api()
|
||||
mock_api.check_sensors.return_value = {"temperature": 25.7}
|
||||
|
||||
device_registry = mock_device_registry(hass)
|
||||
entity_registry = mock_registry(hass)
|
||||
|
||||
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
|
||||
|
||||
device_entry = device_registry.async_get_device(
|
||||
{(DOMAIN, mock_setup.entry.unique_id)}
|
||||
)
|
||||
entries = async_entries_for_device(entity_registry, device_entry.id)
|
||||
entries = er.async_entries_for_device(entity_registry, device_entry.id)
|
||||
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
|
||||
assert len(sensors) == 1
|
||||
|
||||
@@ -166,7 +170,11 @@ async def test_rm_pro_sensor_update(hass: HomeAssistant) -> None:
|
||||
assert sensors_and_states == {(f"{device.name} Temperature", "25.8")}
|
||||
|
||||
|
||||
async def test_rm_pro_filter_crazy_temperature(hass: HomeAssistant) -> None:
|
||||
async def test_rm_pro_filter_crazy_temperature(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test we filter a crazy temperature variation.
|
||||
|
||||
Firmware issue. See https://github.com/home-assistant/core/issues/42100.
|
||||
@@ -175,15 +183,12 @@ async def test_rm_pro_filter_crazy_temperature(hass: HomeAssistant) -> None:
|
||||
mock_api = device.get_mock_api()
|
||||
mock_api.check_sensors.return_value = {"temperature": 22.9}
|
||||
|
||||
device_registry = mock_device_registry(hass)
|
||||
entity_registry = mock_registry(hass)
|
||||
|
||||
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
|
||||
|
||||
device_entry = device_registry.async_get_device(
|
||||
{(DOMAIN, mock_setup.entry.unique_id)}
|
||||
)
|
||||
entries = async_entries_for_device(entity_registry, device_entry.id)
|
||||
entries = er.async_entries_for_device(entity_registry, device_entry.id)
|
||||
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
|
||||
assert len(sensors) == 1
|
||||
|
||||
@@ -201,42 +206,44 @@ async def test_rm_pro_filter_crazy_temperature(hass: HomeAssistant) -> None:
|
||||
assert sensors_and_states == {(f"{device.name} Temperature", "22.9")}
|
||||
|
||||
|
||||
async def test_rm_mini3_no_sensor(hass: HomeAssistant) -> None:
|
||||
async def test_rm_mini3_no_sensor(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test we do not set up sensors for RM mini 3."""
|
||||
device = get_device("Entrance")
|
||||
mock_api = device.get_mock_api()
|
||||
mock_api.check_sensors.return_value = {"temperature": 0}
|
||||
|
||||
device_registry = mock_device_registry(hass)
|
||||
entity_registry = mock_registry(hass)
|
||||
|
||||
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
|
||||
|
||||
assert mock_api.check_sensors.call_count <= 1
|
||||
device_entry = device_registry.async_get_device(
|
||||
{(DOMAIN, mock_setup.entry.unique_id)}
|
||||
)
|
||||
entries = async_entries_for_device(entity_registry, device_entry.id)
|
||||
entries = er.async_entries_for_device(entity_registry, device_entry.id)
|
||||
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
|
||||
assert len(sensors) == 0
|
||||
|
||||
|
||||
async def test_rm4_pro_hts2_sensor_setup(hass: HomeAssistant) -> None:
|
||||
async def test_rm4_pro_hts2_sensor_setup(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test a successful RM4 pro sensor setup with HTS2 cable."""
|
||||
device = get_device("Garage")
|
||||
mock_api = device.get_mock_api()
|
||||
mock_api.check_sensors.return_value = {"temperature": 22.5, "humidity": 43.7}
|
||||
|
||||
device_registry = mock_device_registry(hass)
|
||||
entity_registry = mock_registry(hass)
|
||||
|
||||
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
|
||||
|
||||
assert mock_api.check_sensors.call_count == 1
|
||||
device_entry = device_registry.async_get_device(
|
||||
{(DOMAIN, mock_setup.entry.unique_id)}
|
||||
)
|
||||
entries = async_entries_for_device(entity_registry, device_entry.id)
|
||||
entries = er.async_entries_for_device(entity_registry, device_entry.id)
|
||||
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
|
||||
assert len(sensors) == 2
|
||||
|
||||
@@ -253,21 +260,22 @@ async def test_rm4_pro_hts2_sensor_setup(hass: HomeAssistant) -> None:
|
||||
}
|
||||
|
||||
|
||||
async def test_rm4_pro_hts2_sensor_update(hass: HomeAssistant) -> None:
|
||||
async def test_rm4_pro_hts2_sensor_update(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test a successful RM4 pro sensor update with HTS2 cable."""
|
||||
device = get_device("Garage")
|
||||
mock_api = device.get_mock_api()
|
||||
mock_api.check_sensors.return_value = {"temperature": 16.7, "humidity": 34.1}
|
||||
|
||||
device_registry = mock_device_registry(hass)
|
||||
entity_registry = mock_registry(hass)
|
||||
|
||||
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
|
||||
|
||||
device_entry = device_registry.async_get_device(
|
||||
{(DOMAIN, mock_setup.entry.unique_id)}
|
||||
)
|
||||
entries = async_entries_for_device(entity_registry, device_entry.id)
|
||||
entries = er.async_entries_for_device(entity_registry, device_entry.id)
|
||||
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
|
||||
assert len(sensors) == 2
|
||||
|
||||
@@ -288,27 +296,32 @@ async def test_rm4_pro_hts2_sensor_update(hass: HomeAssistant) -> None:
|
||||
}
|
||||
|
||||
|
||||
async def test_rm4_pro_no_sensor(hass: HomeAssistant) -> None:
|
||||
async def test_rm4_pro_no_sensor(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test we do not set up sensors for RM4 pro without HTS2 cable."""
|
||||
device = get_device("Garage")
|
||||
mock_api = device.get_mock_api()
|
||||
mock_api.check_sensors.return_value = {"temperature": 0, "humidity": 0}
|
||||
|
||||
device_registry = mock_device_registry(hass)
|
||||
entity_registry = mock_registry(hass)
|
||||
|
||||
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
|
||||
|
||||
assert mock_api.check_sensors.call_count <= 1
|
||||
device_entry = device_registry.async_get_device(
|
||||
{(DOMAIN, mock_setup.entry.unique_id)}
|
||||
)
|
||||
entries = async_entries_for_device(entity_registry, device_entry.id)
|
||||
entries = er.async_entries_for_device(entity_registry, device_entry.id)
|
||||
sensors = {entry for entry in entries if entry.domain == Platform.SENSOR}
|
||||
assert len(sensors) == 0
|
||||
|
||||
|
||||
async def test_scb1e_sensor_setup(hass: HomeAssistant) -> None:
|
||||
async def test_scb1e_sensor_setup(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test a successful SCB1E sensor setup."""
|
||||
device = get_device("Dining room")
|
||||
mock_api = device.get_mock_api()
|
||||
@@ -324,16 +337,13 @@ async def test_scb1e_sensor_setup(hass: HomeAssistant) -> None:
|
||||
"childlock": 0,
|
||||
}
|
||||
|
||||
device_registry = mock_device_registry(hass)
|
||||
entity_registry = mock_registry(hass)
|
||||
|
||||
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
|
||||
|
||||
assert mock_api.get_state.call_count == 1
|
||||
device_entry = device_registry.async_get_device(
|
||||
{(DOMAIN, mock_setup.entry.unique_id)}
|
||||
)
|
||||
entries = async_entries_for_device(entity_registry, device_entry.id)
|
||||
entries = er.async_entries_for_device(entity_registry, device_entry.id)
|
||||
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
|
||||
assert len(sensors) == 5
|
||||
|
||||
@@ -353,7 +363,11 @@ async def test_scb1e_sensor_setup(hass: HomeAssistant) -> None:
|
||||
}
|
||||
|
||||
|
||||
async def test_scb1e_sensor_update(hass: HomeAssistant) -> None:
|
||||
async def test_scb1e_sensor_update(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test a successful SCB1E sensor update."""
|
||||
device = get_device("Dining room")
|
||||
mock_api = device.get_mock_api()
|
||||
@@ -369,9 +383,6 @@ async def test_scb1e_sensor_update(hass: HomeAssistant) -> None:
|
||||
"childlock": 0,
|
||||
}
|
||||
|
||||
device_registry = mock_device_registry(hass)
|
||||
entity_registry = mock_registry(hass)
|
||||
|
||||
target_time = (
|
||||
dt.utcnow() + BroadlinkSP4UpdateManager.SCAN_INTERVAL * 3 + timedelta(seconds=1)
|
||||
)
|
||||
@@ -381,7 +392,7 @@ async def test_scb1e_sensor_update(hass: HomeAssistant) -> None:
|
||||
device_entry = device_registry.async_get_device(
|
||||
{(DOMAIN, mock_setup.entry.unique_id)}
|
||||
)
|
||||
entries = async_entries_for_device(entity_registry, device_entry.id)
|
||||
entries = er.async_entries_for_device(entity_registry, device_entry.id)
|
||||
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
|
||||
assert len(sensors) == 5
|
||||
|
||||
|
||||
Reference in New Issue
Block a user