Prevent vesync doing I/O in event loop (#13862)
This commit is contained in:
parent
80a3220b88
commit
ee6acadae2
1 changed files with 6 additions and 2 deletions
|
@ -60,6 +60,8 @@ class VeSyncSwitchHA(SwitchDevice):
|
||||||
def __init__(self, plug):
|
def __init__(self, plug):
|
||||||
"""Initialize the VeSync switch device."""
|
"""Initialize the VeSync switch device."""
|
||||||
self.smartplug = plug
|
self.smartplug = plug
|
||||||
|
self._current_power_w = None
|
||||||
|
self._today_energy_kwh = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
|
@ -74,12 +76,12 @@ class VeSyncSwitchHA(SwitchDevice):
|
||||||
@property
|
@property
|
||||||
def current_power_w(self):
|
def current_power_w(self):
|
||||||
"""Return the current power usage in W."""
|
"""Return the current power usage in W."""
|
||||||
return self.smartplug.get_power()
|
return self._current_power_w
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def today_energy_kwh(self):
|
def today_energy_kwh(self):
|
||||||
"""Return the today total energy usage in kWh."""
|
"""Return the today total energy usage in kWh."""
|
||||||
return self.smartplug.get_kwh_today()
|
return self._today_energy_kwh
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
|
@ -102,3 +104,5 @@ class VeSyncSwitchHA(SwitchDevice):
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Handle data changes for node values."""
|
"""Handle data changes for node values."""
|
||||||
self.smartplug.update()
|
self.smartplug.update()
|
||||||
|
self._current_power_w = self.smartplug.get_power()
|
||||||
|
self._today_energy_kwh = self.smartplug.get_kwh_today()
|
||||||
|
|
Loading…
Add table
Reference in a new issue