Skip to content

Commit

Permalink
Fix proper merging of config entries
Browse files Browse the repository at this point in the history
  • Loading branch information
wrodie committed Jan 21, 2024
1 parent 09b1f44 commit 4816c22
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
29 changes: 28 additions & 1 deletion custom_components/ha_behringer_mixer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from homeassistant.core import HomeAssistant

from .api import BehringerMixerApiClient
from .const import DOMAIN
from .const import DOMAIN, LOGGER
from .coordinator import MixerDataUpdateCoordinator

PLATFORMS: list[Platform] = [
Expand Down Expand Up @@ -53,3 +53,30 @@ async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Reload config entry."""
await async_unload_entry(hass, entry)
await async_setup_entry(hass, entry)


async def async_migrate_entry(hass, config_entry: ConfigEntry):
"""Migrate old entry."""
LOGGER.debug("Migrating from version %s", config_entry.version)

if config_entry.version < 2:
"""Update Config data to include valid channels/bussses etc."""
client = BehringerMixerApiClient(mixer_ip=config_entry.data.get("MIXER_IP"), mixer_type=config_entry.data.get("MIXER_TYPE"))
await client.setup(test_connection_only=True)
await client.async_get_data()
await client.stop()
mixer_info = client.mixer_info()
new = {**config_entry.data}
new["CHANNEL_CONFIG"] = list(range(1, mixer_info.get('channel', {}).get("number") + 1))
new["BUS_CONFIG"] = list(range(1, mixer_info.get('bus', {}).get("number") + 1))
new["DCA_CONFIG"] = list(range(1, mixer_info.get('dca', {}).get("number") + 1))
new["MATRIX_CONFIG"] = list(range(1, mixer_info.get('matrix', {}).get("number") + 1))
new["AUXIN_CONFIG"] = list(range(1, mixer_info.get('auxin', {}).get("number") + 1))
new["MAIN_CONFIG"] = True
new["CHANNELSENDS_CONFIG"] = False
new["BUSSENDS_CONFIG"] = False
config_entry.version = 2
hass.config_entries.async_update_entry(config_entry, data=new)
LOGGER.debug("Migration to version %s successful", config_entry.version)

return True
2 changes: 1 addition & 1 deletion custom_components/ha_behringer_mixer/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class BehringerMixerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Config flow for BehringerMixer."""

VERSION = 1
VERSION = 2

async def async_step_user(
self,
Expand Down
7 changes: 4 additions & 3 deletions custom_components/ha_behringer_mixer/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ def build_entity_catalog(self, mixer_info):
for entity_type in types:
# num_type = mixer_info.get(entity_type, {}).get("number")
base_key = mixer_info.get(entity_type, {}).get("base_address")
for index_number in self.config_entry.data[entity_type.upper() + "_CONFIG"]:
config_key = entity_type.upper() + "_CONFIG"
for index_number in self.config_entry.data.get(config_key, []):
self.fader_group(entities, entity_type, index_number, base_key)
# Channel to bus sends
if self.config_entry.data.get("CHANNELSENDS_CONFIG"):
base_key = mixer_info.get("channel_sends", {}).get("base_address")
for channel_number in self.config_entry.data["CHANNEL_CONFIG"]:
for bus_number in self.config_entry.data["BUS_CONFIG"]:
for channel_number in self.config_entry.data.get("CHANNEL_CONFIG", []):
for bus_number in self.config_entry.data.get("BUS_CONFIG", []):
self.fader_group(
entities,
"chsend",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ha_behringer_mixer/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"requirements": [
"behringer-mixer==0.4.2"
],
"version": "0.1.3"
"version": "0.1.4"
}

0 comments on commit 4816c22

Please sign in to comment.