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,5 +1,6 @@
|
|||
"""Support for TPLink HS100/HS110/HS200 smart switch."""
|
||||
import asyncio
|
||||
from contextlib import suppress
|
||||
import logging
|
||||
import time
|
||||
|
||||
|
@ -151,13 +152,10 @@ class SmartPlugSwitch(SwitchEntity):
|
|||
)
|
||||
|
||||
emeter_statics = self.smartplug.get_emeter_daily()
|
||||
try:
|
||||
with suppress(KeyError): # Device returned no daily history
|
||||
self._emeter_params[ATTR_TODAY_ENERGY_KWH] = "{:.3f}".format(
|
||||
emeter_statics[int(time.strftime("%e"))]
|
||||
)
|
||||
except KeyError:
|
||||
# Device returned no daily history
|
||||
pass
|
||||
return True
|
||||
except (SmartDeviceException, OSError) as ex:
|
||||
if update_attempt == 0:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue