Skip to content

Commit

Permalink
Update config_flow.py
Browse files Browse the repository at this point in the history
  • Loading branch information
pnbruckner committed Nov 26, 2024
1 parent e12784e commit 34acae3
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions custom_components/illuminance/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from homeassistant.config_entries import (
SOURCE_IMPORT,
ConfigEntry,
ConfigEntryBaseFlow,
ConfigFlow,
ConfigFlowResult,
OptionsFlowWithConfigEntry,
)
from homeassistant.const import (
Expand All @@ -21,7 +23,6 @@
CONF_UNIQUE_ID,
)
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowHandler, FlowResult
from homeassistant.helpers.selector import (
EntitySelector,
EntitySelectorConfig,
Expand All @@ -43,7 +44,7 @@
from .sensor import MODES


class IlluminanceFlow(FlowHandler):
class IlluminanceFlow(ConfigEntryBaseFlow):
"""Illuminance flow mixin."""

@property
Expand All @@ -53,7 +54,7 @@ def options(self) -> dict[str, Any]:

async def async_step_options(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
) -> ConfigFlowResult:
"""Get sensor options."""
if user_input is not None:
self.options.clear()
Expand Down Expand Up @@ -100,7 +101,9 @@ async def async_step_options(
return self.async_show_form(step_id="options", data_schema=data_schema)

@abstractmethod
async def async_step_done(self, _: dict[str, Any] | None = None) -> FlowResult:
async def async_step_done(
self, _: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Finish the flow."""


Expand Down Expand Up @@ -136,7 +139,7 @@ def options(self) -> dict[str, Any]:
"""Return mutable copy of options."""
return self._options

async def async_step_import(self, data: dict[str, Any]) -> FlowResult:
async def async_step_import(self, data: dict[str, Any]) -> ConfigFlowResult:
"""Import config entry from configuration."""
title = data.pop(CONF_NAME)
# Convert from timedelta to float in minutes.
Expand All @@ -151,13 +154,15 @@ async def async_step_import(self, data: dict[str, Any]) -> FlowResult:

return self.async_create_entry(title=title, data={}, options=data)

async def async_step_user(self, _: dict[str, Any] | None = None) -> FlowResult:
async def async_step_user(
self, _: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Start user config flow."""
return await self.async_step_name()

async def async_step_name(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
) -> ConfigFlowResult:
"""Get name."""
if user_input is not None:
self._name = user_input[CONF_NAME]
Expand All @@ -168,14 +173,18 @@ async def async_step_name(
step_id="name", data_schema=vol.Schema(schema), last_step=False
)

async def async_step_done(self, _: dict[str, Any] | None = None) -> FlowResult:
async def async_step_done(
self, _: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Finish the flow."""
return self.async_create_entry(title=self._name, data={}, options=self.options)


class IlluminanceOptionsFlow(OptionsFlowWithConfigEntry, IlluminanceFlow):
"""Sun2 integration options flow."""

async def async_step_done(self, _: dict[str, Any] | None = None) -> FlowResult:
async def async_step_done(
self, _: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Finish the flow."""
return self.async_create_entry(title="", data=self.options or {})

0 comments on commit 34acae3

Please sign in to comment.