def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the Environment Canada camera.""" if config.get(CONF_STATION): radar_object = ECRadar(station_id=config[CONF_STATION], precip_type=config.get(CONF_PRECIP_TYPE)) else: lat = config.get(CONF_LATITUDE, hass.config.latitude) lon = config.get(CONF_LONGITUDE, hass.config.longitude) radar_object = ECRadar(coordinates=(lat, lon)) add_devices([ECCamera(radar_object, config.get(CONF_NAME))], True)
async def async_setup_entry(hass, config_entry): """Set up EC as config entry.""" lat = config_entry.data.get(CONF_LATITUDE) lon = config_entry.data.get(CONF_LONGITUDE) station = config_entry.data.get(CONF_STATION) lang = config_entry.data.get(CONF_LANGUAGE, "English") coordinators = {} weather_data = ECWeather( station_id=station, coordinates=(lat, lon), language=lang.lower(), ) coordinators["weather_coordinator"] = ECDataUpdateCoordinator( hass, weather_data, "weather", DEFAULT_WEATHER_UPDATE_INTERVAL) await coordinators["weather_coordinator"].async_config_entry_first_refresh( ) radar_data = ECRadar(coordinates=(lat, lon)) coordinators["radar_coordinator"] = ECDataUpdateCoordinator( hass, radar_data, "radar", DEFAULT_RADAR_UPDATE_INTERVAL) await coordinators["radar_coordinator"].async_config_entry_first_refresh() hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][config_entry.entry_id] = coordinators hass.config_entries.async_setup_platforms(config_entry, PLATFORMS) return True
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Set up EC as config entry.""" lat = config_entry.data.get(CONF_LATITUDE) lon = config_entry.data.get(CONF_LONGITUDE) station = config_entry.data.get(CONF_STATION) lang = config_entry.data.get(CONF_LANGUAGE, "English") coordinators = {} errors = 0 weather_data = ECWeather( station_id=station, coordinates=(lat, lon), language=lang.lower(), ) coordinators["weather_coordinator"] = ECDataUpdateCoordinator( hass, weather_data, "weather", DEFAULT_WEATHER_UPDATE_INTERVAL) try: await coordinators["weather_coordinator" ].async_config_entry_first_refresh() except ConfigEntryNotReady: errors = errors + 1 _LOGGER.warning("Unable to retrieve Environment Canada weather") radar_data = ECRadar(coordinates=(lat, lon)) coordinators["radar_coordinator"] = ECDataUpdateCoordinator( hass, radar_data, "radar", DEFAULT_RADAR_UPDATE_INTERVAL) try: await coordinators["radar_coordinator" ].async_config_entry_first_refresh() except ConfigEntryNotReady: errors = errors + 1 _LOGGER.warning("Unable to retrieve Environment Canada radar") aqhi_data = ECAirQuality(coordinates=(lat, lon)) coordinators["aqhi_coordinator"] = ECDataUpdateCoordinator( hass, aqhi_data, "AQHI", DEFAULT_WEATHER_UPDATE_INTERVAL) try: await coordinators["aqhi_coordinator" ].async_config_entry_first_refresh() except ConfigEntryNotReady: errors = errors + 1 _LOGGER.warning("Unable to retrieve Environment Canada AQHI") if errors == 3: raise ConfigEntryNotReady hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][config_entry.entry_id] = coordinators await hass.config_entries.async_forward_entry_setups( config_entry, PLATFORMS) return True
def test_radar(): return ECRadar(coordinates=(50, -100))
def test_ecradar(init_parameters): radar = ECRadar(**init_parameters) assert isinstance(radar, ECRadar)
def test_ecradar(init_parameters): radar = ECRadar(**init_parameters) frame = asyncio.run(radar.get_latest_frame()) image = Image.open(BytesIO(frame)) assert image.format == "PNG"