mirror of
https://github.com/alexhopeoconnor/bom-local-card.git
synced 2026-10-03 22:22:00 +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
79 lines
2.5 KiB
Python
79 lines
2.5 KiB
Python
"""The BOM Local Radar integration."""
|
|
import logging
|
|
import voluptuous as vol
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.components.http import StaticPathConfig
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.helpers import config_validation as cv
|
|
|
|
from .const import DOMAIN, CONF_SERVICE_URL, DEFAULT_SERVICE_URL
|
|
from .views import BomLocalProxyView
|
|
from .websocket import async_setup_websocket
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
CONFIG_SCHEMA = vol.Schema(
|
|
{
|
|
DOMAIN: vol.Schema(
|
|
{
|
|
vol.Required(CONF_SERVICE_URL, default=DEFAULT_SERVICE_URL): cv.string,
|
|
}
|
|
)
|
|
},
|
|
extra=vol.ALLOW_EXTRA,
|
|
)
|
|
|
|
async def async_setup(hass: HomeAssistant, config: dict):
|
|
"""Set up the BOM Local Radar component from YAML."""
|
|
if DOMAIN not in config:
|
|
return True
|
|
|
|
conf = config[DOMAIN]
|
|
service_url = conf.get(CONF_SERVICE_URL)
|
|
|
|
hass.data.setdefault(DOMAIN, {})
|
|
hass.data[DOMAIN]["service_url"] = service_url
|
|
|
|
await _async_setup_integration(hass, service_url)
|
|
|
|
return True
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|
"""Set up BOM Local Radar from a config entry."""
|
|
service_url = entry.data.get(CONF_SERVICE_URL)
|
|
|
|
hass.data.setdefault(DOMAIN, {})
|
|
hass.data[DOMAIN]["service_url"] = service_url
|
|
|
|
await _async_setup_integration(hass, service_url)
|
|
|
|
return True
|
|
|
|
async def _async_setup_integration(hass: HomeAssistant, service_url: str):
|
|
"""Common setup logic for YAML and Config Entry."""
|
|
# Register the proxy view
|
|
hass.http.register_view(BomLocalProxyView(service_url))
|
|
|
|
# Register the websocket commands
|
|
async_setup_websocket(hass, service_url)
|
|
|
|
# Register the card as a resource automatically
|
|
# Note: In a real HACS install, the path would be /local/community/bom-local-card/bom-local-card.js
|
|
# but since this is an integration, it's /local/community/bom_local/bom-local-card.js
|
|
await hass.http.async_register_static_paths([
|
|
StaticPathConfig(
|
|
"/local/community/bom_local/bom-local-card.js",
|
|
hass.config.path("custom_components/bom_local/www/bom-local-card.js"),
|
|
True
|
|
),
|
|
StaticPathConfig(
|
|
"/local/community/bom_local/icon.png",
|
|
hass.config.path("custom_components/bom_local/icon.png"),
|
|
True
|
|
)
|
|
])
|
|
|
|
_LOGGER.info("BOM Local Radar integration setup completed with service URL: %s", service_url)
|
|
|