PR: Add badge for power values - #615
Merged
Merged
Conversation
patricknitsch
commented
Jun 12, 2026
Contributor
- Add a badge for power values, like temperature and humidity on main folder
- Use therefore alias from type information and change ACTUAL typ to number - value.power
- Test in admin and web successful
The previous detection only checked the state named 'ACTUAL' for a power role. Standard socket/plug devices expose their power measurement as a separate state (e.g. ELECTRIC_POWER, role value.power) while ACTUAL holds the on/off switch state (role indicator.power/switch), so power was never detected. Now, if no power role is found on ACTUAL, all states are scanned for a matching stateRole. The found power state (not necessarily ACTUAL) is then used for the subscription, ensuring the folder badge receives the correct value. https://claude.ai/code/session_012kU6fNn1JUoEpMc1u9KBXK
… is absent The backend assigned stateRole exclusively from the state object's common.role and then unconditionally deleted the type-detector's own role property. If an adapter omits common.role on a state (fairly common for energy/power states), stateRole ended up undefined. The frontend's detection logic then found nothing to match against POWER_ROLE_PATTERN, so no power badge was ever shown. Now stateRole falls back to the type-detector's pattern role (via ??) before the pattern role is deleted, so the frontend always receives a usable role string even when the adapter has not set common.role. https://claude.ai/code/session_012kU6fNn1JUoEpMc1u9KBXK
Power detection mirrors temperature/humidity: dedicated sensor devices expose a standalone ACTUAL state with role value.power, so scanning only ACTUAL (not every state) is the correct and consistent approach. https://claude.ai/code/session_012kU6fNn1JUoEpMc1u9KBXK
…er devices The ioBroker type-detector assigns the state name ELECTRIC_POWER (not ACTUAL) to value.power states in socket/dimmer/light device types. The previous code only checked the ACTUAL state's stateRole, so devices that have power in an ELECTRIC_POWER state never triggered the badge. This change adds a targeted fallback: after the ACTUAL-based check, if no power role was detected yet but an ELECTRIC_POWER state exists, subscribe to it for the power badge. The ACTUAL-based path is preserved unchanged for standalone power-sensor devices (Types.info). https://claude.ai/code/session_012kU6fNn1JUoEpMc1u9KBXK
The compiled admin bundle was stale — it predated all the TypeScript changes that add power badge detection in the category header. Running `cd src-admin && npm install && npm run build` produces a fresh bundle (index-DRz4O4R1.js) that contains: - POWER_ROLE_PATTERN matching value.power / value.level.power / watt / consumption - subscribeWidgetsForStatus checking ACTUAL.stateRole for power role - ELECTRIC_POWER fallback for socket/dimmer/light devices - renderCategoryStatus/renderSubCategoryStatus rendering power value with ElectricBolt icon https://claude.ai/code/session_012kU6fNn1JUoEpMc1u9KBXK
- Remove ELECTRIC_POWER fallback; power detection now exclusively uses the ACTUAL state's stateRole (same pattern as temperature/humidity). Standalone Info Channel sensors with common.role = 'value.power' on their ACTUAL state are the only target. - Guard onStatusChange against a null state object: ioBroker delivers null to callbacks when a state is deleted, so store null instead of crashing or storing a garbage value. null → power stays null → badge is hidden (consistent with temperature/humidity behaviour). https://claude.ai/code/session_012kU6fNn1JUoEpMc1u9KBXK
The www/ directory (served by the web adapter) had its own stale compiled bundle that predated all power badge changes. Rebuilt from src-www (which imports the same src-admin/src/WidgetsManager sources) so that the web adapter view also shows power badges via ACTUAL.stateRole. https://claude.ai/code/session_012kU6fNn1JUoEpMc1u9KBXK
This was referenced Jun 12, 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.