Fix SP2-CL (0x7544) sensor update (#36242)

* Fix SP2-CL (0x7544) sensor update

This device does not support get_energy(). We need to ignore the CommandNotSupportedError in the update method.

* Format with Black

* Only wrap code that throws with catch

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
pull/36442/head
Felipe Martins Diel 2020-06-02 23:44:45 -03:00 committed by GitHub
parent 8cd640867c
commit a7a58b9eac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 5 deletions

View File

@ -4,7 +4,7 @@ from ipaddress import ip_address
import logging
import broadlink as blk
from broadlink.exceptions import BroadlinkException
from broadlink.exceptions import BroadlinkException, CommandNotSupportedError
import voluptuous as vol
from homeassistant.components.switch import DOMAIN, PLATFORM_SCHEMA, SwitchEntity
@ -264,13 +264,19 @@ class BroadlinkSP2Switch(BroadlinkSP1Switch):
async def async_update(self):
"""Update the state of the device."""
try:
state = await self.device.async_request(self.device.api.check_power)
load_power = await self.device.async_request(self.device.api.get_energy)
self._state = await self.device.async_request(self.device.api.check_power)
except BroadlinkException as err_msg:
_LOGGER.error("Failed to update state: %s", err_msg)
return
self._state = state
self._load_power = load_power
try:
self._load_power = await self.device.async_request(
self.device.api.get_energy
)
except CommandNotSupportedError:
return
except BroadlinkException as err_msg:
_LOGGER.error("Failed to update load power: %s", err_msg)
class BroadlinkMP1Slot(BroadlinkRMSwitch):