added options flow
This commit is contained in:
1 parent
5a6dbb8d00
commit
886ab957bb
5 files changed
+79
-3
No files matched your search
@@ -14,9 +14,10 @@ from homeassistant.components.bluetooth import (
|
|||||||
)
|
)
|
||||||
from homeassistant.const import CONF_ADDRESS, CONF_TYPE, CONF_NAME
|
from homeassistant.const import CONF_ADDRESS, CONF_TYPE, CONF_NAME
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
from homeassistant.helpers import selector
|
||||||
|
|
||||||
from . import get_type_by_bt_name
|
from . import get_type_by_bt_name
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN, CONF_USE_CONTROLS
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -86,3 +87,56 @@ class BluettiConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
step_id="user",
|
step_id="user",
|
||||||
data_schema=data_schema,
|
data_schema=data_schema,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def async_get_options_flow(
|
||||||
|
config_entry: config_entries.ConfigEntry,
|
||||||
|
) -> config_entries.OptionsFlow:
|
||||||
|
"""Create the options flow."""
|
||||||
|
return OptionsFlowHandler(config_entry)
|
||||||
|
|
||||||
|
|
||||||
|
class OptionsFlowHandler(config_entries.OptionsFlow):
|
||||||
|
"""Handle a option flow."""
|
||||||
|
|
||||||
|
def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
|
||||||
|
"""Initialize options flow."""
|
||||||
|
self.config_entry = config_entry
|
||||||
|
|
||||||
|
async def async_step_init(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
|
"""Manage the options."""
|
||||||
|
if user_input is not None:
|
||||||
|
changed = self.hass.config_entries.async_update_entry(
|
||||||
|
self.config_entry,
|
||||||
|
data={
|
||||||
|
**self.config_entry.data,
|
||||||
|
**{
|
||||||
|
CONF_USE_CONTROLS: user_input[CONF_USE_CONTROLS],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if changed is False:
|
||||||
|
_LOGGER.error(
|
||||||
|
"Method OptionsFlowHandler.async_step_init: Config entry %s has not been changed",
|
||||||
|
self.config_entry.entry_id,
|
||||||
|
)
|
||||||
|
return self.async_create_entry(
|
||||||
|
title="",
|
||||||
|
data={
|
||||||
|
CONF_USE_CONTROLS: user_input[CONF_USE_CONTROLS],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
return self.async_show_form(
|
||||||
|
step_id="init",
|
||||||
|
data_schema=vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Required(
|
||||||
|
CONF_USE_CONTROLS,
|
||||||
|
default=self.config_entry.data.get(CONF_USE_CONTROLS, False),
|
||||||
|
): selector.BooleanSelector(),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
@@ -6,6 +6,7 @@ DOMAIN = "bluetti_bt"
|
|||||||
MANUFACTURER = "Bluetti"
|
MANUFACTURER = "Bluetti"
|
||||||
|
|
||||||
CONF_OPTIONS = "options"
|
CONF_OPTIONS = "options"
|
||||||
|
CONF_USE_CONTROLS = "use_controls"
|
||||||
|
|
||||||
DIAGNOSTIC_FIELDS = [
|
DIAGNOSTIC_FIELDS = [
|
||||||
"max_ac_input_power",
|
"max_ac_input_power",
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
"""Coordinator for Bluetti integration."""
|
"""Coordinator for Bluetti integration."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from typing import List
|
from typing import List, cast
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import cast
|
|
||||||
import async_timeout
|
import async_timeout
|
||||||
|
|
||||||
from bleak import BleakClient, BleakError
|
from bleak import BleakClient, BleakError
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"options": {
|
||||||
|
"step": {
|
||||||
|
"init": {
|
||||||
|
"data": {
|
||||||
|
"use_controls": "Steuerung aktivieren (auf eigenes Risiko)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"options": {
|
||||||
|
"step": {
|
||||||
|
"init": {
|
||||||
|
"data": {
|
||||||
|
"use_controls": "Use controls (use at own risk)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user