68 lines
1.6 KiB
Python
68 lines
1.6 KiB
Python
|
"""
|
||
|
homeassistant.components.switch.verisure
|
||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||
|
Support for Verisure Smartplugs
|
||
|
|
||
|
Configuration:
|
||
|
|
||
|
switch:
|
||
|
platform: verisure
|
||
|
|
||
|
Variables:
|
||
|
|
||
|
"""
|
||
|
import logging
|
||
|
|
||
|
import homeassistant.components.verisure as verisure
|
||
|
from homeassistant.components.switch import SwitchDevice
|
||
|
|
||
|
DEPENDENCIES = ['verisure']
|
||
|
|
||
|
_LOGGER = logging.getLogger(__name__)
|
||
|
|
||
|
|
||
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||
|
""" Sets up the Arduino platform. """
|
||
|
|
||
|
if not verisure.MY_PAGES:
|
||
|
_LOGGER.error('A connection has not been made to Verisure mypages.')
|
||
|
return False
|
||
|
|
||
|
switches = []
|
||
|
|
||
|
switches.extend([
|
||
|
VerisureSmartplug(value)
|
||
|
for value in verisure.get_smartplug_status().values()
|
||
|
])
|
||
|
|
||
|
add_devices(switches)
|
||
|
|
||
|
|
||
|
class VerisureSmartplug(SwitchDevice):
|
||
|
""" Represents a Verisure smartplug. """
|
||
|
def __init__(self, smartplug_status):
|
||
|
self._id = smartplug_status.id
|
||
|
|
||
|
@property
|
||
|
def name(self):
|
||
|
""" Get the name (location) of the smartplug. """
|
||
|
return verisure.get_smartplug_status()[self._id].location
|
||
|
|
||
|
@property
|
||
|
def is_on(self):
|
||
|
""" Returns True if on """
|
||
|
plug_status = verisure.get_smartplug_status()[self._id].status
|
||
|
return plug_status == verisure.MY_PAGES.SMARTPLUG_ON
|
||
|
|
||
|
def turn_on(self):
|
||
|
""" Set smartplug status on """
|
||
|
verisure.MY_PAGES.set_smartplug_status(
|
||
|
self._id,
|
||
|
verisure.MY_PAGES.SMARTPLUG_ON)
|
||
|
|
||
|
def turn_off(self):
|
||
|
""" Set smartplug status off. """
|
||
|
verisure.MY_PAGES.set_smartplug_status(
|
||
|
self._id,
|
||
|
verisure.MY_PAGES.SMARTPLUG_OFF)
|