Skip to content

Commit

Permalink
Merge pull request #39 from pawkakol1/bugFix/forecast
Browse files Browse the repository at this point in the history
bugFix/forecast
  • Loading branch information
pawkakol1 committed Mar 3, 2023
2 parents 42ca73a + 97799b2 commit 83ccbf8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 31 deletions.
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<img src="https://github.com/pawkakol1/worlds-air-quality-index/tree/main/readme_files/forecast.png">

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:

Expand All @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion custom_components/worlds_air_quality_index/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/worlds_air_quality_index/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
52 changes: 28 additions & 24 deletions custom_components/worlds_air_quality_index/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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"
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"
Binary file added readme_files/forecast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 83ccbf8

Please sign in to comment.