Repository navigation
[bot] Add CredentialsOption and the button credentials type - #6
Merged
Merged
Conversation
- Discovery.expected_credentials_options carries type, mask and hint; bare types still validate and still match `in` checks - Discovery.accepts() checks provided credentials against the options - Deprecate CredentialsType.with_mask(); it no longer mutates the enum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For review, do not merge yet.
Problem
CredentialsType.with_mask()setcode_maskon the single shared enum member, so the last mask won for every discovery.expected_credentials_optionsdumped only"code".API diff
CredentialsOption(Base):type: CredentialsType,mask: str | None = None,hint: str | None = None(exported fromschemas).Discovery.expected_credentials_options: list[CredentialsType]becomeslist[CredentialsOption]. Wire form:[{"type": "code", "mask": "DDDD-DDD-DDDD", "hint": null}](unset fields dump asnull, the pydantic default).Discovery.accepts(credentials: ProvidedCredentials | None) -> bool; no credentials count asnone.CredentialsType.button: the user physically confirms on the device (ESPHome Improv authorizer, Matter/HomeKit setup button). A confirmation step with no value, distinct fromnone(nothing asked of the user).ProvidedCredentials(type=button)validates with no value.CredentialsType.with_mask(mask, hint=None)and newCredentialsType.with_hint(hint)are the short form: they return a newCredentialsOptionand never mutate the shared enum member. Thewith_maskparameter is renamedcode_mask->mask(all known callers pass it positionally). Both together:CredentialsType.code.with_mask("DDD-DD-DDD", hint="On the box").CredentialsOptionstays a plain data model without builders.discoveriesprintso.type.value.MissingCredentialsError(type: str = "wifi")(aLookupError, exported from the package root, moduleerrors):typeis a lower_snake_case string (validated,ValueErrorotherwise), kept open so an integration can add its own and document it.MissingCredentialsError.WIFI = "wifi",MissingCredentialsError.THREAD = "thread".{type: "missing_credentials", msg: "Missing credentials: <type>", device_id, credentials_type}(Hub PR #149); the message is"Missing credentials: <type>".Compatibility
expected_credentials_optionsaccepts bareCredentialsTypeorstritems, so stored discoveries (["code"]) and older integrations ([CredentialsType.none]) still validate.CredentialsOption.__eq__matches a bare type/str of the same type, so existingcredentials.type in discovery.expected_credentials_optionschecks (matter, homekit, esphome) keep working unchanged..valueon an item, or a Hub/iOS client expecting a list of strings).MissingCredentialsErroris additive.Release order
majordom-integration-sdkin integration-esphome#9 to that release (it raisesMissingCredentialsError), then merge it.Tests
tests/test_credentials.py(17 tests): mask round-trip, legacy bare types (enum and str, and from stored JSON),with_masknot mutating and emitting no warning,with_hint,with_mask(mask, hint=...)with serialization, each call returning a new option,CredentialsOptionhaving no builders,incompat,accepts,buttonwithout a value.tests/test_errors.py(red first): default and known types, message, custom type, lower_snake_case validation,LookupError.poe check --cigreen locally on Python 3.13 (116 passed, ruff, ty, build,poetry check).Note:
spec_drift.pyformatting on develop is fixed separately infix/ci-gate; it is not in this diff.