Add motion detection switch entity to ring (#126278)

Add motion detection switch to ring
This commit is contained in:
Steven B. 2024-09-20 10:27:05 +01:00 committed by GitHub
parent d56a7217d9
commit 42f8d9d10f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 162 additions and 0 deletions

View File

@ -55,6 +55,12 @@
"state": { "state": {
"on": "mdi:bell-ring" "on": "mdi:bell-ring"
} }
},
"motion_detection": {
"default": "mdi:motion-sensor-off",
"state": {
"on": "mdi:motion-sensor"
}
} }
} }
} }

View File

@ -112,6 +112,9 @@
}, },
"in_home_chime": { "in_home_chime": {
"name": "In-home chime" "name": "In-home chime"
},
"motion_detection": {
"name": "Motion detection"
} }
} }
}, },

View File

@ -68,6 +68,14 @@ SWITCHES: Sequence[RingSwitchEntityDescription[Any]] = (
False False
), ),
), ),
RingSwitchEntityDescription[RingDoorBell](
key="motion_detection",
translation_key="motion_detection",
exists_fn=lambda device: device.has_capability(RingCapability.MOTION_DETECTION),
is_on_fn=lambda device: device.motion_detection,
turn_on_fn=lambda device: device.async_set_motion_detection(True),
turn_off_fn=lambda device: device.async_set_motion_detection(False),
),
) )

View File

@ -145,6 +145,9 @@ def _mocked_ring_device(device_dict, device_family, device_class, capabilities):
mock_device.configure_mock( mock_device.configure_mock(
motion_detection=device_dict["settings"].get("motion_detection_enabled"), motion_detection=device_dict["settings"].get("motion_detection_enabled"),
) )
mock_device.async_set_motion_detection.side_effect = (
lambda i: mock_device.configure_mock(motion_detection=i)
)
if has_capability(RingCapability.LIGHT): if has_capability(RingCapability.LIGHT):
mock_device.configure_mock(lights=device_dict.get("led_status")) mock_device.configure_mock(lights=device_dict.get("led_status"))

View File

@ -46,6 +46,100 @@
'state': 'on', 'state': 'on',
}) })
# --- # ---
# name: test_states[switch.front_door_motion_detection-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'switch',
'entity_category': None,
'entity_id': 'switch.front_door_motion_detection',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Motion detection',
'platform': 'ring',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'motion_detection',
'unique_id': '987654-motion_detection',
'unit_of_measurement': None,
})
# ---
# name: test_states[switch.front_door_motion_detection-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by Ring.com',
'friendly_name': 'Front Door Motion detection',
}),
'context': <ANY>,
'entity_id': 'switch.front_door_motion_detection',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_states[switch.front_motion_detection-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'switch',
'entity_category': None,
'entity_id': 'switch.front_motion_detection',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Motion detection',
'platform': 'ring',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'motion_detection',
'unique_id': '765432-motion_detection',
'unit_of_measurement': None,
})
# ---
# name: test_states[switch.front_motion_detection-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by Ring.com',
'friendly_name': 'Front Motion detection',
}),
'context': <ANY>,
'entity_id': 'switch.front_motion_detection',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_states[switch.front_siren-entry] # name: test_states[switch.front_siren-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
@ -93,6 +187,53 @@
'state': 'off', 'state': 'off',
}) })
# --- # ---
# name: test_states[switch.internal_motion_detection-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'switch',
'entity_category': None,
'entity_id': 'switch.internal_motion_detection',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Motion detection',
'platform': 'ring',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'motion_detection',
'unique_id': '345678-motion_detection',
'unit_of_measurement': None,
})
# ---
# name: test_states[switch.internal_motion_detection-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by Ring.com',
'friendly_name': 'Internal Motion detection',
}),
'context': <ANY>,
'entity_id': 'switch.internal_motion_detection',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_states[switch.internal_siren-entry] # name: test_states[switch.internal_siren-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({

View File

@ -108,6 +108,7 @@ async def test_siren_on_reports_correctly(
[ [
("switch.front_siren"), ("switch.front_siren"),
("switch.front_door_in_home_chime"), ("switch.front_door_in_home_chime"),
("switch.front_motion_detection"),
], ],
) )
async def test_switch_can_be_turned_on_and_off( async def test_switch_can_be_turned_on_and_off(