Skip to content

Stop scanning and writing the global state machine - #1127

Open
zorxd wants to merge 2 commits into
dvd-dev:mainfrom
zorxd:refactor/drop-global-state-scans
Open

zorxd wants to merge 2 commits into
dvd-dev:mainfrom
zorxd:refactor/drop-global-state-scans

Conversation

@zorxd

@zorxd zorxd commented Nov 7, 2026

Copy link
Copy Markdown

Every coordinator update currently goes through every entity in Home Assistant, which AGENTS.md forbids:

  • check_tarif calls set_tarif on every entity in hass.states.async_all() and uses name filters to find the Hilo tariff selects.
  • handle_unknown_power adds up every entity ending in _power, including other integrations' entities. It also rewrites utility meter sensor attributes through set_state (hass.states.async_set).
  • find_meter guesses the smart meter from entity IDs containing meter and _power.
  • The climate challenge lock and high_times read sensor.defi_hilo by entity ID, so both break if the user renames that entity.

Changes

  • The sensor platform keeps a reference to the challenge sensor it creates (hilo.challenge_sensor) and records the keys of the energy meters it creates (hilo.energy_meter_keys).
  • check_tarif only switches select.<key> for those meters. When untarificated_devices is on, it switches only the total meter.
  • Unknown power is the smart meter's power reading minus the readings of the other power devices. Unavailable devices, UNMONITORED_DEVICES models (which get no power sensor) and null readings are skipped, matching what the entity-based sum ignored.
  • find_meter, set_state and fix_utility_sensor are removed.

About removing fix_utility_sensor

It was only called from handle_unknown_power, so it only ran when unknown source tracking was enabled. Utility meter sensors take their device_class and unit from their source energy sensor, which declares SensorDeviceClass.ENERGY itself and also passes it to IntegrationSensor on 2026.11 (#1106).

Tests

  • test_check_tarif_switches_own_meters: selects that aren't Hilo energy meters are left alone, and in untarificated mode only the total meter is switched.
  • test_unknown_power.py: the meter-minus-devices calculation, the skipped devices, and an unavailable smart meter.
  • The challenge test now sets hilo.challenge_sensor instead of sensor.defi_hilo.

No entity IDs, unique IDs or snapshots change.

Context

This is the first of the smaller, focused changes offered in #1084. It stands on its own (it fixes the AGENTS.md violations for single-account installs), and it also removes the hardcoded entity IDs that would otherwise collide between accounts.

It overlaps with #1107/#1112 in one hunk of sensor.py (create_energy_entity's signature, next to the new hilo.energy_meter_keys = []). Whichever lands second can resolve it trivially; I'm happy to rebase on top of them.

🤖 Generated with Claude Code

zorxd and others added 2 commits November 6, 2026 17:29
AGENTS.md forbids async_all() scans during coordinator updates and
async_set() on entities the integration does not own, yet every update
did both: check_tarif called set_tarif on every entity in Home Assistant
and relied on name filters to pick the Hilo tariff selects, and
handle_unknown_power summed every entity ending in "_power" (including
other integrations') and rewrote attributes of utility meter sensors
through set_state. find_meter guessed the smart meter from entity IDs
containing "meter" and "_power", and the challenge lock and high_times
read sensor.defi_hilo by its entity ID, which breaks once a user renames
it.

The integration already holds all of this: the sensor platform now
records the challenge sensor and the energy meter keys it creates, and
unknown power is the smart meter reading minus the readings of the other
power devices (skipping unavailable ones, models without a power sensor
and null readings, which the entity sum also ignored).

fix_utility_sensor only ran while unknown source tracking was enabled,
and utility meters inherit device_class and unit from their source
energy sensor, which declares them itself, so it is dropped along with
set_state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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