Skip to content

Commit edb7234

Browse files
authored
Update __init__.py
1 parent bace13b commit edb7234

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

custom_components/ha_felicity/__init__.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
DEFAULT_BYTESIZE,
2727
DEFAULT_PARITY,
2828
DEFAULT_STOPBITS,
29-
# CONF_INVERTER_MODEL,
30-
_REGISTERS,
29+
# CONF_INVERTER_MODEL,
3130
MODEL_DATA,
31+
_REGISTERS,
3232
)
3333
from .coordinator import HA_FelicityCoordinator
3434

@@ -45,15 +45,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
4545

4646
register_set_key = entry.options.get(CONF_REGISTER_SET, DEFAULT_REGISTER_SET)
4747

48-
# Get the list of keys for the selected set
49-
register_keys = _REGISTER_SETS.get(register_set_key, list(_REGISTERS.keys()))
48+
# Select model data (fallback to default model)
49+
model = entry.data.get(CONF_INVERTER_MODEL, DEFAULT_INVERTER_MODEL)
50+
model_data = MODEL_DATA.get(model, MODEL_DATA[DEFAULT_INVERTER_MODEL])
5051

51-
# Filter _REGISTERS to only include selected keys
52-
selected_registers = {key: _REGISTERS[key] for key in register_keys if key in _REGISTERS}
53-
54-
# NEW: Future-proof – select map based on model (for now, all use _REGISTERS)
55-
# model = entry.data.get(CONF_INVERTER_MODEL)
56-
# register_map = _REGISTERS # Can add if model == "other": _OTHER_REGISTERS # Use options for the register set so users can change it without reinstalling
52+
# Select register set from options (filtered on model's registers)
53+
register_set_key = entry.options.get(CONF_REGISTER_SET, DEFAULT_REGISTER_SET)
54+
selected_registers = model_data["sets"].get(register_set_key, model_data["registers"])
5755

5856
# Get or create shared hub for this connection
5957
hubs = hass.data.setdefault(DOMAIN, {}).setdefault("hubs", {})
@@ -83,7 +81,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
8381
hass,
8482
hub.client,
8583
config[CONF_SLAVE_ID],
86-
selected_registers
84+
selected_registers,
85+
groups=model_data["groups"]
8786
)
8887
# Store config and hub_key for unload cleanup
8988
coordinator.config = config

0 commit comments

Comments
 (0)