Skip to content

refactor(arch): modularize config_flow, gateway identity, and decoder pool (#732) - #744

Merged
GreenGrassBlueOcean merged 6 commits into
v2-phase1-architecturefrom
arch/issue-732-modularize-monoliths
Oct 20, 2026
Merged

GreenGrassBlueOcean merged 6 commits into
v2-phase1-architecturefrom
arch/issue-732-modularize-monoliths

Conversation

@GreenGrassBlueOcean

@GreenGrassBlueOcean GreenGrassBlueOcean commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes #732
Depends on #742

What is the problem

Three core integration files had grown into multi-responsibility monoliths that exceeded maintainable size boundaries and mixed unrelated concerns:

  1. custom_components/myhome/config_flow.py (1,422 lines / ~65 KB):
    • Combined initial user/SSDP/USB discovery flows, reauth/reconfigure flows, shared-bus multi-gateway topology validation, F441M audio matrix / tuner / decoder pool options, and general gateway options inside a single file.
  2. custom_components/myhome/gateway.py (1,383 lines):
    • Combined core session/frame routing with WHO=13 / WHO=1013 gateway model & firmware identification (_record_gateway_identity, conflict tracking, device-registry updates, worker trimming) and shared-bus cross-gateway topology correlation (_correlate_shared_bus_traffic, peer_gateways, topology_role).
  3. custom_components/myhome/decoder_pool.py (1,028 lines):
    • Combined pure slot-allocation data structures, group membership bookkeeping, and diagnostic snapshot serialization with async bus operations (claim, release, set_group, restore_zones).

How is it solved

Decomposed all three monoliths into cohesive, single-responsibility modules meeting every explicit line-count budget from #732 while preserving all public entry points (MyhomeFlowHandler / MyhomeConfigFlow, MyhomeOptionsFlowHandler, MyHOMEGatewayHandler, DecoderPool), hassfest discovery rules, mypy --strict zero-error ratchet, and 100.0% statement coverage:

  1. Config Flow Decomposition (config_flow.py: 1,422 $\rightarrow$ 333 lines, budget < 350):
  2. Gateway Decomposition (gateway.py: 1,383 $\rightarrow$ 640 lines, budget < 700):
    • custom_components/myhome/gateway.py (640 lines): Core gateway lifecycle, session orchestration, paced sweeps, and frame dispatch.
    • custom_components/myhome/identity.py (632 lines): GatewayIdentityMixin (WHO=13 Dimension 15/16/23/24 and WHO=1013 Dimension 1 model/firmware resolution, identity conflict repair issues, device-registry synchronization, and single-session worker trimming).
    • custom_components/myhome/topology.py (696 lines): GatewayTopologyMixin (shared-bus cross-gateway frame correlation, peer gateway discovery, and topology role helpers).
  3. Decoder Pool Decomposition (decoder_pool.py: 1,028 $\rightarrow$ 434 lines, budget < 450):
  4. Architectural Validator Updates (scripts/verify_ha_standards.py):
    • Updated check_discovery_flows() and IQS Gold reconfiguration-flow rule to inspect config_flow*.py across the decomposed config flow package, and added decoder_allocation.py to RUNTIME_DATA_READERS.

How is it tested

  • tests/test_config_flow.py, tests/test_config_flow_serial.py, tests/test_shared_bus_onboarding.py, tests/test_gateway.py (including test_replay_f461_who14_live_2026_10_18_gateway_identity), tests/test_gateway_identification.py, tests/test_decoder_pool.py, tests/test_where_usage_guard.py, and full 4,193-test suite: all passing with 100.0% statement coverage across every extracted module.
  • scripts/typing_ratchet.py: mypy --strict: 0 error(s) in 0 module(s); baseline 0.
  • scripts/verify_ha_standards.py: all 69 Python source files verified, 54/54 Home Assistant Platinum Quality Scale rules satisfied.
  • scripts/sync_documentation.py --check and hassfest: 0 violations.

State Diagram

flowchart TD
    subgraph ConfigFlowPackage["Config & Options Flow Package"]
        CF["config_flow.py\nMyhomeFlowHandler (333 lines)"]
        CFD["config_flow_discovery.py\nConfigFlowDiscoveryMixin (482 lines)"]
        CFT["config_flow_topology.py\nConfigFlowTopologyMixin /\nOptionsFlowTopologyMixin (379 lines)"]
        CFA["config_flow_audio.py\nOptionsFlowAudioMixin (287 lines)"]
        CFO["config_flow_options.py\nMyhomeOptionsFlowHandler (292 lines)"]
        CFD --> CF
        CFT --> CF
        CFT --> CFO
        CFA --> CFO
        CF --> CFO
    end

    subgraph GatewayPackage["Gateway Handler Package"]
        GW["gateway.py\nMyHOMEGatewayHandler (640 lines)"]
        GWI["identity.py\nGatewayIdentityMixin (632 lines)\n(WHO 13 / WHO 1013)"]
        GWT["topology.py\nGatewayTopologyMixin (696 lines)\n(Shared-Bus Correlation)"]
        GWI --> GW
        GWT --> GW
    end

    subgraph DecoderPoolPackage["Audio Decoder Pool Package"]
        DP["decoder_pool.py\nDecoderPool (434 lines)"]
        DPA["decoder_allocation.py\nDecoderAllocationMixin (404 lines)"]
        DPA --> DP
    end
Loading

Where are the traces


What does the Oracle / Encyclopedia say

  • WHO=13 vs. WHO=1013 Gateway Identification (identity.py & tests/golden/firmware_oracle.json):
    • Across the 12 emulated gateways in tests/golden/firmware_oracle.json, Linux-based gateways (F454 020051, F459 020105, F460 020012, F461 020011, MH202 010024, MyHomeServer1 028206) all reply to *#13**15## with shared family code 200 (*#13**15*200##), whereas *#1013*0*1## disambiguates the exact hardware model via bt_device (*#1013**1*51## for F454, *#1013**1*65## for F459, *#1013**1*134## for F461, *#1013**1*5## for MH202, *#1013**1*67## for MyHomeServer1, *#1013**1*19## for H4684, *#1013**1*12## for F453AV, *#1013**1*22## for F453, *#1013**1*4## for MH200, *#1013**1*44## for MH200N).
    • Isolating this multi-stage WHO=13 / WHO=1013 state machine in identity.py (GatewayIdentityMixin) keeps gateway.py focused strictly on session transport and frame routing.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@GreenGrassBlueOcean
GreenGrassBlueOcean force-pushed the arch/issue-732-modularize-monoliths branch from e99c6b4 to eb84a8e Compare October 17, 2026 10:16
@GreenGrassBlueOcean
GreenGrassBlueOcean force-pushed the arch/issue-733-sweep-gating-and-yaml-migration branch from f77599f to 91ce456 Compare October 17, 2026 10:16
@GreenGrassBlueOcean
GreenGrassBlueOcean force-pushed the arch/issue-732-modularize-monoliths branch from 08267ae to bbdcf40 Compare October 17, 2026 10:40
@GreenGrassBlueOcean
GreenGrassBlueOcean force-pushed the arch/issue-733-sweep-gating-and-yaml-migration branch 2 times, most recently from 461550b to 0479504 Compare October 19, 2026 09:54
@GreenGrassBlueOcean
GreenGrassBlueOcean force-pushed the arch/issue-732-modularize-monoliths branch from db0113c to aba7687 Compare October 19, 2026 09:58
@GreenGrassBlueOcean
GreenGrassBlueOcean force-pushed the arch/issue-732-modularize-monoliths branch from aba7687 to 3ef903f Compare October 19, 2026 10:04
GreenGrassBlueOcean added a commit that referenced this pull request Oct 19, 2026
….0.0 documentation (#735)

- Rebase onto #744 (3ef903f) and latest v2-phase1-architecture (fcdb507)
- Deduplicate _ensure_oracle_verified_profiles in scripts/update_gateway_profiles.py
- Add test_f461_live_traces_2026_10_18_conformance_with_oracle verifying physical BTicino F461 (2.0.11) live traces against OWNd parser and F461 oracle verdicts
GreenGrassBlueOcean added a commit that referenced this pull request Oct 19, 2026
….0.0 documentation (#735)

- Rebase onto #744 (3ef903f) and latest v2-phase1-architecture (fcdb507)
- Deduplicate _ensure_oracle_verified_profiles in scripts/update_gateway_profiles.py
- Add test_f461_live_traces_2026_10_18_conformance_with_oracle verifying physical BTicino F461 (2.0.11) live traces against OWNd parser and F461 oracle verdicts
@GreenGrassBlueOcean
GreenGrassBlueOcean force-pushed the arch/issue-733-sweep-gating-and-yaml-migration branch from 0479504 to 9a83cf6 Compare October 19, 2026 12:37
@GreenGrassBlueOcean
GreenGrassBlueOcean force-pushed the arch/issue-732-modularize-monoliths branch from 3ef903f to 3acf978 Compare October 19, 2026 12:37
Base automatically changed from arch/issue-733-sweep-gating-and-yaml-migration to v2-phase1-architecture October 20, 2026 20:01
… packages (#732)

- Rebase onto #742 (0479504) and latest v2-phase1-architecture (fcdb507)
- Add test_replay_f461_who14_live_2026_10_18_gateway_identity replaying live BTicino F461 (2.0.11, kernel 5.10.35, distribution 2.26.4) WHO=13 Dims 15/16/23/24 and WHO=1013 Dim 1
@GreenGrassBlueOcean
GreenGrassBlueOcean force-pushed the arch/issue-732-modularize-monoliths branch from 3acf978 to b6966a6 Compare October 20, 2026 20:05
@GreenGrassBlueOcean
GreenGrassBlueOcean merged commit 493e2ce into v2-phase1-architecture Oct 20, 2026
15 of 16 checks passed
@GreenGrassBlueOcean
GreenGrassBlueOcean deleted the arch/issue-732-modularize-monoliths branch October 20, 2026 20:16
GreenGrassBlueOcean added a commit that referenced this pull request Oct 20, 2026
)

Bring in #742 (sweep gating, myhome.yaml copy in entry options) and
#744 (#732 modularization of config_flow, gateway and platforms).

Conflicts:
- validate.py: import list; keep both CONF_STEP_*_ACTION and
  CONF_STRATEGY.
- legacy_yaml.py: keep the base's _load_live_yaml/_apply_yaml_platforms
  structure and re-apply the expose handling on top: a top-level
  `expose:` key counts as single-gateway config, the where-filling loop
  skips `expose`, and the validated expose list is collected into
  configured_expose (threaded through _load_live_yaml).
- config_flow.py: take the base's split module and move
  ExposeSubentryFlowHandler into config_flow_expose.py, next to
  config_flow_options.py; config_flow.py keeps
  async_get_supported_subentry_types and re-exports the handler.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GreenGrassBlueOcean added a commit that referenced this pull request Oct 21, 2026
….0.0 documentation (#735)

- Rebase onto #744 (3ef903f) and latest v2-phase1-architecture (fcdb507)
- Deduplicate _ensure_oracle_verified_profiles in scripts/update_gateway_profiles.py
- Add test_f461_live_traces_2026_10_18_conformance_with_oracle verifying physical BTicino F461 (2.0.11) live traces against OWNd parser and F461 oracle verdicts
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