mirror of
https://github.com/alexhopeoconnor/bom-local-card.git
synced 2026-10-04 04:28:11 +10:00
- Fix BomLocalOptionsFlow AttributeError by using super().__init__() instead of direct assignment - Add single_config_entry to manifest to enforce single integration instance - Add YAML config check to prevent UI config when YAML config exists - Add icon static path registration for /local/community/bom_local/icon.png - Add loading overlay with animated icon to card - Bump version to 0.3.0 Fixes #1
63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
import logging
|
|
import voluptuous as vol
|
|
|
|
from homeassistant import config_entries
|
|
from homeassistant.core import callback
|
|
from homeassistant.const import CONF_URL
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
from .const import DOMAIN, CONF_SERVICE_URL, DEFAULT_SERVICE_URL
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
class BomLocalConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|
"""Handle a config flow for BOM Local Radar."""
|
|
|
|
VERSION = 1
|
|
|
|
async def async_step_user(self, user_input=None):
|
|
"""Handle the initial step."""
|
|
# Check if YAML configuration already exists by checking if component is loaded
|
|
if DOMAIN in self.hass.config.components:
|
|
return self.async_abort(reason="already_configured")
|
|
|
|
errors = {}
|
|
if user_input is not None:
|
|
# We could validate the URL here by trying a fetch
|
|
return self.async_create_entry(title="BOM Local Radar", data=user_input)
|
|
|
|
return self.async_show_form(
|
|
step_id="user",
|
|
data_schema=vol.Schema({
|
|
vol.Required(CONF_SERVICE_URL, default=DEFAULT_SERVICE_URL): str,
|
|
}),
|
|
errors=errors,
|
|
)
|
|
|
|
@staticmethod
|
|
@callback
|
|
def async_get_options_flow(config_entry):
|
|
return BomLocalOptionsFlow(config_entry)
|
|
|
|
class BomLocalOptionsFlow(config_entries.OptionsFlow):
|
|
"""Handle options flow."""
|
|
|
|
def __init__(self, config_entry):
|
|
super().__init__(config_entry)
|
|
|
|
async def async_step_init(self, user_input=None):
|
|
"""Manage the options."""
|
|
if user_input is not None:
|
|
return self.async_create_entry(title="", data=user_input)
|
|
|
|
return self.async_show_form(
|
|
step_id="init",
|
|
data_schema=vol.Schema({
|
|
vol.Required(
|
|
CONF_SERVICE_URL,
|
|
default=self.config_entry.data.get(CONF_SERVICE_URL, DEFAULT_SERVICE_URL),
|
|
): str,
|
|
}),
|
|
)
|
|
|