diff --git a/tests/components/unifiprotect/test_binary_sensor.py b/tests/components/unifiprotect/test_binary_sensor.py index 3aa441659b0..0c4d6e00066 100644 --- a/tests/components/unifiprotect/test_binary_sensor.py +++ b/tests/components/unifiprotect/test_binary_sensor.py @@ -111,8 +111,8 @@ async def test_binary_sensor_setup_light( assert_entity_counts(hass, Platform.BINARY_SENSOR, 8, 8) for description in LIGHT_SENSOR_WRITE: - unique_id, entity_id = ids_from_device_description( - Platform.BINARY_SENSOR, light, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.BINARY_SENSOR, light, description ) entity = entity_registry.async_get(entity_id) @@ -139,8 +139,8 @@ async def test_binary_sensor_setup_camera_all( assert_entity_counts(hass, Platform.BINARY_SENSOR, 9, 6) description = EVENT_SENSORS[0] - unique_id, entity_id = ids_from_device_description( - Platform.BINARY_SENSOR, doorbell, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.BINARY_SENSOR, doorbell, description ) entity = entity_registry.async_get(entity_id) @@ -154,8 +154,8 @@ async def test_binary_sensor_setup_camera_all( # Is Dark description = CAMERA_SENSORS[0] - unique_id, entity_id = ids_from_device_description( - Platform.BINARY_SENSOR, doorbell, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.BINARY_SENSOR, doorbell, description ) entity = entity_registry.async_get(entity_id) @@ -169,8 +169,8 @@ async def test_binary_sensor_setup_camera_all( # Motion description = EVENT_SENSORS[1] - unique_id, entity_id = ids_from_device_description( - Platform.BINARY_SENSOR, doorbell, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.BINARY_SENSOR, doorbell, description ) entity = entity_registry.async_get(entity_id) @@ -197,8 +197,8 @@ async def test_binary_sensor_setup_camera_none( description = CAMERA_SENSORS[0] - unique_id, entity_id = ids_from_device_description( - Platform.BINARY_SENSOR, camera, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.BINARY_SENSOR, camera, description ) entity = entity_registry.async_get(entity_id) @@ -229,8 +229,8 @@ async def test_binary_sensor_setup_sensor( STATE_OFF, ] for index, description in enumerate(SENSE_SENSORS_WRITE): - unique_id, entity_id = ids_from_device_description( - Platform.BINARY_SENSOR, sensor_all, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.BINARY_SENSOR, sensor_all, description ) entity = entity_registry.async_get(entity_id) @@ -262,8 +262,8 @@ async def test_binary_sensor_setup_sensor_leak( STATE_OFF, ] for index, description in enumerate(SENSE_SENSORS_WRITE): - unique_id, entity_id = ids_from_device_description( - Platform.BINARY_SENSOR, sensor, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.BINARY_SENSOR, sensor, description ) entity = entity_registry.async_get(entity_id) @@ -288,8 +288,8 @@ async def test_binary_sensor_update_motion( await init_entry(hass, ufp, [doorbell, unadopted_camera]) assert_entity_counts(hass, Platform.BINARY_SENSOR, 15, 12) - _, entity_id = ids_from_device_description( - Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[1] + _, entity_id = await ids_from_device_description( + hass, Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[1] ) event = Event( @@ -334,8 +334,8 @@ async def test_binary_sensor_update_light_motion( await init_entry(hass, ufp, [light]) assert_entity_counts(hass, Platform.BINARY_SENSOR, 8, 8) - _, entity_id = ids_from_device_description( - Platform.BINARY_SENSOR, light, LIGHT_SENSOR_WRITE[1] + _, entity_id = await ids_from_device_description( + hass, Platform.BINARY_SENSOR, light, LIGHT_SENSOR_WRITE[1] ) event_metadata = EventMetadata(light_id=light.id) @@ -378,8 +378,8 @@ async def test_binary_sensor_update_mount_type_window( await init_entry(hass, ufp, [sensor_all]) assert_entity_counts(hass, Platform.BINARY_SENSOR, 11, 11) - _, entity_id = ids_from_device_description( - Platform.BINARY_SENSOR, sensor_all, MOUNTABLE_SENSE_SENSORS[0] + _, entity_id = await ids_from_device_description( + hass, Platform.BINARY_SENSOR, sensor_all, MOUNTABLE_SENSE_SENSORS[0] ) state = hass.states.get(entity_id) @@ -410,8 +410,8 @@ async def test_binary_sensor_update_mount_type_garage( await init_entry(hass, ufp, [sensor_all]) assert_entity_counts(hass, Platform.BINARY_SENSOR, 11, 11) - _, entity_id = ids_from_device_description( - Platform.BINARY_SENSOR, sensor_all, MOUNTABLE_SENSE_SENSORS[0] + _, entity_id = await ids_from_device_description( + hass, Platform.BINARY_SENSOR, sensor_all, MOUNTABLE_SENSE_SENSORS[0] ) state = hass.states.get(entity_id) @@ -451,8 +451,8 @@ async def test_binary_sensor_package_detected( doorbell.smart_detect_settings.object_types.append(SmartDetectObjectType.PACKAGE) - _, entity_id = ids_from_device_description( - Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[6] + _, entity_id = await ids_from_device_description( + hass, Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[6] ) event = Event( @@ -592,8 +592,8 @@ async def test_binary_sensor_person_detected( doorbell.smart_detect_settings.object_types.append(SmartDetectObjectType.PERSON) - _, entity_id = ids_from_device_description( - Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[3] + _, entity_id = await ids_from_device_description( + hass, Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[3] ) events = async_capture_events(hass, EVENT_STATE_CHANGED) diff --git a/tests/components/unifiprotect/test_event.py b/tests/components/unifiprotect/test_event.py index 032a3b253a7..80b11c047cc 100644 --- a/tests/components/unifiprotect/test_event.py +++ b/tests/components/unifiprotect/test_event.py @@ -57,8 +57,8 @@ async def test_doorbell_ring( def _capture_event(event: HAEvent) -> None: events.append(event) - _, entity_id = ids_from_device_description( - Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[0] + _, entity_id = await ids_from_device_description( + hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[0] ) unsub = async_track_state_change_event(hass, entity_id, _capture_event) @@ -171,8 +171,8 @@ async def test_doorbell_nfc_scanned( def _capture_event(event: HAEvent) -> None: events.append(event) - _, entity_id = ids_from_device_description( - Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[1] + _, entity_id = await ids_from_device_description( + hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[1] ) ulp_id = "ulp_id" @@ -246,8 +246,8 @@ async def test_doorbell_nfc_scanned_ulpusr_deactivated( def _capture_event(event: HAEvent) -> None: events.append(event) - _, entity_id = ids_from_device_description( - Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[1] + _, entity_id = await ids_from_device_description( + hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[1] ) ulp_id = "ulp_id" @@ -322,8 +322,8 @@ async def test_doorbell_nfc_scanned_no_ulpusr( def _capture_event(event: HAEvent) -> None: events.append(event) - _, entity_id = ids_from_device_description( - Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[1] + _, entity_id = await ids_from_device_description( + hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[1] ) ulp_id = "ulp_id" @@ -390,8 +390,8 @@ async def test_doorbell_nfc_scanned_no_keyring( def _capture_event(event: HAEvent) -> None: events.append(event) - _, entity_id = ids_from_device_description( - Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[1] + _, entity_id = await ids_from_device_description( + hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[1] ) test_nfc_id = "test_nfc_id" @@ -451,8 +451,8 @@ async def test_doorbell_fingerprint_identified( def _capture_event(event: HAEvent) -> None: events.append(event) - _, entity_id = ids_from_device_description( - Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[2] + _, entity_id = await ids_from_device_description( + hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[2] ) ulp_id = "ulp_id" @@ -519,8 +519,8 @@ async def test_doorbell_fingerprint_identified_user_deactivated( def _capture_event(event: HAEvent) -> None: events.append(event) - _, entity_id = ids_from_device_description( - Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[2] + _, entity_id = await ids_from_device_description( + hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[2] ) ulp_id = "ulp_id" @@ -588,8 +588,8 @@ async def test_doorbell_fingerprint_identified_no_user( def _capture_event(event: HAEvent) -> None: events.append(event) - _, entity_id = ids_from_device_description( - Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[2] + _, entity_id = await ids_from_device_description( + hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[2] ) ulp_id = "ulp_id" @@ -649,8 +649,8 @@ async def test_doorbell_fingerprint_not_identified( def _capture_event(event: HAEvent) -> None: events.append(event) - _, entity_id = ids_from_device_description( - Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[2] + _, entity_id = await ids_from_device_description( + hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[2] ) unsub = async_track_state_change_event(hass, entity_id, _capture_event) diff --git a/tests/components/unifiprotect/test_number.py b/tests/components/unifiprotect/test_number.py index 1838a574bc4..a93c49a2ebe 100644 --- a/tests/components/unifiprotect/test_number.py +++ b/tests/components/unifiprotect/test_number.py @@ -80,8 +80,8 @@ async def test_number_setup_light( assert_entity_counts(hass, Platform.NUMBER, 2, 2) for description in LIGHT_NUMBERS: - unique_id, entity_id = ids_from_device_description( - Platform.NUMBER, light, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.NUMBER, light, description ) entity = entity_registry.async_get(entity_id) @@ -111,8 +111,8 @@ async def test_number_setup_camera_all( assert_entity_counts(hass, Platform.NUMBER, 5, 5) for description in CAMERA_NUMBERS: - unique_id, entity_id = ids_from_device_description( - Platform.NUMBER, camera, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.NUMBER, camera, description ) entity = entity_registry.async_get(entity_id) @@ -165,7 +165,9 @@ async def test_number_light_sensitivity( light.__pydantic_fields__["set_sensitivity"] = Mock(final=False, frozen=False) light.set_sensitivity = AsyncMock() - _, entity_id = ids_from_device_description(Platform.NUMBER, light, description) + _, entity_id = await ids_from_device_description( + hass, Platform.NUMBER, light, description + ) await hass.services.async_call( "number", "set_value", {ATTR_ENTITY_ID: entity_id, "value": 15.0}, blocking=True @@ -187,7 +189,9 @@ async def test_number_light_duration( light.__pydantic_fields__["set_duration"] = Mock(final=False, frozen=False) light.set_duration = AsyncMock() - _, entity_id = ids_from_device_description(Platform.NUMBER, light, description) + _, entity_id = await ids_from_device_description( + hass, Platform.NUMBER, light, description + ) await hass.services.async_call( "number", "set_value", {ATTR_ENTITY_ID: entity_id, "value": 15.0}, blocking=True @@ -215,7 +219,9 @@ async def test_number_camera_simple( ) setattr(camera, description.ufp_set_method, AsyncMock()) - _, entity_id = ids_from_device_description(Platform.NUMBER, camera, description) + _, entity_id = await ids_from_device_description( + hass, Platform.NUMBER, camera, description + ) await hass.services.async_call( "number", "set_value", {ATTR_ENTITY_ID: entity_id, "value": 1.0}, blocking=True @@ -237,7 +243,9 @@ async def test_number_lock_auto_close( ) doorlock.set_auto_close_time = AsyncMock() - _, entity_id = ids_from_device_description(Platform.NUMBER, doorlock, description) + _, entity_id = await ids_from_device_description( + hass, Platform.NUMBER, doorlock, description + ) await hass.services.async_call( "number", "set_value", {ATTR_ENTITY_ID: entity_id, "value": 15.0}, blocking=True diff --git a/tests/components/unifiprotect/test_recorder.py b/tests/components/unifiprotect/test_recorder.py index 1f025a63306..c1eef3f7839 100644 --- a/tests/components/unifiprotect/test_recorder.py +++ b/tests/components/unifiprotect/test_recorder.py @@ -35,8 +35,8 @@ async def test_exclude_attributes( now = fixed_now await init_entry(hass, ufp, [doorbell, unadopted_camera]) - _, entity_id = ids_from_device_description( - Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[1] + _, entity_id = await ids_from_device_description( + hass, Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[1] ) event = Event( diff --git a/tests/components/unifiprotect/test_select.py b/tests/components/unifiprotect/test_select.py index 6db3ae22dcb..f8485e678a1 100644 --- a/tests/components/unifiprotect/test_select.py +++ b/tests/components/unifiprotect/test_select.py @@ -98,8 +98,8 @@ async def test_select_setup_light( expected_values = ("On Motion - When Dark", "Not Paired") for index, description in enumerate(LIGHT_SELECTS): - unique_id, entity_id = ids_from_device_description( - Platform.SELECT, light, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SELECT, light, description ) entity = entity_registry.async_get(entity_id) @@ -127,8 +127,8 @@ async def test_select_setup_viewer( description = VIEWER_SELECTS[0] - unique_id, entity_id = ids_from_device_description( - Platform.SELECT, viewer, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SELECT, viewer, description ) entity = entity_registry.async_get(entity_id) @@ -161,8 +161,8 @@ async def test_select_setup_camera_all( ) for index, description in enumerate(CAMERA_SELECTS): - unique_id, entity_id = ids_from_device_description( - Platform.SELECT, doorbell, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SELECT, doorbell, description ) entity = entity_registry.async_get(entity_id) @@ -192,8 +192,8 @@ async def test_select_setup_camera_none( if index == 2: return - unique_id, entity_id = ids_from_device_description( - Platform.SELECT, camera, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SELECT, camera, description ) entity = entity_registry.async_get(entity_id) @@ -215,8 +215,8 @@ async def test_select_update_liveview( await init_entry(hass, ufp, [viewer]) assert_entity_counts(hass, Platform.SELECT, 1, 1) - _, entity_id = ids_from_device_description( - Platform.SELECT, viewer, VIEWER_SELECTS[0] + _, entity_id = await ids_from_device_description( + hass, Platform.SELECT, viewer, VIEWER_SELECTS[0] ) state = hass.states.get(entity_id) @@ -252,8 +252,8 @@ async def test_select_update_doorbell_settings( expected_length = len(ufp.api.bootstrap.nvr.doorbell_settings.all_messages) + 1 - _, entity_id = ids_from_device_description( - Platform.SELECT, doorbell, CAMERA_SELECTS[2] + _, entity_id = await ids_from_device_description( + hass, Platform.SELECT, doorbell, CAMERA_SELECTS[2] ) state = hass.states.get(entity_id) @@ -296,8 +296,8 @@ async def test_select_update_doorbell_message( await init_entry(hass, ufp, [doorbell]) assert_entity_counts(hass, Platform.SELECT, 5, 5) - _, entity_id = ids_from_device_description( - Platform.SELECT, doorbell, CAMERA_SELECTS[2] + _, entity_id = await ids_from_device_description( + hass, Platform.SELECT, doorbell, CAMERA_SELECTS[2] ) state = hass.states.get(entity_id) @@ -330,7 +330,9 @@ async def test_select_set_option_light_motion( await init_entry(hass, ufp, [light]) assert_entity_counts(hass, Platform.SELECT, 2, 2) - _, entity_id = ids_from_device_description(Platform.SELECT, light, LIGHT_SELECTS[0]) + _, entity_id = await ids_from_device_description( + hass, Platform.SELECT, light, LIGHT_SELECTS[0] + ) light.__pydantic_fields__["set_light_settings"] = Mock(final=False, frozen=False) light.set_light_settings = AsyncMock() @@ -355,7 +357,9 @@ async def test_select_set_option_light_camera( await init_entry(hass, ufp, [light, camera]) assert_entity_counts(hass, Platform.SELECT, 4, 4) - _, entity_id = ids_from_device_description(Platform.SELECT, light, LIGHT_SELECTS[1]) + _, entity_id = await ids_from_device_description( + hass, Platform.SELECT, light, LIGHT_SELECTS[1] + ) light.__pydantic_fields__["set_paired_camera"] = Mock(final=False, frozen=False) light.set_paired_camera = AsyncMock() @@ -389,8 +393,8 @@ async def test_select_set_option_camera_recording( await init_entry(hass, ufp, [doorbell]) assert_entity_counts(hass, Platform.SELECT, 5, 5) - _, entity_id = ids_from_device_description( - Platform.SELECT, doorbell, CAMERA_SELECTS[0] + _, entity_id = await ids_from_device_description( + hass, Platform.SELECT, doorbell, CAMERA_SELECTS[0] ) doorbell.__pydantic_fields__["set_recording_mode"] = Mock(final=False, frozen=False) @@ -414,8 +418,8 @@ async def test_select_set_option_camera_ir( await init_entry(hass, ufp, [doorbell]) assert_entity_counts(hass, Platform.SELECT, 5, 5) - _, entity_id = ids_from_device_description( - Platform.SELECT, doorbell, CAMERA_SELECTS[1] + _, entity_id = await ids_from_device_description( + hass, Platform.SELECT, doorbell, CAMERA_SELECTS[1] ) doorbell.__pydantic_fields__["set_ir_led_model"] = Mock(final=False, frozen=False) @@ -439,8 +443,8 @@ async def test_select_set_option_camera_doorbell_custom( await init_entry(hass, ufp, [doorbell]) assert_entity_counts(hass, Platform.SELECT, 5, 5) - _, entity_id = ids_from_device_description( - Platform.SELECT, doorbell, CAMERA_SELECTS[2] + _, entity_id = await ids_from_device_description( + hass, Platform.SELECT, doorbell, CAMERA_SELECTS[2] ) doorbell.__pydantic_fields__["set_lcd_text"] = Mock(final=False, frozen=False) @@ -466,8 +470,8 @@ async def test_select_set_option_camera_doorbell_unifi( await init_entry(hass, ufp, [doorbell]) assert_entity_counts(hass, Platform.SELECT, 5, 5) - _, entity_id = ids_from_device_description( - Platform.SELECT, doorbell, CAMERA_SELECTS[2] + _, entity_id = await ids_from_device_description( + hass, Platform.SELECT, doorbell, CAMERA_SELECTS[2] ) doorbell.__pydantic_fields__["set_lcd_text"] = Mock(final=False, frozen=False) @@ -508,8 +512,8 @@ async def test_select_set_option_camera_doorbell_default( await init_entry(hass, ufp, [doorbell]) assert_entity_counts(hass, Platform.SELECT, 5, 5) - _, entity_id = ids_from_device_description( - Platform.SELECT, doorbell, CAMERA_SELECTS[2] + _, entity_id = await ids_from_device_description( + hass, Platform.SELECT, doorbell, CAMERA_SELECTS[2] ) doorbell.__pydantic_fields__["set_lcd_text"] = Mock(final=False, frozen=False) @@ -537,8 +541,8 @@ async def test_select_set_option_viewer( await init_entry(hass, ufp, [viewer]) assert_entity_counts(hass, Platform.SELECT, 1, 1) - _, entity_id = ids_from_device_description( - Platform.SELECT, viewer, VIEWER_SELECTS[0] + _, entity_id = await ids_from_device_description( + hass, Platform.SELECT, viewer, VIEWER_SELECTS[0] ) viewer.__pydantic_fields__["set_liveview"] = Mock(final=False, frozen=False) diff --git a/tests/components/unifiprotect/test_sensor.py b/tests/components/unifiprotect/test_sensor.py index c65b3ac8e4e..a5c6d437006 100644 --- a/tests/components/unifiprotect/test_sensor.py +++ b/tests/components/unifiprotect/test_sensor.py @@ -119,8 +119,8 @@ async def test_sensor_setup_sensor( for index, description in enumerate(SENSE_SENSORS_WRITE): if not description.entity_registry_enabled_default: continue - unique_id, entity_id = ids_from_device_description( - Platform.SENSOR, sensor_all, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, sensor_all, description ) entity = entity_registry.async_get(entity_id) @@ -133,7 +133,8 @@ async def test_sensor_setup_sensor( assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION # BLE signal - unique_id, entity_id = ids_from_device_description( + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, sensor_all, get_sensor_by_key(ALL_DEVICES_SENSORS, "ble_signal"), @@ -173,8 +174,8 @@ async def test_sensor_setup_sensor_none( for index, description in enumerate(SENSE_SENSORS_WRITE): if not description.entity_registry_enabled_default: continue - unique_id, entity_id = ids_from_device_description( - Platform.SENSOR, sensor, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, sensor, description ) entity = entity_registry.async_get(entity_id) @@ -228,8 +229,8 @@ async def test_sensor_setup_nvr( "50", ) for index, description in enumerate(NVR_SENSORS): - unique_id, entity_id = ids_from_device_description( - Platform.SENSOR, nvr, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, nvr, description ) entity = entity_registry.async_get(entity_id) @@ -247,8 +248,8 @@ async def test_sensor_setup_nvr( expected_values = ("50.0", "50.0", "50.0") for index, description in enumerate(NVR_DISABLED_SENSORS): - unique_id, entity_id = ids_from_device_description( - Platform.SENSOR, nvr, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, nvr, description ) entity = entity_registry.async_get(entity_id) @@ -283,8 +284,8 @@ async def test_sensor_nvr_missing_values( # Uptime description = get_sensor_by_key(NVR_SENSORS, "uptime") - unique_id, entity_id = ids_from_device_description( - Platform.SENSOR, nvr, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, nvr, description ) entity = entity_registry.async_get(entity_id) @@ -300,8 +301,8 @@ async def test_sensor_nvr_missing_values( # Recording capacity description = get_sensor_by_key(NVR_SENSORS, "record_capacity") - unique_id, entity_id = ids_from_device_description( - Platform.SENSOR, nvr, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, nvr, description ) entity = entity_registry.async_get(entity_id) @@ -315,8 +316,8 @@ async def test_sensor_nvr_missing_values( # Memory utilization description = get_sensor_by_key(NVR_DISABLED_SENSORS, "memory_utilization") - unique_id, entity_id = ids_from_device_description( - Platform.SENSOR, nvr, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, nvr, description ) entity = entity_registry.async_get(entity_id) @@ -353,8 +354,8 @@ async def test_sensor_setup_camera( for index, description in enumerate(CAMERA_SENSORS_WRITE): if not description.entity_registry_enabled_default: continue - unique_id, entity_id = ids_from_device_description( - Platform.SENSOR, doorbell, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, doorbell, description ) entity = entity_registry.async_get(entity_id) @@ -369,8 +370,8 @@ async def test_sensor_setup_camera( expected_values = ("0.0001", "0.0001") for index, description in enumerate(CAMERA_DISABLED_SENSORS): - unique_id, entity_id = ids_from_device_description( - Platform.SENSOR, doorbell, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, doorbell, description ) entity = entity_registry.async_get(entity_id) @@ -386,8 +387,11 @@ async def test_sensor_setup_camera( assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION # Wired signal (phy_rate / link speed) - unique_id, entity_id = ids_from_device_description( - Platform.SENSOR, doorbell, get_sensor_by_key(ALL_DEVICES_SENSORS, "phy_rate") + unique_id, entity_id = await ids_from_device_description( + hass, + Platform.SENSOR, + doorbell, + get_sensor_by_key(ALL_DEVICES_SENSORS, "phy_rate"), ) entity = entity_registry.async_get(entity_id) @@ -403,7 +407,8 @@ async def test_sensor_setup_camera( assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION # WiFi signal - unique_id, entity_id = ids_from_device_description( + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, doorbell, get_sensor_by_key(ALL_DEVICES_SENSORS, "wifi_signal"), @@ -436,7 +441,8 @@ async def test_sensor_setup_camera_with_last_trip_time( assert_entity_counts(hass, Platform.SENSOR, 24, 24) # Last Trip Time - unique_id, entity_id = ids_from_device_description( + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, doorbell, get_sensor_by_key(MOTION_TRIP_SENSORS, "motion_last_trip_time"), @@ -463,8 +469,11 @@ async def test_sensor_update_alarm( await init_entry(hass, ufp, [sensor_all]) assert_entity_counts(hass, Platform.SENSOR, 22, 14) - _, entity_id = ids_from_device_description( - Platform.SENSOR, sensor_all, get_sensor_by_key(SENSE_SENSORS, "alarm_sound") + _, entity_id = await ids_from_device_description( + hass, + Platform.SENSOR, + sensor_all, + get_sensor_by_key(SENSE_SENSORS, "alarm_sound"), ) event_metadata = EventMetadata(sensor_id=sensor_all.id, alarm_type="smoke") @@ -514,7 +523,8 @@ async def test_sensor_update_alarm_with_last_trip_time( assert_entity_counts(hass, Platform.SENSOR, 22, 22) # Last Trip Time - unique_id, entity_id = ids_from_device_description( + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, sensor_all, get_sensor_by_key(SENSE_SENSORS, "door_last_trip_time"), @@ -547,7 +557,8 @@ async def test_camera_update_license_plate( await init_entry(hass, ufp, [camera]) assert_entity_counts(hass, Platform.SENSOR, 23, 13) - _, entity_id = ids_from_device_description( + _, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, camera, get_sensor_by_key(LICENSE_PLATE_EVENT_SENSORS, "smart_obj_licenseplate"), @@ -664,7 +675,8 @@ async def test_camera_update_license_plate_changes_number_during_detect( await init_entry(hass, ufp, [camera]) assert_entity_counts(hass, Platform.SENSOR, 23, 13) - _, entity_id = ids_from_device_description( + _, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, camera, get_sensor_by_key(LICENSE_PLATE_EVENT_SENSORS, "smart_obj_licenseplate"), @@ -753,7 +765,8 @@ async def test_camera_update_license_plate_multiple_updates( await init_entry(hass, ufp, [camera]) assert_entity_counts(hass, Platform.SENSOR, 23, 13) - _, entity_id = ids_from_device_description( + _, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, camera, get_sensor_by_key(LICENSE_PLATE_EVENT_SENSORS, "smart_obj_licenseplate"), @@ -878,7 +891,8 @@ async def test_camera_update_license_no_dupes( await init_entry(hass, ufp, [camera]) assert_entity_counts(hass, Platform.SENSOR, 23, 13) - _, entity_id = ids_from_device_description( + _, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, camera, get_sensor_by_key(LICENSE_PLATE_EVENT_SENSORS, "smart_obj_licenseplate"), @@ -973,8 +987,8 @@ async def test_sensor_precision( assert_entity_counts(hass, Platform.SENSOR, 22, 14) nvr: NVR = ufp.api.bootstrap.nvr - _, entity_id = ids_from_device_description( - Platform.SENSOR, nvr, get_sensor_by_key(NVR_SENSORS, "resolution_4K") + _, entity_id = await ids_from_device_description( + hass, Platform.SENSOR, nvr, get_sensor_by_key(NVR_SENSORS, "resolution_4K") ) assert hass.states.get(entity_id).state == "17.49" diff --git a/tests/components/unifiprotect/test_switch.py b/tests/components/unifiprotect/test_switch.py index 1a899550204..501418948c6 100644 --- a/tests/components/unifiprotect/test_switch.py +++ b/tests/components/unifiprotect/test_switch.py @@ -135,8 +135,8 @@ async def test_switch_setup_light( description = LIGHT_SWITCHES[1] - unique_id, entity_id = ids_from_device_description( - Platform.SWITCH, light, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SWITCH, light, description ) entity = entity_registry.async_get(entity_id) @@ -178,8 +178,8 @@ async def test_switch_setup_camera_all( assert_entity_counts(hass, Platform.SWITCH, 17, 15) for description in CAMERA_SWITCHES_BASIC: - unique_id, entity_id = ids_from_device_description( - Platform.SWITCH, doorbell, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SWITCH, doorbell, description ) entity = entity_registry.async_get(entity_id) @@ -224,8 +224,8 @@ async def test_switch_setup_camera_none( if description.ufp_required_field is not None: continue - unique_id, entity_id = ids_from_device_description( - Platform.SWITCH, camera, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.SWITCH, camera, description ) entity = entity_registry.async_get(entity_id) @@ -268,7 +268,9 @@ async def test_switch_light_status( light.__pydantic_fields__["set_status_light"] = Mock(final=False, frozen=False) light.set_status_light = AsyncMock() - _, entity_id = ids_from_device_description(Platform.SWITCH, light, description) + _, entity_id = await ids_from_device_description( + hass, Platform.SWITCH, light, description + ) await hass.services.async_call( "switch", "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True @@ -296,7 +298,9 @@ async def test_switch_camera_ssh( doorbell.__pydantic_fields__["set_ssh"] = Mock(final=False, frozen=False) doorbell.set_ssh = AsyncMock() - _, entity_id = ids_from_device_description(Platform.SWITCH, doorbell, description) + _, entity_id = await ids_from_device_description( + hass, Platform.SWITCH, doorbell, description + ) await enable_entity(hass, ufp.entry.entry_id, entity_id) await hass.services.async_call( @@ -332,7 +336,9 @@ async def test_switch_camera_simple( setattr(doorbell, description.ufp_set_method, AsyncMock()) set_method = getattr(doorbell, description.ufp_set_method) - _, entity_id = ids_from_device_description(Platform.SWITCH, doorbell, description) + _, entity_id = await ids_from_device_description( + hass, Platform.SWITCH, doorbell, description + ) await hass.services.async_call( "switch", "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True @@ -360,7 +366,9 @@ async def test_switch_camera_highfps( doorbell.__pydantic_fields__["set_video_mode"] = Mock(final=False, frozen=False) doorbell.set_video_mode = AsyncMock() - _, entity_id = ids_from_device_description(Platform.SWITCH, doorbell, description) + _, entity_id = await ids_from_device_description( + hass, Platform.SWITCH, doorbell, description + ) await hass.services.async_call( "switch", "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True @@ -391,7 +399,9 @@ async def test_switch_camera_privacy( doorbell.__pydantic_fields__["set_privacy"] = Mock(final=False, frozen=False) doorbell.set_privacy = AsyncMock() - _, entity_id = ids_from_device_description(Platform.SWITCH, doorbell, description) + _, entity_id = await ids_from_device_description( + hass, Platform.SWITCH, doorbell, description + ) state = hass.states.get(entity_id) assert state and state.state == "off" @@ -443,7 +453,9 @@ async def test_switch_camera_privacy_already_on( doorbell.__pydantic_fields__["set_privacy"] = Mock(final=False, frozen=False) doorbell.set_privacy = AsyncMock() - _, entity_id = ids_from_device_description(Platform.SWITCH, doorbell, description) + _, entity_id = await ids_from_device_description( + hass, Platform.SWITCH, doorbell, description + ) await hass.services.async_call( "switch", "turn_off", {ATTR_ENTITY_ID: entity_id}, blocking=True diff --git a/tests/components/unifiprotect/test_text.py b/tests/components/unifiprotect/test_text.py index c34611c43a9..99f16fcbb75 100644 --- a/tests/components/unifiprotect/test_text.py +++ b/tests/components/unifiprotect/test_text.py @@ -51,8 +51,8 @@ async def test_text_camera_setup( assert_entity_counts(hass, Platform.TEXT, 1, 1) description = CAMERA[0] - unique_id, entity_id = ids_from_device_description( - Platform.TEXT, doorbell, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.TEXT, doorbell, description ) entity = entity_registry.async_get(entity_id) @@ -74,8 +74,8 @@ async def test_text_camera_set( assert_entity_counts(hass, Platform.TEXT, 1, 1) description = CAMERA[0] - unique_id, entity_id = ids_from_device_description( - Platform.TEXT, doorbell, description + unique_id, entity_id = await ids_from_device_description( + hass, Platform.TEXT, doorbell, description ) doorbell.__pydantic_fields__["set_lcd_text"] = Mock(final=False, frozen=False) diff --git a/tests/components/unifiprotect/utils.py b/tests/components/unifiprotect/utils.py index ddd6fdf0189..6514f672d90 100644 --- a/tests/components/unifiprotect/utils.py +++ b/tests/components/unifiprotect/utils.py @@ -23,7 +23,7 @@ from uiprotect.websocket import WebsocketState from homeassistant.const import Platform from homeassistant.core import HomeAssistant, split_entity_id -from homeassistant.helpers import entity_registry as er +from homeassistant.helpers import entity_registry as er, translation from homeassistant.helpers.entity import EntityDescription from homeassistant.util import dt as dt_util @@ -100,17 +100,43 @@ def normalize_name(name: str) -> str: return name.lower().replace(":", "").replace(" ", "_").replace("-", "_") -def ids_from_device_description( +async def async_get_translated_entity_name( + hass: HomeAssistant, platform: Platform, translation_key: str +) -> str: + """Get the translated entity name for a given platform and translation key.""" + platform_name = "unifiprotect" + + # Get the translations for the UniFi Protect integration + translations = await translation.async_get_translations( + hass, "en", "entity", {platform_name} + ) + + # Build the translation key in the format that Home Assistant uses + # component.{integration}.entity.{platform}.{translation_key}.name + full_translation_key = ( + f"component.{platform_name}.entity.{platform.value}.{translation_key}.name" + ) + + # Get the translated name, fall back to the translation key if not found + return translations.get(full_translation_key, translation_key) + + +async def ids_from_device_description( + hass: HomeAssistant, platform: Platform, device: ProtectAdoptableDeviceModel, description: EntityDescription, ) -> tuple[str, str]: - """Return expected unique_id and entity_id for a give platform/device/description combination.""" + """Return expected unique_id and entity_id using real Home Assistant translation logic.""" entity_name = normalize_name(device.display_name) if getattr(description, "translation_key", None): - description_entity_name = normalize_name(description.translation_key) + # Get the actual translated name from Home Assistant + translated_name = await async_get_translated_entity_name( + hass, platform, description.translation_key + ) + description_entity_name = normalize_name(translated_name) elif getattr(description, "device_class", None): description_entity_name = normalize_name(description.device_class) else: