async def async_update(self, *_): """Update the data from buienradar.""" content = await self.get_data(JSON_FEED_URL) if content.get(SUCCESS) is not True: # unable to get the data self.load_error_count += 1 threshold_log( self.load_error_count, "Unable to retrieve json data from Buienradar (Msg: %s, status: %s)", content.get(MESSAGE), content.get(STATUS_CODE), ) # schedule new call await self.schedule_update(SCHEDULE_NOK) return self.load_error_count = 0 # rounding coordinates prevents unnecessary redirects/calls lat = self.coordinates[CONF_LATITUDE] lon = self.coordinates[CONF_LONGITUDE] rainurl = json_precipitation_forecast_url(lat, lon) raincontent = await self.get_data(rainurl) if raincontent.get(SUCCESS) is not True: self.rain_error_count += 1 # unable to get the data threshold_log( self.rain_error_count, "Unable to retrieve rain data from Buienradar (Msg: %s, status: %s)", raincontent.get(MESSAGE), raincontent.get(STATUS_CODE), ) # schedule new call await self.schedule_update(SCHEDULE_NOK) return self.rain_error_count = 0 result = parse_data( content.get(CONTENT), raincontent.get(CONTENT), self.coordinates[CONF_LATITUDE], self.coordinates[CONF_LONGITUDE], self.timeframe, False, ) _LOGGER.debug("Buienradar parsed data: %s", result) if result.get(SUCCESS) is not True: if int(datetime.now().strftime("%H")) > 0: _LOGGER.warning( "Unable to parse data from Buienradar. (Msg: %s)", result.get(MESSAGE), ) await self.schedule_update(SCHEDULE_NOK) return self.data = result.get(DATA) await self.update_devices() await self.schedule_update(SCHEDULE_OK)
def test_base_urls(): """Test the url functions.""" json_url = json_precipitation_forecast_url(1.23, 4.56) xml_url = xml_precipitation_forecast_url(1.23, 4.56) assert 'https://gpsgadget.buienradar.nl/data/raintext?' in json_url assert 'http://gadgets.buienradar.nl/data/raintext/?' in xml_url assert 'https://api.buienradar.nl/image/1.0/RadarMapNL?' in radar_url()
def __get_precipfc_data(latitude, longitude): """Get buienradar forecasted precipitation.""" return __get_url(json_precipitation_forecast_url(latitude, longitude))