Skip to content

feat: add encoder_leak, endpoint_reading_missed, device_alert binary sensors#178

Open
GeorgeIoak wants to merge 2 commits intokdeyev:masterfrom
GeorgeIoak:pr2-binary-sensor-additions
Open

feat: add encoder_leak, endpoint_reading_missed, device_alert binary sensors#178
GeorgeIoak wants to merge 2 commits intokdeyev:masterfrom
GeorgeIoak:pr2-binary-sensor-additions

Conversation

@GeorgeIoak
Copy link
Copy Markdown
Contributor

Summary

Exposes three binary sensor flag fields that are present in the EyeOnWater API response but not yet surfaced as Home Assistant entities:

  • encoder_leak (BinarySensorDeviceClass.MOISTURE) — secondary leak indicator reported by the encoder mechanism
  • endpoint_reading_missed (BinarySensorDeviceClass.PROBLEM) — meter endpoint failed to report on schedule
  • device_alert (BinarySensorDeviceClass.PROBLEM) — general device-level alert condition

All three are disabled by default (entity_registry_enabled_default=False), so there is zero impact on existing users. Users who want them can enable them individually in the HA entity registry.

Other changes in this PR

  • Adds enabled_by_default: bool = True field to the Description dataclass and wires it through to BinarySensorEntityDescription.entity_registry_enabled_default
  • Switches get_flag() from flags.__dict__[key] to getattr(flags, key, False) — prevents KeyError on meters that do not include all flag fields in their API response (important for new sensors that older meter firmware may not populate)
  • Adds tests/test_binary_sensor.py with tests covering catalog presence, device class, enabled_by_default values, get_flag behaviour, and graceful handling of missing flag attributes
  • Updates FakeFlags in tests/conftest.py to include the three new fields

Test plan

  • Run poetry run pytest — all existing tests plus new tests/test_binary_sensor.py pass
  • Run poetry run ruff check . — no lint errors
  • Verify new sensors appear as disabled entities on a live meter after installation
  • Verify existing sensors are unaffected

…sensors

Add three new binary sensor descriptions that are present in the EyeOnWater
API response flags but were not yet exposed as entities:

- encoder_leak (MOISTURE) — secondary leak indicator from the encoder
- endpoint_reading_missed (PROBLEM) — meter failed to report on schedule
- device_alert (PROBLEM) — general device-level alert condition

All three are disabled by default (entity_registry_enabled_default=False)
so they have no impact on existing users. Users can enable them individually
in the HA entity registry if needed.

Also adds enabled_by_default field to the Description dataclass and wires
it through to BinarySensorEntityDescription.entity_registry_enabled_default,
and switches get_flag() from __dict__ lookup to getattr(..., False) to avoid
KeyError on meters that do not carry all flag fields.

Tests cover catalog presence, device class, enabled_by_default values,
get_flag behaviour, and graceful handling of missing flag attributes.
- Bump manifest version from 2.7.9-beta.1 to 2.7.10-beta.1 (required by
  version-check CI for PRs that touch Python source files)
- Apply black formatting to tests/test_binary_sensor.py (long method
  signatures now wrapped per black's style + COM812 trailing commas)
- Fix test_get_flag_missing_field_returns_false: remove invalid
  `del __dataclass_fields__` (class attribute, not deletable via instance);
  FakeFlags already doesn't define 'nonexistent_flag' so getattr fallback
  is exercised correctly without any setup
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