Fix Luftdaten.info data retrieval (#43471)

Fix Luftdaten.info data retrieval
This commit is contained in:
FlavorFx 2020-11-21 11:52:34 +01:00 committed by GitHub
parent db0dee1ab2
commit f22f568169
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View File

@ -198,6 +198,7 @@ class LuftDatenData:
try: try:
await self.client.get_data() await self.client.get_data()
if self.client.values:
self.data[DATA_LUFTDATEN] = self.client.values self.data[DATA_LUFTDATEN] = self.client.values
self.data[DATA_LUFTDATEN].update(self.client.meta) self.data[DATA_LUFTDATEN].update(self.client.meta)

View File

@ -69,7 +69,10 @@ class LuftdatenSensor(Entity):
def state(self): def state(self):
"""Return the state of the device.""" """Return the state of the device."""
if self._data is not None: if self._data is not None:
try:
return self._data[self.sensor_type] return self._data[self.sensor_type]
except KeyError:
return None
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
@ -85,7 +88,10 @@ class LuftdatenSensor(Entity):
def unique_id(self) -> str: def unique_id(self) -> str:
"""Return a unique, friendly identifier for this entity.""" """Return a unique, friendly identifier for this entity."""
if self._data is not None: if self._data is not None:
try:
return f"{self._data['sensor_id']}_{self.sensor_type}" return f"{self._data['sensor_id']}_{self.sensor_type}"
except KeyError:
return None
@property @property
def device_state_attributes(self): def device_state_attributes(self):
@ -93,7 +99,10 @@ class LuftdatenSensor(Entity):
self._attrs[ATTR_ATTRIBUTION] = DEFAULT_ATTRIBUTION self._attrs[ATTR_ATTRIBUTION] = DEFAULT_ATTRIBUTION
if self._data is not None: if self._data is not None:
try:
self._attrs[ATTR_SENSOR_ID] = self._data["sensor_id"] self._attrs[ATTR_SENSOR_ID] = self._data["sensor_id"]
except KeyError:
return None
on_map = ATTR_LATITUDE, ATTR_LONGITUDE on_map = ATTR_LATITUDE, ATTR_LONGITUDE
no_map = "lat", "long" no_map = "lat", "long"