Add Airly integration (#26375)

* Add Airly integration

* Update .coveragerc file

* Remove AVAILABLE_CONDITIONS and fix device_class

* Don't create client on every update

* Rename client to session

* Rename state_attributes to device_state_attributes

* Remove log latitude and longitude

* Fix try...except

* Change latitude and longitude to HA defaults

* _show_config_form doesn't need coroutine

* Simplify config_flow errors handlig

* Preetier

* Remove unnecessary condition

* Change sensor platform to air_quality

* Remove PM1

* Make unique_id more unique

* Remove ,

* Add tests for config_flow

* Move conf to CONFIG

* Remove domain from unique_id

* Change the way update of attrs

* Language and attrs

* Fix attrs

* Add aiohttp error handling

* Throttle as decorator

* Suggested change

* Suggested change

* Invert condition

* Cleaning

* Add tests

* Polish no sesnor error handling

* Better strings

* Fix test_invalid_api_key

* Fix documentation url

* Remove unnecessary test

* Remove language option

* Fix test_invalid_api_key once again

* Sort imports

* Remove splits in strings
This commit is contained in:
Maciej Bieniek authored and Martin Hjelmare committed 2019-10-04 13:58:29 +02:00
1 parent 4b4a290f71
commit 8ba4ee1012
16 files changed
+2845

No files matched your search

+1
View File
@@ -0,0 +1 @@
"""Tests for Airly."""
@@ -0,0 +1,93 @@
"""Define tests for the Airly config flow."""
import json
from airly.exceptions import AirlyError
from asynctest import patch
from homeassistant import data_entry_flow
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
from homeassistant.components.airly import config_flow
from homeassistant.components.airly.const import DOMAIN
from tests.common import load_fixture, MockConfigEntry
CONFIG = {
CONF_NAME: "abcd",
CONF_API_KEY: "foo",
CONF_LATITUDE: 123,
CONF_LONGITUDE: 456,
}
async def test_show_form(hass):
"""Test that the form is served with no input."""
flow = config_flow.AirlyFlowHandler()
flow.hass = hass
result = await flow.async_step_user(user_input=None)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user"
async def test_invalid_api_key(hass):
"""Test that errors are shown when API key is invalid."""
with patch(
"airly._private._RequestsHandler.get",
side_effect=AirlyError(403, {"message": "Invalid authentication credentials"}),
):
flow = config_flow.AirlyFlowHandler()
flow.hass = hass
result = await flow.async_step_user(user_input=CONFIG)
assert result["errors"] == {"base": "auth"}
async def test_invalid_location(hass):
"""Test that errors are shown when location is invalid."""
with patch(
"airly._private._RequestsHandler.get",
return_value=json.loads(load_fixture("airly_no_station.json")),
):
flow = config_flow.AirlyFlowHandler()
flow.hass = hass
result = await flow.async_step_user(user_input=CONFIG)
assert result["errors"] == {"base": "wrong_location"}
async def test_duplicate_error(hass):
"""Test that errors are shown when duplicates are added."""
with patch(
"airly._private._RequestsHandler.get",
return_value=json.loads(load_fixture("airly_valid_station.json")),
):
MockConfigEntry(domain=DOMAIN, data=CONFIG).add_to_hass(hass)
flow = config_flow.AirlyFlowHandler()
flow.hass = hass
result = await flow.async_step_user(user_input=CONFIG)
assert result["errors"] == {CONF_NAME: "name_exists"}
async def test_create_entry(hass):
"""Test that the user step works."""
with patch(
"airly._private._RequestsHandler.get",
return_value=json.loads(load_fixture("airly_valid_station.json")),
):
flow = config_flow.AirlyFlowHandler()
flow.hass = hass
result = await flow.async_step_user(user_input=CONFIG)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == CONFIG[CONF_NAME]
assert result["data"][CONF_LATITUDE] == CONFIG[CONF_LATITUDE]
assert result["data"][CONF_LONGITUDE] == CONFIG[CONF_LONGITUDE]
assert result["data"][CONF_API_KEY] == CONFIG[CONF_API_KEY]
+642
View File
@@ -0,0 +1,642 @@
{
"current": {
"fromDateTime": "2019-10-02T05:53:00.608Z",
"tillDateTime": "2019-10-02T06:53:00.608Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
},
"history": [{
"fromDateTime": "2019-10-01T06:00:00.000Z",
"tillDateTime": "2019-10-01T07:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-01T07:00:00.000Z",
"tillDateTime": "2019-10-01T08:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-01T08:00:00.000Z",
"tillDateTime": "2019-10-01T09:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-01T09:00:00.000Z",
"tillDateTime": "2019-10-01T10:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-01T10:00:00.000Z",
"tillDateTime": "2019-10-01T11:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-01T11:00:00.000Z",
"tillDateTime": "2019-10-01T12:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-01T12:00:00.000Z",
"tillDateTime": "2019-10-01T13:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-01T13:00:00.000Z",
"tillDateTime": "2019-10-01T14:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-01T14:00:00.000Z",
"tillDateTime": "2019-10-01T15:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-01T15:00:00.000Z",
"tillDateTime": "2019-10-01T16:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-01T16:00:00.000Z",
"tillDateTime": "2019-10-01T17:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-01T17:00:00.000Z",
"tillDateTime": "2019-10-01T18:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-01T18:00:00.000Z",
"tillDateTime": "2019-10-01T19:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-01T19:00:00.000Z",
"tillDateTime": "2019-10-01T20:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-01T20:00:00.000Z",
"tillDateTime": "2019-10-01T21:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-01T21:00:00.000Z",
"tillDateTime": "2019-10-01T22:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-01T22:00:00.000Z",
"tillDateTime": "2019-10-01T23:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-01T23:00:00.000Z",
"tillDateTime": "2019-10-02T00:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T00:00:00.000Z",
"tillDateTime": "2019-10-02T01:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T01:00:00.000Z",
"tillDateTime": "2019-10-02T02:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T02:00:00.000Z",
"tillDateTime": "2019-10-02T03:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T03:00:00.000Z",
"tillDateTime": "2019-10-02T04:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T04:00:00.000Z",
"tillDateTime": "2019-10-02T05:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T05:00:00.000Z",
"tillDateTime": "2019-10-02T06:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}],
"forecast": [{
"fromDateTime": "2019-10-02T06:00:00.000Z",
"tillDateTime": "2019-10-02T07:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T07:00:00.000Z",
"tillDateTime": "2019-10-02T08:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T08:00:00.000Z",
"tillDateTime": "2019-10-02T09:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T09:00:00.000Z",
"tillDateTime": "2019-10-02T10:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T10:00:00.000Z",
"tillDateTime": "2019-10-02T11:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T11:00:00.000Z",
"tillDateTime": "2019-10-02T12:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T12:00:00.000Z",
"tillDateTime": "2019-10-02T13:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T13:00:00.000Z",
"tillDateTime": "2019-10-02T14:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T14:00:00.000Z",
"tillDateTime": "2019-10-02T15:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T15:00:00.000Z",
"tillDateTime": "2019-10-02T16:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T16:00:00.000Z",
"tillDateTime": "2019-10-02T17:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T17:00:00.000Z",
"tillDateTime": "2019-10-02T18:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T18:00:00.000Z",
"tillDateTime": "2019-10-02T19:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T19:00:00.000Z",
"tillDateTime": "2019-10-02T20:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T20:00:00.000Z",
"tillDateTime": "2019-10-02T21:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T21:00:00.000Z",
"tillDateTime": "2019-10-02T22:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T22:00:00.000Z",
"tillDateTime": "2019-10-02T23:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-02T23:00:00.000Z",
"tillDateTime": "2019-10-03T00:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-03T00:00:00.000Z",
"tillDateTime": "2019-10-03T01:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-03T01:00:00.000Z",
"tillDateTime": "2019-10-03T02:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-03T02:00:00.000Z",
"tillDateTime": "2019-10-03T03:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-03T03:00:00.000Z",
"tillDateTime": "2019-10-03T04:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-03T04:00:00.000Z",
"tillDateTime": "2019-10-03T05:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}, {
"fromDateTime": "2019-10-03T05:00:00.000Z",
"tillDateTime": "2019-10-03T06:00:00.000Z",
"values": [],
"indexes": [{
"name": "AIRLY_CAQI",
"value": null,
"level": "UNKNOWN",
"description": "There are no Airly sensors in this area yet.",
"advice": null,
"color": "#999999"
}],
"standards": []
}]
}
File diff suppressed because it is too large. Load diff