Skip to content

fix(doorbot): return None for unknown existing_doorbell_type instead of raising KeyError (#542) - #566

Open
PCTEJA wants to merge 2 commits into
python-ring-doorbell:masterfrom
PCTEJA:fix-existing-doorbell-type-542
Open

PCTEJA wants to merge 2 commits into
python-ring-doorbell:masterfrom
PCTEJA:fix-existing-doorbell-type-542

Conversation

@PCTEJA

@PCTEJA PCTEJA commented Nov 14, 2026

Copy link
Copy Markdown

Fixes #542

Problem

existing_doorbell_type does a direct dict lookup, DOORBELL_EXISTING_TYPE[dtype], so an unknown chime type raises KeyError. For a Ring Doorbell 4 (doorbell_oyster) reporting type 5, that takes down the entire Home Assistant switch platform during setup. The same lookup also raises for type 3 (see #543).

Fix

  • Getter: use .get(dtype) in existing_doorbell_type, so unknown types return None instead of raising. The in-home-chime switch is simply not created for an unknown type, and the rest of the platform keeps working. No map entries were invented.
  • Setters: a new shared helper _validate_existing_doorbell_type() runs first in all three setters (async_set_existing_doorbell_type, _enabled, _duration). A present-but-unknown current type now raises RingError("Unsupported existing doorbell type: {dtype}") before any request is made, instead of silently succeeding. A missing type keeps its existing silent no-op, and known types 0/1/2 are unchanged.

Tests

  • Repro, run against master and with the fix: types 0/1/2 return Mechanical/Digital/Not Present on both; types 3 and 5 raise KeyError: 3 / KeyError: 5 on master and return None with the fix.
  • New regression tests fail on the base commit and pass with the fix: getter test, setter test, and CLI test.
  • Full suite: 43 passed (41 before + 2 new). Ruff check + format clean on the changed files; mypy on ring_doorbell clean.

Edge cases

  • Unknown non-integer/unhashable types still raise TypeError — a pre-existing malformed-data limitation, out of scope here.
  • Home Assistant integration code is outside this checkout, so end-to-end switch-platform setup was not verified here; the fix addresses the getter that setup path calls.

Disclosure: I used AI assistance to implement and review this fix; the reproduction and tests above were run locally by me.

…yError

Ring devices can report chime_settings types outside the known
{0: Mechanical, 1: Digital, 2: Not Present} mapping (e.g. type 5 on
Ring Doorbell 4 / doorbell_oyster, type 3 on cocoa_doorbell_v3).
The unguarded dict lookup in existing_doorbell_type raised KeyError,
which in Home Assistant aborts setup of the entire switch platform.

Use .get(dtype) so unknown values return None; all callers already
guard on a falsy value, so the in-home-chime switch is simply not
created instead of crashing the platform.

Fixes python-ring-doorbell#542
…orbell#542)

On devices reporting chime type 3 or 5 the tolerant getter returns
None, which made the in-home-chime setters silently succeed without
sending any update while the CLI still printed success. Validate the
device's current chime type up front in all three setters and raise
RingError for a present but unsupported type, so a skipped update can
no longer be mistaken for success. A missing type keeps its existing
silent no-op; known types 0/1/2 are unchanged.

Add setter coverage for types 3 and 5 (no PUT sent, RingError raised)
plus a direct CLI test proving no success message is printed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KeyError on unknown existing_doorbell_type (5) takes down the entire HA switch platform — still present in 0.9.14 (doorbell_oyster)

1 participant