ToddGreenfield / homebridge-airnow

Homebridge plugin for AirNow Web-API Air Quality Sensor
36 stars 10 forks source link

aqicq availability #6

Closed johan-de-jong closed 6 years ago

johan-de-jong commented 6 years ago

I really like this plugin!

Apparently the aqicq api / api.aqicn.org is undergoing some issues. I often receive an unexpected response, e.g:

When api.aqicn.org returns an unexpected response the Air Quality is reported as: UNKNOWN in the Apple Home app. Would you consider updating the plugin to show the last known valid result instead, when the plugin receives invalid data?

GET /feed/@4572/?token=xxx HTTP/1.1
host: api.waqi.info
accept: application/json
Connection: close

HTTP/1.1 200 OK
Server: nginx
Date: Thu, 12 Apr 2018 08:41:26 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 28
Connection: close
Vary: Accept-Encoding
Access-Control-Allow-Origin: *
X-Gen-Time: 1137
X-Powered-By: rxstreamer-waqi/1.2

{"status":"nug","data":null}

A correct response would be:

HTTP/1.1 200 OK
Server: nginx
Date: Thu, 12 Apr 2018 08:46:11 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 522
Connection: close
Vary: Accept-Encoding
Access-Control-Allow-Origin: *
X-Gen-Time: 306603
X-Powered-By: rxstreamer-waqi/1.2

{
    "status": "ok",
    "data": {
        "aqi": 80,
        "idx": 4572,
        "attributions": [{
            "url": "http://www.luchtmeetnet.nl/",
            "name": "RIVM - Rijksinstituut voor Volksgezondheid en Milieum, Landelijk Meetnet Luchtkwaliteit"
        }],
        "city": {
            "geo": [51.914233, 4.479923],
            "name": "Schiedamsevest, Rotterdam",
            "url": "http://aqicn.org/city/netherland/rotterdam/schiedamsevest/"
        },
        "dominentpol": "pm25",
        "iaqi": {
            "no2": {
                "v": 14.4
            },
            "o3": {
                "v": 5.3
            },
            "pm10": {
                "v": 30
            },
            "pm25": {
                "v": 80
            },
            "w": {
                "v": 6.1
            },
            "wg": {
                "v": 11.3
            }
        },
        "time": {
            "s": "2018-04-12 09:00:00",
            "tz": "+01:00",
            "v": 1523523600
        }
    }
}
ToddGreenfield commented 6 years ago

Thanks for the feedback. The problem I see though is displaying the last known values would not show the correct current status. How would someone know the status is unavailable? Or how long it was out of date? Might be best to fork the plugin and make that mod if you wanted/are able.