Repository navigation
Disable the controls a user may not operate - #44
Merged
Merged
Conversation
With the panel's "Who may operate the panel" option set to administrators only, a user who is not one could still toggle a breaker: the integration's control gate refused it, the card said "Unable to toggle relay" and left the toggle as clicked. panel_topology now says whether the user who asked may operate the panel's controls (control_access: may_operate, reason). Where it says not, every relay and priority control the card draws is disabled and titled with why: the side panel's relay switch and priority select, under a note; each toggle in the breaker grid and in the By Activity and By Area rows; and Enable Switches, which can no longer be armed, with a note under the panel's name. The gear, the favorite, the graph horizon and the read-only monitoring stay open. In the Favorites view each circuit keeps its own panel's answer. Where the topology says nothing, as from an older integration or the entity fallback, the controls stay operable, as before. Every relay and priority change now goes through one module, which sends nothing where the user may not operate the controls. A change refused anyway, as by an armed control lock, a relay operated a moment ago or a policy changed since, shows the control as Home Assistant reports it again, and the banner says why in the gate's words. The access arrives with each topology, so the views draw again as it changes, and an open side panel takes it in place.
Add control-access.ts to the project structure, and a Control Changes section beside Monitoring Changes: what control_access says, the one send path and its guard test, how a refusal is reported, what is drawn disabled where the user may not operate the controls, and how a change of access reaches the views and an open side panel.
control_access may also give the reason read_only: the user's Home Assistant permissions do not let them control the panel's entities, as for a user in the Read Only group. The integration gives the first reason that applies, control_disabled, then admin_only, then read_only. The card disables the controls for it as for the others, and says "Your Home Assistant account can't operate this panel's controls." in each of its five languages. may_operate decides whether the controls can be operated; the reason only picks the hint, and one the card does not know gets the generic hint.
Copy each capture's topology unchanged from the integration's test fixtures, which now carry control_access. Each says the user may operate the panel's controls, and each circuit now names its own device (device_id), which the integration has given every circuit since it made each one a child device. The card draws every capture as before, and a new check says each is drawn operable, with no forbidden toggle, slider or note.
Nothing in the card called RetryManager.callService, and a generic service call is a way round the one module that sends relay and priority changes. The card now calls Home Assistant's callService nowhere; the short-circuit test that used it reads through callWS.
A forbidden toggle pill and Enable Switches slider carried aria-disabled, but both are plain elements with no role, so the state meant nothing to assistive technology. Their titles, and the note beside the slider, say why they cannot be operated.
…nt's refusal The integration lets a user operate a panel who may control some of its circuits' entities, and Home Assistant refuses that user the others with its own Unauthorized, whose message is English in every language. A relay or priority change refused so now says, in the user's language, that their account can't operate this control, and the side panel still shows the control as Home Assistant reports it. isUnauthorized moves to helpers/error-text.ts, where monitoring reads it too. Only the wire reader, controlAccess(), takes the integration's silence as operable. A circuit side panel's config and each Favorites circuit ref must now carry the access, FavoriteRef being a union on kind, so the compiler flags any path that leaves it out, and a Favorites circuit with no circuit ref is not operable. The side panel holds no operable access while no circuit is open. controlWrites() takes a Home Assistant, so the not-connected refusal can no longer be reached. The hints are looked up as t() calls, which the i18n check can see. isFavoritesTopology has one definition, in types.ts. The side panel's relay switch and priority select are named by their labels and described by the note while one shows. The guard test now also fails where callService is called at all, and where a call_service message outside the controls module names any domain but INTEGRATION_DOMAIN.
…d a mixed Favorites view A change the control gate refuses from a breaker grid toggle and from a list row's toggle puts the gate's words, in the user's language, in the banner. On the sidebar's By Panel tab, drawn for real, a re-seed that takes the user's access away reaches an open side panel at once, and the tab is drawn again only once it closes. A Favorites view of two panels, one the user may not operate, draws each circuit's toggle as its own panel allows, keeps the slider armable, and sends a change only for the panel the user may operate.
…iew's changes The sidebar waits for an open side panel to close before it draws a view again, but the card draws its view again at once: its By Panel side panel sits outside the view and takes the new access in place, while a list view's side panel goes with its list. Say so in DEVELOPER.md, the controller and the card. DEVELOPER.md also says that only the wire reader takes silence as operable, how Home Assistant's Unauthorized is reported, what the guard test now checks, and how the side panel's controls are named and described.
…d on a tap A Favorites view that mixes a panel the user may operate with one they may not has an armable slider, so nothing there said why the other panel's toggles do nothing, and a toggle's title never shows on touch. Each panel the user may not operate now says why under its own name in the view's stats grid, with its own hint; a panel that gives the view only sub-devices has nothing to forbid and says nothing. The strip's slider leaves its note to those cards. A tap on a forbidden toggle puts the same hint in the banner as a transient warning, in the error store's one transient slot, so tapping again replaces it rather than stacking it, and it clears as other transient messages do.
…oved A dashboard moves a card, and the side panel open in it, between columns, as a masonry view re-columning on rotation does. The side panel's disconnectedCallback forgot its circuit, its stored monitoring and, since the controls became fail-closed, its control access, while it stayed open with its controls and their listeners live. An administrator's relay or priority change was then refused with "You can't operate this panel's controls." and nothing was sent. disconnectedCallback now only cancels a pending debounced write. A moved panel goes on as it was; its state is reset only as it opens or closes.
…odule
The guard now also fails where call_service appears other than as a
message's type, so a message whose type is held in a constant is seen;
where a call_service message holds a spread, which could bring a
domain in; where callApi( or the execute_script command appears; and
where toggle is named after its domain or in a REST path
("switch.toggle", "services/switch/toggle") as well as quoted alone.
One checker applies every rule to the card's source and to a sample
of each way round it, each sample tripping its own rule.
DEVELOPER.md says exactly what the guard checks, and that it reads
text, so a message changed after it is built is not seen.
…trol A Favorites panel card said its panel's controls were locked even where its favorited circuits draw no switch or select, as metered circuits do, and the view's slider counted such a panel's access too, so it could be armable with nothing to arm. favoritesPanelAccess now counts a circuit only where it has a control the card draws: a relay switch the user may control, judged as switchPresence judges it before reading the switch's state, or a priority select. viewControlAccess reads the view's panels from it, so the slider and the panel cards agree.
…s moved A graph horizon chosen just before a dashboard moved the side panel, as a masonry view re-columning does, was silently lost: the panel cancelled its pending debounced write as it left the page, while the select went on showing the horizon chosen. The side panel no longer cancels anything as it leaves the page. A pending write is the user's change and is sent when its time comes, once, whether the panel was moved or removed; each write reads only what it captured and Home Assistant. Only close cancels one.
Enable Switches arms toggle pills alone, but in the Favorites view it counted a panel whose favorites draw only a priority select. A view of such a panel the user may operate and a panel with relays they may not then had an armable slider over nothing but forbidden toggles. viewControlAccess now counts only the panels whose favorites draw a relay toggle. A panel's note still counts a priority select too.
…s closed Closing the side panel cancelled its pending debounced writes, so a graph horizon chosen just before closing it was lost while the select had shown it. The writes read only what they captured and Home Assistant, never the panel's config, so close now leaves them to be sent once their time comes, as a move does. Each write is now keyed by its config entry as well as its circuit or sub-device, so a change of a circuit with the same id on another panel, made within the wait, no longer replaces the first; a later change of the same circuit on the same panel still does.
This was referenced Nov 18, 2026
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.
The card and the sidebar dashboard now show each breaker switch, priority select and Enable Switches disabled, with the reason, for a user who may not operate the panel. A refused change returns its control to the panel's actual state. Part of the unreleased 0.12.0.
Before, with "Who may operate the panel" set to Administrators only, a non-administrator could open a circuit's side panel and toggle its breaker. The integration's control gate refused the change, and the switch stayed showing it.
How the card knows
The integration's
span_panel/panel_topologyanswerscontrol_access: {may_operate, reason}for the requesting user. It uses the same rule its control gate enforces.reasoniscontrol_disabled,admin_onlyorread_only, the last for an account whose Home Assistant permissions allow control of none of the panel's relay and priority controls.may_operatedecides, andreasononly picks the hint. An unknown reason gets a generic hint.What changes
Disabled controls: for a user who may not operate the panel, these are disabled and titled with the reason, with a note:
The gear, favorites, graph horizon and the read-only monitoring view stay open.
Favorites: each panel's stats card shows its own note, and Enable Switches arms only for panels whose favorites draw a toggle the user may operate. Tapping a locked toggle gives a short warning instead of nothing.
One send path: every relay and priority change goes through one module,
src/core/control-access.ts. A guard test fails on any other send route, and its own samples prove each check. The unused genericRetryManager.callServiceis removed.Refusals: a change refused anyway snaps back to Home Assistant's state and shows the integration's localized message. That covers a lock armed meanwhile, the relay debounce, and a policy changed since the topology was read. Core's per-entity
Unauthorizedgets its own localized message.Access changes: a topology re-fetch that changes access redraws the views, and an open side panel takes the new access in place.
Side panel:
Fixtures: the topology fixtures are refreshed as byte copies of the integration's captures, with
control_accessand the per-circuitdevice_id.Checks
lint, typecheck, 84 files and 1695 tests, build, i18n validation, prettier and markdownlint all pass.
dist/is rebuilt last and matches a fresh build.