Skip to content

Commit

Permalink
Options flow fix (#2567)
Browse files Browse the repository at this point in the history
* Draft new options flow handler

* WIP
  • Loading branch information
andrew-codechimp authored Dec 31, 2024
1 parent 5bc8614 commit 55ddfc6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/integration/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BN Integration",
"image": "mcr.microsoft.com/devcontainers/python:3.12",
"image": "mcr.microsoft.com/devcontainers/python:dev-3.13",
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {
"installDirectlyFromGitHubRelease": true,
Expand Down
30 changes: 16 additions & 14 deletions custom_components/battery_notes/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ class BatteryNotesFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
@staticmethod
@callback
def async_get_options_flow(config_entry: ConfigEntry) -> OptionsFlow:
# pylint: disable=unused-argument
"""Get the options flow for this handler."""
return OptionsFlowHandler(config_entry)
return OptionsFlowHandler()

async def async_step_integration_discovery(
self,
Expand All @@ -143,6 +144,7 @@ async def async_step_user(
self,
user_input: dict | None = None,
) -> config_entries.FlowResult:
# pylint: disable=unused-argument
"""Handle a flow initialized by the user."""

return self.async_show_menu(step_id="user", menu_options=["device", "entity"])
Expand Down Expand Up @@ -349,9 +351,7 @@ async def async_step_battery(self, user_input: dict[str, Any] | None = None):
if source_entity_id:
entity_registry = er.async_get(self.hass)
entity_entry = entity_registry.async_get(source_entity_id)
source_entity_domain, source_object_id = split_entity_id(
source_entity_id
)
_, source_object_id = split_entity_id(source_entity_id)
entity_unique_id = (
entity_entry.unique_id or entity_entry.entity_id or source_object_id
)
Expand Down Expand Up @@ -424,17 +424,14 @@ class OptionsFlowHandler(OptionsFlow):

model_info: ModelInfo = None

def __init__(self, config_entry: ConfigEntry) -> None:
def __init__(self) -> None:
"""Initialize options flow."""
self.config_entry = config_entry
self.current_config: dict = dict(config_entry.data)
self.source_device_id: str = self.current_config.get(CONF_DEVICE_ID) # type: ignore
self.name: str = self.current_config.get(CONF_NAME)
self.battery_type: str = self.current_config.get(CONF_BATTERY_TYPE)
self.battery_quantity: int = self.current_config.get(CONF_BATTERY_QUANTITY)
self.battery_low_template: str = self.current_config.get(
CONF_BATTERY_LOW_TEMPLATE
)
self.current_config: dict
self.source_device_id: str
self.name: str
self.battery_type: str
self.battery_quantity: int
self.battery_low_template: str

async def async_step_init(
self,
Expand All @@ -443,6 +440,11 @@ async def async_step_init(
"""Handle options flow."""
errors = {}
self.current_config = dict(self.config_entry.data)
self.source_device_id = self.current_config.get(CONF_DEVICE_ID) # type: ignore
self.name = self.current_config.get(CONF_NAME)
self.battery_type = self.current_config.get(CONF_BATTERY_TYPE)
self.battery_quantity = self.current_config.get(CONF_BATTERY_QUANTITY)
self.battery_low_template = self.current_config.get(CONF_BATTERY_LOW_TEMPLATE)

if self.source_device_id:
device_registry = dr.async_get(self.hass)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/battery_notes/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

LOGGER: Logger = getLogger(__package__)

MIN_HA_VERSION = "2024.10"
MIN_HA_VERSION = "2024.12"

manifestfile = Path(__file__).parent / "manifest.json"
with open(file=manifestfile, encoding="UTF-8") as json_file:
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Battery Notes",
"filename": "battery_notes.zip",
"hide_default_branch": true,
"homeassistant": "2024.10.0",
"homeassistant": "2024.12.0",
"render_readme": true,
"zip_release": true,
"persistent_directory": "data"
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ repository = "https://github.com/andrew-codechimp/HA-Battery-Notes"
version = "0.0.0"

[tool.poetry.dependencies]
homeassistant = "2024.10.0"
homeassistant = "2024.12.0"
python = ">=3.12,<3.13"

[tool.poetry.group.dev.dependencies]
hass-nabucasa = "0.84.0"
pre-commit = "4.0.1"
pre-commit-hooks = "5.0.0"
pylint = "3.1.0"
ruff = "0.7.3"
ruff = "0.8.2"

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/andrew-codechimp/HA-Battery-Notes/issues"
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
colorlog>=6.8.2,<7.0
homeassistant==2024.10.0
ruff>=0.5.0,<0.8
homeassistant==2024.12.0
ruff>=0.5.0,<0.8.2

0 comments on commit 55ddfc6

Please sign in to comment.