1 """The Ecowitt Weather Station Component."""
3 from __future__
import annotations
5 from aioecowitt
import EcoWittListener
6 from aiohttp
import web
13 from .const
import DOMAIN
15 PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.SENSOR]
17 type EcowittConfigEntry = ConfigEntry[EcoWittListener]
21 """Set up the Ecowitt component from UI."""
22 ecowitt = entry.runtime_data = EcoWittListener()
24 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
27 hass: HomeAssistant, webhook_id: str, request: web.Request
29 """Handle webhook callback."""
30 return await ecowitt.handler(request)
32 webhook.async_register(
33 hass, DOMAIN, entry.title, entry.data[CONF_WEBHOOK_ID], handle_webhook
37 def _stop_ecowitt(_: Event) ->
None:
38 """Stop the Ecowitt listener."""
39 webhook.async_unregister(hass, entry.data[CONF_WEBHOOK_ID])
41 entry.async_on_unload(
42 hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _stop_ecowitt)
49 """Unload a config entry."""
50 webhook.async_unregister(hass, entry.data[CONF_WEBHOOK_ID])
52 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, EcowittConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, EcowittConfigEntry entry)
web.Response handle_webhook(HomeAssistant hass, str webhook_id, web.Request request)