mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
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
@ -260,6 +260,7 @@ class BroadlinkSP1Switch(BroadlinkRMSwitch):
|
|||||||
super().__init__(friendly_name, friendly_name, device, None, None)
|
super().__init__(friendly_name, friendly_name, device, None, None)
|
||||||
self._command_on = 1
|
self._command_on = 1
|
||||||
self._command_off = 0
|
self._command_off = 0
|
||||||
|
self._load_power = None
|
||||||
|
|
||||||
def _sendpacket(self, packet, retry=2):
|
def _sendpacket(self, packet, retry=2):
|
||||||
"""Send packet to device."""
|
"""Send packet to device."""
|
||||||
@ -288,6 +289,14 @@ class BroadlinkSP2Switch(BroadlinkSP1Switch):
|
|||||||
"""Return the polling state."""
|
"""Return the polling state."""
|
||||||
return True
|
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):
|
def update(self):
|
||||||
"""Synchronize state with switch."""
|
"""Synchronize state with switch."""
|
||||||
self._update()
|
self._update()
|
||||||
@ -296,6 +305,7 @@ class BroadlinkSP2Switch(BroadlinkSP1Switch):
|
|||||||
"""Update the state of the device."""
|
"""Update the state of the device."""
|
||||||
try:
|
try:
|
||||||
state = self._device.check_power()
|
state = self._device.check_power()
|
||||||
|
load_power = self._device.get_energy()
|
||||||
except (socket.timeout, ValueError) as error:
|
except (socket.timeout, ValueError) as error:
|
||||||
if retry < 1:
|
if retry < 1:
|
||||||
_LOGGER.error(error)
|
_LOGGER.error(error)
|
||||||
@ -306,6 +316,7 @@ class BroadlinkSP2Switch(BroadlinkSP1Switch):
|
|||||||
if state is None and retry > 0:
|
if state is None and retry > 0:
|
||||||
return self._update(retry-1)
|
return self._update(retry-1)
|
||||||
self._state = state
|
self._state = state
|
||||||
|
self._load_power = load_power
|
||||||
|
|
||||||
|
|
||||||
class BroadlinkMP1Slot(BroadlinkRMSwitch):
|
class BroadlinkMP1Slot(BroadlinkRMSwitch):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user