Use contextlib.suppress where possible (#48189)

This commit is contained in:
Franck Nijhof 2021-03-23 14:36:43 +01:00 committed by GitHub
parent 9656f260a4
commit 6932cf9534
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
86 changed files with 238 additions and 398 deletions

View file

@ -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