fix: correct entity IDs for rate sensors in dashboard#12
Conversation
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>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughChart and dashboard updates: five sensor entity IDs were renamed to Changes
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)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
custom_components/pricehawk/www/dashboard.html
| 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', |
There was a problem hiding this comment.
🧩 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 2Repository: 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.
| 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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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
- 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>
Summary
Rate sensors were missing the
pricehawk_prefix in the dashboard entity mapping, causing all current rates to show 0.00.sensor.amber_import_ratesensor.pricehawk_amber_import_ratesensor.amber_feed_in_tariffsensor.pricehawk_amber_feed_in_tariffsensor.globird_import_ratesensor.pricehawk_globird_import_ratesensor.globird_feed_in_tariffsensor.pricehawk_globird_feed_in_tariffsensor.globird_peak_ratesensor.pricehawk_globird_peak_rateTest plan
🤖 Generated with Claude Code