Allow more than one AirVisual config entry with the same API k… (#33072)

* Allow more than one AirVisual config entry with the same API key

* Add tests

* Correctly pop geography

* Code review

* Code review
This commit is contained in:
Aaron Bach
2020-03-24 12:39:38 -06:00
committed by GitHub
parent 109f083c5d
commit 0e2fa7700d
7 changed files with 169 additions and 86 deletions

View File

@@ -191,16 +191,19 @@ class AirVisualSensor(Entity):
}
)
geography = self._airvisual.geographies[self._geography_id]
if CONF_LATITUDE in geography:
if CONF_LATITUDE in self._airvisual.geography_data:
if self._airvisual.options[CONF_SHOW_ON_MAP]:
self._attrs[ATTR_LATITUDE] = geography[CONF_LATITUDE]
self._attrs[ATTR_LONGITUDE] = geography[CONF_LONGITUDE]
self._attrs[ATTR_LATITUDE] = self._airvisual.geography_data[
CONF_LATITUDE
]
self._attrs[ATTR_LONGITUDE] = self._airvisual.geography_data[
CONF_LONGITUDE
]
self._attrs.pop("lati", None)
self._attrs.pop("long", None)
else:
self._attrs["lati"] = geography[CONF_LATITUDE]
self._attrs["long"] = geography[CONF_LONGITUDE]
self._attrs["lati"] = self._airvisual.geography_data[CONF_LATITUDE]
self._attrs["long"] = self._airvisual.geography_data[CONF_LONGITUDE]
self._attrs.pop(ATTR_LATITUDE, None)
self._attrs.pop(ATTR_LONGITUDE, None)