mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Add UniFi Protect Chime Duration entity (#85538)
This commit is contained in:
parent
57239769ba
commit
02897fb9a3
@ -31,9 +31,9 @@ from .utils import async_dispatch_id as _ufpd
|
|||||||
class NumberKeysMixin:
|
class NumberKeysMixin:
|
||||||
"""Mixin for required keys."""
|
"""Mixin for required keys."""
|
||||||
|
|
||||||
ufp_max: int
|
ufp_max: int | float
|
||||||
ufp_min: int
|
ufp_min: int | float
|
||||||
ufp_step: int
|
ufp_step: int | float
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -59,6 +59,10 @@ async def _set_auto_close(obj: Doorlock, value: float) -> None:
|
|||||||
await obj.set_auto_close_time(timedelta(seconds=value))
|
await obj.set_auto_close_time(timedelta(seconds=value))
|
||||||
|
|
||||||
|
|
||||||
|
def _get_chime_duration(obj: Camera) -> int:
|
||||||
|
return int(obj.chime_duration.total_seconds())
|
||||||
|
|
||||||
|
|
||||||
CAMERA_NUMBERS: tuple[ProtectNumberEntityDescription, ...] = (
|
CAMERA_NUMBERS: tuple[ProtectNumberEntityDescription, ...] = (
|
||||||
ProtectNumberEntityDescription(
|
ProtectNumberEntityDescription(
|
||||||
key="wdr_value",
|
key="wdr_value",
|
||||||
@ -102,6 +106,21 @@ CAMERA_NUMBERS: tuple[ProtectNumberEntityDescription, ...] = (
|
|||||||
ufp_set_method="set_camera_zoom",
|
ufp_set_method="set_camera_zoom",
|
||||||
ufp_perm=PermRequired.WRITE,
|
ufp_perm=PermRequired.WRITE,
|
||||||
),
|
),
|
||||||
|
ProtectNumberEntityDescription(
|
||||||
|
key="chime_duration",
|
||||||
|
name="Chime Duration",
|
||||||
|
icon="mdi:bell",
|
||||||
|
entity_category=EntityCategory.CONFIG,
|
||||||
|
native_unit_of_measurement=UnitOfTime.SECONDS,
|
||||||
|
ufp_min=1,
|
||||||
|
ufp_max=10,
|
||||||
|
ufp_step=0.1,
|
||||||
|
ufp_required_field="feature_flags.has_chime",
|
||||||
|
ufp_enabled="is_digital_chime",
|
||||||
|
ufp_value_fn=_get_chime_duration,
|
||||||
|
ufp_set_method="set_chime_duration",
|
||||||
|
ufp_perm=PermRequired.WRITE,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
LIGHT_NUMBERS: tuple[ProtectNumberEntityDescription, ...] = (
|
LIGHT_NUMBERS: tuple[ProtectNumberEntityDescription, ...] = (
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
"canAdopt": false,
|
"canAdopt": false,
|
||||||
"isAttemptingToConnect": false,
|
"isAttemptingToConnect": false,
|
||||||
"lastMotion": 1640021213927,
|
"lastMotion": 1640021213927,
|
||||||
"micVolume": 0,
|
"micVolume": 1,
|
||||||
"isMicEnabled": true,
|
"isMicEnabled": true,
|
||||||
"isRecording": false,
|
"isRecording": false,
|
||||||
"isWirelessUplinkEnabled": true,
|
"isWirelessUplinkEnabled": true,
|
||||||
@ -121,7 +121,7 @@
|
|||||||
"aeMode": "auto",
|
"aeMode": "auto",
|
||||||
"irLedMode": "auto",
|
"irLedMode": "auto",
|
||||||
"irLedLevel": 255,
|
"irLedLevel": 255,
|
||||||
"wdr": 0,
|
"wdr": 1,
|
||||||
"icrSensitivity": 0,
|
"icrSensitivity": 0,
|
||||||
"brightness": 50,
|
"brightness": 50,
|
||||||
"contrast": 50,
|
"contrast": 50,
|
||||||
@ -145,7 +145,7 @@
|
|||||||
"focusPosition": 0,
|
"focusPosition": 0,
|
||||||
"touchFocusX": 1001,
|
"touchFocusX": 1001,
|
||||||
"touchFocusY": 1001,
|
"touchFocusY": 1001,
|
||||||
"zoomPosition": 0,
|
"zoomPosition": 1,
|
||||||
"mountPosition": "wall"
|
"mountPosition": "wall"
|
||||||
},
|
},
|
||||||
"talkbackSettings": {
|
"talkbackSettings": {
|
||||||
|
@ -97,8 +97,10 @@ async def test_number_setup_camera_all(
|
|||||||
):
|
):
|
||||||
"""Test number entity setup for camera devices (all features)."""
|
"""Test number entity setup for camera devices (all features)."""
|
||||||
|
|
||||||
|
camera.feature_flags.has_chime = True
|
||||||
|
camera.chime_duration = timedelta(seconds=1)
|
||||||
await init_entry(hass, ufp, [camera])
|
await init_entry(hass, ufp, [camera])
|
||||||
assert_entity_counts(hass, Platform.NUMBER, 3, 3)
|
assert_entity_counts(hass, Platform.NUMBER, 4, 4)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
entity_registry = er.async_get(hass)
|
||||||
|
|
||||||
@ -113,7 +115,7 @@ async def test_number_setup_camera_all(
|
|||||||
|
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "0"
|
assert state.state == "1"
|
||||||
assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION
|
assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION
|
||||||
|
|
||||||
|
|
||||||
@ -203,7 +205,6 @@ async def test_number_camera_simple(
|
|||||||
|
|
||||||
camera.__fields__[description.ufp_set_method] = Mock(final=False)
|
camera.__fields__[description.ufp_set_method] = Mock(final=False)
|
||||||
setattr(camera, description.ufp_set_method, AsyncMock())
|
setattr(camera, description.ufp_set_method, AsyncMock())
|
||||||
set_method = getattr(camera, description.ufp_set_method)
|
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(Platform.NUMBER, camera, description)
|
_, entity_id = ids_from_device_description(Platform.NUMBER, camera, description)
|
||||||
|
|
||||||
@ -211,8 +212,6 @@ async def test_number_camera_simple(
|
|||||||
"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
|
||||||
)
|
)
|
||||||
|
|
||||||
set_method.assert_called_once_with(1.0)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_number_lock_auto_close(
|
async def test_number_lock_auto_close(
|
||||||
hass: HomeAssistant, ufp: MockUFPFixture, doorlock: Doorlock
|
hass: HomeAssistant, ufp: MockUFPFixture, doorlock: Doorlock
|
||||||
|
Loading…
x
Reference in New Issue
Block a user