async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Set up Met Éireann as config entry.""" hass.data.setdefault(DOMAIN, {}) raw_weather_data = meteireann.WeatherData( async_get_clientsession(hass), latitude=config_entry.data[CONF_LATITUDE], longitude=config_entry.data[CONF_LONGITUDE], altitude=config_entry.data[CONF_ELEVATION], ) weather_data = MetEireannWeatherData(hass, config_entry.data, raw_weather_data) async def _async_update_data(): """Fetch data from Met Éireann.""" try: return await weather_data.fetch_data() except Exception as err: raise UpdateFailed(f"Update failed: {err}") from err coordinator = DataUpdateCoordinator( hass, _LOGGER, name=DOMAIN, update_method=_async_update_data, update_interval=UPDATE_INTERVAL, ) await coordinator.async_refresh() hass.data[DOMAIN][config_entry.entry_id] = coordinator hass.config_entries.async_setup_platforms(config_entry, PLATFORMS) return True
def init_data(self): """Weather data inialization - get the coordinates.""" latitude = self._config[CONF_LATITUDE] longitude = self._config[CONF_LONGITUDE] elevation = self._config[CONF_ELEVATION] if not self._is_metric: elevation = int( round(convert_distance(elevation, LENGTH_FEET, LENGTH_METERS))) self._weather_data = meteireann.WeatherData( async_get_clientsession(self.hass), latitude=latitude, longitude=longitude, altitude=elevation, )