diff --git a/homeassistant/components/ring/icons.json b/homeassistant/components/ring/icons.json index a5411e3e54f547..de999a5ef37aa0 100644 --- a/homeassistant/components/ring/icons.json +++ b/homeassistant/components/ring/icons.json @@ -55,6 +55,12 @@ "state": { "on": "mdi:bell-ring" } + }, + "motion_detection": { + "default": "mdi:motion-sensor-off", + "state": { + "on": "mdi:motion-sensor" + } } } } diff --git a/homeassistant/components/ring/strings.json b/homeassistant/components/ring/strings.json index 1094b3abd4291f..da0a8af5324cf0 100644 --- a/homeassistant/components/ring/strings.json +++ b/homeassistant/components/ring/strings.json @@ -112,6 +112,9 @@ }, "in_home_chime": { "name": "In-home chime" + }, + "motion_detection": { + "name": "Motion detection" } } }, diff --git a/homeassistant/components/ring/switch.py b/homeassistant/components/ring/switch.py index 79c049792dbbf4..0ac31fec209c0d 100644 --- a/homeassistant/components/ring/switch.py +++ b/homeassistant/components/ring/switch.py @@ -68,6 +68,14 @@ class RingSwitchEntityDescription( 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), + ), ) diff --git a/tests/components/ring/device_mocks.py b/tests/components/ring/device_mocks.py index 99ee6cd11be9f4..4c475c0be879dd 100644 --- a/tests/components/ring/device_mocks.py +++ b/tests/components/ring/device_mocks.py @@ -145,6 +145,9 @@ def update_history_data(fixture): mock_device.configure_mock( 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): mock_device.configure_mock(lights=device_dict.get("led_status")) diff --git a/tests/components/ring/snapshots/test_switch.ambr b/tests/components/ring/snapshots/test_switch.ambr index c45b36c430bf77..57c27cfedfa944 100644 --- a/tests/components/ring/snapshots/test_switch.ambr +++ b/tests/components/ring/snapshots/test_switch.ambr @@ -46,6 +46,100 @@ 'state': 'on', }) # --- +# name: test_states[switch.front_door_motion_detection-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + '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': , + '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': , + 'entity_id': 'switch.front_door_motion_detection', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'on', + }) +# --- +# name: test_states[switch.front_motion_detection-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'switch', + 'entity_category': None, + 'entity_id': 'switch.front_motion_detection', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + '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': , + 'entity_id': 'switch.front_motion_detection', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'off', + }) +# --- # name: test_states[switch.front_siren-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ @@ -93,6 +187,53 @@ 'state': 'off', }) # --- +# name: test_states[switch.internal_motion_detection-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'switch', + 'entity_category': None, + 'entity_id': 'switch.internal_motion_detection', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + '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': , + 'entity_id': 'switch.internal_motion_detection', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'on', + }) +# --- # name: test_states[switch.internal_siren-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ diff --git a/tests/components/ring/test_switch.py b/tests/components/ring/test_switch.py index a29dbf72cde39c..d18add827ecd44 100644 --- a/tests/components/ring/test_switch.py +++ b/tests/components/ring/test_switch.py @@ -108,6 +108,7 @@ async def test_siren_on_reports_correctly( [ ("switch.front_siren"), ("switch.front_door_in_home_chime"), + ("switch.front_motion_detection"), ], ) async def test_switch_can_be_turned_on_and_off(