mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
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>
This commit is contained in:
parent
8cd640867c
commit
a7a58b9eac
@ -4,7 +4,7 @@ from ipaddress import ip_address
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import broadlink as blk
|
import broadlink as blk
|
||||||
from broadlink.exceptions import BroadlinkException
|
from broadlink.exceptions import BroadlinkException, CommandNotSupportedError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.switch import DOMAIN, PLATFORM_SCHEMA, SwitchEntity
|
from homeassistant.components.switch import DOMAIN, PLATFORM_SCHEMA, SwitchEntity
|
||||||
@ -264,13 +264,19 @@ class BroadlinkSP2Switch(BroadlinkSP1Switch):
|
|||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Update the state of the device."""
|
"""Update the state of the device."""
|
||||||
try:
|
try:
|
||||||
state = await self.device.async_request(self.device.api.check_power)
|
self._state = await self.device.async_request(self.device.api.check_power)
|
||||||
load_power = await self.device.async_request(self.device.api.get_energy)
|
|
||||||
except BroadlinkException as err_msg:
|
except BroadlinkException as err_msg:
|
||||||
_LOGGER.error("Failed to update state: %s", err_msg)
|
_LOGGER.error("Failed to update state: %s", err_msg)
|
||||||
return
|
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):
|
class BroadlinkMP1Slot(BroadlinkRMSwitch):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user