Skip to content

Commit

Permalink
Add motion detection switch entity to ring (#126278)
Browse files Browse the repository at this point in the history
Add motion detection switch to ring
  • Loading branch information
sdb9696 authored Sep 20, 2024
1 parent d56a721 commit 42f8d9d
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 0 deletions.
6 changes: 6 additions & 0 deletions homeassistant/components/ring/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
"state": {
"on": "mdi:bell-ring"
}
},
"motion_detection": {
"default": "mdi:motion-sensor-off",
"state": {
"on": "mdi:motion-sensor"
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/ring/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@
},
"in_home_chime": {
"name": "In-home chime"
},
"motion_detection": {
"name": "Motion detection"
}
}
},
Expand Down
8 changes: 8 additions & 0 deletions homeassistant/components/ring/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
)


Expand Down
3 changes: 3 additions & 0 deletions tests/components/ring/device_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
141 changes: 141 additions & 0 deletions tests/components/ring/snapshots/test_switch.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -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': <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]
EntityRegistryEntrySnapshot({
'aliases': set({
Expand Down Expand Up @@ -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': <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]
EntityRegistryEntrySnapshot({
'aliases': set({
Expand Down
1 change: 1 addition & 0 deletions tests/components/ring/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 42f8d9d

Please sign in to comment.