Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions ring_doorbell/doorbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@

_LOGGER = logging.getLogger(__name__)

# Kinds are logged once each, the model and capability properties are read on
# every entity refresh and logging each time would flood consumer logs.
_UNMAPPED_KINDS_LOGGED: set[str] = set()


def _log_unmapped_kind(kind: str) -> None:
"""Warn once about a doorbell kind that is not mapped."""
if kind in _UNMAPPED_KINDS_LOGGED:
return
_UNMAPPED_KINDS_LOGGED.add(kind)
_LOGGER.warning(
"Unmapped doorbell kind: %s. Assuming it supports the standard doorbell "
"capabilities (ding, motion detection, video). Please report the kind if "
"this device exposes different capabilities",
kind,
)


class RingDoorBell(RingGeneric):
"""Implementation for Ring Doorbell."""
Expand Down Expand Up @@ -106,6 +123,7 @@ def model(self) -> str: # noqa: C901, PLR0911
return "Doorbell (2nd Gen)"
if self.kind in PEEPHOLE_CAM_KINDS:
return "Peephole Cam"
_log_unmapped_kind(self.kind)
return "Unknown Doorbell"

def has_capability(self, capability: RingCapability | str) -> bool: # noqa: PLR0911
Expand Down Expand Up @@ -139,7 +157,7 @@ def has_capability(self, capability: RingCapability | str) -> bool: # noqa: PLR
RingCapability.VIDEO,
RingCapability.DING,
]:
return self.kind in (
if self.kind in (
DOORBELL_KINDS
+ DOORBELL_2_KINDS
+ DOORBELL_3_KINDS
Expand All @@ -152,7 +170,15 @@ def has_capability(self, capability: RingCapability | str) -> bool: # noqa: PLR
+ DOORBELL_GEN2_KINDS
+ DOORBELL_ELITE_KINDS
+ PEEPHOLE_CAM_KINDS
)
):
return True
# Ring releases new doorbell models faster than this mapping is
# updated, and everything in the doorbots families is a doorbell, so
# assume the standard alerts rather than dropping ding, motion and
# video. Without them consumers leave the realtime event listener
# disabled and poll for events instead, which delays every alert.
_log_unmapped_kind(self.kind)
return True
return False

@property
Expand Down
29 changes: 29 additions & 0 deletions tests/test_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,35 @@ async def test_doorbell_attributes(ring):
assert dev.wifi_signal_strength == -58


def test_unmapped_doorbell_kind_keeps_capabilities(ring, caplog):
"""Test unmapped doorbell kinds are assumed to support the standard alerts."""
dev = ring.devices()["doorbots"][0]
dev._attrs["kind"] = "unmapped_doorbell_v1"

assert dev.has_capability("ding") is True
assert dev.has_capability("motion_detection") is True
assert dev.has_capability("video") is True
assert dev.has_capability("history") is True
assert dev.has_capability("volume") is True
# Battery is hardware dependent and is not inferred from the kind
assert dev.has_capability("battery") is False

assert dev.model == "Unknown Doorbell"
assert "Unmapped doorbell kind: unmapped_doorbell_v1" in caplog.text


def test_unmapped_doorbell_kind_is_logged_once(ring, caplog):
"""Test the unmapped kind warning is logged once and not on every access."""
dev = ring.devices()["doorbots"][0]
dev._attrs["kind"] = "unmapped_doorbell_v2"

for _ in range(3):
assert dev.has_capability("ding") is True
assert dev.model == "Unknown Doorbell"

assert caplog.text.count("Unmapped doorbell kind: unmapped_doorbell_v2") == 1


def test_shared_doorbell_attributes(ring):
data = ring.devices()
dev = data["authorized_doorbots"][0]
Expand Down