diff --git a/tests/components/zwave_js/test_button.py b/tests/components/zwave_js/test_button.py index e1a1c6d665a..b0c06668926 100644 --- a/tests/components/zwave_js/test_button.py +++ b/tests/components/zwave_js/test_button.py @@ -7,11 +7,12 @@ from homeassistant.components.zwave_js.const import DOMAIN, SERVICE_REFRESH_VALU from homeassistant.components.zwave_js.helpers import get_valueless_base_unique_id from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity_registry import async_get +from homeassistant.helpers import entity_registry as er async def test_ping_entity( hass: HomeAssistant, + entity_registry: er.EntityRegistry, client, climate_radio_thermostat_ct100_plus_different_endpoints, integration, @@ -56,7 +57,7 @@ async def test_ping_entity( node = driver.controller.nodes[1] assert node.is_controller_node assert ( - async_get(hass).async_get_entity_id( + entity_registry.async_get_entity_id( DOMAIN, "sensor", f"{get_valueless_base_unique_id(driver, node)}.ping" ) is None diff --git a/tests/components/zwave_js/test_device_trigger.py b/tests/components/zwave_js/test_device_trigger.py index e739393471e..0fa228288ec 100644 --- a/tests/components/zwave_js/test_device_trigger.py +++ b/tests/components/zwave_js/test_device_trigger.py @@ -21,9 +21,11 @@ from homeassistant.components.zwave_js.helpers import ( ) from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers import config_validation as cv -from homeassistant.helpers.device_registry import async_get as async_get_dev_reg -from homeassistant.helpers.entity_registry import async_get as async_get_ent_reg +from homeassistant.helpers import ( + config_validation as cv, + device_registry as dr, + entity_registry as er, +) from homeassistant.setup import async_setup_component from tests.common import async_get_device_automations, async_mock_service @@ -35,10 +37,11 @@ def calls(hass: HomeAssistant) -> list[ServiceCall]: return async_mock_service(hass, "test", "automation") -async def test_no_controller_triggers(hass: HomeAssistant, client, integration) -> None: +async def test_no_controller_triggers( + hass: HomeAssistant, device_registry: dr.DeviceRegistry, client, integration +) -> None: """Test that we do not get triggers for the controller.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, client.driver.controller.nodes[1])} ) assert device @@ -51,11 +54,14 @@ async def test_no_controller_triggers(hass: HomeAssistant, client, integration) async def test_get_notification_notification_triggers( - hass: HomeAssistant, client, lock_schlage_be469, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + lock_schlage_be469, + integration, ) -> None: """Test we get the expected triggers from a zwave_js device with the Notification CC.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device @@ -75,6 +81,7 @@ async def test_get_notification_notification_triggers( async def test_if_notification_notification_fires( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, client, lock_schlage_be469, integration, @@ -82,8 +89,7 @@ async def test_if_notification_notification_fires( ) -> None: """Test for event.notification.notification trigger firing.""" node: Node = lock_schlage_be469 - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device @@ -174,11 +180,14 @@ async def test_if_notification_notification_fires( async def test_get_trigger_capabilities_notification_notification( - hass: HomeAssistant, client, lock_schlage_be469, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + lock_schlage_be469, + integration, ) -> None: """Test we get the expected capabilities from a notification.notification trigger.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device @@ -208,6 +217,7 @@ async def test_get_trigger_capabilities_notification_notification( async def test_if_entry_control_notification_fires( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, client, lock_schlage_be469, integration, @@ -215,8 +225,7 @@ async def test_if_entry_control_notification_fires( ) -> None: """Test for notification.entry_control trigger firing.""" node: Node = lock_schlage_be469 - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device @@ -306,11 +315,14 @@ async def test_if_entry_control_notification_fires( async def test_get_trigger_capabilities_entry_control_notification( - hass: HomeAssistant, client, lock_schlage_be469, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + lock_schlage_be469, + integration, ) -> None: """Test we get the expected capabilities from a notification.entry_control trigger.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device @@ -337,19 +349,22 @@ async def test_get_trigger_capabilities_entry_control_notification( async def test_get_node_status_triggers( - hass: HomeAssistant, client, lock_schlage_be469, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + client, + lock_schlage_be469, + integration, ) -> None: """Test we get the expected triggers from a device with node status sensor enabled.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device - ent_reg = async_get_ent_reg(hass) entity_id = async_get_node_status_sensor_entity_id( - hass, device.id, ent_reg, dev_reg + hass, device.id, entity_registry, device_registry ) - entity = ent_reg.async_update_entity(entity_id, disabled_by=None) + entity = entity_registry.async_update_entity(entity_id, disabled_by=None) await hass.config_entries.async_reload(integration.entry_id) await hass.async_block_till_done() @@ -369,6 +384,8 @@ async def test_get_node_status_triggers( async def test_if_node_status_change_fires( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, client, lock_schlage_be469, integration, @@ -376,16 +393,14 @@ async def test_if_node_status_change_fires( ) -> None: """Test for node_status trigger firing.""" node: Node = lock_schlage_be469 - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device - ent_reg = async_get_ent_reg(hass) entity_id = async_get_node_status_sensor_entity_id( - hass, device.id, ent_reg, dev_reg + hass, device.id, entity_registry, device_registry ) - entity = ent_reg.async_update_entity(entity_id, disabled_by=None) + entity = entity_registry.async_update_entity(entity_id, disabled_by=None) await hass.config_entries.async_reload(integration.entry_id) await hass.async_block_till_done() @@ -452,6 +467,8 @@ async def test_if_node_status_change_fires( async def test_if_node_status_change_fires_legacy( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, client, lock_schlage_be469, integration, @@ -459,16 +476,14 @@ async def test_if_node_status_change_fires_legacy( ) -> None: """Test for node_status trigger firing.""" node: Node = lock_schlage_be469 - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( {get_device_id(client.driver, lock_schlage_be469)} ) assert device - ent_reg = async_get_ent_reg(hass) entity_id = async_get_node_status_sensor_entity_id( - hass, device.id, ent_reg, dev_reg + hass, device.id, entity_registry, device_registry ) - ent_reg.async_update_entity(entity_id, disabled_by=None) + entity_registry.async_update_entity(entity_id, disabled_by=None) await hass.config_entries.async_reload(integration.entry_id) await hass.async_block_till_done() @@ -534,19 +549,22 @@ async def test_if_node_status_change_fires_legacy( async def test_get_trigger_capabilities_node_status( - hass: HomeAssistant, client, lock_schlage_be469, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + client, + lock_schlage_be469, + integration, ) -> None: """Test we get the expected capabilities from a node_status trigger.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device - ent_reg = async_get_ent_reg(hass) entity_id = async_get_node_status_sensor_entity_id( - hass, device.id, ent_reg, dev_reg + hass, device.id, entity_registry, device_registry ) - ent_reg.async_update_entity(entity_id, disabled_by=None) + entity_registry.async_update_entity(entity_id, disabled_by=None) await hass.config_entries.async_reload(integration.entry_id) await hass.async_block_till_done() @@ -592,11 +610,14 @@ async def test_get_trigger_capabilities_node_status( async def test_get_basic_value_notification_triggers( - hass: HomeAssistant, client, ge_in_wall_dimmer_switch, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + ge_in_wall_dimmer_switch, + integration, ) -> None: """Test we get the expected triggers from a zwave_js device with the Basic CC.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, ge_in_wall_dimmer_switch)} ) assert device @@ -620,6 +641,7 @@ async def test_get_basic_value_notification_triggers( async def test_if_basic_value_notification_fires( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, client, ge_in_wall_dimmer_switch, integration, @@ -627,8 +649,7 @@ async def test_if_basic_value_notification_fires( ) -> None: """Test for event.value_notification.basic trigger firing.""" node: Node = ge_in_wall_dimmer_switch - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, ge_in_wall_dimmer_switch)} ) assert device @@ -733,11 +754,14 @@ async def test_if_basic_value_notification_fires( async def test_get_trigger_capabilities_basic_value_notification( - hass: HomeAssistant, client, ge_in_wall_dimmer_switch, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + ge_in_wall_dimmer_switch, + integration, ) -> None: """Test we get the expected capabilities from a value_notification.basic trigger.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, ge_in_wall_dimmer_switch)} ) assert device @@ -771,11 +795,14 @@ async def test_get_trigger_capabilities_basic_value_notification( async def test_get_central_scene_value_notification_triggers( - hass: HomeAssistant, client, wallmote_central_scene, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + wallmote_central_scene, + integration, ) -> None: """Test we get the expected triggers from a zwave_js device with the Central Scene CC.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, wallmote_central_scene)} ) assert device @@ -799,6 +826,7 @@ async def test_get_central_scene_value_notification_triggers( async def test_if_central_scene_value_notification_fires( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, client, wallmote_central_scene, integration, @@ -806,8 +834,7 @@ async def test_if_central_scene_value_notification_fires( ) -> None: """Test for event.value_notification.central_scene trigger firing.""" node: Node = wallmote_central_scene - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, wallmote_central_scene)} ) assert device @@ -918,11 +945,14 @@ async def test_if_central_scene_value_notification_fires( async def test_get_trigger_capabilities_central_scene_value_notification( - hass: HomeAssistant, client, wallmote_central_scene, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + wallmote_central_scene, + integration, ) -> None: """Test we get the expected capabilities from a value_notification.central_scene trigger.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, wallmote_central_scene)} ) assert device @@ -955,11 +985,14 @@ async def test_get_trigger_capabilities_central_scene_value_notification( async def test_get_scene_activation_value_notification_triggers( - hass: HomeAssistant, client, hank_binary_switch, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + hank_binary_switch, + integration, ) -> None: """Test we get the expected triggers from a zwave_js device with the SceneActivation CC.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, hank_binary_switch)} ) assert device @@ -983,6 +1016,7 @@ async def test_get_scene_activation_value_notification_triggers( async def test_if_scene_activation_value_notification_fires( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, client, hank_binary_switch, integration, @@ -990,8 +1024,7 @@ async def test_if_scene_activation_value_notification_fires( ) -> None: """Test for event.value_notification.scene_activation trigger firing.""" node: Node = hank_binary_switch - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, hank_binary_switch)} ) assert device @@ -1096,11 +1129,14 @@ async def test_if_scene_activation_value_notification_fires( async def test_get_trigger_capabilities_scene_activation_value_notification( - hass: HomeAssistant, client, hank_binary_switch, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + hank_binary_switch, + integration, ) -> None: """Test we get the expected capabilities from a value_notification.scene_activation trigger.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, hank_binary_switch)} ) assert device @@ -1134,11 +1170,14 @@ async def test_get_trigger_capabilities_scene_activation_value_notification( async def test_get_value_updated_value_triggers( - hass: HomeAssistant, client, lock_schlage_be469, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + lock_schlage_be469, + integration, ) -> None: """Test we get the zwave_js.value_updated.value trigger from a zwave_js device.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device @@ -1157,6 +1196,7 @@ async def test_get_value_updated_value_triggers( async def test_if_value_updated_value_fires( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, client, lock_schlage_be469, integration, @@ -1164,8 +1204,7 @@ async def test_if_value_updated_value_fires( ) -> None: """Test for zwave_js.value_updated.value trigger firing.""" node: Node = lock_schlage_be469 - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device @@ -1253,6 +1292,7 @@ async def test_if_value_updated_value_fires( async def test_value_updated_value_no_driver( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, client, lock_schlage_be469, integration, @@ -1260,8 +1300,7 @@ async def test_value_updated_value_no_driver( ) -> None: """Test zwave_js.value_updated.value trigger with missing driver.""" node: Node = lock_schlage_be469 - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device @@ -1327,11 +1366,14 @@ async def test_value_updated_value_no_driver( async def test_get_trigger_capabilities_value_updated_value( - hass: HomeAssistant, client, lock_schlage_be469, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + lock_schlage_be469, + integration, ) -> None: """Test we get the expected capabilities from a zwave_js.value_updated.value trigger.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device @@ -1378,11 +1420,14 @@ async def test_get_trigger_capabilities_value_updated_value( async def test_get_value_updated_config_parameter_triggers( - hass: HomeAssistant, client, lock_schlage_be469, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + lock_schlage_be469, + integration, ) -> None: """Test we get the zwave_js.value_updated.config_parameter trigger from a zwave_js device.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device @@ -1406,6 +1451,7 @@ async def test_get_value_updated_config_parameter_triggers( async def test_if_value_updated_config_parameter_fires( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, client, lock_schlage_be469, integration, @@ -1413,8 +1459,7 @@ async def test_if_value_updated_config_parameter_fires( ) -> None: """Test for zwave_js.value_updated.config_parameter trigger firing.""" node: Node = lock_schlage_be469 - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device @@ -1480,11 +1525,14 @@ async def test_if_value_updated_config_parameter_fires( async def test_get_trigger_capabilities_value_updated_config_parameter_range( - hass: HomeAssistant, client, lock_schlage_be469, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + lock_schlage_be469, + integration, ) -> None: """Test we get the expected capabilities from a range zwave_js.value_updated.config_parameter trigger.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device @@ -1525,11 +1573,14 @@ async def test_get_trigger_capabilities_value_updated_config_parameter_range( async def test_get_trigger_capabilities_value_updated_config_parameter_enumerated( - hass: HomeAssistant, client, lock_schlage_be469, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + lock_schlage_be469, + integration, ) -> None: """Test we get the expected capabilities from an enumerated zwave_js.value_updated.config_parameter trigger.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device @@ -1568,7 +1619,11 @@ async def test_get_trigger_capabilities_value_updated_config_parameter_enumerate async def test_failure_scenarios( - hass: HomeAssistant, client, hank_binary_switch, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + hank_binary_switch, + integration, ) -> None: """Test failure scenarios.""" with pytest.raises(HomeAssistantError): @@ -1584,8 +1639,7 @@ async def test_failure_scenarios( {}, ) - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, hank_binary_switch)} ) assert device diff --git a/tests/components/zwave_js/test_init.py b/tests/components/zwave_js/test_init.py index 8c9c05a124e..51aeee72c1d 100644 --- a/tests/components/zwave_js/test_init.py +++ b/tests/components/zwave_js/test_init.py @@ -368,6 +368,7 @@ async def test_existing_node_not_ready( async def test_existing_node_not_replaced_when_not_ready( hass: HomeAssistant, + area_registry: ar.AreaRegistry, device_registry: dr.DeviceRegistry, entity_registry: er.EntityRegistry, zp3111, @@ -375,7 +376,6 @@ async def test_existing_node_not_replaced_when_not_ready( zp3111_state, client, integration, - area_registry: ar.AreaRegistry, ) -> None: """Test when a node added event with a non-ready node is received. diff --git a/tests/components/zwave_js/test_services.py b/tests/components/zwave_js/test_services.py index 5462bcf9946..ec13d0262f8 100644 --- a/tests/components/zwave_js/test_services.py +++ b/tests/components/zwave_js/test_services.py @@ -41,9 +41,11 @@ from homeassistant.components.zwave_js.helpers import get_device_id from homeassistant.const import ATTR_AREA_ID, ATTR_DEVICE_ID, ATTR_ENTITY_ID from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers.area_registry import async_get as async_get_area_reg -from homeassistant.helpers.device_registry import async_get as async_get_dev_reg -from homeassistant.helpers.entity_registry import async_get as async_get_ent_reg +from homeassistant.helpers import ( + area_registry as ar, + device_registry as dr, + entity_registry as er, +) from homeassistant.setup import async_setup_component from .common import ( @@ -61,6 +63,9 @@ from tests.common import MockConfigEntry async def test_set_config_parameter( hass: HomeAssistant, + area_registry: ar.AreaRegistry, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, client, multisensor_6, aeotec_zw164_siren, @@ -68,9 +73,7 @@ async def test_set_config_parameter( caplog: pytest.LogCaptureFixture, ) -> None: """Test the set_config_parameter service.""" - dev_reg = async_get_dev_reg(hass) - ent_reg = async_get_ent_reg(hass) - entity_entry = ent_reg.async_get(AIR_TEMPERATURE_SENSOR) + entity_entry = entity_registry.async_get(AIR_TEMPERATURE_SENSOR) # Test setting config parameter by property and property_key await hass.services.async_call( @@ -179,9 +182,8 @@ async def test_set_config_parameter( client.async_send_command_no_wait.reset_mock() # Test using area ID - area_reg = async_get_area_reg(hass) - area = area_reg.async_get_or_create("test") - ent_reg.async_update_entity(entity_entry.entity_id, area_id=area.id) + area = area_registry.async_get_or_create("test") + entity_registry.async_update_entity(entity_entry.entity_id, area_id=area.id) await hass.services.async_call( DOMAIN, SERVICE_SET_CONFIG_PARAMETER, @@ -345,16 +347,16 @@ async def test_set_config_parameter( non_zwave_js_config_entry = MockConfigEntry(entry_id="fake_entry_id") non_zwave_js_config_entry.add_to_hass(hass) - non_zwave_js_device = dev_reg.async_get_or_create( + non_zwave_js_device = device_registry.async_get_or_create( config_entry_id=non_zwave_js_config_entry.entry_id, identifiers={("test", "test")}, ) - zwave_js_device_with_invalid_node_id = dev_reg.async_get_or_create( + zwave_js_device_with_invalid_node_id = device_registry.async_get_or_create( config_entry_id=integration.entry_id, identifiers={(DOMAIN, "500-500")} ) - non_zwave_js_entity = ent_reg.async_get_or_create( + non_zwave_js_entity = entity_registry.async_get_or_create( "test", "sensor", "test_sensor", @@ -601,11 +603,15 @@ async def test_set_config_parameter_gather( async def test_bulk_set_config_parameters( - hass: HomeAssistant, client, multisensor_6, integration + hass: HomeAssistant, + area_registry: ar.AreaRegistry, + device_registry: dr.DeviceRegistry, + client, + multisensor_6, + integration, ) -> None: """Test the bulk_set_partial_config_parameters service.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, multisensor_6)} ) assert device @@ -636,9 +642,8 @@ async def test_bulk_set_config_parameters( client.async_send_command_no_wait.reset_mock() # Test using area ID - area_reg = async_get_area_reg(hass) - area = area_reg.async_get_or_create("test") - dev_reg.async_update_device(device.id, area_id=area.id) + area = area_registry.async_get_or_create("test") + device_registry.async_update_device(device.id, area_id=area.id) await hass.services.async_call( DOMAIN, SERVICE_BULK_SET_PARTIAL_CONFIG_PARAMETERS, @@ -968,11 +973,15 @@ async def test_refresh_value( async def test_set_value( - hass: HomeAssistant, client, climate_danfoss_lc_13, integration + hass: HomeAssistant, + area_registry: ar.AreaRegistry, + device_registry: dr.DeviceRegistry, + client, + climate_danfoss_lc_13, + integration, ) -> None: """Test set_value service.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, climate_danfoss_lc_13)} ) assert device @@ -1030,9 +1039,8 @@ async def test_set_value( client.async_send_command.reset_mock() # Test using area ID - area_reg = async_get_area_reg(hass) - area = area_reg.async_get_or_create("test") - dev_reg.async_update_device(device.id, area_id=area.id) + area = area_registry.async_get_or_create("test") + device_registry.async_update_device(device.id, area_id=area.id) await hass.services.async_call( DOMAIN, SERVICE_SET_VALUE, @@ -1254,6 +1262,8 @@ async def test_set_value_gather( async def test_multicast_set_value( hass: HomeAssistant, + area_registry: ar.AreaRegistry, + device_registry: dr.DeviceRegistry, client, climate_danfoss_lc_13, climate_eurotronic_spirit_z, @@ -1327,19 +1337,17 @@ async def test_multicast_set_value( client.async_send_command.reset_mock() # Test using area ID - dev_reg = async_get_dev_reg(hass) - device_eurotronic = dev_reg.async_get_device( + device_eurotronic = device_registry.async_get_device( identifiers={get_device_id(client.driver, climate_eurotronic_spirit_z)} ) assert device_eurotronic - device_danfoss = dev_reg.async_get_device( + device_danfoss = device_registry.async_get_device( identifiers={get_device_id(client.driver, climate_danfoss_lc_13)} ) assert device_danfoss - area_reg = async_get_area_reg(hass) - area = area_reg.async_get_or_create("test") - dev_reg.async_update_device(device_eurotronic.id, area_id=area.id) - dev_reg.async_update_device(device_danfoss.id, area_id=area.id) + area = area_registry.async_get_or_create("test") + device_registry.async_update_device(device_eurotronic.id, area_id=area.id) + device_registry.async_update_device(device_danfoss.id, area_id=area.id) await hass.services.async_call( DOMAIN, SERVICE_MULTICAST_SET_VALUE, @@ -1646,14 +1654,15 @@ async def test_multicast_set_value_string( async def test_ping( hass: HomeAssistant, + area_registry: ar.AreaRegistry, + device_registry: dr.DeviceRegistry, client, climate_danfoss_lc_13, climate_radio_thermostat_ct100_plus_different_endpoints, integration, ) -> None: """Test ping service.""" - dev_reg = async_get_dev_reg(hass) - device_radio_thermostat = dev_reg.async_get_device( + device_radio_thermostat = device_registry.async_get_device( identifiers={ get_device_id( client.driver, climate_radio_thermostat_ct100_plus_different_endpoints @@ -1661,7 +1670,7 @@ async def test_ping( } ) assert device_radio_thermostat - device_danfoss = dev_reg.async_get_device( + device_danfoss = device_registry.async_get_device( identifiers={get_device_id(client.driver, climate_danfoss_lc_13)} ) assert device_danfoss @@ -1721,10 +1730,9 @@ async def test_ping( client.async_send_command.reset_mock() # Test successful ping call with area - area_reg = async_get_area_reg(hass) - area = area_reg.async_get_or_create("test") - dev_reg.async_update_device(device_radio_thermostat.id, area_id=area.id) - dev_reg.async_update_device(device_danfoss.id, area_id=area.id) + area = area_registry.async_get_or_create("test") + device_registry.async_update_device(device_radio_thermostat.id, area_id=area.id) + device_registry.async_update_device(device_danfoss.id, area_id=area.id) await hass.services.async_call( DOMAIN, SERVICE_PING, @@ -1803,14 +1811,15 @@ async def test_ping( async def test_invoke_cc_api( hass: HomeAssistant, + area_registry: ar.AreaRegistry, + device_registry: dr.DeviceRegistry, client, climate_danfoss_lc_13, climate_radio_thermostat_ct100_plus_different_endpoints, integration, ) -> None: """Test invoke_cc_api service.""" - dev_reg = async_get_dev_reg(hass) - device_radio_thermostat = dev_reg.async_get_device( + device_radio_thermostat = device_registry.async_get_device( identifiers={ get_device_id( client.driver, climate_radio_thermostat_ct100_plus_different_endpoints @@ -1818,7 +1827,7 @@ async def test_invoke_cc_api( } ) assert device_radio_thermostat - device_danfoss = dev_reg.async_get_device( + device_danfoss = device_registry.async_get_device( identifiers={get_device_id(client.driver, climate_danfoss_lc_13)} ) assert device_danfoss @@ -1868,9 +1877,8 @@ async def test_invoke_cc_api( client.async_send_command_no_wait.reset_mock() # Test successful invoke_cc_api call without an endpoint (include area) - area_reg = async_get_area_reg(hass) - area = area_reg.async_get_or_create("test") - dev_reg.async_update_device(device_danfoss.id, area_id=area.id) + area = area_registry.async_get_or_create("test") + device_registry.async_update_device(device_danfoss.id, area_id=area.id) client.async_send_command.return_value = {"response": True} client.async_send_command_no_wait.return_value = {"response": True} @@ -1969,22 +1977,26 @@ async def test_invoke_cc_api( async def test_refresh_notifications( - hass: HomeAssistant, client, zen_31, multisensor_6, integration + hass: HomeAssistant, + area_registry: ar.AreaRegistry, + device_registry: dr.DeviceRegistry, + client, + zen_31, + multisensor_6, + integration, ) -> None: """Test refresh_notifications service.""" - dev_reg = async_get_dev_reg(hass) - zen_31_device = dev_reg.async_get_device( + zen_31_device = device_registry.async_get_device( identifiers={get_device_id(client.driver, zen_31)} ) assert zen_31_device - multisensor_6_device = dev_reg.async_get_device( + multisensor_6_device = device_registry.async_get_device( identifiers={get_device_id(client.driver, multisensor_6)} ) assert multisensor_6_device - area_reg = async_get_area_reg(hass) - area = area_reg.async_get_or_create("test") - dev_reg.async_update_device(zen_31_device.id, area_id=area.id) + area = area_registry.async_get_or_create("test") + device_registry.async_update_device(zen_31_device.id, area_id=area.id) # Test successful refresh_notifications call client.async_send_command.return_value = {"response": True} diff --git a/tests/components/zwave_js/test_trigger.py b/tests/components/zwave_js/test_trigger.py index 23c97913400..5822afe7b9f 100644 --- a/tests/components/zwave_js/test_trigger.py +++ b/tests/components/zwave_js/test_trigger.py @@ -20,7 +20,7 @@ from homeassistant.components.zwave_js.triggers.trigger_helpers import ( ) from homeassistant.const import CONF_PLATFORM, SERVICE_RELOAD from homeassistant.core import HomeAssistant -from homeassistant.helpers.device_registry import async_get as async_get_dev_reg +from homeassistant.helpers import device_registry as dr from homeassistant.setup import async_setup_component from .common import SCHLAGE_BE469_LOCK_ENTITY @@ -29,13 +29,16 @@ from tests.common import async_capture_events async def test_zwave_js_value_updated( - hass: HomeAssistant, client, lock_schlage_be469, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + lock_schlage_be469, + integration, ) -> None: """Test for zwave_js.value_updated automation trigger.""" trigger_type = f"{DOMAIN}.value_updated" node: Node = lock_schlage_be469 - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device @@ -453,13 +456,16 @@ async def test_zwave_js_value_updated_bypass_dynamic_validation_no_driver( async def test_zwave_js_event( - hass: HomeAssistant, client, lock_schlage_be469, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + lock_schlage_be469, + integration, ) -> None: """Test for zwave_js.event automation trigger.""" trigger_type = f"{DOMAIN}.event" node: Node = lock_schlage_be469 - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device @@ -1009,11 +1015,14 @@ async def test_invalid_trigger_configs(hass: HomeAssistant) -> None: async def test_zwave_js_trigger_config_entry_unloaded( - hass: HomeAssistant, client, lock_schlage_be469, integration + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + client, + lock_schlage_be469, + integration, ) -> None: """Test zwave_js triggers bypass dynamic validation when needed.""" - dev_reg = async_get_dev_reg(hass) - device = dev_reg.async_get_device( + device = device_registry.async_get_device( identifiers={get_device_id(client.driver, lock_schlage_be469)} ) assert device diff --git a/tests/components/zwave_js/test_update.py b/tests/components/zwave_js/test_update.py index 338d1511fc3..abdceb155f7 100644 --- a/tests/components/zwave_js/test_update.py +++ b/tests/components/zwave_js/test_update.py @@ -25,7 +25,7 @@ from homeassistant.components.zwave_js.helpers import get_valueless_base_unique_ from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON, STATE_UNKNOWN from homeassistant.core import CoreState, HomeAssistant, State from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers.entity_registry import async_get +from homeassistant.helpers import entity_registry as er from homeassistant.util import dt as dt_util from tests.common import ( @@ -113,6 +113,7 @@ FIRMWARE_UPDATES = { async def test_update_entity_states( hass: HomeAssistant, + entity_registry: er.EntityRegistry, client, climate_radio_thermostat_ct100_plus_different_endpoints, integration, @@ -194,7 +195,7 @@ async def test_update_entity_states( node = driver.controller.nodes[1] assert node.is_controller_node assert ( - async_get(hass).async_get_entity_id( + entity_registry.async_get_entity_id( DOMAIN, "sensor", f"{get_valueless_base_unique_id(driver, node)}.firmware_update",