Skip to content

Commit

Permalink
Update post review
Browse files Browse the repository at this point in the history
  • Loading branch information
sdb9696 committed Sep 4, 2024
1 parent 696288a commit f59c94d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 29 deletions.
14 changes: 4 additions & 10 deletions homeassistant/components/ring/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,18 @@ class RingBinarySensorEntityDescription(
key=KIND_DING,
translation_key=KIND_DING,
device_class=BinarySensorDeviceClass.OCCUPANCY,
entity_registry_enabled_default=True,
capability=RingCapability.DING,
deprecated_info=DeprecatedInfo(
new_platform=Platform.EVENT, breaks_in_ha_version="2025.3.0"
new_platform=Platform.EVENT, breaks_in_ha_version="2025.4.0"
),
),
RingBinarySensorEntityDescription(
key=KIND_MOTION,
translation_key=KIND_MOTION,
device_class=BinarySensorDeviceClass.MOTION,
entity_registry_enabled_default=True,
capability=RingCapability.MOTION_DETECTION,
deprecated_info=DeprecatedInfo(
new_platform=Platform.EVENT, breaks_in_ha_version="2025.3.0"
new_platform=Platform.EVENT, breaks_in_ha_version="2025.4.0"
),
),
)
Expand All @@ -73,7 +71,7 @@ async def async_setup_entry(
ring_data = entry.runtime_data
listen_coordinator = ring_data.listen_coordinator

entities = [
async_add_entities(
RingBinarySensor(device, listen_coordinator, description)
for description in BINARY_SENSOR_TYPES
for device in ring_data.devices.all_devices
Expand All @@ -84,8 +82,7 @@ async def async_setup_entry(
f"{device.id}-{description.key}",
description,
)
]
async_add_entities(entities)
)


class RingBinarySensor(
Expand All @@ -109,9 +106,6 @@ def __init__(
)
self.entity_description = description
self._attr_unique_id = f"{device.id}-{description.key}"
self._attr_entity_registry_enabled_default = (
description.entity_registry_enabled_default
)
self._attr_is_on = False
self._active_alert: RingEvent | None = None
self._cancel_callback: TimerHandle | None = None
Expand Down
18 changes: 5 additions & 13 deletions homeassistant/components/ring/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,20 @@ class RingEventEntityDescription(EventEntityDescription, Generic[RingDeviceT]):
translation_key=KIND_DING,
device_class=EventDeviceClass.DOORBELL,
event_types=[KIND_DING],
entity_registry_enabled_default=True,
capability=RingCapability.DING,
),
RingEventEntityDescription(
key=KIND_MOTION,
translation_key=KIND_MOTION,
device_class=EventDeviceClass.MOTION,
event_types=[KIND_MOTION],
entity_registry_enabled_default=True,
capability=RingCapability.MOTION_DETECTION,
),
RingEventEntityDescription(
key=KIND_INTERCOM_UNLOCK,
translation_key=KIND_INTERCOM_UNLOCK,
device_class=EventDeviceClass.BUTTON,
event_types=[KIND_INTERCOM_UNLOCK],
entity_registry_enabled_default=True,
capability=RingCapability.OPEN,
),
)
Expand All @@ -59,22 +56,20 @@ async def async_setup_entry(
entry: RingConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up a sensor for a Ring device."""
"""Set up events for a Ring device."""
ring_data = entry.runtime_data
listen_coordinator = ring_data.listen_coordinator

entities = [
async_add_entities(
RingEvent(device, listen_coordinator, description)
for description in EVENT_DESCRIPTIONS
for device in ring_data.devices.all_devices
if device.has_capability(description.capability)
]

async_add_entities(entities)
)


class RingEvent(RingBaseEntity[RingListenCoordinator, RingDeviceT], EventEntity):
"""A sensor implementation for Ring device."""
"""An event implementation for Ring device."""

entity_description: RingEventEntityDescription[RingDeviceT]

Expand All @@ -84,13 +79,10 @@ def __init__(
coordinator: RingListenCoordinator,
description: RingEventEntityDescription[RingDeviceT],
) -> None:
"""Initialize a sensor for Ring device."""
"""Initialize a event entity for Ring device."""
super().__init__(device, coordinator)
self.entity_description = description
self._attr_unique_id = f"{device.id}-{description.key}"
self._attr_entity_registry_enabled_default = (
description.entity_registry_enabled_default
)

@callback
def _async_handle_event(self, event: str) -> None:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/ring/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class RingSensorEntityDescription(
else None,
exists_fn=lambda device: device.has_capability(RingCapability.HISTORY),
deprecated_info=DeprecatedInfo(
new_platform=Platform.EVENT, breaks_in_ha_version="2025.3.0"
new_platform=Platform.EVENT, breaks_in_ha_version="2025.4.0"
),
),
RingSensorEntityDescription[RingGeneric](
Expand All @@ -207,7 +207,7 @@ class RingSensorEntityDescription(
else None,
exists_fn=lambda device: device.has_capability(RingCapability.HISTORY),
deprecated_info=DeprecatedInfo(
new_platform=Platform.EVENT, breaks_in_ha_version="2025.3.0"
new_platform=Platform.EVENT, breaks_in_ha_version="2025.4.0"
),
),
RingSensorEntityDescription[RingDoorBell | RingChime](
Expand Down
3 changes: 0 additions & 3 deletions homeassistant/components/ring/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
"ding": {
"name": "Ding"
},
"motion": {
"name": "Motion"
},
"intercom_unlock": {
"name": "Intercom unlock"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/components/ring/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async def setup_platform(hass: HomeAssistant, platform: Platform) -> None:
await hass.async_block_till_done(wait_background_tasks=True)


async def setup_automation(hass: HomeAssistant, alias: str, entity_id: str):
async def setup_automation(hass: HomeAssistant, alias: str, entity_id: str) -> None:
"""Set up an automation for tests."""
assert await async_setup_component(
hass,
Expand Down

0 comments on commit f59c94d

Please sign in to comment.