Skip to content

Minor cleanup#3647

Merged
springfall2008 merged 1 commit intomainfrom
fix13
Mar 24, 2026
Merged

Minor cleanup#3647
springfall2008 merged 1 commit intomainfrom
fix13

Conversation

@springfall2008
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings March 24, 2026 19:42
@springfall2008 springfall2008 merged commit 4093fd2 into main Mar 24, 2026
3 checks passed
@springfall2008 springfall2008 deleted the fix13 branch March 24, 2026 19:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_FILES hardcoded file list from predbat.py.
  • Updated Octopus/Kraken get_entity_name() to use self.prefix instead of hardcoding predbat.
  • Changed Kraken’s periodic scheduling logic to derive count_minutes from 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()

Comment on lines 935 to +938
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
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
Comment on lines 267 to 270
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()
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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.

2 participants