1 """The GeoNet NZ Volcano integration."""
3 from __future__
import annotations
5 from datetime
import datetime, timedelta
8 from aio_geojson_geonetnz_volcano
import GeonetnzVolcanoFeedManager
9 import voluptuous
as vol
27 from .config_flow
import configured_instances
30 DEFAULT_SCAN_INTERVAL,
37 _LOGGER = logging.getLogger(__name__)
39 CONFIG_SCHEMA = vol.Schema(
43 vol.Optional(CONF_LATITUDE): cv.latitude,
44 vol.Optional(CONF_LONGITUDE): cv.longitude,
45 vol.Optional(CONF_RADIUS, default=DEFAULT_RADIUS): vol.Coerce(float),
47 CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL
52 extra=vol.ALLOW_EXTRA,
56 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
57 """Set up the GeoNet NZ Volcano component."""
58 if DOMAIN
not in config:
63 latitude = conf.get(CONF_LATITUDE, hass.config.latitude)
64 longitude = conf.get(CONF_LONGITUDE, hass.config.longitude)
65 scan_interval = conf[CONF_SCAN_INTERVAL]
67 identifier = f
"{latitude}, {longitude}"
71 hass.async_create_task(
72 hass.config_entries.flow.async_init(
74 context={
"source": SOURCE_IMPORT},
76 CONF_LATITUDE: latitude,
77 CONF_LONGITUDE: longitude,
78 CONF_RADIUS: conf[CONF_RADIUS],
79 CONF_SCAN_INTERVAL: scan_interval,
88 """Set up the GeoNet NZ Volcano component as config entry."""
89 hass.data.setdefault(DOMAIN, {})
90 hass.data[DOMAIN].setdefault(FEED, {})
92 radius = config_entry.data[CONF_RADIUS]
93 unit_system = config_entry.data[CONF_UNIT_SYSTEM]
94 if unit_system == IMPERIAL_UNITS:
95 radius = DistanceConverter.convert(
96 radius, UnitOfLength.MILES, UnitOfLength.KILOMETERS
100 hass.data[DOMAIN][FEED][config_entry.entry_id] = manager
101 _LOGGER.debug(
"Feed entity manager added for %s", config_entry.entry_id)
102 await manager.async_init()
107 """Unload an GeoNet NZ Volcano component config entry."""
108 manager = hass.data[DOMAIN][FEED].pop(entry.entry_id)
109 await manager.async_stop()
110 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
114 """Feed Entity Manager for GeoNet NZ Volcano feed."""
116 def __init__(self, hass, config_entry, radius_in_km, unit_system):
117 """Initialize the Feed Entity Manager."""
121 config_entry.data[CONF_LATITUDE],
122 config_entry.data[CONF_LONGITUDE],
124 websession = aiohttp_client.async_get_clientsession(hass)
131 filter_radius=radius_in_km,
140 """Schedule initial and regular updates based on configured time interval."""
142 await self.
_hass_hass.config_entries.async_forward_entry_setups(
146 async
def update(event_time):
155 _LOGGER.debug(
"Feed entity manager initialized")
160 _LOGGER.debug(
"Feed entity manager updated")
163 """Stop this feed entity manager from refreshing."""
164 for unsub_dispatcher
in self.
listenerslisteners:
169 _LOGGER.debug(
"Feed entity manager stopped")
173 """Return manager specific event to signal new entity."""
174 return f
"geonetnz_volcano_new_sensor_{self._config_entry_id}"
177 """Get feed entry by external id."""
178 return self.
_feed_manager_feed_manager.feed_entries.get(external_id)
181 """Return the last update of this feed."""
185 """Return the last successful update of this feed."""
186 return self.
_feed_manager_feed_manager.last_update_successful
189 """Generate new entity."""
203 """Ignore removing entity."""
def _generate_entity(self, external_id)
datetime|None last_update_successful(self)
def _remove_entity(self, external_id)
datetime|None last_update(self)
def _update_entity(self, external_id)
def get_entry(self, external_id)
_track_time_remove_callback
def async_event_new_entity(self)
def __init__(self, hass, config_entry, radius_in_km, unit_system)
set[str] configured_instances(HomeAssistant hass)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry config_entry)
bool async_setup(HomeAssistant hass, ConfigType config)
IssData update(pyiss.ISS iss)
None async_dispatcher_send(HomeAssistant hass, str signal, *Any args)
CALLBACK_TYPE async_track_time_interval(HomeAssistant hass, Callable[[datetime], Coroutine[Any, Any, None]|None] action, timedelta interval, *str|None name=None, bool|None cancel_on_shutdown=None)