Update a-c* tests to use entity & device registry fixtures (#103793)

* Update a-c* tests to use entity & device registry fixtures

* Revert some changes

* Revert formatting

* retrigger CI
This commit is contained in:
Jan-Philipp Benecke 2023-11-12 19:45:30 +01:00 committed by GitHub
parent abb1328a67
commit 9ab1cb83d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 239 additions and 161 deletions

View file

@ -30,14 +30,15 @@ SENSORS_ALL_LEGACY = [*SENSORS_DEFAULT, *SENSORS_LOAD_AVG, *SENSORS_TEMPERATURES
@pytest.fixture(name="create_device_registry_devices") @pytest.fixture(name="create_device_registry_devices")
def create_device_registry_devices_fixture(hass: HomeAssistant): def create_device_registry_devices_fixture(
hass: HomeAssistant, device_registry: dr.DeviceRegistry
):
"""Create device registry devices so the device tracker entities are enabled when added.""" """Create device registry devices so the device tracker entities are enabled when added."""
dev_reg = dr.async_get(hass)
config_entry = MockConfigEntry(domain="something_else") config_entry = MockConfigEntry(domain="something_else")
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
for idx, device in enumerate((MOCK_MACS[2], MOCK_MACS[3])): for idx, device in enumerate((MOCK_MACS[2], MOCK_MACS[3])):
dev_reg.async_get_or_create( device_registry.async_get_or_create(
name=f"Device {idx}", name=f"Device {idx}",
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(dr.CONNECTION_NETWORK_MAC, dr.format_mac(device))}, connections={(dr.CONNECTION_NETWORK_MAC, dr.format_mac(device))},
@ -274,7 +275,9 @@ async def test_options_reload(hass: HomeAssistant, connect_legacy) -> None:
assert connect_legacy.return_value.connection.async_connect.call_count == 2 assert connect_legacy.return_value.connection.async_connect.call_count == 2
async def test_unique_id_migration(hass: HomeAssistant, connect_legacy) -> None: async def test_unique_id_migration(
hass: HomeAssistant, entity_registry: er.EntityRegistry, connect_legacy
) -> None:
"""Test AsusWRT entities unique id format migration.""" """Test AsusWRT entities unique id format migration."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -283,9 +286,8 @@ async def test_unique_id_migration(hass: HomeAssistant, connect_legacy) -> None:
) )
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
entity_reg = er.async_get(hass)
obj_entity_id = slugify(f"{HOST} Upload") obj_entity_id = slugify(f"{HOST} Upload")
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
sensor.DOMAIN, sensor.DOMAIN,
DOMAIN, DOMAIN,
f"{DOMAIN} {ROUTER_MAC_ADDR} Upload", f"{DOMAIN} {ROUTER_MAC_ADDR} Upload",
@ -297,6 +299,6 @@ async def test_unique_id_migration(hass: HomeAssistant, connect_legacy) -> None:
assert await hass.config_entries.async_setup(config_entry.entry_id) assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
migr_entity = entity_reg.async_get(f"{sensor.DOMAIN}.{obj_entity_id}") migr_entity = entity_registry.async_get(f"{sensor.DOMAIN}.{obj_entity_id}")
assert migr_entity is not None assert migr_entity is not None
assert migr_entity.unique_id == slugify(f"{ROUTER_MAC_ADDR}_sensor_tx_bytes") assert migr_entity.unique_id == slugify(f"{ROUTER_MAC_ADDR}_sensor_tx_bytes")

View file

@ -28,7 +28,9 @@ def airsensor_fixture() -> tuple[AsyncMock, str]:
return feature, "binary_sensor.windrainsensor_0_rain" return feature, "binary_sensor.windrainsensor_0_rain"
async def test_init(rainsensor: AsyncMock, hass: HomeAssistant) -> None: async def test_init(
rainsensor: AsyncMock, device_registry: dr.DeviceRegistry, hass: HomeAssistant
) -> None:
"""Test binary_sensor initialisation.""" """Test binary_sensor initialisation."""
_, entity_id = rainsensor _, entity_id = rainsensor
entry = await async_setup_entity(hass, entity_id) entry = await async_setup_entity(hass, entity_id)
@ -40,7 +42,6 @@ async def test_init(rainsensor: AsyncMock, hass: HomeAssistant) -> None:
assert state.attributes[ATTR_DEVICE_CLASS] == BinarySensorDeviceClass.MOISTURE assert state.attributes[ATTR_DEVICE_CLASS] == BinarySensorDeviceClass.MOISTURE
assert state.state == STATE_ON assert state.state == STATE_ON
device_registry = dr.async_get(hass)
device = device_registry.async_get(entry.device_id) device = device_registry.async_get(entry.device_id)
assert device.name == "My rain sensor" assert device.name == "My rain sensor"

View file

@ -76,7 +76,9 @@ def thermobox_fixture():
return (feature, "climate.thermobox_thermostat") return (feature, "climate.thermobox_thermostat")
async def test_init(saunabox, hass: HomeAssistant) -> None: async def test_init(
saunabox, hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test default state.""" """Test default state."""
_, entity_id = saunabox _, entity_id = saunabox
@ -102,7 +104,6 @@ async def test_init(saunabox, hass: HomeAssistant) -> None:
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
device_registry = dr.async_get(hass)
device = device_registry.async_get(entry.device_id) device = device_registry.async_get(entry.device_id)
assert device.name == "My sauna" assert device.name == "My sauna"

View file

@ -98,7 +98,9 @@ def gate_fixture():
return (feature, "cover.gatecontroller_position") return (feature, "cover.gatecontroller_position")
async def test_init_gatecontroller(gatecontroller, hass: HomeAssistant) -> None: async def test_init_gatecontroller(
gatecontroller, hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test gateController default state.""" """Test gateController default state."""
_, entity_id = gatecontroller _, entity_id = gatecontroller
@ -118,7 +120,6 @@ async def test_init_gatecontroller(gatecontroller, hass: HomeAssistant) -> None:
assert ATTR_CURRENT_POSITION not in state.attributes assert ATTR_CURRENT_POSITION not in state.attributes
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
device_registry = dr.async_get(hass)
device = device_registry.async_get(entry.device_id) device = device_registry.async_get(entry.device_id)
assert device.name == "My gate controller" assert device.name == "My gate controller"
@ -128,7 +129,9 @@ async def test_init_gatecontroller(gatecontroller, hass: HomeAssistant) -> None:
assert device.sw_version == "1.23" assert device.sw_version == "1.23"
async def test_init_shutterbox(shutterbox, hass: HomeAssistant) -> None: async def test_init_shutterbox(
shutterbox, hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test gateBox default state.""" """Test gateBox default state."""
_, entity_id = shutterbox _, entity_id = shutterbox
@ -148,7 +151,6 @@ async def test_init_shutterbox(shutterbox, hass: HomeAssistant) -> None:
assert ATTR_CURRENT_POSITION not in state.attributes assert ATTR_CURRENT_POSITION not in state.attributes
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
device_registry = dr.async_get(hass)
device = device_registry.async_get(entry.device_id) device = device_registry.async_get(entry.device_id)
assert device.name == "My shutter" assert device.name == "My shutter"
@ -158,7 +160,9 @@ async def test_init_shutterbox(shutterbox, hass: HomeAssistant) -> None:
assert device.sw_version == "1.23" assert device.sw_version == "1.23"
async def test_init_gatebox(gatebox, hass: HomeAssistant) -> None: async def test_init_gatebox(
gatebox, hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test cover default state.""" """Test cover default state."""
_, entity_id = gatebox _, entity_id = gatebox
@ -180,7 +184,6 @@ async def test_init_gatebox(gatebox, hass: HomeAssistant) -> None:
assert ATTR_CURRENT_POSITION not in state.attributes assert ATTR_CURRENT_POSITION not in state.attributes
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
device_registry = dr.async_get(hass)
device = device_registry.async_get(entry.device_id) device = device_registry.async_get(entry.device_id)
assert device.name == "My gatebox" assert device.name == "My gatebox"

View file

@ -50,7 +50,9 @@ def dimmer_fixture():
return (feature, "light.dimmerbox_brightness") return (feature, "light.dimmerbox_brightness")
async def test_dimmer_init(dimmer, hass: HomeAssistant) -> None: async def test_dimmer_init(
dimmer, hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test cover default state.""" """Test cover default state."""
_, entity_id = dimmer _, entity_id = dimmer
@ -66,7 +68,6 @@ async def test_dimmer_init(dimmer, hass: HomeAssistant) -> None:
assert state.attributes[ATTR_BRIGHTNESS] == 65 assert state.attributes[ATTR_BRIGHTNESS] == 65
assert state.state == STATE_ON assert state.state == STATE_ON
device_registry = dr.async_get(hass)
device = device_registry.async_get(entry.device_id) device = device_registry.async_get(entry.device_id)
assert device.name == "My dimmer" assert device.name == "My dimmer"
@ -223,7 +224,9 @@ def wlightboxs_fixture():
return (feature, "light.wlightboxs_color") return (feature, "light.wlightboxs_color")
async def test_wlightbox_s_init(wlightbox_s, hass: HomeAssistant) -> None: async def test_wlightbox_s_init(
wlightbox_s, hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test cover default state.""" """Test cover default state."""
_, entity_id = wlightbox_s _, entity_id = wlightbox_s
@ -239,7 +242,6 @@ async def test_wlightbox_s_init(wlightbox_s, hass: HomeAssistant) -> None:
assert state.attributes[ATTR_BRIGHTNESS] is None assert state.attributes[ATTR_BRIGHTNESS] is None
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
device_registry = dr.async_get(hass)
device = device_registry.async_get(entry.device_id) device = device_registry.async_get(entry.device_id)
assert device.name == "My wLightBoxS" assert device.name == "My wLightBoxS"
@ -326,7 +328,9 @@ def wlightbox_fixture():
return (feature, "light.wlightbox_color") return (feature, "light.wlightbox_color")
async def test_wlightbox_init(wlightbox, hass: HomeAssistant) -> None: async def test_wlightbox_init(
wlightbox, hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test cover default state.""" """Test cover default state."""
_, entity_id = wlightbox _, entity_id = wlightbox
@ -343,7 +347,6 @@ async def test_wlightbox_init(wlightbox, hass: HomeAssistant) -> None:
assert state.attributes[ATTR_RGBW_COLOR] is None assert state.attributes[ATTR_RGBW_COLOR] is None
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
device_registry = dr.async_get(hass)
device = device_registry.async_get(entry.device_id) device = device_registry.async_get(entry.device_id)
assert device.name == "My wLightBox" assert device.name == "My wLightBox"

View file

@ -56,7 +56,9 @@ def tempsensor_fixture():
return (feature, "sensor.tempsensor_0_temperature") return (feature, "sensor.tempsensor_0_temperature")
async def test_init(tempsensor, hass: HomeAssistant) -> None: async def test_init(
tempsensor, hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test sensor default state.""" """Test sensor default state."""
_, entity_id = tempsensor _, entity_id = tempsensor
@ -70,7 +72,6 @@ async def test_init(tempsensor, hass: HomeAssistant) -> None:
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTemperature.CELSIUS assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTemperature.CELSIUS
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
device_registry = dr.async_get(hass)
device = device_registry.async_get(entry.device_id) device = device_registry.async_get(entry.device_id)
assert device.name == "My temperature sensor" assert device.name == "My temperature sensor"
@ -110,7 +111,9 @@ async def test_update_failure(
assert f"Updating '{feature_mock.full_name}' failed: " in caplog.text assert f"Updating '{feature_mock.full_name}' failed: " in caplog.text
async def test_airsensor_init(airsensor, hass: HomeAssistant) -> None: async def test_airsensor_init(
airsensor, hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test airSensor default state.""" """Test airSensor default state."""
_, entity_id = airsensor _, entity_id = airsensor
@ -123,7 +126,6 @@ async def test_airsensor_init(airsensor, hass: HomeAssistant) -> None:
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.PM1 assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.PM1
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
device_registry = dr.async_get(hass)
device = device_registry.async_get(entry.device_id) device = device_registry.async_get(entry.device_id)
assert device.name == "My air sensor" assert device.name == "My air sensor"

View file

@ -44,7 +44,9 @@ def switchbox_fixture():
return (feature, "switch.switchbox_0_relay") return (feature, "switch.switchbox_0_relay")
async def test_switchbox_init(switchbox, hass: HomeAssistant, config) -> None: async def test_switchbox_init(
switchbox, hass: HomeAssistant, device_registry: dr.DeviceRegistry, config
) -> None:
"""Test switch default state.""" """Test switch default state."""
feature_mock, entity_id = switchbox feature_mock, entity_id = switchbox
@ -60,7 +62,6 @@ async def test_switchbox_init(switchbox, hass: HomeAssistant, config) -> None:
assert state.state == STATE_OFF assert state.state == STATE_OFF
device_registry = dr.async_get(hass)
device = device_registry.async_get(entry.device_id) device = device_registry.async_get(entry.device_id)
assert device.name == "My switch box" assert device.name == "My switch box"
@ -189,7 +190,9 @@ def switchbox_d_fixture():
return (features, ["switch.switchboxd_0_relay", "switch.switchboxd_1_relay"]) return (features, ["switch.switchboxd_0_relay", "switch.switchboxd_1_relay"])
async def test_switchbox_d_init(switchbox_d, hass: HomeAssistant) -> None: async def test_switchbox_d_init(
switchbox_d, hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test switch default state.""" """Test switch default state."""
feature_mocks, entity_ids = switchbox_d feature_mocks, entity_ids = switchbox_d
@ -206,7 +209,6 @@ async def test_switchbox_d_init(switchbox_d, hass: HomeAssistant) -> None:
assert state.attributes[ATTR_DEVICE_CLASS] == SwitchDeviceClass.SWITCH assert state.attributes[ATTR_DEVICE_CLASS] == SwitchDeviceClass.SWITCH
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
device_registry = dr.async_get(hass)
device = device_registry.async_get(entry.device_id) device = device_registry.async_get(entry.device_id)
assert device.name == "My relays" assert device.name == "My relays"
@ -223,7 +225,6 @@ async def test_switchbox_d_init(switchbox_d, hass: HomeAssistant) -> None:
assert state.attributes[ATTR_DEVICE_CLASS] == SwitchDeviceClass.SWITCH assert state.attributes[ATTR_DEVICE_CLASS] == SwitchDeviceClass.SWITCH
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
device_registry = dr.async_get(hass)
device = device_registry.async_get(entry.device_id) device = device_registry.async_get(entry.device_id)
assert device.name == "My relays" assert device.name == "My relays"

View file

@ -45,6 +45,7 @@ async def test_config_entry_diagnostics(
async def test_device_diagnostics( async def test_device_diagnostics(
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
device_registry: dr.DeviceRegistry,
bmw_fixture, bmw_fixture,
snapshot: SnapshotAssertion, snapshot: SnapshotAssertion,
) -> None: ) -> None:
@ -56,7 +57,6 @@ async def test_device_diagnostics(
mock_config_entry = await setup_mocked_integration(hass) mock_config_entry = await setup_mocked_integration(hass)
device_registry = dr.async_get(hass)
reg_device = device_registry.async_get_device( reg_device = device_registry.async_get_device(
identifiers={(DOMAIN, "WBY00000000REXI01")}, identifiers={(DOMAIN, "WBY00000000REXI01")},
) )
@ -73,6 +73,7 @@ async def test_device_diagnostics(
async def test_device_diagnostics_vehicle_not_found( async def test_device_diagnostics_vehicle_not_found(
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
device_registry: dr.DeviceRegistry,
bmw_fixture, bmw_fixture,
snapshot: SnapshotAssertion, snapshot: SnapshotAssertion,
) -> None: ) -> None:
@ -84,7 +85,6 @@ async def test_device_diagnostics_vehicle_not_found(
mock_config_entry = await setup_mocked_integration(hass) mock_config_entry = await setup_mocked_integration(hass)
device_registry = dr.async_get(hass)
reg_device = device_registry.async_get_device( reg_device = device_registry.async_get_device(
identifiers={(DOMAIN, "WBY00000000REXI01")}, identifiers={(DOMAIN, "WBY00000000REXI01")},
) )

View file

@ -49,12 +49,12 @@ async def test_migrate_unique_ids(
entitydata: dict, entitydata: dict,
old_unique_id: str, old_unique_id: str,
new_unique_id: str, new_unique_id: str,
entity_registry: er.EntityRegistry,
) -> None: ) -> None:
"""Test successful migration of entity unique_ids.""" """Test successful migration of entity unique_ids."""
mock_config_entry = MockConfigEntry(**FIXTURE_CONFIG_ENTRY) mock_config_entry = MockConfigEntry(**FIXTURE_CONFIG_ENTRY)
mock_config_entry.add_to_hass(hass) mock_config_entry.add_to_hass(hass)
entity_registry = er.async_get(hass)
entity: er.RegistryEntry = entity_registry.async_get_or_create( entity: er.RegistryEntry = entity_registry.async_get_or_create(
**entitydata, **entitydata,
config_entry=mock_config_entry, config_entry=mock_config_entry,
@ -95,13 +95,12 @@ async def test_dont_migrate_unique_ids(
entitydata: dict, entitydata: dict,
old_unique_id: str, old_unique_id: str,
new_unique_id: str, new_unique_id: str,
entity_registry: er.EntityRegistry,
) -> None: ) -> None:
"""Test successful migration of entity unique_ids.""" """Test successful migration of entity unique_ids."""
mock_config_entry = MockConfigEntry(**FIXTURE_CONFIG_ENTRY) mock_config_entry = MockConfigEntry(**FIXTURE_CONFIG_ENTRY)
mock_config_entry.add_to_hass(hass) mock_config_entry.add_to_hass(hass)
entity_registry = er.async_get(hass)
# create existing entry with new_unique_id # create existing entry with new_unique_id
existing_entity = entity_registry.async_get_or_create( existing_entity = entity_registry.async_get_or_create(
SENSOR_DOMAIN, SENSOR_DOMAIN,

View file

@ -32,14 +32,12 @@ ATTR_REMAINING_PAGES = "remaining_pages"
ATTR_COUNTER = "counter" ATTR_COUNTER = "counter"
async def test_sensors(hass: HomeAssistant) -> None: async def test_sensors(hass: HomeAssistant, entity_registry: er.EntityRegistry) -> None:
"""Test states of the sensors.""" """Test states of the sensors."""
entry = await init_integration(hass, skip_setup=True) entry = await init_integration(hass, skip_setup=True)
registry = er.async_get(hass)
# Pre-create registry entries for disabled by default sensors # Pre-create registry entries for disabled by default sensors
registry.async_get_or_create( entity_registry.async_get_or_create(
SENSOR_DOMAIN, SENSOR_DOMAIN,
DOMAIN, DOMAIN,
"0123456789_uptime", "0123456789_uptime",
@ -62,7 +60,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "waiting" assert state.state == "waiting"
assert state.attributes.get(ATTR_STATE_CLASS) is None assert state.attributes.get(ATTR_STATE_CLASS) is None
entry = registry.async_get("sensor.hl_l2340dw_status") entry = entity_registry.async_get("sensor.hl_l2340dw_status")
assert entry assert entry
assert entry.unique_id == "0123456789_status" assert entry.unique_id == "0123456789_status"
@ -73,7 +71,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "75" assert state.state == "75"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_black_toner_remaining") entry = entity_registry.async_get("sensor.hl_l2340dw_black_toner_remaining")
assert entry assert entry
assert entry.unique_id == "0123456789_black_toner_remaining" assert entry.unique_id == "0123456789_black_toner_remaining"
@ -84,7 +82,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "10" assert state.state == "10"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_cyan_toner_remaining") entry = entity_registry.async_get("sensor.hl_l2340dw_cyan_toner_remaining")
assert entry assert entry
assert entry.unique_id == "0123456789_cyan_toner_remaining" assert entry.unique_id == "0123456789_cyan_toner_remaining"
@ -95,7 +93,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "8" assert state.state == "8"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_magenta_toner_remaining") entry = entity_registry.async_get("sensor.hl_l2340dw_magenta_toner_remaining")
assert entry assert entry
assert entry.unique_id == "0123456789_magenta_toner_remaining" assert entry.unique_id == "0123456789_magenta_toner_remaining"
@ -106,7 +104,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "2" assert state.state == "2"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_yellow_toner_remaining") entry = entity_registry.async_get("sensor.hl_l2340dw_yellow_toner_remaining")
assert entry assert entry
assert entry.unique_id == "0123456789_yellow_toner_remaining" assert entry.unique_id == "0123456789_yellow_toner_remaining"
@ -117,7 +115,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "92" assert state.state == "92"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_drum_remaining_lifetime") entry = entity_registry.async_get("sensor.hl_l2340dw_drum_remaining_lifetime")
assert entry assert entry
assert entry.unique_id == "0123456789_drum_remaining_life" assert entry.unique_id == "0123456789_drum_remaining_life"
@ -128,7 +126,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "11014" assert state.state == "11014"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_drum_remaining_pages") entry = entity_registry.async_get("sensor.hl_l2340dw_drum_remaining_pages")
assert entry assert entry
assert entry.unique_id == "0123456789_drum_remaining_pages" assert entry.unique_id == "0123456789_drum_remaining_pages"
@ -139,7 +137,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "986" assert state.state == "986"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_drum_page_counter") entry = entity_registry.async_get("sensor.hl_l2340dw_drum_page_counter")
assert entry assert entry
assert entry.unique_id == "0123456789_drum_counter" assert entry.unique_id == "0123456789_drum_counter"
@ -150,7 +148,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "92" assert state.state == "92"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_black_drum_remaining_lifetime") entry = entity_registry.async_get("sensor.hl_l2340dw_black_drum_remaining_lifetime")
assert entry assert entry
assert entry.unique_id == "0123456789_black_drum_remaining_life" assert entry.unique_id == "0123456789_black_drum_remaining_life"
@ -161,7 +159,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "16389" assert state.state == "16389"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_black_drum_remaining_pages") entry = entity_registry.async_get("sensor.hl_l2340dw_black_drum_remaining_pages")
assert entry assert entry
assert entry.unique_id == "0123456789_black_drum_remaining_pages" assert entry.unique_id == "0123456789_black_drum_remaining_pages"
@ -172,7 +170,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "1611" assert state.state == "1611"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_black_drum_page_counter") entry = entity_registry.async_get("sensor.hl_l2340dw_black_drum_page_counter")
assert entry assert entry
assert entry.unique_id == "0123456789_black_drum_counter" assert entry.unique_id == "0123456789_black_drum_counter"
@ -183,7 +181,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "92" assert state.state == "92"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_cyan_drum_remaining_lifetime") entry = entity_registry.async_get("sensor.hl_l2340dw_cyan_drum_remaining_lifetime")
assert entry assert entry
assert entry.unique_id == "0123456789_cyan_drum_remaining_life" assert entry.unique_id == "0123456789_cyan_drum_remaining_life"
@ -194,7 +192,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "16389" assert state.state == "16389"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_cyan_drum_remaining_pages") entry = entity_registry.async_get("sensor.hl_l2340dw_cyan_drum_remaining_pages")
assert entry assert entry
assert entry.unique_id == "0123456789_cyan_drum_remaining_pages" assert entry.unique_id == "0123456789_cyan_drum_remaining_pages"
@ -205,7 +203,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "1611" assert state.state == "1611"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_cyan_drum_page_counter") entry = entity_registry.async_get("sensor.hl_l2340dw_cyan_drum_page_counter")
assert entry assert entry
assert entry.unique_id == "0123456789_cyan_drum_counter" assert entry.unique_id == "0123456789_cyan_drum_counter"
@ -216,7 +214,9 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "92" assert state.state == "92"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_magenta_drum_remaining_lifetime") entry = entity_registry.async_get(
"sensor.hl_l2340dw_magenta_drum_remaining_lifetime"
)
assert entry assert entry
assert entry.unique_id == "0123456789_magenta_drum_remaining_life" assert entry.unique_id == "0123456789_magenta_drum_remaining_life"
@ -227,7 +227,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "16389" assert state.state == "16389"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_magenta_drum_remaining_pages") entry = entity_registry.async_get("sensor.hl_l2340dw_magenta_drum_remaining_pages")
assert entry assert entry
assert entry.unique_id == "0123456789_magenta_drum_remaining_pages" assert entry.unique_id == "0123456789_magenta_drum_remaining_pages"
@ -238,7 +238,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "1611" assert state.state == "1611"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_magenta_drum_page_counter") entry = entity_registry.async_get("sensor.hl_l2340dw_magenta_drum_page_counter")
assert entry assert entry
assert entry.unique_id == "0123456789_magenta_drum_counter" assert entry.unique_id == "0123456789_magenta_drum_counter"
@ -249,7 +249,9 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "92" assert state.state == "92"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_yellow_drum_remaining_lifetime") entry = entity_registry.async_get(
"sensor.hl_l2340dw_yellow_drum_remaining_lifetime"
)
assert entry assert entry
assert entry.unique_id == "0123456789_yellow_drum_remaining_life" assert entry.unique_id == "0123456789_yellow_drum_remaining_life"
@ -260,7 +262,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "16389" assert state.state == "16389"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_yellow_drum_remaining_pages") entry = entity_registry.async_get("sensor.hl_l2340dw_yellow_drum_remaining_pages")
assert entry assert entry
assert entry.unique_id == "0123456789_yellow_drum_remaining_pages" assert entry.unique_id == "0123456789_yellow_drum_remaining_pages"
@ -271,7 +273,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "1611" assert state.state == "1611"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_yellow_drum_page_counter") entry = entity_registry.async_get("sensor.hl_l2340dw_yellow_drum_page_counter")
assert entry assert entry
assert entry.unique_id == "0123456789_yellow_drum_counter" assert entry.unique_id == "0123456789_yellow_drum_counter"
@ -282,7 +284,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "97" assert state.state == "97"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_fuser_remaining_lifetime") entry = entity_registry.async_get("sensor.hl_l2340dw_fuser_remaining_lifetime")
assert entry assert entry
assert entry.unique_id == "0123456789_fuser_remaining_life" assert entry.unique_id == "0123456789_fuser_remaining_life"
@ -293,7 +295,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "97" assert state.state == "97"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_belt_unit_remaining_lifetime") entry = entity_registry.async_get("sensor.hl_l2340dw_belt_unit_remaining_lifetime")
assert entry assert entry
assert entry.unique_id == "0123456789_belt_unit_remaining_life" assert entry.unique_id == "0123456789_belt_unit_remaining_life"
@ -304,7 +306,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "98" assert state.state == "98"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_pf_kit_1_remaining_lifetime") entry = entity_registry.async_get("sensor.hl_l2340dw_pf_kit_1_remaining_lifetime")
assert entry assert entry
assert entry.unique_id == "0123456789_pf_kit_1_remaining_life" assert entry.unique_id == "0123456789_pf_kit_1_remaining_life"
@ -315,7 +317,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "986" assert state.state == "986"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_page_counter") entry = entity_registry.async_get("sensor.hl_l2340dw_page_counter")
assert entry assert entry
assert entry.unique_id == "0123456789_page_counter" assert entry.unique_id == "0123456789_page_counter"
@ -326,7 +328,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "538" assert state.state == "538"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_duplex_unit_page_counter") entry = entity_registry.async_get("sensor.hl_l2340dw_duplex_unit_page_counter")
assert entry assert entry
assert entry.unique_id == "0123456789_duplex_unit_pages_counter" assert entry.unique_id == "0123456789_duplex_unit_pages_counter"
@ -337,7 +339,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "709" assert state.state == "709"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_b_w_pages") entry = entity_registry.async_get("sensor.hl_l2340dw_b_w_pages")
assert entry assert entry
assert entry.unique_id == "0123456789_bw_counter" assert entry.unique_id == "0123456789_bw_counter"
@ -348,7 +350,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "902" assert state.state == "902"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.hl_l2340dw_color_pages") entry = entity_registry.async_get("sensor.hl_l2340dw_color_pages")
assert entry assert entry
assert entry.unique_id == "0123456789_color_counter" assert entry.unique_id == "0123456789_color_counter"
@ -360,20 +362,21 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state.state == "2019-09-24T12:14:56+00:00" assert state.state == "2019-09-24T12:14:56+00:00"
assert state.attributes.get(ATTR_STATE_CLASS) is None assert state.attributes.get(ATTR_STATE_CLASS) is None
entry = registry.async_get("sensor.hl_l2340dw_last_restart") entry = entity_registry.async_get("sensor.hl_l2340dw_last_restart")
assert entry assert entry
assert entry.unique_id == "0123456789_uptime" assert entry.unique_id == "0123456789_uptime"
async def test_disabled_by_default_sensors(hass: HomeAssistant) -> None: async def test_disabled_by_default_sensors(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test the disabled by default Brother sensors.""" """Test the disabled by default Brother sensors."""
await init_integration(hass) await init_integration(hass)
registry = er.async_get(hass)
state = hass.states.get("sensor.hl_l2340dw_last_restart") state = hass.states.get("sensor.hl_l2340dw_last_restart")
assert state is None assert state is None
entry = registry.async_get("sensor.hl_l2340dw_last_restart") entry = entity_registry.async_get("sensor.hl_l2340dw_last_restart")
assert entry assert entry
assert entry.unique_id == "0123456789_uptime" assert entry.unique_id == "0123456789_uptime"
assert entry.disabled assert entry.disabled
@ -434,11 +437,12 @@ async def test_manual_update_entity(hass: HomeAssistant) -> None:
assert len(mock_update.mock_calls) == 1 assert len(mock_update.mock_calls) == 1
async def test_unique_id_migration(hass: HomeAssistant) -> None: async def test_unique_id_migration(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test states of the unique_id migration.""" """Test states of the unique_id migration."""
registry = er.async_get(hass)
registry.async_get_or_create( entity_registry.async_get_or_create(
SENSOR_DOMAIN, SENSOR_DOMAIN,
DOMAIN, DOMAIN,
"0123456789_b/w_counter", "0123456789_b/w_counter",
@ -448,6 +452,6 @@ async def test_unique_id_migration(hass: HomeAssistant) -> None:
await init_integration(hass) await init_integration(hass)
entry = registry.async_get("sensor.hl_l2340dw_b_w_counter") entry = entity_registry.async_get("sensor.hl_l2340dw_b_w_counter")
assert entry assert entry
assert entry.unique_id == "0123456789_bw_counter" assert entry.unique_id == "0123456789_bw_counter"

View file

@ -367,7 +367,10 @@ async def test_websocket_update_preload_prefs(
async def test_websocket_update_orientation_prefs( async def test_websocket_update_orientation_prefs(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, mock_camera hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
entity_registry: er.EntityRegistry,
mock_camera,
) -> None: ) -> None:
"""Test updating camera preferences.""" """Test updating camera preferences."""
await async_setup_component(hass, "homeassistant", {}) await async_setup_component(hass, "homeassistant", {})
@ -387,11 +390,10 @@ async def test_websocket_update_orientation_prefs(
assert not response["success"] assert not response["success"]
assert response["error"]["code"] == "update_failed" assert response["error"]["code"] == "update_failed"
registry = er.async_get(hass) assert not entity_registry.async_get("camera.demo_uniquecamera")
assert not registry.async_get("camera.demo_uniquecamera")
# Since we don't have a unique id, we need to create a registry entry # Since we don't have a unique id, we need to create a registry entry
registry.async_get_or_create(DOMAIN, "demo", "uniquecamera") entity_registry.async_get_or_create(DOMAIN, "demo", "uniquecamera")
registry.async_update_entity_options( entity_registry.async_update_entity_options(
"camera.demo_uniquecamera", "camera.demo_uniquecamera",
DOMAIN, DOMAIN,
{}, {},
@ -408,7 +410,9 @@ async def test_websocket_update_orientation_prefs(
response = await client.receive_json() response = await client.receive_json()
assert response["success"] assert response["success"]
er_camera_prefs = registry.async_get("camera.demo_uniquecamera").options[DOMAIN] er_camera_prefs = entity_registry.async_get("camera.demo_uniquecamera").options[
DOMAIN
]
assert er_camera_prefs[PREF_ORIENTATION] == camera.Orientation.ROTATE_180 assert er_camera_prefs[PREF_ORIENTATION] == camera.Orientation.ROTATE_180
assert response["result"][PREF_ORIENTATION] == er_camera_prefs[PREF_ORIENTATION] assert response["result"][PREF_ORIENTATION] == er_camera_prefs[PREF_ORIENTATION]
# Check that the preference was saved # Check that the preference was saved

View file

@ -552,6 +552,7 @@ async def test_auto_cast_chromecasts(hass: HomeAssistant) -> None:
async def test_discover_dynamic_group( async def test_discover_dynamic_group(
hass: HomeAssistant, hass: HomeAssistant,
entity_registry: er.EntityRegistry,
get_multizone_status_mock, get_multizone_status_mock,
get_chromecast_mock, get_chromecast_mock,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
@ -562,8 +563,6 @@ async def test_discover_dynamic_group(
zconf_1 = get_fake_zconf(host="host_1", port=23456) zconf_1 = get_fake_zconf(host="host_1", port=23456)
zconf_2 = get_fake_zconf(host="host_2", port=34567) zconf_2 = get_fake_zconf(host="host_2", port=34567)
reg = er.async_get(hass)
# Fake dynamic group info # Fake dynamic group info
tmp1 = MagicMock() tmp1 = MagicMock()
tmp1.uuid = FakeUUID tmp1.uuid = FakeUUID
@ -606,7 +605,9 @@ async def test_discover_dynamic_group(
get_chromecast_mock.assert_called() get_chromecast_mock.assert_called()
get_chromecast_mock.reset_mock() get_chromecast_mock.reset_mock()
assert add_dev1.call_count == 0 assert add_dev1.call_count == 0
assert reg.async_get_entity_id("media_player", "cast", cast_1.uuid) is None assert (
entity_registry.async_get_entity_id("media_player", "cast", cast_1.uuid) is None
)
# Discover other dynamic group cast service # Discover other dynamic group cast service
with patch( with patch(
@ -632,7 +633,9 @@ async def test_discover_dynamic_group(
get_chromecast_mock.assert_called() get_chromecast_mock.assert_called()
get_chromecast_mock.reset_mock() get_chromecast_mock.reset_mock()
assert add_dev1.call_count == 0 assert add_dev1.call_count == 0
assert reg.async_get_entity_id("media_player", "cast", cast_2.uuid) is None assert (
entity_registry.async_get_entity_id("media_player", "cast", cast_2.uuid) is None
)
# Get update for cast service # Get update for cast service
with patch( with patch(
@ -655,7 +658,9 @@ async def test_discover_dynamic_group(
assert len(tasks) == 0 assert len(tasks) == 0
get_chromecast_mock.assert_not_called() get_chromecast_mock.assert_not_called()
assert add_dev1.call_count == 0 assert add_dev1.call_count == 0
assert reg.async_get_entity_id("media_player", "cast", cast_1.uuid) is None assert (
entity_registry.async_get_entity_id("media_player", "cast", cast_1.uuid) is None
)
# Remove cast service # Remove cast service
assert "Disconnecting from chromecast" not in caplog.text assert "Disconnecting from chromecast" not in caplog.text
@ -765,14 +770,17 @@ async def test_entity_availability(hass: HomeAssistant) -> None:
@pytest.mark.parametrize(("port", "entry_type"), ((8009, None), (12345, None))) @pytest.mark.parametrize(("port", "entry_type"), ((8009, None), (12345, None)))
async def test_device_registry( async def test_device_registry(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, port, entry_type hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
port,
entry_type,
) -> None: ) -> None:
"""Test device registry integration.""" """Test device registry integration."""
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
entity_id = "media_player.speaker" entity_id = "media_player.speaker"
reg = er.async_get(hass)
dev_reg = dr.async_get(hass)
info = get_fake_chromecast_info(port=port) info = get_fake_chromecast_info(port=port)
@ -790,9 +798,11 @@ async def test_device_registry(
assert state is not None assert state is not None
assert state.name == "Speaker" assert state.name == "Speaker"
assert state.state == "off" assert state.state == "off"
assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) assert entity_id == entity_registry.async_get_entity_id(
entity_entry = reg.async_get(entity_id) "media_player", "cast", str(info.uuid)
device_entry = dev_reg.async_get(entity_entry.device_id) )
entity_entry = entity_registry.async_get(entity_id)
device_entry = device_registry.async_get(entity_entry.device_id)
assert entity_entry.device_id == device_entry.id assert entity_entry.device_id == device_entry.id
assert device_entry.entry_type == entry_type assert device_entry.entry_type == entry_type
@ -815,14 +825,15 @@ async def test_device_registry(
await hass.async_block_till_done() await hass.async_block_till_done()
chromecast.disconnect.assert_called_once() chromecast.disconnect.assert_called_once()
assert reg.async_get(entity_id) is None assert entity_registry.async_get(entity_id) is None
assert dev_reg.async_get(entity_entry.device_id) is None assert device_registry.async_get(entity_entry.device_id) is None
async def test_entity_cast_status(hass: HomeAssistant) -> None: async def test_entity_cast_status(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test handling of cast status.""" """Test handling of cast status."""
entity_id = "media_player.speaker" entity_id = "media_player.speaker"
reg = er.async_get(hass)
info = get_fake_chromecast_info() info = get_fake_chromecast_info()
@ -839,7 +850,9 @@ async def test_entity_cast_status(hass: HomeAssistant) -> None:
assert state is not None assert state is not None
assert state.name == "Speaker" assert state.name == "Speaker"
assert state.state == "off" assert state.state == "off"
assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) assert entity_id == entity_registry.async_get_entity_id(
"media_player", "cast", str(info.uuid)
)
# No media status, pause, play, stop not supported # No media status, pause, play, stop not supported
assert state.attributes.get("supported_features") == ( assert state.attributes.get("supported_features") == (
@ -1088,10 +1101,11 @@ async def test_entity_browse_media_audio_only(
assert expected_child_2 in response["result"]["children"] assert expected_child_2 in response["result"]["children"]
async def test_entity_play_media(hass: HomeAssistant, quick_play_mock) -> None: async def test_entity_play_media(
hass: HomeAssistant, entity_registry: er.EntityRegistry, quick_play_mock
) -> None:
"""Test playing media.""" """Test playing media."""
entity_id = "media_player.speaker" entity_id = "media_player.speaker"
reg = er.async_get(hass)
info = get_fake_chromecast_info() info = get_fake_chromecast_info()
@ -1107,7 +1121,9 @@ async def test_entity_play_media(hass: HomeAssistant, quick_play_mock) -> None:
assert state is not None assert state is not None
assert state.name == "Speaker" assert state.name == "Speaker"
assert state.state == "off" assert state.state == "off"
assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) assert entity_id == entity_registry.async_get_entity_id(
"media_player", "cast", str(info.uuid)
)
# Play_media # Play_media
await hass.services.async_call( await hass.services.async_call(
@ -1134,10 +1150,11 @@ async def test_entity_play_media(hass: HomeAssistant, quick_play_mock) -> None:
) )
async def test_entity_play_media_cast(hass: HomeAssistant, quick_play_mock) -> None: async def test_entity_play_media_cast(
hass: HomeAssistant, entity_registry: er.EntityRegistry, quick_play_mock
) -> None:
"""Test playing media with cast special features.""" """Test playing media with cast special features."""
entity_id = "media_player.speaker" entity_id = "media_player.speaker"
reg = er.async_get(hass)
info = get_fake_chromecast_info() info = get_fake_chromecast_info()
@ -1153,7 +1170,9 @@ async def test_entity_play_media_cast(hass: HomeAssistant, quick_play_mock) -> N
assert state is not None assert state is not None
assert state.name == "Speaker" assert state.name == "Speaker"
assert state.state == "off" assert state.state == "off"
assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) assert entity_id == entity_registry.async_get_entity_id(
"media_player", "cast", str(info.uuid)
)
# Play_media - cast with app ID # Play_media - cast with app ID
await common.async_play_media(hass, "cast", '{"app_id": "abc123"}', entity_id) await common.async_play_media(hass, "cast", '{"app_id": "abc123"}', entity_id)
@ -1177,11 +1196,13 @@ async def test_entity_play_media_cast(hass: HomeAssistant, quick_play_mock) -> N
async def test_entity_play_media_cast_invalid( async def test_entity_play_media_cast_invalid(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, quick_play_mock hass: HomeAssistant,
entity_registry: er.EntityRegistry,
caplog: pytest.LogCaptureFixture,
quick_play_mock,
) -> None: ) -> None:
"""Test playing media.""" """Test playing media."""
entity_id = "media_player.speaker" entity_id = "media_player.speaker"
reg = er.async_get(hass)
info = get_fake_chromecast_info() info = get_fake_chromecast_info()
@ -1197,7 +1218,9 @@ async def test_entity_play_media_cast_invalid(
assert state is not None assert state is not None
assert state.name == "Speaker" assert state.name == "Speaker"
assert state.state == "off" assert state.state == "off"
assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) assert entity_id == entity_registry.async_get_entity_id(
"media_player", "cast", str(info.uuid)
)
# play_media - media_type cast with invalid JSON # play_media - media_type cast with invalid JSON
with pytest.raises(json.decoder.JSONDecodeError): with pytest.raises(json.decoder.JSONDecodeError):
@ -1345,11 +1368,13 @@ async def test_entity_play_media_playlist(
], ],
) )
async def test_entity_media_content_type( async def test_entity_media_content_type(
hass: HomeAssistant, cast_type, default_content_type hass: HomeAssistant,
entity_registry: er.EntityRegistry,
cast_type,
default_content_type,
) -> None: ) -> None:
"""Test various content types.""" """Test various content types."""
entity_id = "media_player.speaker" entity_id = "media_player.speaker"
reg = er.async_get(hass)
info = get_fake_chromecast_info() info = get_fake_chromecast_info()
@ -1366,7 +1391,9 @@ async def test_entity_media_content_type(
assert state is not None assert state is not None
assert state.name == "Speaker" assert state.name == "Speaker"
assert state.state == "off" assert state.state == "off"
assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) assert entity_id == entity_registry.async_get_entity_id(
"media_player", "cast", str(info.uuid)
)
media_status = MagicMock(images=None) media_status = MagicMock(images=None)
media_status.media_is_movie = False media_status.media_is_movie = False
@ -1398,10 +1425,11 @@ async def test_entity_media_content_type(
assert state.attributes.get("media_content_type") == "movie" assert state.attributes.get("media_content_type") == "movie"
async def test_entity_control(hass: HomeAssistant, quick_play_mock) -> None: async def test_entity_control(
hass: HomeAssistant, entity_registry: er.EntityRegistry, quick_play_mock
) -> None:
"""Test various device and media controls.""" """Test various device and media controls."""
entity_id = "media_player.speaker" entity_id = "media_player.speaker"
reg = er.async_get(hass)
info = get_fake_chromecast_info() info = get_fake_chromecast_info()
@ -1427,7 +1455,9 @@ async def test_entity_control(hass: HomeAssistant, quick_play_mock) -> None:
assert state is not None assert state is not None
assert state.name == "Speaker" assert state.name == "Speaker"
assert state.state == "playing" assert state.state == "playing"
assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) assert entity_id == entity_registry.async_get_entity_id(
"media_player", "cast", str(info.uuid)
)
assert state.attributes.get("supported_features") == ( assert state.attributes.get("supported_features") == (
MediaPlayerEntityFeature.PAUSE MediaPlayerEntityFeature.PAUSE
@ -1527,10 +1557,11 @@ async def test_entity_control(hass: HomeAssistant, quick_play_mock) -> None:
("app_id", "state_no_media"), ("app_id", "state_no_media"),
[(pychromecast.APP_YOUTUBE, "idle"), ("Netflix", "playing")], [(pychromecast.APP_YOUTUBE, "idle"), ("Netflix", "playing")],
) )
async def test_entity_media_states(hass: HomeAssistant, app_id, state_no_media) -> None: async def test_entity_media_states(
hass: HomeAssistant, entity_registry: er.EntityRegistry, app_id, state_no_media
) -> None:
"""Test various entity media states.""" """Test various entity media states."""
entity_id = "media_player.speaker" entity_id = "media_player.speaker"
reg = er.async_get(hass)
info = get_fake_chromecast_info() info = get_fake_chromecast_info()
@ -1546,7 +1577,9 @@ async def test_entity_media_states(hass: HomeAssistant, app_id, state_no_media)
assert state is not None assert state is not None
assert state.name == "Speaker" assert state.name == "Speaker"
assert state.state == "off" assert state.state == "off"
assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) assert entity_id == entity_registry.async_get_entity_id(
"media_player", "cast", str(info.uuid)
)
# App id updated, but no media status # App id updated, but no media status
chromecast.app_id = app_id chromecast.app_id = app_id
@ -1606,10 +1639,11 @@ async def test_entity_media_states(hass: HomeAssistant, app_id, state_no_media)
assert state.state == "unknown" assert state.state == "unknown"
async def test_entity_media_states_lovelace_app(hass: HomeAssistant) -> None: async def test_entity_media_states_lovelace_app(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test various entity media states when the lovelace app is active.""" """Test various entity media states when the lovelace app is active."""
entity_id = "media_player.speaker" entity_id = "media_player.speaker"
reg = er.async_get(hass)
info = get_fake_chromecast_info() info = get_fake_chromecast_info()
@ -1625,7 +1659,9 @@ async def test_entity_media_states_lovelace_app(hass: HomeAssistant) -> None:
assert state is not None assert state is not None
assert state.name == "Speaker" assert state.name == "Speaker"
assert state.state == "off" assert state.state == "off"
assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) assert entity_id == entity_registry.async_get_entity_id(
"media_player", "cast", str(info.uuid)
)
chromecast.app_id = CAST_APP_ID_HOMEASSISTANT_LOVELACE chromecast.app_id = CAST_APP_ID_HOMEASSISTANT_LOVELACE
cast_status = MagicMock() cast_status = MagicMock()
@ -1677,10 +1713,11 @@ async def test_entity_media_states_lovelace_app(hass: HomeAssistant) -> None:
assert state.state == "unknown" assert state.state == "unknown"
async def test_group_media_states(hass: HomeAssistant, mz_mock) -> None: async def test_group_media_states(
hass: HomeAssistant, entity_registry: er.EntityRegistry, mz_mock
) -> None:
"""Test media states are read from group if entity has no state.""" """Test media states are read from group if entity has no state."""
entity_id = "media_player.speaker" entity_id = "media_player.speaker"
reg = er.async_get(hass)
info = get_fake_chromecast_info() info = get_fake_chromecast_info()
@ -1698,7 +1735,9 @@ async def test_group_media_states(hass: HomeAssistant, mz_mock) -> None:
assert state is not None assert state is not None
assert state.name == "Speaker" assert state.name == "Speaker"
assert state.state == "off" assert state.state == "off"
assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) assert entity_id == entity_registry.async_get_entity_id(
"media_player", "cast", str(info.uuid)
)
group_media_status = MagicMock(images=None) group_media_status = MagicMock(images=None)
player_media_status = MagicMock(images=None) player_media_status = MagicMock(images=None)
@ -1734,13 +1773,14 @@ async def test_group_media_states(hass: HomeAssistant, mz_mock) -> None:
assert state.state == "playing" assert state.state == "playing"
async def test_group_media_states_early(hass: HomeAssistant, mz_mock) -> None: async def test_group_media_states_early(
hass: HomeAssistant, entity_registry: er.EntityRegistry, mz_mock
) -> None:
"""Test media states are read from group if entity has no state. """Test media states are read from group if entity has no state.
This tests case asserts group state is polled when the player is created. This tests case asserts group state is polled when the player is created.
""" """
entity_id = "media_player.speaker" entity_id = "media_player.speaker"
reg = er.async_get(hass)
info = get_fake_chromecast_info() info = get_fake_chromecast_info()
@ -1756,7 +1796,9 @@ async def test_group_media_states_early(hass: HomeAssistant, mz_mock) -> None:
assert state is not None assert state is not None
assert state.name == "Speaker" assert state.name == "Speaker"
assert state.state == "unavailable" assert state.state == "unavailable"
assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) assert entity_id == entity_registry.async_get_entity_id(
"media_player", "cast", str(info.uuid)
)
# Check group state is polled when player is first created # Check group state is polled when player is first created
connection_status = MagicMock() connection_status = MagicMock()
@ -1788,11 +1830,10 @@ async def test_group_media_states_early(hass: HomeAssistant, mz_mock) -> None:
async def test_group_media_control( async def test_group_media_control(
hass: HomeAssistant, mz_mock, quick_play_mock hass: HomeAssistant, entity_registry: er.EntityRegistry, mz_mock, quick_play_mock
) -> None: ) -> None:
"""Test media controls are handled by group if entity has no state.""" """Test media controls are handled by group if entity has no state."""
entity_id = "media_player.speaker" entity_id = "media_player.speaker"
reg = er.async_get(hass)
info = get_fake_chromecast_info() info = get_fake_chromecast_info()
@ -1811,7 +1852,9 @@ async def test_group_media_control(
assert state is not None assert state is not None
assert state.name == "Speaker" assert state.name == "Speaker"
assert state.state == "off" assert state.state == "off"
assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid)) assert entity_id == entity_registry.async_get_entity_id(
"media_player", "cast", str(info.uuid)
)
group_media_status = MagicMock(images=None) group_media_status = MagicMock(images=None)
player_media_status = MagicMock(images=None) player_media_status = MagicMock(images=None)

View file

@ -248,10 +248,12 @@ async def test_webhook_msg(
async def test_google_config_expose_entity( async def test_google_config_expose_entity(
hass: HomeAssistant, mock_cloud_setup, mock_cloud_login hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_cloud_setup,
mock_cloud_login,
) -> None: ) -> None:
"""Test Google config exposing entity method uses latest config.""" """Test Google config exposing entity method uses latest config."""
entity_registry = er.async_get(hass)
# Enable exposing new entities to Google # Enable exposing new entities to Google
exposed_entities: ExposedEntities = hass.data[DATA_EXPOSED_ENTITIES] exposed_entities: ExposedEntities = hass.data[DATA_EXPOSED_ENTITIES]
@ -274,10 +276,12 @@ async def test_google_config_expose_entity(
async def test_google_config_should_2fa( async def test_google_config_should_2fa(
hass: HomeAssistant, mock_cloud_setup, mock_cloud_login hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_cloud_setup,
mock_cloud_login,
) -> None: ) -> None:
"""Test Google config disabling 2FA method uses latest config.""" """Test Google config disabling 2FA method uses latest config."""
entity_registry = er.async_get(hass)
# Register a light entity # Register a light entity
entity_entry = entity_registry.async_get_or_create( entity_entry = entity_registry.async_get_or_create(

View file

@ -120,11 +120,10 @@ async def test_sync_entities(mock_conf, hass: HomeAssistant, cloud_prefs) -> Non
async def test_google_update_expose_trigger_sync( async def test_google_update_expose_trigger_sync(
hass: HomeAssistant, cloud_prefs hass: HomeAssistant, entity_registry: er.EntityRegistry, cloud_prefs
) -> None: ) -> None:
"""Test Google config responds to updating exposed entities.""" """Test Google config responds to updating exposed entities."""
assert await async_setup_component(hass, "homeassistant", {}) assert await async_setup_component(hass, "homeassistant", {})
entity_registry = er.async_get(hass)
# Enable exposing new entities to Google # Enable exposing new entities to Google
expose_new(hass, True) expose_new(hass, True)
@ -176,10 +175,12 @@ async def test_google_update_expose_trigger_sync(
async def test_google_entity_registry_sync( async def test_google_entity_registry_sync(
hass: HomeAssistant, mock_cloud_login, cloud_prefs hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_cloud_login,
cloud_prefs,
) -> None: ) -> None:
"""Test Google config responds to entity registry.""" """Test Google config responds to entity registry."""
entity_registry = er.async_get(hass)
# Enable exposing new entities to Google # Enable exposing new entities to Google
expose_new(hass, True) expose_new(hass, True)
@ -246,19 +247,25 @@ async def test_google_entity_registry_sync(
async def test_google_device_registry_sync( async def test_google_device_registry_sync(
hass: HomeAssistant, mock_cloud_login, cloud_prefs hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_cloud_login,
cloud_prefs,
) -> None: ) -> None:
"""Test Google config responds to device registry.""" """Test Google config responds to device registry."""
config = CloudGoogleConfig( config = CloudGoogleConfig(
hass, GACTIONS_SCHEMA({}), "mock-user-id", cloud_prefs, hass.data["cloud"] hass, GACTIONS_SCHEMA({}), "mock-user-id", cloud_prefs, hass.data["cloud"]
) )
ent_reg = er.async_get(hass)
# Enable exposing new entities to Google # Enable exposing new entities to Google
expose_new(hass, True) expose_new(hass, True)
entity_entry = ent_reg.async_get_or_create("light", "hue", "1234", device_id="1234") entity_entry = entity_registry.async_get_or_create(
entity_entry = ent_reg.async_update_entity(entity_entry.entity_id, area_id="ABCD") "light", "hue", "1234", device_id="1234"
)
entity_entry = entity_registry.async_update_entity(
entity_entry.entity_id, area_id="ABCD"
)
with patch.object(config, "async_sync_entities_all"): with patch.object(config, "async_sync_entities_all"):
await config.async_initialize() await config.async_initialize()
@ -293,7 +300,7 @@ async def test_google_device_registry_sync(
assert len(mock_sync.mock_calls) == 0 assert len(mock_sync.mock_calls) == 0
ent_reg.async_update_entity(entity_entry.entity_id, area_id=None) entity_registry.async_update_entity(entity_entry.entity_id, area_id=None)
# Device registry updated with relevant changes # Device registry updated with relevant changes
# but entity has area ID so not impacted # but entity has area ID so not impacted

View file

@ -337,13 +337,13 @@ async def test_bad_formatted_automations(
async def test_delete_automation( async def test_delete_automation(
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
entity_registry: er.EntityRegistry,
hass_config_store, hass_config_store,
setup_automation, setup_automation,
) -> None: ) -> None:
"""Test deleting an automation.""" """Test deleting an automation."""
ent_reg = er.async_get(hass)
assert len(ent_reg.entities) == 2 assert len(entity_registry.entities) == 2
with patch.object(config, "SECTIONS", ["automation"]): with patch.object(config, "SECTIONS", ["automation"]):
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
@ -371,7 +371,7 @@ async def test_delete_automation(
assert hass_config_store["automations.yaml"] == [{"id": "moon"}] assert hass_config_store["automations.yaml"] == [{"id": "moon"}]
assert len(ent_reg.entities) == 1 assert len(entity_registry.entities) == 1
@pytest.mark.parametrize("automation_config", ({},)) @pytest.mark.parametrize("automation_config", ({},))

View file

@ -184,13 +184,13 @@ async def test_bad_formatted_scene(
async def test_delete_scene( async def test_delete_scene(
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
entity_registry: er.EntityRegistry,
hass_config_store, hass_config_store,
setup_scene, setup_scene,
) -> None: ) -> None:
"""Test deleting a scene.""" """Test deleting a scene."""
ent_reg = er.async_get(hass)
assert len(ent_reg.entities) == 2 assert len(entity_registry.entities) == 2
with patch.object(config, "SECTIONS", ["scene"]): with patch.object(config, "SECTIONS", ["scene"]):
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
@ -220,7 +220,7 @@ async def test_delete_scene(
{"id": "light_off"}, {"id": "light_off"},
] ]
assert len(ent_reg.entities) == 1 assert len(entity_registry.entities) == 1
@pytest.mark.parametrize("scene_config", ({},)) @pytest.mark.parametrize("scene_config", ({},))

View file

@ -281,7 +281,10 @@ async def test_update_remove_key_script_config(
), ),
) )
async def test_delete_script( async def test_delete_script(
hass: HomeAssistant, hass_client: ClientSessionGenerator, hass_config_store hass: HomeAssistant,
hass_client: ClientSessionGenerator,
entity_registry: er.EntityRegistry,
hass_config_store,
) -> None: ) -> None:
"""Test deleting a script.""" """Test deleting a script."""
with patch.object(config, "SECTIONS", ["script"]): with patch.object(config, "SECTIONS", ["script"]):
@ -292,8 +295,7 @@ async def test_delete_script(
"script.two", "script.two",
] ]
ent_reg = er.async_get(hass) assert len(entity_registry.entities) == 2
assert len(ent_reg.entities) == 2
client = await hass_client() client = await hass_client()
@ -313,7 +315,7 @@ async def test_delete_script(
assert hass_config_store["scripts.yaml"] == {"one": {}} assert hass_config_store["scripts.yaml"] == {"one": {}}
assert len(ent_reg.entities) == 1 assert len(entity_registry.entities) == 1
@pytest.mark.parametrize("script_config", ({},)) @pytest.mark.parametrize("script_config", ({},))

View file

@ -502,18 +502,20 @@ async def test_ws_list(
async def test_ws_delete( async def test_ws_delete(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, storage_setup hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
entity_registry: er.EntityRegistry,
storage_setup,
) -> None: ) -> None:
"""Test WS delete cleans up entity registry.""" """Test WS delete cleans up entity registry."""
assert await storage_setup() assert await storage_setup()
input_id = "from_storage" input_id = "from_storage"
input_entity_id = f"{DOMAIN}.{input_id}" input_entity_id = f"{DOMAIN}.{input_id}"
ent_reg = er.async_get(hass)
state = hass.states.get(input_entity_id) state = hass.states.get(input_entity_id)
assert state is not None assert state is not None
assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, input_id) is not None assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, input_id) is not None
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
@ -525,7 +527,7 @@ async def test_ws_delete(
state = hass.states.get(input_entity_id) state = hass.states.get(input_entity_id)
assert state is None assert state is None
assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, input_id) is None assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, input_id) is None
async def test_update_min_max( async def test_update_min_max(
@ -546,7 +548,7 @@ async def test_update_min_max(
input_id = "from_storage" input_id = "from_storage"
input_entity_id = f"{DOMAIN}.{input_id}" input_entity_id = f"{DOMAIN}.{input_id}"
ent_reg = er.async_get(hass) entity_registry = er.async_get(hass)
state = hass.states.get(input_entity_id) state = hass.states.get(input_entity_id)
assert state is not None assert state is not None
@ -554,7 +556,7 @@ async def test_update_min_max(
assert state.attributes[ATTR_MAXIMUM] == 100 assert state.attributes[ATTR_MAXIMUM] == 100
assert state.attributes[ATTR_MINIMUM] == 10 assert state.attributes[ATTR_MINIMUM] == 10
assert state.attributes[ATTR_STEP] == 3 assert state.attributes[ATTR_STEP] == 3
assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, input_id) is not None assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, input_id) is not None
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
@ -627,11 +629,11 @@ async def test_create(
counter_id = "new_counter" counter_id = "new_counter"
input_entity_id = f"{DOMAIN}.{counter_id}" input_entity_id = f"{DOMAIN}.{counter_id}"
ent_reg = er.async_get(hass) entity_registry = er.async_get(hass)
state = hass.states.get(input_entity_id) state = hass.states.get(input_entity_id)
assert state is None assert state is None
assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, counter_id) is None assert entity_registry.async_get_entity_id(DOMAIN, DOMAIN, counter_id) is None
client = await hass_ws_client(hass) client = await hass_ws_client(hass)

View file

@ -25,13 +25,13 @@ from tests.common import MockConfigEntry
async def test_sensor( async def test_sensor(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
mock_cpuinfo: MagicMock, mock_cpuinfo: MagicMock,
init_integration: MockConfigEntry, init_integration: MockConfigEntry,
) -> None: ) -> None:
"""Test the CPU Speed sensor.""" """Test the CPU Speed sensor."""
await async_setup_component(hass, "homeassistant", {}) await async_setup_component(hass, "homeassistant", {})
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
entry = entity_registry.async_get("sensor.cpu_speed") entry = entity_registry.async_get("sensor.cpu_speed")
assert entry assert entry