Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to do minor cleanup/consistency work in PredBat, touching the self-update file list and standardizing entity naming to respect the configured prefix for Octopus/Kraken components.
Changes:
- Removed the (now unused)
PREDBAT_FILEShardcoded file list frompredbat.py. - Updated Octopus/Kraken
get_entity_name()to useself.prefixinstead of hardcodingpredbat. - Changed Kraken’s periodic scheduling logic to derive
count_minutesfrom the component runtime counter.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| apps/predbat/predbat.py | Removes the previously hardcoded PredBat file list constant. |
| apps/predbat/octopus.py | Uses configured prefix when constructing Octopus component entity IDs. |
| apps/predbat/kraken.py | Uses configured prefix for Kraken entity IDs and adjusts run cadence computation. |
Comments suppressed due to low confidence (1)
apps/predbat/kraken.py:315
- count_minutes is now derived from the ComponentBase seconds counter (minutes since component start) rather than wall-clock minutes. That changes the cadence from being aligned to real 10/30-minute boundaries (as OctopusAPI.run does) to being start-time dependent and drifting across restarts, which contradicts the docstring claim that it mirrors OctopusAPI. If alignment is desired, compute count_minutes from current time (or reuse base.minutes_now) instead.
async def run(self, seconds, first):
"""Component run method — called by ComponentBase.start() every 60s.
Timing (mirrors OctopusAPI pattern):
- First run + every 30 min: discover tariff via GraphQL
- First run + every 10 min: fetch rates + standing charges from REST
- First run: wire into fetch.py via set_arg
"""
count_minutes = seconds // 60
had_success = False
# Tariff discovery — first run + every 30 minutes
if first or (count_minutes % 30) == 0:
tariff_change = await self.async_find_tariffs()
| if index: | ||
| entity_name = root + ".predbat_octopus_" + self.account_id.replace("-", "_") + "_" + suffix + "_" + index | ||
| entity_name = root + "." + self.prefix + "_octopus_" + self.account_id.replace("-", "_") + "_" + suffix + "_" + index | ||
| else: | ||
| entity_name = root + ".predbat_octopus_" + self.account_id.replace("-", "_") + "_" + suffix | ||
| entity_name = root + "." + self.prefix + "_octopus_" + self.account_id.replace("-", "_") + "_" + suffix |
There was a problem hiding this comment.
Changing Octopus entity IDs to use self.prefix will break component event routing when prefix != "predbat": Components.select_event/number_event filters on the hardcoded substring "predbat_octopus_". With a custom prefix, UI events (select/number) for Octopus entities won’t be forwarded to OctopusAPI. Consider updating the event_filter logic to incorporate the configured prefix (or accept both legacy and prefixed forms for a migration period).
| def get_entity_name(self, root, suffix): | ||
| """Construct entity name. Same pattern as OctopusAPI.get_entity_name.""" | ||
| entity_name = root + ".predbat_kraken_" + self.account_id.replace("-", "_") + "_" + suffix | ||
| entity_name = root + "." + self.prefix + "_kraken_" + self.account_id.replace("-", "_") + "_" + suffix | ||
| return entity_name.lower() |
There was a problem hiding this comment.
This change makes the published entity IDs depend on the configured prefix, but Components routes events using a hardcoded filter substring ("predbat_kraken_"). With a non-default prefix, select/number events for Kraken entities won’t reach KrakenAPI. Update event_filter to be prefix-aware (or keep backward-compatible naming) to avoid breaking custom-prefix setups.
No description provided.