Skip to content

Cover spook_inverse schema config flow + options flow + hide_source side-effects #1259

@frenckatron

Description

@frenckatron

Why This Matters

integrations/spook_inverse/config_flow.py is materially more complex than the main flow: it uses SchemaConfigFlowHandler with menu + per-platform form steps (Platform.BINARY_SENSOR, Platform.SWITCH), an options flow, and two registry-mutating callbacks async_config_flow_finished / async_options_flow_finished that flip hidden_by=RegistryEntryHider.INTEGRATION on the source entity. The unhide-on-remove logic in __init__.py:40-54 only fires when hidden_by is exactly INTEGRATION — a regression where some other component changed hidden_by first would silently leak a hidden entity. This is the second config flow the user implicitly cares about and the one where untested behavior has user-visible side-effects.

Approach

Add tests/integrations/spook_inverse/test_config_flow.py. Pre-register a fake source entity via PHACC's entity_registry fixture. Drive the menu → form → finished sequence for both binary_sensor and switch branches; assert the created entry has options["inverse_type"] set correctly by the set_inverse_type wrapper (config_flow.py:62-77). Then drive the options flow via hass.config_entries.options.async_init, toggling CONF_HIDE_SOURCE true→false and asserting the source entity's hidden_by transitions through INTEGRATION and back to None. Add a test_async_remove_entry_unhides_source that exercises the guard in __init__.py:51 — a source entity hidden by something other than INTEGRATION must NOT be unhidden.

Acceptance Criteria

  • Both binary_sensor and switch config paths produce a valid entry
  • Options flow round-trips CONF_HIDE_SOURCE and updates the registry
  • async_remove_entry unhides only RegistryEntryHider.INTEGRATION entities
  • entity_selector_without_own_entities does not include the spook_inverse entity in its choices (covers a known footgun)

Risks & Caveats

The entity_selector_without_own_entities import comes from homeassistant.helpers.schema_config_entry_flow — this is an internal HA helper whose signature can shift between releases. The test will be the first place that breaks on an HA bump, which is good (early warning) but means you'll need a clear failure mode. The InverseBinarySensor/Switch entities themselves are not covered by this issue — leave platform tests for a follow-up.

Scores

  • Impact: ███████░░░ 7/10
  • Difficulty: █████░░░░░ 5/10
  • Short-Term ROI: ███████░░░ 7/10
  • Long-Term Value: ████████░░ 8/10

Priority

Immediate

Dependencies

#1257, #1258

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions