Use contextlib.suppress where possible (#48189)
This commit is contained in:
parent
9656f260a4
commit
6932cf9534
86 changed files with 238 additions and 398 deletions
|
@ -1,4 +1,6 @@
|
|||
"""Support for Fibaro sensors."""
|
||||
from contextlib import suppress
|
||||
|
||||
from homeassistant.components.sensor import DOMAIN, SensorEntity
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
|
@ -71,7 +73,7 @@ class FibaroSensor(FibaroDevice, SensorEntity):
|
|||
self._unit = None
|
||||
self._icon = None
|
||||
self._device_class = None
|
||||
try:
|
||||
with suppress(KeyError, ValueError):
|
||||
if not self._unit:
|
||||
if self.fibaro_device.properties.unit == "lux":
|
||||
self._unit = LIGHT_LUX
|
||||
|
@ -81,8 +83,6 @@ class FibaroSensor(FibaroDevice, SensorEntity):
|
|||
self._unit = TEMP_FAHRENHEIT
|
||||
else:
|
||||
self._unit = self.fibaro_device.properties.unit
|
||||
except (KeyError, ValueError):
|
||||
pass
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
@ -106,7 +106,5 @@ class FibaroSensor(FibaroDevice, SensorEntity):
|
|||
|
||||
def update(self):
|
||||
"""Update the state."""
|
||||
try:
|
||||
with suppress(KeyError, ValueError):
|
||||
self.current_value = float(self.fibaro_device.properties.value)
|
||||
except (KeyError, ValueError):
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue