feat: type listen_Credits with a CreditsEvent dataclass - #39
Merged
Conversation
Replace the bare dict[str, str | int] callback type with a CreditsEvent dataclass, following the same pattern as EnergyHistoryTotals/TeslaLocation.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
Intent
listen_Creditswas typedCallable[[dict[str, str | int]], None]- a bare, incomplete dict shape (it doesn't even account for thequotakey, which isn't astr | int). Callers had to hand-parse the dict with no static guarantee of what keys exist.CreditsEventinconst.pyas a@dataclass, following the same construct asEnergyHistoryTotals(afrom_dictclassmethod building it from the event's nested dict).type: str,cost: int,name: str,balance: int,quota: dict[str, Any]) are drawn from the one real fixture intests/test_energysite_events.py(CREDITS_EVENT), all required since nothing in that sample is omitted.quotais kept asdict[str, Any]rather than a nested dataclass - every observed payload ships it empty, so there's no evidence yet of its internal shape.listen_Creditsnow returnsCreditsEventinstead of the bare dict. Purely additive from the caller's perspective (a plain function still works); the callback's payload shape changes, so this is worth a version bump on release.