fix_broadlink_sp2_show_energy (#17271)
* fix_broadlink_sp2_show_energy Signed-off-by: 朱海涛 <zhumu.zht@alibaba-inc.com> * fix_broadlink_sp2_show_energy Signed-off-by: 朱海涛 <zhumu.zht@alibaba-inc.com> * fix_broadlink_sp2_show_energy Signed-off-by: 朱海涛 <zhumu.zht@alibaba-inc.com> * fix_broadlink_sp2_show_energy Signed-off-by: 朱海涛 <zhumu.zht@alibaba-inc.com> * fix_broadlink_sp2_show_energy Signed-off-by: 朱海涛 <zhumu.zht@alibaba-inc.com>
This commit is contained in:
parent
99c6622ee2
commit
c434ad6af5
1 changed files with 11 additions and 0 deletions
|
@ -260,6 +260,7 @@ class BroadlinkSP1Switch(BroadlinkRMSwitch):
|
|||
super().__init__(friendly_name, friendly_name, device, None, None)
|
||||
self._command_on = 1
|
||||
self._command_off = 0
|
||||
self._load_power = None
|
||||
|
||||
def _sendpacket(self, packet, retry=2):
|
||||
"""Send packet to device."""
|
||||
|
@ -288,6 +289,14 @@ class BroadlinkSP2Switch(BroadlinkSP1Switch):
|
|||
"""Return the polling state."""
|
||||
return True
|
||||
|
||||
@property
|
||||
def current_power_w(self):
|
||||
"""Return the current power usage in Watt."""
|
||||
try:
|
||||
return round(self._load_power, 2)
|
||||
except (ValueError, TypeError):
|
||||
return None
|
||||
|
||||
def update(self):
|
||||
"""Synchronize state with switch."""
|
||||
self._update()
|
||||
|
@ -296,6 +305,7 @@ class BroadlinkSP2Switch(BroadlinkSP1Switch):
|
|||
"""Update the state of the device."""
|
||||
try:
|
||||
state = self._device.check_power()
|
||||
load_power = self._device.get_energy()
|
||||
except (socket.timeout, ValueError) as error:
|
||||
if retry < 1:
|
||||
_LOGGER.error(error)
|
||||
|
@ -306,6 +316,7 @@ class BroadlinkSP2Switch(BroadlinkSP1Switch):
|
|||
if state is None and retry > 0:
|
||||
return self._update(retry-1)
|
||||
self._state = state
|
||||
self._load_power = load_power
|
||||
|
||||
|
||||
class BroadlinkMP1Slot(BroadlinkRMSwitch):
|
||||
|
|
Loading…
Add table
Reference in a new issue