mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Fix Luftdaten.info data retrieval (#43471)
Fix Luftdaten.info data retrieval
This commit is contained in:
parent
db0dee1ab2
commit
f22f568169
@ -198,8 +198,9 @@ class LuftDatenData:
|
||||
try:
|
||||
await self.client.get_data()
|
||||
|
||||
self.data[DATA_LUFTDATEN] = self.client.values
|
||||
self.data[DATA_LUFTDATEN].update(self.client.meta)
|
||||
if self.client.values:
|
||||
self.data[DATA_LUFTDATEN] = self.client.values
|
||||
self.data[DATA_LUFTDATEN].update(self.client.meta)
|
||||
|
||||
except LuftdatenError:
|
||||
_LOGGER.error("Unable to retrieve data from luftdaten.info")
|
||||
|
@ -69,7 +69,10 @@ class LuftdatenSensor(Entity):
|
||||
def state(self):
|
||||
"""Return the state of the device."""
|
||||
if self._data is not None:
|
||||
return self._data[self.sensor_type]
|
||||
try:
|
||||
return self._data[self.sensor_type]
|
||||
except KeyError:
|
||||
return None
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
@ -85,7 +88,10 @@ class LuftdatenSensor(Entity):
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique, friendly identifier for this entity."""
|
||||
if self._data is not None:
|
||||
return f"{self._data['sensor_id']}_{self.sensor_type}"
|
||||
try:
|
||||
return f"{self._data['sensor_id']}_{self.sensor_type}"
|
||||
except KeyError:
|
||||
return None
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
@ -93,7 +99,10 @@ class LuftdatenSensor(Entity):
|
||||
self._attrs[ATTR_ATTRIBUTION] = DEFAULT_ATTRIBUTION
|
||||
|
||||
if self._data is not None:
|
||||
self._attrs[ATTR_SENSOR_ID] = self._data["sensor_id"]
|
||||
try:
|
||||
self._attrs[ATTR_SENSOR_ID] = self._data["sensor_id"]
|
||||
except KeyError:
|
||||
return None
|
||||
|
||||
on_map = ATTR_LATITUDE, ATTR_LONGITUDE
|
||||
no_map = "lat", "long"
|
||||
|
Loading…
x
Reference in New Issue
Block a user