mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 15:57:06 +00:00
Luftdaten traceback (#19666)
* Suppress traceback if there is not connection available * Remove line break
This commit is contained in:
parent
ff80fc347b
commit
7c302bfd7e
@ -37,8 +37,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
sensors.append(
|
sensors.append(
|
||||||
LuftdatenSensor(
|
LuftdatenSensor(
|
||||||
luftdaten, sensor_type, name, icon, unit,
|
luftdaten, sensor_type, name, icon, unit,
|
||||||
entry.data[CONF_SHOW_ON_MAP])
|
entry.data[CONF_SHOW_ON_MAP]))
|
||||||
)
|
|
||||||
|
|
||||||
async_add_entities(sensors, True)
|
async_add_entities(sensors, True)
|
||||||
|
|
||||||
@ -67,7 +66,8 @@ class LuftdatenSensor(Entity):
|
|||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self._data[self.sensor_type]
|
if self._data is not None:
|
||||||
|
return self._data[self.sensor_type]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
@ -82,23 +82,26 @@ class LuftdatenSensor(Entity):
|
|||||||
@property
|
@property
|
||||||
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."""
|
||||||
return '{0}_{1}'.format(self._data['sensor_id'], self.sensor_type)
|
if self._data is not None:
|
||||||
|
return '{0}_{1}'.format(self._data['sensor_id'], self.sensor_type)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
self._attrs[ATTR_SENSOR_ID] = self._data['sensor_id']
|
|
||||||
self._attrs[ATTR_ATTRIBUTION] = DEFAULT_ATTRIBUTION
|
self._attrs[ATTR_ATTRIBUTION] = DEFAULT_ATTRIBUTION
|
||||||
|
|
||||||
on_map = ATTR_LATITUDE, ATTR_LONGITUDE
|
if self._data is not None:
|
||||||
no_map = 'lat', 'long'
|
self._attrs[ATTR_SENSOR_ID] = self._data['sensor_id']
|
||||||
lat_format, lon_format = on_map if self._show_on_map else no_map
|
|
||||||
try:
|
on_map = ATTR_LATITUDE, ATTR_LONGITUDE
|
||||||
self._attrs[lon_format] = self._data['longitude']
|
no_map = 'lat', 'long'
|
||||||
self._attrs[lat_format] = self._data['latitude']
|
lat_format, lon_format = on_map if self._show_on_map else no_map
|
||||||
return self._attrs
|
try:
|
||||||
except KeyError:
|
self._attrs[lon_format] = self._data['longitude']
|
||||||
return
|
self._attrs[lat_format] = self._data['latitude']
|
||||||
|
return self._attrs
|
||||||
|
except KeyError:
|
||||||
|
return
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Register callbacks."""
|
"""Register callbacks."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user