-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add spider power plug component (#15682)
* Add spider power plug component * rounding down the numbers * ability to throttle the API * updated to the lastest api * resolved an issue within the API
- Loading branch information
1 parent
e30510a
commit 33f3e72
Showing
4 changed files
with
93 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
""" | ||
Support for Spider switches. | ||
For more details about this platform, please refer to the documentation at | ||
https://home-assistant.io/components/switch.spider/ | ||
""" | ||
|
||
import logging | ||
|
||
from homeassistant.components.spider import DOMAIN as SPIDER_DOMAIN | ||
from homeassistant.components.switch import SwitchDevice | ||
|
||
DEPENDENCIES = ['spider'] | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def setup_platform(hass, config, add_devices, discovery_info=None): | ||
"""Set up the Spider thermostat.""" | ||
if discovery_info is None: | ||
return | ||
|
||
devices = [SpiderPowerPlug(hass.data[SPIDER_DOMAIN]['controller'], device) | ||
for device in hass.data[SPIDER_DOMAIN]['power_plugs']] | ||
|
||
add_devices(devices, True) | ||
|
||
|
||
class SpiderPowerPlug(SwitchDevice): | ||
"""Representation of a Spider Power Plug.""" | ||
|
||
def __init__(self, api, power_plug): | ||
"""Initialize the Vera device.""" | ||
self.api = api | ||
self.power_plug = power_plug | ||
|
||
@property | ||
def unique_id(self): | ||
"""Return the ID of this switch.""" | ||
return self.power_plug.id | ||
|
||
@property | ||
def name(self): | ||
"""Return the name of the switch if any.""" | ||
return self.power_plug.name | ||
|
||
@property | ||
def current_power_w(self): | ||
"""Return the current power usage in W.""" | ||
return round(self.power_plug.current_energy_consumption) | ||
|
||
@property | ||
def today_energy_kwh(self): | ||
"""Return the current power usage in Kwh.""" | ||
return round(self.power_plug.today_energy_consumption / 1000, 2) | ||
|
||
@property | ||
def is_on(self): | ||
"""Return true if switch is on. Standby is on.""" | ||
return self.power_plug.is_on | ||
|
||
@property | ||
def available(self): | ||
"""Return true if switch is available.""" | ||
return self.power_plug.is_available | ||
|
||
def turn_on(self, **kwargs): | ||
"""Turn device on.""" | ||
self.power_plug.turn_on() | ||
|
||
def turn_off(self, **kwargs): | ||
"""Turn device off.""" | ||
self.power_plug.turn_off() | ||
|
||
def update(self): | ||
"""Get the latest data.""" | ||
self.power_plug = self.api.get_power_plug(self.unique_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters