2015-08-12 11:00:47 +00:00
|
|
|
"""
|
|
|
|
homeassistant.components.switch.verisure
|
2015-09-07 17:39:16 +00:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
Support for Verisure Smartplugs.
|
2015-11-09 12:12:18 +00:00
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
documentation at https://home-assistant.io/components/verisure/
|
2015-08-12 11:00:47 +00:00
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import homeassistant.components.verisure as verisure
|
|
|
|
from homeassistant.components.switch import SwitchDevice
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2015-09-07 17:39:16 +00:00
|
|
|
""" Sets up the Verisure platform. """
|
2015-08-12 11:00:47 +00:00
|
|
|
|
|
|
|
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()
|
2015-08-17 11:05:49 +00:00
|
|
|
if verisure.SHOW_SMARTPLUGS
|
2015-08-12 11:00:47 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
add_devices(switches)
|
|
|
|
|
|
|
|
|
|
|
|
class VerisureSmartplug(SwitchDevice):
|
|
|
|
""" Represents a Verisure smartplug. """
|
|
|
|
def __init__(self, smartplug_status):
|
|
|
|
self._id = smartplug_status.id
|
2015-08-16 06:03:19 +00:00
|
|
|
self.status_on = verisure.MY_PAGES.SMARTPLUG_ON
|
2015-08-16 04:51:09 +00:00
|
|
|
self.status_off = verisure.MY_PAGES.SMARTPLUG_OFF
|
2015-08-12 11:00:47 +00:00
|
|
|
|
|
|
|
@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
|
2015-08-16 06:03:19 +00:00
|
|
|
return plug_status == self.status_on
|
2015-08-12 11:00:47 +00:00
|
|
|
|
|
|
|
def turn_on(self):
|
2015-09-07 17:39:16 +00:00
|
|
|
""" Set smartplug status on. """
|
2015-08-12 11:00:47 +00:00
|
|
|
verisure.MY_PAGES.set_smartplug_status(
|
|
|
|
self._id,
|
2015-08-16 04:51:09 +00:00
|
|
|
self.status_on)
|
2015-08-12 11:00:47 +00:00
|
|
|
|
|
|
|
def turn_off(self):
|
2015-09-07 17:39:16 +00:00
|
|
|
""" Set smartplug status off. """
|
2015-08-12 11:00:47 +00:00
|
|
|
verisure.MY_PAGES.set_smartplug_status(
|
|
|
|
self._id,
|
2015-08-16 04:51:09 +00:00
|
|
|
self.status_off)
|
2015-08-15 11:36:30 +00:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
verisure.update()
|