1 """Support for Meteoclimatic weather data."""
5 from meteoclimatic
import MeteoclimaticClient
6 from meteoclimatic.exceptions
import MeteoclimaticError
12 from .const
import CONF_STATION_CODE, DOMAIN, PLATFORMS, SCAN_INTERVAL
14 _LOGGER = logging.getLogger(__name__)
18 """Set up a Meteoclimatic entry."""
19 station_code = entry.data[CONF_STATION_CODE]
20 meteoclimatic_client = MeteoclimaticClient()
22 async
def async_update_data():
23 """Obtain the latest data from Meteoclimatic."""
25 data = await hass.async_add_executor_job(
26 meteoclimatic_client.weather_at_station, station_code
28 except MeteoclimaticError
as err:
29 raise UpdateFailed(f
"Error while retrieving data: {err}")
from err
36 name=f
"Meteoclimatic weather for {entry.title} ({station_code})",
37 update_method=async_update_data,
38 update_interval=SCAN_INTERVAL,
41 await coordinator.async_config_entry_first_refresh()
43 hass.data.setdefault(DOMAIN, {})
44 hass.data[DOMAIN][entry.entry_id] = coordinator
46 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
52 """Unload a config entry."""
53 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)