Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 17 additions & 25 deletions custom_components/marstek_local_api/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,18 +345,31 @@ async def async_step_discovery_confirm(
@staticmethod
def async_get_options_flow(config_entry: ConfigEntry) -> OptionsFlow:
"""Get the options flow for this handler."""
return OptionsFlow(config_entry)
return OptionsFlow()


class OptionsFlow(config_entries.OptionsFlow):
"""Handle options flow for Marstek Local API."""

def __init__(self, config_entry: ConfigEntry) -> None:
def __init__(self) -> None:
"""Initialise the options flow."""
self.config_entry = config_entry
self._devices: list[dict[str, Any]] = list(config_entry.data.get("devices", []))
self._discovered_devices: list[dict[str, Any]] = []

@property
def _devices(self) -> list[dict[str, Any]]:
"""Return the current list of configured devices."""
return list(self.config_entry.data.get("devices", []))

@_devices.setter
def _devices(self, updated_devices: list[dict[str, Any]]) -> None:
"""Set the current list of configured devices."""
new_data = {**self.config_entry.data, "devices": updated_devices}
self.hass.config_entries.async_update_entry(
self.config_entry,
data=new_data,
)


async def async_step_init(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
Expand Down Expand Up @@ -446,12 +459,6 @@ async def async_step_rename_device(
updated_device = dict(updated_devices[device_index])
updated_device["device"] = new_name
updated_devices[device_index] = updated_device

new_data = {**self.config_entry.data, "devices": updated_devices}
self.hass.config_entries.async_update_entry(
self.config_entry,
data=new_data,
)
self._devices = updated_devices
return self.async_create_entry(title="", data={})

Expand Down Expand Up @@ -514,11 +521,6 @@ async def async_step_remove_device(
if not updated_devices:
errors["base"] = "cannot_remove_last_device"
else:
new_data = {**self.config_entry.data, "devices": updated_devices}
self.hass.config_entries.async_update_entry(
self.config_entry,
data=new_data,
)
self._devices = updated_devices
return self.async_create_entry(title="", data={})

Expand Down Expand Up @@ -589,11 +591,6 @@ async def async_step_add_device(
"firmware": device["firmware"],
}
)
new_data = {**self.config_entry.data, "devices": updated_devices}
self.hass.config_entries.async_update_entry(
self.config_entry,
data=new_data,
)
self._devices = updated_devices
return self.async_create_entry(title="", data={})

Expand Down Expand Up @@ -643,11 +640,6 @@ async def async_step_add_device_manual(
"firmware": info.get("firmware"),
}
)
new_data = {**self.config_entry.data, "devices": updated_devices}
self.hass.config_entries.async_update_entry(
self.config_entry,
data=new_data,
)
self._devices = updated_devices
return self.async_create_entry(title="", data={})

Expand Down