diff --git a/README.md b/README.md index 735ee1c..2a76ed4 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,20 @@ Integration supports below sensors of WAQI station: Diffrent stations support diffrent data, "World's Air Quality Index" integration will recognise all parameters (availible in station) according to list of integration's supported sensors. -WAQI supports diffrents API from +If station's API supports forecast for pollution sensors (these on above list): + +- Carbon monoxide (CO) +- Nitrogen dioxide (NO2) +- Ozone (O3) +- Particulate matter (PM10) +- Particulate matter (PM2,5) +- Sulphur dioxide (SO2) + +Pollution sensors will update forecast, and it will be able to read as attributes of the sensor: + + + +If the station supports forecast of soem pollution sensor, but it doesn't support actual value of this sensor, then the forecast will be omitted. There are 2 supported integration methods: @@ -46,10 +59,10 @@ To add integration use "Add Integration" button in section Settings->Devices&Ser In popup window choose method of station adding: - using geographic localization (NOTICE: it works with WAQI internal stations only), -- using station ID (NOTICE: it works with all API types available in WAQI: - - WAQI internal stations, - - stations from CanAir.IO, - - stations from Citizen Science project luftdaten.info. +- using station ID (NOTICE: it works with all API types available in WAQI: + - WAQI internal stations, + - stations from CanAir.IO, + - stations from Citizen Science project luftdaten.info. In case of geographic localization, there will be shown next window, where you need to put: diff --git a/custom_components/worlds_air_quality_index/const.py b/custom_components/worlds_air_quality_index/const.py index 81294b2..08316fa 100644 --- a/custom_components/worlds_air_quality_index/const.py +++ b/custom_components/worlds_air_quality_index/const.py @@ -18,7 +18,7 @@ DOMAIN = "worlds_air_quality_index" PLATFORMS = [Platform.SENSOR] -SW_VERSION = "0.3.7" +SW_VERSION = "1.0.1" DEFAULT_NAME = 'waqi1' DISCOVERY_TYPE = "discovery_type" diff --git a/custom_components/worlds_air_quality_index/manifest.json b/custom_components/worlds_air_quality_index/manifest.json index 7598b0e..afc0d87 100644 --- a/custom_components/worlds_air_quality_index/manifest.json +++ b/custom_components/worlds_air_quality_index/manifest.json @@ -10,6 +10,6 @@ "issue_tracker": "https://github.com/pawkakol1/worlds-air-quality-index/issues", "requirements": [], "ssdp": [], - "version": "0.3.7", + "version": "1.0.1", "zeroconf": [] } diff --git a/custom_components/worlds_air_quality_index/sensor.py b/custom_components/worlds_air_quality_index/sensor.py index 4ba8655..c411710 100644 --- a/custom_components/worlds_air_quality_index/sensor.py +++ b/custom_components/worlds_air_quality_index/sensor.py @@ -103,6 +103,9 @@ async def async_setup_entry( scannedData = requester.GetData() _LOGGER.debug("Got station data from WAQI server:") _LOGGER.debug(scannedData) + + if not "forecast" in scannedData['data']: + _LOGGER.warning(f"Station {name} doesn't support forecast") scannedDataSensors = scannedData["data"]["iaqi"] entities = [] @@ -211,27 +214,28 @@ def update(self) -> None: "StationName": self._requester.GetStationName(), "LastUpdate": self._requester.GetUpdateLastTime() } - if self._resType in self._data['data']['forecast']['daily']: - scannedDataForecast = self._data['data']['forecast']['daily'][self._resType] - day = date.today() - dayName = "Today" - if scannedDataForecast is not None: - for res in scannedDataForecast: - readDate = date.fromisoformat(res["day"]) - if readDate == day: - self._attr_extra_state_attributes['Forecast' + dayName + 'Avg'] = res['avg'] - self._attr_extra_state_attributes['Forecast' + dayName + 'Min'] = res['min'] - self._attr_extra_state_attributes['Forecast' + dayName + 'Max'] = res['max'] - _LOGGER.debug(f"Forecast{dayName} Avg/Min/Max extra state attributes added.") - - day = day + timedelta(days=1) - if dayName == "Today": - dayName = "Tomorrow" - elif dayName == "Tomorrow": - dayName = "2Days" - elif dayName == "2Days": - dayName = "3Days" - elif dayName == "3Days": - dayName = "4Days" - elif dayName == "4Days": - dayName = "5Days" \ No newline at end of file + if "forecast" in self._data['data']: + if self._resType in self._data['data']['forecast']['daily']: + scannedDataForecast = self._data['data']['forecast']['daily'][self._resType] + day = date.today() + dayName = "Today" + if scannedDataForecast is not None: + for res in scannedDataForecast: + readDate = date.fromisoformat(res["day"]) + if readDate == day: + self._attr_extra_state_attributes['Forecast' + dayName + 'Avg'] = res['avg'] + self._attr_extra_state_attributes['Forecast' + dayName + 'Min'] = res['min'] + self._attr_extra_state_attributes['Forecast' + dayName + 'Max'] = res['max'] + _LOGGER.debug(f"Forecast{dayName} Avg/Min/Max extra state attributes added.") + + day = day + timedelta(days=1) + if dayName == "Today": + dayName = "Tomorrow" + elif dayName == "Tomorrow": + dayName = "2Days" + elif dayName == "2Days": + dayName = "3Days" + elif dayName == "3Days": + dayName = "4Days" + elif dayName == "4Days": + dayName = "5Days" \ No newline at end of file diff --git a/readme_files/forecast.png b/readme_files/forecast.png new file mode 100644 index 0000000..66b178f Binary files /dev/null and b/readme_files/forecast.png differ