TypingTyping: add TypedDicts and pass mypy --strict#43
Merged
Conversation
- Ship TypedDicts for hub.zones / components / week_profiles / overrides / hub_info so consumers get static field types. - Tighten remaining annotations - Add mypy --strict to GitHub Actions Static-typing notes for consumers under strict mypy: - TypedDicts are not assignable to dict[str, Any]. Switch parameter types to Mapping[str, Any] or the new TypedDicts. - zone.values() narrows from Any to object. - Unknown / variable-keyed lookups (zone["custom_key"], zone[some_var]) are rejected where they were previously Any.
Merged
Collaborator
Author
|
I have verified that Ready to merge and ship 1.9.0! 🚀 |
capelevy
reviewed
May 5, 2026
| def type( | ||
| self, | ||
| ) -> Literal[ | ||
| "THERMOSTAT_HEATER", |
Collaborator
There was a problem hiding this comment.
Third time we are repeating the actual strings, anything we can do to avoid this? Adding THERMOSTAT_HEATER: Final[Literal["THERMOSTAT_HEATER"]] = "THERMOSTAT_HEATER"
or something to the declaration lines seems stupid, but python must have some better way of doing this?
Collaborator
Author
There was a problem hiding this comment.
Good point. We can create a ModelType alias for the typing to reduce to 2 repetitions.
Avoiding the last repetition requires an API change - taking a note to fix this in 2.0.0.
21 tasks
capelevy
approved these changes
May 13, 2026
Collaborator
capelevy
left a comment
There was a problem hiding this comment.
Thank you for updating. Looks good :)
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.
Required for Home Assistant Platinum quality - see Strict typing
TypedDicts forhub.zones/components/week_profiles/overrides/hub_infoso consumers get static field types.mypy --strictto GitHub ActionsStatic-typing notes for consumers under strict
mypy:TypedDicts are not assignable todict[str, Any]. Switch parameter types toMapping[str, Any]or the newTypedDicts.zone.values()narrows fromAnytoobject.zone["custom_key"],zone[some_var]) are rejected where they were previouslyAny.