mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Unifiprotect refactor device description ID retrieval in tests (#149445)
This commit is contained in:
parent
971bd56bee
commit
56fb59e48e
@ -111,8 +111,8 @@ async def test_binary_sensor_setup_light(
|
|||||||
assert_entity_counts(hass, Platform.BINARY_SENSOR, 8, 8)
|
assert_entity_counts(hass, Platform.BINARY_SENSOR, 8, 8)
|
||||||
|
|
||||||
for description in LIGHT_SENSOR_WRITE:
|
for description in LIGHT_SENSOR_WRITE:
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.BINARY_SENSOR, light, description
|
hass, Platform.BINARY_SENSOR, light, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
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)
|
assert_entity_counts(hass, Platform.BINARY_SENSOR, 9, 6)
|
||||||
|
|
||||||
description = EVENT_SENSORS[0]
|
description = EVENT_SENSORS[0]
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.BINARY_SENSOR, doorbell, description
|
hass, Platform.BINARY_SENSOR, doorbell, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
entity = entity_registry.async_get(entity_id)
|
||||||
@ -154,8 +154,8 @@ async def test_binary_sensor_setup_camera_all(
|
|||||||
|
|
||||||
# Is Dark
|
# Is Dark
|
||||||
description = CAMERA_SENSORS[0]
|
description = CAMERA_SENSORS[0]
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.BINARY_SENSOR, doorbell, description
|
hass, Platform.BINARY_SENSOR, doorbell, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
entity = entity_registry.async_get(entity_id)
|
||||||
@ -169,8 +169,8 @@ async def test_binary_sensor_setup_camera_all(
|
|||||||
|
|
||||||
# Motion
|
# Motion
|
||||||
description = EVENT_SENSORS[1]
|
description = EVENT_SENSORS[1]
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.BINARY_SENSOR, doorbell, description
|
hass, Platform.BINARY_SENSOR, doorbell, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
entity = entity_registry.async_get(entity_id)
|
||||||
@ -197,8 +197,8 @@ async def test_binary_sensor_setup_camera_none(
|
|||||||
|
|
||||||
description = CAMERA_SENSORS[0]
|
description = CAMERA_SENSORS[0]
|
||||||
|
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.BINARY_SENSOR, camera, description
|
hass, Platform.BINARY_SENSOR, camera, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
entity = entity_registry.async_get(entity_id)
|
||||||
@ -229,8 +229,8 @@ async def test_binary_sensor_setup_sensor(
|
|||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
]
|
]
|
||||||
for index, description in enumerate(SENSE_SENSORS_WRITE):
|
for index, description in enumerate(SENSE_SENSORS_WRITE):
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.BINARY_SENSOR, sensor_all, description
|
hass, Platform.BINARY_SENSOR, sensor_all, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
entity = entity_registry.async_get(entity_id)
|
||||||
@ -262,8 +262,8 @@ async def test_binary_sensor_setup_sensor_leak(
|
|||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
]
|
]
|
||||||
for index, description in enumerate(SENSE_SENSORS_WRITE):
|
for index, description in enumerate(SENSE_SENSORS_WRITE):
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.BINARY_SENSOR, sensor, description
|
hass, Platform.BINARY_SENSOR, sensor, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
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])
|
await init_entry(hass, ufp, [doorbell, unadopted_camera])
|
||||||
assert_entity_counts(hass, Platform.BINARY_SENSOR, 15, 12)
|
assert_entity_counts(hass, Platform.BINARY_SENSOR, 15, 12)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[1]
|
hass, Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[1]
|
||||||
)
|
)
|
||||||
|
|
||||||
event = Event(
|
event = Event(
|
||||||
@ -334,8 +334,8 @@ async def test_binary_sensor_update_light_motion(
|
|||||||
await init_entry(hass, ufp, [light])
|
await init_entry(hass, ufp, [light])
|
||||||
assert_entity_counts(hass, Platform.BINARY_SENSOR, 8, 8)
|
assert_entity_counts(hass, Platform.BINARY_SENSOR, 8, 8)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.BINARY_SENSOR, light, LIGHT_SENSOR_WRITE[1]
|
hass, Platform.BINARY_SENSOR, light, LIGHT_SENSOR_WRITE[1]
|
||||||
)
|
)
|
||||||
|
|
||||||
event_metadata = EventMetadata(light_id=light.id)
|
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])
|
await init_entry(hass, ufp, [sensor_all])
|
||||||
assert_entity_counts(hass, Platform.BINARY_SENSOR, 11, 11)
|
assert_entity_counts(hass, Platform.BINARY_SENSOR, 11, 11)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.BINARY_SENSOR, sensor_all, MOUNTABLE_SENSE_SENSORS[0]
|
hass, Platform.BINARY_SENSOR, sensor_all, MOUNTABLE_SENSE_SENSORS[0]
|
||||||
)
|
)
|
||||||
|
|
||||||
state = hass.states.get(entity_id)
|
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])
|
await init_entry(hass, ufp, [sensor_all])
|
||||||
assert_entity_counts(hass, Platform.BINARY_SENSOR, 11, 11)
|
assert_entity_counts(hass, Platform.BINARY_SENSOR, 11, 11)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.BINARY_SENSOR, sensor_all, MOUNTABLE_SENSE_SENSORS[0]
|
hass, Platform.BINARY_SENSOR, sensor_all, MOUNTABLE_SENSE_SENSORS[0]
|
||||||
)
|
)
|
||||||
|
|
||||||
state = hass.states.get(entity_id)
|
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)
|
doorbell.smart_detect_settings.object_types.append(SmartDetectObjectType.PACKAGE)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[6]
|
hass, Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[6]
|
||||||
)
|
)
|
||||||
|
|
||||||
event = Event(
|
event = Event(
|
||||||
@ -592,8 +592,8 @@ async def test_binary_sensor_person_detected(
|
|||||||
|
|
||||||
doorbell.smart_detect_settings.object_types.append(SmartDetectObjectType.PERSON)
|
doorbell.smart_detect_settings.object_types.append(SmartDetectObjectType.PERSON)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[3]
|
hass, Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[3]
|
||||||
)
|
)
|
||||||
|
|
||||||
events = async_capture_events(hass, EVENT_STATE_CHANGED)
|
events = async_capture_events(hass, EVENT_STATE_CHANGED)
|
||||||
|
@ -57,8 +57,8 @@ async def test_doorbell_ring(
|
|||||||
def _capture_event(event: HAEvent) -> None:
|
def _capture_event(event: HAEvent) -> None:
|
||||||
events.append(event)
|
events.append(event)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[0]
|
hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[0]
|
||||||
)
|
)
|
||||||
|
|
||||||
unsub = async_track_state_change_event(hass, entity_id, _capture_event)
|
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:
|
def _capture_event(event: HAEvent) -> None:
|
||||||
events.append(event)
|
events.append(event)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[1]
|
hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[1]
|
||||||
)
|
)
|
||||||
|
|
||||||
ulp_id = "ulp_id"
|
ulp_id = "ulp_id"
|
||||||
@ -246,8 +246,8 @@ async def test_doorbell_nfc_scanned_ulpusr_deactivated(
|
|||||||
def _capture_event(event: HAEvent) -> None:
|
def _capture_event(event: HAEvent) -> None:
|
||||||
events.append(event)
|
events.append(event)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[1]
|
hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[1]
|
||||||
)
|
)
|
||||||
|
|
||||||
ulp_id = "ulp_id"
|
ulp_id = "ulp_id"
|
||||||
@ -322,8 +322,8 @@ async def test_doorbell_nfc_scanned_no_ulpusr(
|
|||||||
def _capture_event(event: HAEvent) -> None:
|
def _capture_event(event: HAEvent) -> None:
|
||||||
events.append(event)
|
events.append(event)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[1]
|
hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[1]
|
||||||
)
|
)
|
||||||
|
|
||||||
ulp_id = "ulp_id"
|
ulp_id = "ulp_id"
|
||||||
@ -390,8 +390,8 @@ async def test_doorbell_nfc_scanned_no_keyring(
|
|||||||
def _capture_event(event: HAEvent) -> None:
|
def _capture_event(event: HAEvent) -> None:
|
||||||
events.append(event)
|
events.append(event)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[1]
|
hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[1]
|
||||||
)
|
)
|
||||||
|
|
||||||
test_nfc_id = "test_nfc_id"
|
test_nfc_id = "test_nfc_id"
|
||||||
@ -451,8 +451,8 @@ async def test_doorbell_fingerprint_identified(
|
|||||||
def _capture_event(event: HAEvent) -> None:
|
def _capture_event(event: HAEvent) -> None:
|
||||||
events.append(event)
|
events.append(event)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[2]
|
hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[2]
|
||||||
)
|
)
|
||||||
|
|
||||||
ulp_id = "ulp_id"
|
ulp_id = "ulp_id"
|
||||||
@ -519,8 +519,8 @@ async def test_doorbell_fingerprint_identified_user_deactivated(
|
|||||||
def _capture_event(event: HAEvent) -> None:
|
def _capture_event(event: HAEvent) -> None:
|
||||||
events.append(event)
|
events.append(event)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[2]
|
hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[2]
|
||||||
)
|
)
|
||||||
|
|
||||||
ulp_id = "ulp_id"
|
ulp_id = "ulp_id"
|
||||||
@ -588,8 +588,8 @@ async def test_doorbell_fingerprint_identified_no_user(
|
|||||||
def _capture_event(event: HAEvent) -> None:
|
def _capture_event(event: HAEvent) -> None:
|
||||||
events.append(event)
|
events.append(event)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[2]
|
hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[2]
|
||||||
)
|
)
|
||||||
|
|
||||||
ulp_id = "ulp_id"
|
ulp_id = "ulp_id"
|
||||||
@ -649,8 +649,8 @@ async def test_doorbell_fingerprint_not_identified(
|
|||||||
def _capture_event(event: HAEvent) -> None:
|
def _capture_event(event: HAEvent) -> None:
|
||||||
events.append(event)
|
events.append(event)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[2]
|
hass, Platform.EVENT, doorbell, EVENT_DESCRIPTIONS[2]
|
||||||
)
|
)
|
||||||
|
|
||||||
unsub = async_track_state_change_event(hass, entity_id, _capture_event)
|
unsub = async_track_state_change_event(hass, entity_id, _capture_event)
|
||||||
|
@ -80,8 +80,8 @@ async def test_number_setup_light(
|
|||||||
assert_entity_counts(hass, Platform.NUMBER, 2, 2)
|
assert_entity_counts(hass, Platform.NUMBER, 2, 2)
|
||||||
|
|
||||||
for description in LIGHT_NUMBERS:
|
for description in LIGHT_NUMBERS:
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.NUMBER, light, description
|
hass, Platform.NUMBER, light, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
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)
|
assert_entity_counts(hass, Platform.NUMBER, 5, 5)
|
||||||
|
|
||||||
for description in CAMERA_NUMBERS:
|
for description in CAMERA_NUMBERS:
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.NUMBER, camera, description
|
hass, Platform.NUMBER, camera, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
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.__pydantic_fields__["set_sensitivity"] = Mock(final=False, frozen=False)
|
||||||
light.set_sensitivity = AsyncMock()
|
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(
|
await hass.services.async_call(
|
||||||
"number", "set_value", {ATTR_ENTITY_ID: entity_id, "value": 15.0}, blocking=True
|
"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.__pydantic_fields__["set_duration"] = Mock(final=False, frozen=False)
|
||||||
light.set_duration = AsyncMock()
|
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(
|
await hass.services.async_call(
|
||||||
"number", "set_value", {ATTR_ENTITY_ID: entity_id, "value": 15.0}, blocking=True
|
"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())
|
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(
|
await hass.services.async_call(
|
||||||
"number", "set_value", {ATTR_ENTITY_ID: entity_id, "value": 1.0}, blocking=True
|
"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()
|
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(
|
await hass.services.async_call(
|
||||||
"number", "set_value", {ATTR_ENTITY_ID: entity_id, "value": 15.0}, blocking=True
|
"number", "set_value", {ATTR_ENTITY_ID: entity_id, "value": 15.0}, blocking=True
|
||||||
|
@ -35,8 +35,8 @@ async def test_exclude_attributes(
|
|||||||
now = fixed_now
|
now = fixed_now
|
||||||
await init_entry(hass, ufp, [doorbell, unadopted_camera])
|
await init_entry(hass, ufp, [doorbell, unadopted_camera])
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[1]
|
hass, Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[1]
|
||||||
)
|
)
|
||||||
|
|
||||||
event = Event(
|
event = Event(
|
||||||
|
@ -98,8 +98,8 @@ async def test_select_setup_light(
|
|||||||
expected_values = ("On Motion - When Dark", "Not Paired")
|
expected_values = ("On Motion - When Dark", "Not Paired")
|
||||||
|
|
||||||
for index, description in enumerate(LIGHT_SELECTS):
|
for index, description in enumerate(LIGHT_SELECTS):
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.SELECT, light, description
|
hass, Platform.SELECT, light, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
entity = entity_registry.async_get(entity_id)
|
||||||
@ -127,8 +127,8 @@ async def test_select_setup_viewer(
|
|||||||
|
|
||||||
description = VIEWER_SELECTS[0]
|
description = VIEWER_SELECTS[0]
|
||||||
|
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.SELECT, viewer, description
|
hass, Platform.SELECT, viewer, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
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):
|
for index, description in enumerate(CAMERA_SELECTS):
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.SELECT, doorbell, description
|
hass, Platform.SELECT, doorbell, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
entity = entity_registry.async_get(entity_id)
|
||||||
@ -192,8 +192,8 @@ async def test_select_setup_camera_none(
|
|||||||
if index == 2:
|
if index == 2:
|
||||||
return
|
return
|
||||||
|
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.SELECT, camera, description
|
hass, Platform.SELECT, camera, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
entity = entity_registry.async_get(entity_id)
|
||||||
@ -215,8 +215,8 @@ async def test_select_update_liveview(
|
|||||||
await init_entry(hass, ufp, [viewer])
|
await init_entry(hass, ufp, [viewer])
|
||||||
assert_entity_counts(hass, Platform.SELECT, 1, 1)
|
assert_entity_counts(hass, Platform.SELECT, 1, 1)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.SELECT, viewer, VIEWER_SELECTS[0]
|
hass, Platform.SELECT, viewer, VIEWER_SELECTS[0]
|
||||||
)
|
)
|
||||||
|
|
||||||
state = hass.states.get(entity_id)
|
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
|
expected_length = len(ufp.api.bootstrap.nvr.doorbell_settings.all_messages) + 1
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.SELECT, doorbell, CAMERA_SELECTS[2]
|
hass, Platform.SELECT, doorbell, CAMERA_SELECTS[2]
|
||||||
)
|
)
|
||||||
|
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
@ -296,8 +296,8 @@ async def test_select_update_doorbell_message(
|
|||||||
await init_entry(hass, ufp, [doorbell])
|
await init_entry(hass, ufp, [doorbell])
|
||||||
assert_entity_counts(hass, Platform.SELECT, 5, 5)
|
assert_entity_counts(hass, Platform.SELECT, 5, 5)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.SELECT, doorbell, CAMERA_SELECTS[2]
|
hass, Platform.SELECT, doorbell, CAMERA_SELECTS[2]
|
||||||
)
|
)
|
||||||
|
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
@ -330,7 +330,9 @@ async def test_select_set_option_light_motion(
|
|||||||
await init_entry(hass, ufp, [light])
|
await init_entry(hass, ufp, [light])
|
||||||
assert_entity_counts(hass, Platform.SELECT, 2, 2)
|
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.__pydantic_fields__["set_light_settings"] = Mock(final=False, frozen=False)
|
||||||
light.set_light_settings = AsyncMock()
|
light.set_light_settings = AsyncMock()
|
||||||
@ -355,7 +357,9 @@ async def test_select_set_option_light_camera(
|
|||||||
await init_entry(hass, ufp, [light, camera])
|
await init_entry(hass, ufp, [light, camera])
|
||||||
assert_entity_counts(hass, Platform.SELECT, 4, 4)
|
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.__pydantic_fields__["set_paired_camera"] = Mock(final=False, frozen=False)
|
||||||
light.set_paired_camera = AsyncMock()
|
light.set_paired_camera = AsyncMock()
|
||||||
@ -389,8 +393,8 @@ async def test_select_set_option_camera_recording(
|
|||||||
await init_entry(hass, ufp, [doorbell])
|
await init_entry(hass, ufp, [doorbell])
|
||||||
assert_entity_counts(hass, Platform.SELECT, 5, 5)
|
assert_entity_counts(hass, Platform.SELECT, 5, 5)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.SELECT, doorbell, CAMERA_SELECTS[0]
|
hass, Platform.SELECT, doorbell, CAMERA_SELECTS[0]
|
||||||
)
|
)
|
||||||
|
|
||||||
doorbell.__pydantic_fields__["set_recording_mode"] = Mock(final=False, frozen=False)
|
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])
|
await init_entry(hass, ufp, [doorbell])
|
||||||
assert_entity_counts(hass, Platform.SELECT, 5, 5)
|
assert_entity_counts(hass, Platform.SELECT, 5, 5)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.SELECT, doorbell, CAMERA_SELECTS[1]
|
hass, Platform.SELECT, doorbell, CAMERA_SELECTS[1]
|
||||||
)
|
)
|
||||||
|
|
||||||
doorbell.__pydantic_fields__["set_ir_led_model"] = Mock(final=False, frozen=False)
|
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])
|
await init_entry(hass, ufp, [doorbell])
|
||||||
assert_entity_counts(hass, Platform.SELECT, 5, 5)
|
assert_entity_counts(hass, Platform.SELECT, 5, 5)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.SELECT, doorbell, CAMERA_SELECTS[2]
|
hass, Platform.SELECT, doorbell, CAMERA_SELECTS[2]
|
||||||
)
|
)
|
||||||
|
|
||||||
doorbell.__pydantic_fields__["set_lcd_text"] = Mock(final=False, frozen=False)
|
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])
|
await init_entry(hass, ufp, [doorbell])
|
||||||
assert_entity_counts(hass, Platform.SELECT, 5, 5)
|
assert_entity_counts(hass, Platform.SELECT, 5, 5)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.SELECT, doorbell, CAMERA_SELECTS[2]
|
hass, Platform.SELECT, doorbell, CAMERA_SELECTS[2]
|
||||||
)
|
)
|
||||||
|
|
||||||
doorbell.__pydantic_fields__["set_lcd_text"] = Mock(final=False, frozen=False)
|
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])
|
await init_entry(hass, ufp, [doorbell])
|
||||||
assert_entity_counts(hass, Platform.SELECT, 5, 5)
|
assert_entity_counts(hass, Platform.SELECT, 5, 5)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.SELECT, doorbell, CAMERA_SELECTS[2]
|
hass, Platform.SELECT, doorbell, CAMERA_SELECTS[2]
|
||||||
)
|
)
|
||||||
|
|
||||||
doorbell.__pydantic_fields__["set_lcd_text"] = Mock(final=False, frozen=False)
|
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])
|
await init_entry(hass, ufp, [viewer])
|
||||||
assert_entity_counts(hass, Platform.SELECT, 1, 1)
|
assert_entity_counts(hass, Platform.SELECT, 1, 1)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.SELECT, viewer, VIEWER_SELECTS[0]
|
hass, Platform.SELECT, viewer, VIEWER_SELECTS[0]
|
||||||
)
|
)
|
||||||
|
|
||||||
viewer.__pydantic_fields__["set_liveview"] = Mock(final=False, frozen=False)
|
viewer.__pydantic_fields__["set_liveview"] = Mock(final=False, frozen=False)
|
||||||
|
@ -119,8 +119,8 @@ async def test_sensor_setup_sensor(
|
|||||||
for index, description in enumerate(SENSE_SENSORS_WRITE):
|
for index, description in enumerate(SENSE_SENSORS_WRITE):
|
||||||
if not description.entity_registry_enabled_default:
|
if not description.entity_registry_enabled_default:
|
||||||
continue
|
continue
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.SENSOR, sensor_all, description
|
hass, Platform.SENSOR, sensor_all, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
entity = entity_registry.async_get(entity_id)
|
||||||
@ -133,7 +133,8 @@ async def test_sensor_setup_sensor(
|
|||||||
assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION
|
assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION
|
||||||
|
|
||||||
# BLE signal
|
# BLE signal
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
|
hass,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
sensor_all,
|
sensor_all,
|
||||||
get_sensor_by_key(ALL_DEVICES_SENSORS, "ble_signal"),
|
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):
|
for index, description in enumerate(SENSE_SENSORS_WRITE):
|
||||||
if not description.entity_registry_enabled_default:
|
if not description.entity_registry_enabled_default:
|
||||||
continue
|
continue
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.SENSOR, sensor, description
|
hass, Platform.SENSOR, sensor, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
entity = entity_registry.async_get(entity_id)
|
||||||
@ -228,8 +229,8 @@ async def test_sensor_setup_nvr(
|
|||||||
"50",
|
"50",
|
||||||
)
|
)
|
||||||
for index, description in enumerate(NVR_SENSORS):
|
for index, description in enumerate(NVR_SENSORS):
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.SENSOR, nvr, description
|
hass, Platform.SENSOR, nvr, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
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")
|
expected_values = ("50.0", "50.0", "50.0")
|
||||||
for index, description in enumerate(NVR_DISABLED_SENSORS):
|
for index, description in enumerate(NVR_DISABLED_SENSORS):
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.SENSOR, nvr, description
|
hass, Platform.SENSOR, nvr, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
entity = entity_registry.async_get(entity_id)
|
||||||
@ -283,8 +284,8 @@ async def test_sensor_nvr_missing_values(
|
|||||||
|
|
||||||
# Uptime
|
# Uptime
|
||||||
description = get_sensor_by_key(NVR_SENSORS, "uptime")
|
description = get_sensor_by_key(NVR_SENSORS, "uptime")
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.SENSOR, nvr, description
|
hass, Platform.SENSOR, nvr, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
entity = entity_registry.async_get(entity_id)
|
||||||
@ -300,8 +301,8 @@ async def test_sensor_nvr_missing_values(
|
|||||||
|
|
||||||
# Recording capacity
|
# Recording capacity
|
||||||
description = get_sensor_by_key(NVR_SENSORS, "record_capacity")
|
description = get_sensor_by_key(NVR_SENSORS, "record_capacity")
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.SENSOR, nvr, description
|
hass, Platform.SENSOR, nvr, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
entity = entity_registry.async_get(entity_id)
|
||||||
@ -315,8 +316,8 @@ async def test_sensor_nvr_missing_values(
|
|||||||
|
|
||||||
# Memory utilization
|
# Memory utilization
|
||||||
description = get_sensor_by_key(NVR_DISABLED_SENSORS, "memory_utilization")
|
description = get_sensor_by_key(NVR_DISABLED_SENSORS, "memory_utilization")
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.SENSOR, nvr, description
|
hass, Platform.SENSOR, nvr, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
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):
|
for index, description in enumerate(CAMERA_SENSORS_WRITE):
|
||||||
if not description.entity_registry_enabled_default:
|
if not description.entity_registry_enabled_default:
|
||||||
continue
|
continue
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.SENSOR, doorbell, description
|
hass, Platform.SENSOR, doorbell, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
entity = entity_registry.async_get(entity_id)
|
||||||
@ -369,8 +370,8 @@ async def test_sensor_setup_camera(
|
|||||||
|
|
||||||
expected_values = ("0.0001", "0.0001")
|
expected_values = ("0.0001", "0.0001")
|
||||||
for index, description in enumerate(CAMERA_DISABLED_SENSORS):
|
for index, description in enumerate(CAMERA_DISABLED_SENSORS):
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.SENSOR, doorbell, description
|
hass, Platform.SENSOR, doorbell, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
entity = entity_registry.async_get(entity_id)
|
||||||
@ -386,8 +387,11 @@ async def test_sensor_setup_camera(
|
|||||||
assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION
|
assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION
|
||||||
|
|
||||||
# Wired signal (phy_rate / link speed)
|
# Wired signal (phy_rate / link speed)
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.SENSOR, doorbell, get_sensor_by_key(ALL_DEVICES_SENSORS, "phy_rate")
|
hass,
|
||||||
|
Platform.SENSOR,
|
||||||
|
doorbell,
|
||||||
|
get_sensor_by_key(ALL_DEVICES_SENSORS, "phy_rate"),
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
entity = entity_registry.async_get(entity_id)
|
||||||
@ -403,7 +407,8 @@ async def test_sensor_setup_camera(
|
|||||||
assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION
|
assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION
|
||||||
|
|
||||||
# WiFi signal
|
# WiFi signal
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
|
hass,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
doorbell,
|
doorbell,
|
||||||
get_sensor_by_key(ALL_DEVICES_SENSORS, "wifi_signal"),
|
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)
|
assert_entity_counts(hass, Platform.SENSOR, 24, 24)
|
||||||
|
|
||||||
# Last Trip Time
|
# Last Trip Time
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
|
hass,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
doorbell,
|
doorbell,
|
||||||
get_sensor_by_key(MOTION_TRIP_SENSORS, "motion_last_trip_time"),
|
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])
|
await init_entry(hass, ufp, [sensor_all])
|
||||||
assert_entity_counts(hass, Platform.SENSOR, 22, 14)
|
assert_entity_counts(hass, Platform.SENSOR, 22, 14)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.SENSOR, sensor_all, get_sensor_by_key(SENSE_SENSORS, "alarm_sound")
|
hass,
|
||||||
|
Platform.SENSOR,
|
||||||
|
sensor_all,
|
||||||
|
get_sensor_by_key(SENSE_SENSORS, "alarm_sound"),
|
||||||
)
|
)
|
||||||
|
|
||||||
event_metadata = EventMetadata(sensor_id=sensor_all.id, alarm_type="smoke")
|
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)
|
assert_entity_counts(hass, Platform.SENSOR, 22, 22)
|
||||||
|
|
||||||
# Last Trip Time
|
# Last Trip Time
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
|
hass,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
sensor_all,
|
sensor_all,
|
||||||
get_sensor_by_key(SENSE_SENSORS, "door_last_trip_time"),
|
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])
|
await init_entry(hass, ufp, [camera])
|
||||||
assert_entity_counts(hass, Platform.SENSOR, 23, 13)
|
assert_entity_counts(hass, Platform.SENSOR, 23, 13)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
|
hass,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
camera,
|
camera,
|
||||||
get_sensor_by_key(LICENSE_PLATE_EVENT_SENSORS, "smart_obj_licenseplate"),
|
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])
|
await init_entry(hass, ufp, [camera])
|
||||||
assert_entity_counts(hass, Platform.SENSOR, 23, 13)
|
assert_entity_counts(hass, Platform.SENSOR, 23, 13)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
|
hass,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
camera,
|
camera,
|
||||||
get_sensor_by_key(LICENSE_PLATE_EVENT_SENSORS, "smart_obj_licenseplate"),
|
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])
|
await init_entry(hass, ufp, [camera])
|
||||||
assert_entity_counts(hass, Platform.SENSOR, 23, 13)
|
assert_entity_counts(hass, Platform.SENSOR, 23, 13)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
|
hass,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
camera,
|
camera,
|
||||||
get_sensor_by_key(LICENSE_PLATE_EVENT_SENSORS, "smart_obj_licenseplate"),
|
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])
|
await init_entry(hass, ufp, [camera])
|
||||||
assert_entity_counts(hass, Platform.SENSOR, 23, 13)
|
assert_entity_counts(hass, Platform.SENSOR, 23, 13)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
|
hass,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
camera,
|
camera,
|
||||||
get_sensor_by_key(LICENSE_PLATE_EVENT_SENSORS, "smart_obj_licenseplate"),
|
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)
|
assert_entity_counts(hass, Platform.SENSOR, 22, 14)
|
||||||
nvr: NVR = ufp.api.bootstrap.nvr
|
nvr: NVR = ufp.api.bootstrap.nvr
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = await ids_from_device_description(
|
||||||
Platform.SENSOR, nvr, get_sensor_by_key(NVR_SENSORS, "resolution_4K")
|
hass, Platform.SENSOR, nvr, get_sensor_by_key(NVR_SENSORS, "resolution_4K")
|
||||||
)
|
)
|
||||||
|
|
||||||
assert hass.states.get(entity_id).state == "17.49"
|
assert hass.states.get(entity_id).state == "17.49"
|
||||||
|
@ -135,8 +135,8 @@ async def test_switch_setup_light(
|
|||||||
|
|
||||||
description = LIGHT_SWITCHES[1]
|
description = LIGHT_SWITCHES[1]
|
||||||
|
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.SWITCH, light, description
|
hass, Platform.SWITCH, light, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
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)
|
assert_entity_counts(hass, Platform.SWITCH, 17, 15)
|
||||||
|
|
||||||
for description in CAMERA_SWITCHES_BASIC:
|
for description in CAMERA_SWITCHES_BASIC:
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.SWITCH, doorbell, description
|
hass, Platform.SWITCH, doorbell, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
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:
|
if description.ufp_required_field is not None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.SWITCH, camera, description
|
hass, Platform.SWITCH, camera, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
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.__pydantic_fields__["set_status_light"] = Mock(final=False, frozen=False)
|
||||||
light.set_status_light = AsyncMock()
|
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(
|
await hass.services.async_call(
|
||||||
"switch", "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True
|
"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.__pydantic_fields__["set_ssh"] = Mock(final=False, frozen=False)
|
||||||
doorbell.set_ssh = AsyncMock()
|
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 enable_entity(hass, ufp.entry.entry_id, entity_id)
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
@ -332,7 +336,9 @@ async def test_switch_camera_simple(
|
|||||||
setattr(doorbell, description.ufp_set_method, AsyncMock())
|
setattr(doorbell, description.ufp_set_method, AsyncMock())
|
||||||
set_method = getattr(doorbell, description.ufp_set_method)
|
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(
|
await hass.services.async_call(
|
||||||
"switch", "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True
|
"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.__pydantic_fields__["set_video_mode"] = Mock(final=False, frozen=False)
|
||||||
doorbell.set_video_mode = AsyncMock()
|
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(
|
await hass.services.async_call(
|
||||||
"switch", "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True
|
"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.__pydantic_fields__["set_privacy"] = Mock(final=False, frozen=False)
|
||||||
doorbell.set_privacy = AsyncMock()
|
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)
|
state = hass.states.get(entity_id)
|
||||||
assert state and state.state == "off"
|
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.__pydantic_fields__["set_privacy"] = Mock(final=False, frozen=False)
|
||||||
doorbell.set_privacy = AsyncMock()
|
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(
|
await hass.services.async_call(
|
||||||
"switch", "turn_off", {ATTR_ENTITY_ID: entity_id}, blocking=True
|
"switch", "turn_off", {ATTR_ENTITY_ID: entity_id}, blocking=True
|
||||||
|
@ -51,8 +51,8 @@ async def test_text_camera_setup(
|
|||||||
assert_entity_counts(hass, Platform.TEXT, 1, 1)
|
assert_entity_counts(hass, Platform.TEXT, 1, 1)
|
||||||
|
|
||||||
description = CAMERA[0]
|
description = CAMERA[0]
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.TEXT, doorbell, description
|
hass, Platform.TEXT, doorbell, description
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = entity_registry.async_get(entity_id)
|
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)
|
assert_entity_counts(hass, Platform.TEXT, 1, 1)
|
||||||
|
|
||||||
description = CAMERA[0]
|
description = CAMERA[0]
|
||||||
unique_id, entity_id = ids_from_device_description(
|
unique_id, entity_id = await ids_from_device_description(
|
||||||
Platform.TEXT, doorbell, description
|
hass, Platform.TEXT, doorbell, description
|
||||||
)
|
)
|
||||||
|
|
||||||
doorbell.__pydantic_fields__["set_lcd_text"] = Mock(final=False, frozen=False)
|
doorbell.__pydantic_fields__["set_lcd_text"] = Mock(final=False, frozen=False)
|
||||||
|
@ -23,7 +23,7 @@ from uiprotect.websocket import WebsocketState
|
|||||||
|
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant, split_entity_id
|
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.helpers.entity import EntityDescription
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
@ -100,17 +100,43 @@ def normalize_name(name: str) -> str:
|
|||||||
return name.lower().replace(":", "").replace(" ", "_").replace("-", "_")
|
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,
|
platform: Platform,
|
||||||
device: ProtectAdoptableDeviceModel,
|
device: ProtectAdoptableDeviceModel,
|
||||||
description: EntityDescription,
|
description: EntityDescription,
|
||||||
) -> tuple[str, str]:
|
) -> 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)
|
entity_name = normalize_name(device.display_name)
|
||||||
|
|
||||||
if getattr(description, "translation_key", None):
|
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):
|
elif getattr(description, "device_class", None):
|
||||||
description_entity_name = normalize_name(description.device_class)
|
description_entity_name = normalize_name(description.device_class)
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user