mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
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
This commit is contained in:
parent
e30510a688
commit
33f3e72dda
@ -48,7 +48,6 @@ class SpiderThermostat(ClimateDevice):
|
|||||||
"""Initialize the thermostat."""
|
"""Initialize the thermostat."""
|
||||||
self.api = api
|
self.api = api
|
||||||
self.thermostat = thermostat
|
self.thermostat = thermostat
|
||||||
self.master = self.thermostat.has_operation_mode
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
@ -125,16 +124,4 @@ class SpiderThermostat(ClimateDevice):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data."""
|
"""Get the latest data."""
|
||||||
try:
|
self.thermostat = self.api.get_thermostat(self.unique_id)
|
||||||
# Only let the master thermostat refresh
|
|
||||||
# and let the others use the cache
|
|
||||||
thermostats = self.api.get_thermostats(
|
|
||||||
force_refresh=self.master)
|
|
||||||
for thermostat in thermostats:
|
|
||||||
if thermostat.id == self.unique_id:
|
|
||||||
self.thermostat = thermostat
|
|
||||||
break
|
|
||||||
|
|
||||||
except StopIteration:
|
|
||||||
_LOGGER.error("No data from the Spider API")
|
|
||||||
return
|
|
||||||
|
@ -4,28 +4,35 @@ Support for Spider Smart devices.
|
|||||||
For more details about this component, please refer to the documentation at
|
For more details about this component, please refer to the documentation at
|
||||||
https://home-assistant.io/components/spider/
|
https://home-assistant.io/components/spider/
|
||||||
"""
|
"""
|
||||||
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import (
|
||||||
|
CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.discovery import load_platform
|
from homeassistant.helpers.discovery import load_platform
|
||||||
|
|
||||||
REQUIREMENTS = ['spiderpy==1.0.7']
|
REQUIREMENTS = ['spiderpy==1.1.0']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DOMAIN = 'spider'
|
DOMAIN = 'spider'
|
||||||
|
|
||||||
SPIDER_COMPONENTS = [
|
SPIDER_COMPONENTS = [
|
||||||
'climate'
|
'climate',
|
||||||
|
'switch'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
SCAN_INTERVAL = timedelta(seconds=120)
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
DOMAIN: vol.Schema({
|
DOMAIN: vol.Schema({
|
||||||
vol.Required(CONF_PASSWORD): cv.string,
|
vol.Required(CONF_PASSWORD): cv.string,
|
||||||
vol.Required(CONF_USERNAME): cv.string,
|
vol.Required(CONF_USERNAME): cv.string,
|
||||||
|
vol.Optional(CONF_SCAN_INTERVAL, default=SCAN_INTERVAL):
|
||||||
|
cv.time_period,
|
||||||
})
|
})
|
||||||
}, extra=vol.ALLOW_EXTRA)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
@ -37,13 +44,15 @@ def setup(hass, config):
|
|||||||
|
|
||||||
username = config[DOMAIN][CONF_USERNAME]
|
username = config[DOMAIN][CONF_USERNAME]
|
||||||
password = config[DOMAIN][CONF_PASSWORD]
|
password = config[DOMAIN][CONF_PASSWORD]
|
||||||
|
refresh_rate = config[DOMAIN][CONF_SCAN_INTERVAL]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
api = SpiderApi(username, password)
|
api = SpiderApi(username, password, refresh_rate.total_seconds())
|
||||||
|
|
||||||
hass.data[DOMAIN] = {
|
hass.data[DOMAIN] = {
|
||||||
'controller': api,
|
'controller': api,
|
||||||
'thermostats': api.get_thermostats()
|
'thermostats': api.get_thermostats(),
|
||||||
|
'power_plugs': api.get_power_plugs()
|
||||||
}
|
}
|
||||||
|
|
||||||
for component in SPIDER_COMPONENTS:
|
for component in SPIDER_COMPONENTS:
|
||||||
|
77
homeassistant/components/switch/spider.py
Normal file
77
homeassistant/components/switch/spider.py
Normal file
@ -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)
|
@ -1282,7 +1282,7 @@ somecomfort==0.5.2
|
|||||||
speedtest-cli==2.0.2
|
speedtest-cli==2.0.2
|
||||||
|
|
||||||
# homeassistant.components.spider
|
# homeassistant.components.spider
|
||||||
spiderpy==1.0.7
|
spiderpy==1.1.0
|
||||||
|
|
||||||
# homeassistant.components.sensor.spotcrime
|
# homeassistant.components.sensor.spotcrime
|
||||||
spotcrime==1.0.3
|
spotcrime==1.0.3
|
||||||
|
Loading…
x
Reference in New Issue
Block a user