mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Prevent edimax from doing I/O in event loop (#4584)
This commit is contained in:
parent
32ffd006fa
commit
03e0c7c71c
@ -49,6 +49,9 @@ class SmartPlugSwitch(SwitchDevice):
|
|||||||
"""Initialize the switch."""
|
"""Initialize the switch."""
|
||||||
self.smartplug = smartplug
|
self.smartplug = smartplug
|
||||||
self._name = name
|
self._name = name
|
||||||
|
self._now_power = None
|
||||||
|
self._now_energy_day = None
|
||||||
|
self._state = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -58,27 +61,17 @@ class SmartPlugSwitch(SwitchDevice):
|
|||||||
@property
|
@property
|
||||||
def current_power_mwh(self):
|
def current_power_mwh(self):
|
||||||
"""Return the current power usage in mWh."""
|
"""Return the current power usage in mWh."""
|
||||||
try:
|
return self._now_power
|
||||||
return float(self.smartplug.now_power) / 1000000.0
|
|
||||||
except ValueError:
|
|
||||||
return None
|
|
||||||
except TypeError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def today_power_mw(self):
|
def today_power_mw(self):
|
||||||
"""Return the today total power usage in mW."""
|
"""Return the today total power usage in mW."""
|
||||||
try:
|
return self._now_energy_day
|
||||||
return float(self.smartplug.now_energy_day) / 1000.0
|
|
||||||
except ValueError:
|
|
||||||
return None
|
|
||||||
except TypeError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if switch is on."""
|
"""Return true if switch is on."""
|
||||||
return self.smartplug.state == 'ON'
|
return self._state
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
"""Turn the switch on."""
|
"""Turn the switch on."""
|
||||||
@ -87,3 +80,18 @@ class SmartPlugSwitch(SwitchDevice):
|
|||||||
def turn_off(self):
|
def turn_off(self):
|
||||||
"""Turn the switch off."""
|
"""Turn the switch off."""
|
||||||
self.smartplug.state = 'OFF'
|
self.smartplug.state = 'OFF'
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
"""Update edimax switch."""
|
||||||
|
try:
|
||||||
|
self._now_power = float(self.smartplug.now_power) / 1000000.0
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
self._now_power = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
self._now_energy_day = (float(self.smartplug.now_energy_day) /
|
||||||
|
1000.0)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
self._now_energy_day = None
|
||||||
|
|
||||||
|
self._state = self.smartplug.state == 'ON'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user