Skip to content

fix: correct entity IDs for rate sensors in dashboard#12

Merged
Artic0din merged 3 commits into
mainfrom
fix/dashboard-entity-ids
Apr 6, 2026
Merged

fix: correct entity IDs for rate sensors in dashboard#12
Artic0din merged 3 commits into
mainfrom
fix/dashboard-entity-ids

Conversation

@Artic0din
Copy link
Copy Markdown
Owner

Summary

Rate sensors were missing the pricehawk_ prefix in the dashboard entity mapping, causing all current rates to show 0.00.

Was Should be
sensor.amber_import_rate sensor.pricehawk_amber_import_rate
sensor.amber_feed_in_tariff sensor.pricehawk_amber_feed_in_tariff
sensor.globird_import_rate sensor.pricehawk_globird_import_rate
sensor.globird_feed_in_tariff sensor.pricehawk_globird_feed_in_tariff
sensor.globird_peak_rate sensor.pricehawk_globird_peak_rate

Test plan

  • Current Rates section shows actual values instead of 0.00
  • Hero winner card populates
  • Rate comparison chart draws

🤖 Generated with Claude Code

Rate sensor entity IDs were missing the 'pricehawk_' prefix that HA
adds from the device name. All rate sensors (amber_import_rate,
amber_feed_in_tariff, globird_import_rate, globird_feed_in_tariff,
globird_peak_rate) now use the correct sensor.pricehawk_* IDs.

This caused the Current Rates section to show 0.00 for all values.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 6, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 362a3804-d3f1-4f02-a891-4f33e7a0e7c9

📥 Commits

Reviewing files that changed from the base of the PR and between 58fb203 and 8fde7b2.

📒 Files selected for processing (1)
  • custom_components/pricehawk/www/dashboard.html

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added Amber forecast series and legend; forecast points render as dashed, dimmer step lines and trigger chart redraws when updated.
    • Added a dashed flat projection for GloBird rates for the remainder of the day.
  • Bug Fixes

    • Rate label simplified from "TODAY 24H" to "TODAY".
    • Chart now spans full day with correct midnight tick wrapping.
  • Chores

    • Standardized dashboard sensor references for Amber and GloBird to the new naming convention.

Walkthrough

Chart and dashboard updates: five sensor entity IDs were renamed to sensor.pricehawk_*; chart label changed from "TODAY 24H" to "TODAY"; Amber forecast entities and forecast buffers were added; chart time range and x-axis hour-wrapping logic updated; GloBird forecast rendered as a dashed flat projection.

Changes

Cohort / File(s) Summary
Dashboard UI & Sensor Mapping
custom_components/pricehawk/www/dashboard.html
Renamed Amber/GloBird sensor IDs to sensor.pricehawk_*. Added ENTITY.amberForecast (sensor.sandhurst_general_forecast) and ENTITY.amberFeedInForecast (sensor.sandhurst_feed_in_forecast). Added forecast point buffers to client state and parse logic for forecast attributes.
Chart Rendering & Labels
custom_components/pricehawk/www/dashboard.html
Changed rate-card label from "TODAY 24H" to "TODAY". Set chart maxTime to end-of-day (midnight-to-midnight+1 day) instead of current timestamp. Adjusted x-axis hour tick labeling to use h % 24 and advance day at midnight. Included Amber forecast points in dataset aggregation; forecast series rendered as dashed, dimmer step lines. For GloBird (no forecast), draw dashed flat projection at current import rate for remainder of day. Redraw chart on Amber forecast entity updates.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant UI as Browser UI
    participant HA as Home Assistant
    participant Chart as Chart Renderer

    UI->>HA: Subscribe to sensor entities (pricehawk_* and forecast sensors)
    HA-->>UI: Push entity state updates (including forecast attributes)
    UI->>UI: Parse state + extract forecast points, update client state buffers
    UI->>Chart: Provide updated datasets (actual, Amber forecast, GloBird projection)
    Chart-->>UI: Render updated chart (dashed forecast series, flat GloBird projection)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: correcting entity IDs for rate sensors in the dashboard to include the missing pricehawk_ prefix.
Description check ✅ Passed The description is directly related to the changeset, providing a clear explanation of the problem (missing pricehawk_ prefix), a table showing the corrections, and a test plan.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/dashboard-entity-ids

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@custom_components/pricehawk/www/dashboard.html`:
- Around line 897-901: The feed-in sensor entity IDs in dashboard.html are
incorrect: replace the non-existent 'sensor.pricehawk_amber_feed_in_tariff' and
'sensor.pricehawk_globird_feed_in_tariff' values with the correct entity IDs
that match sensor.py keys (amber_export_rate and globird_export_rate). Use the
same unique_id-based naming convention used when creating sensors
(f"{entry.entry_id}_{key}") so the properties named amberFeedIn and
globirdFeedIn point to 'sensor.pricehawk_amber_export_rate' and
'sensor.pricehawk_globird_export_rate' respectively to match the keys defined in
sensor.py (amber_export_rate, globird_export_rate).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c3244238-971c-42a9-af0a-2215f99db8b4

📥 Commits

Reviewing files that changed from the base of the PR and between a652f37 and 536f532.

📒 Files selected for processing (1)
  • custom_components/pricehawk/www/dashboard.html

Comment on lines +897 to +901
amberImport: 'sensor.pricehawk_amber_import_rate',
amberFeedIn: 'sensor.pricehawk_amber_feed_in_tariff',
globirdImport: 'sensor.pricehawk_globird_import_rate',
globirdFeedIn: 'sensor.pricehawk_globird_feed_in_tariff',
globirdPeak: 'sensor.pricehawk_globird_peak_rate',
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Verify the RATE_SENSORS keys in sensor.py to confirm expected entity IDs.

echo "=== RATE_SENSORS definition ==="
rg -nA 10 'RATE_SENSORS.*=' --type=py

echo ""
echo "=== unique_id construction pattern ==="
rg -n '_attr_unique_id.*=' --type=py -C 2

Repository: Artic0din/ha-pricehawk

Length of output: 1364


Fix entity IDs for feed-in sensors to match sensor.py keys.

Lines 898 and 900 reference non-existent sensor IDs. The correct keys in sensor.py:27-34 are amber_export_rate and globird_export_rate, not _feed_in_tariff. Entity IDs are generated from unique_id (f"{entry.entry_id}_{key}"), so the feed-in sensors must use _export_rate suffixes.

Proposed fix
   amberImport:     'sensor.pricehawk_amber_import_rate',
-  amberFeedIn:     'sensor.pricehawk_amber_feed_in_tariff',
+  amberFeedIn:     'sensor.pricehawk_amber_export_rate',
   globirdImport:   'sensor.pricehawk_globird_import_rate',
-  globirdFeedIn:   'sensor.pricehawk_globird_feed_in_tariff',
+  globirdFeedIn:   'sensor.pricehawk_globird_export_rate',
   globirdPeak:     'sensor.pricehawk_globird_peak_rate',
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
amberImport: 'sensor.pricehawk_amber_import_rate',
amberFeedIn: 'sensor.pricehawk_amber_feed_in_tariff',
globirdImport: 'sensor.pricehawk_globird_import_rate',
globirdFeedIn: 'sensor.pricehawk_globird_feed_in_tariff',
globirdPeak: 'sensor.pricehawk_globird_peak_rate',
amberImport: 'sensor.pricehawk_amber_import_rate',
amberFeedIn: 'sensor.pricehawk_amber_export_rate',
globirdImport: 'sensor.pricehawk_globird_import_rate',
globirdFeedIn: 'sensor.pricehawk_globird_export_rate',
globirdPeak: 'sensor.pricehawk_globird_peak_rate',
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@custom_components/pricehawk/www/dashboard.html` around lines 897 - 901, The
feed-in sensor entity IDs in dashboard.html are incorrect: replace the
non-existent 'sensor.pricehawk_amber_feed_in_tariff' and
'sensor.pricehawk_globird_feed_in_tariff' values with the correct entity IDs
that match sensor.py keys (amber_export_rate and globird_export_rate). Use the
same unique_id-based naming convention used when creating sensors
(f"{entry.entry_id}_{key}") so the properties named amberFeedIn and
globirdFeedIn point to 'sensor.pricehawk_amber_export_rate' and
'sensor.pricehawk_globird_export_rate' respectively to match the keys defined in
sensor.py (amber_export_rate, globird_export_rate).

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a bug — the entity_id is derived from the friendly name ("Amber Feed In Tariff" → sensor.pricehawk_amber_feed_in_tariff), not the unique_id key (amber_export_rate). Verified against the entity registry on the live HA instance. The dashboard entity IDs are correct.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Artic0din, thank you for the clarification and for verifying against the live entity registry. You're absolutely right — in Home Assistant, the entity_id is derived from the entity's friendly name (e.g., "Amber Feed In Tariff" → sensor.pricehawk_amber_feed_in_tariff), not the unique_id key (amber_export_rate). My analysis incorrectly assumed the entity_id was constructed from the unique_id key. The dashboard entity IDs in this PR are correct as-is.


✏️ Learnings added
Learnt from: Artic0din
Repo: Artic0din/ha-pricehawk PR: 12
File: custom_components/pricehawk/www/dashboard.html:898-902
Timestamp: 2026-04-06T07:04:14.362Z
Learning: In the Artic0din/ha-pricehawk repository (custom_components/pricehawk), Home Assistant sensor entity_ids are derived from the entity's friendly name, NOT from the unique_id key defined in sensor.py's RATE_SENSORS dict. For example, the sensor with unique_id key `amber_export_rate` has friendly name "Amber Feed In Tariff" and therefore gets entity_id `sensor.pricehawk_amber_feed_in_tariff`. Do not flag dashboard entity ID references as incorrect based solely on unique_id key names.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: CR
Repo: Artic0din/ha-pricehawk PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-06T04:43:21.159Z
Learning: Applies to custom_components/energy_compare/sensor.py : All sensor calculations must use Home Assistant's energy sensors as source data

Artic0din and others added 2 commits April 6, 2026 16:51
- Change "TODAY 24H" to "TODAY" (chart shows midnight-to-now, not 24h)
- Extend chart X-axis to full day (midnight-to-midnight) so the "now"
  marker shows position in context of the whole day
- Show all time labels (00:00 through 00:00) instead of stopping at
  current time

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add Amber forecast entities (sandhurst_general_forecast,
  sandhurst_feed_in_forecast) to tracked entity set
- Parse 30-min interval forecast data from entity attributes
- Draw forecast as dashed lines from "now" to end of day
- GloBird has no API: draw flat projection from current rate
- Include forecast values in Y-axis scale calculation
- Add "Amber Forecast" legend entry

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Artic0din Artic0din merged commit 68d0519 into main Apr 6, 2026
2 of 3 checks passed
@Artic0din Artic0din deleted the fix/dashboard-entity-ids branch April 6, 2026 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant