-
-
Notifications
You must be signed in to change notification settings - Fork 13
Scope long-form pin Mode flags to the pin's provider #590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5e94836
Scope long-form pin Mode flags to the pin's provider
bdraco 521115d
Harden pin-mode scoping against edge cases (review)
bdraco 2eb2d47
Merge branch 'main' into bugfix/pin-mode-registry-scope
bdraco 3f3c295
Merge branch 'main' into bugfix/pin-mode-registry-scope
bdraco fc62120
Tighten pin-mode-scoping docstrings per CLAUDE.md
bdraco c393365
Keep set-but-disallowed pin mode flags visible; fetch the map once
bdraco cc2a4b3
Use null-prototype maps for the pin-registry-modes payload
bdraco 82a8378
Merge branch 'main' into bugfix/pin-mode-registry-scope
bdraco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import type { ESPHomeAPI } from "../api/esphome-api.js"; | ||
|
|
||
| /** | ||
| * Session cache of the ``{provider_key: [allowed_mode_flags]}`` map | ||
| * (`components/get_pin_registry_modes`), fetched once and shared across pin | ||
| * renderers. A failed fetch caches ``{}`` so renders don't retry-storm. | ||
| */ | ||
|
|
||
| let _cache: Record<string, string[]> | undefined; | ||
| let _inflight: Promise<Record<string, string[]>> | undefined; | ||
| const _listeners = new Set<() => void>(); | ||
|
|
||
| /** Read the cached map; ``undefined`` until the first fetch resolves. */ | ||
| export function getCachedPinRegistryModes(): Record<string, string[]> | undefined { | ||
| return _cache; | ||
| } | ||
|
|
||
| /** Subscribe to cache population; returns an unsubscribe function. */ | ||
| export function subscribePinRegistryModes(cb: () => void): () => void { | ||
| _listeners.add(cb); | ||
| return () => { | ||
| _listeners.delete(cb); | ||
| }; | ||
| } | ||
|
|
||
| /** Fetch once per session; concurrent callers share the in-flight promise. */ | ||
| export function fetchPinRegistryModes( | ||
| api: ESPHomeAPI | ||
| ): Promise<Record<string, string[]>> { | ||
| if (_cache) return Promise.resolve(_cache); | ||
| if (!_inflight) { | ||
| _inflight = api | ||
| .getPinRegistryModes() | ||
| .catch((err) => { | ||
| // Cache an empty map so renders don't retry-storm; log so the lost | ||
| // scoping shows. Null-prototype to match the populated map's shape. | ||
| console.warn("pin-registry-modes fetch failed; Mode flags unscoped", err); | ||
| return Object.create(null) as Record<string, string[]>; | ||
| }) | ||
|
bdraco marked this conversation as resolved.
|
||
| .then((modes) => { | ||
| _cache = modes; | ||
| _inflight = undefined; | ||
| // Isolate listeners so one throw can't break others or reject this promise. | ||
| for (const cb of _listeners) { | ||
| try { | ||
| cb(); | ||
| } catch (err) { | ||
| console.error("pin-registry-modes listener threw", err); | ||
| } | ||
| } | ||
| return modes; | ||
| }); | ||
| } | ||
| return _inflight; | ||
| } | ||
|
|
||
| /** Test-only: reset the cached map, in-flight fetch, and listeners. */ | ||
| export function _resetPinRegistryModesCache(): void { | ||
| _cache = undefined; | ||
| _inflight = undefined; | ||
| _listeners.clear(); | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.