custom_components/bahmcloud_store/__init__.py hinzugefügt
This commit is contained in:
66
custom_components/bahmcloud_store/__init__.py
Normal file
66
custom_components/bahmcloud_store/__init__.py
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.components import frontend
|
||||||
|
from homeassistant.const import Platform
|
||||||
|
from homeassistant.helpers.event import async_track_time_interval
|
||||||
|
|
||||||
|
from .store import BahmcloudStore, StoreConfig, StoreError
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DOMAIN = "bahmcloud_store"
|
||||||
|
PLATFORMS = [Platform.UPDATE]
|
||||||
|
|
||||||
|
DEFAULT_STORE_URL = "https://git.bahmcloud.de/bahmcloud/ha_store/raw/branch/main/store.yaml"
|
||||||
|
CONF_STORE_URL = "store_url"
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
||||||
|
cfg = config.get(DOMAIN, {})
|
||||||
|
store_url = cfg.get(CONF_STORE_URL, DEFAULT_STORE_URL)
|
||||||
|
|
||||||
|
store = BahmcloudStore(hass, StoreConfig(store_url=store_url))
|
||||||
|
hass.data[DOMAIN] = store
|
||||||
|
|
||||||
|
# Sidebar Panel
|
||||||
|
frontend.async_register_built_in_panel(
|
||||||
|
hass,
|
||||||
|
component_name=DOMAIN,
|
||||||
|
sidebar_title="Bahmcloud Store",
|
||||||
|
sidebar_icon="mdi:store",
|
||||||
|
frontend_url_path="bahmcloud-store",
|
||||||
|
config={},
|
||||||
|
require_admin=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
# HTTP (Panel static + API)
|
||||||
|
await store.register_http_views()
|
||||||
|
|
||||||
|
# Initial load
|
||||||
|
try:
|
||||||
|
await store.refresh()
|
||||||
|
except StoreError as e:
|
||||||
|
_LOGGER.error("Initial store refresh failed: %s", e)
|
||||||
|
|
||||||
|
# Periodisch NUR index+latest versions refresh (keine Auto-Install)
|
||||||
|
async def periodic(_now) -> None:
|
||||||
|
try:
|
||||||
|
await store.refresh()
|
||||||
|
store.signal_entities_updated()
|
||||||
|
except StoreError as e:
|
||||||
|
_LOGGER.warning("Periodic refresh failed: %s", e)
|
||||||
|
|
||||||
|
async_track_time_interval(
|
||||||
|
hass,
|
||||||
|
periodic,
|
||||||
|
timedelta(seconds=store.refresh_seconds or 300),
|
||||||
|
)
|
||||||
|
|
||||||
|
# Update entities laden (damit Updates in Settings erscheinen)
|
||||||
|
await hass.helpers.discovery.async_load_platform(Platform.UPDATE, DOMAIN, {}, config)
|
||||||
|
|
||||||
|
return True
|
||||||
Reference in New Issue
Block a user