Skip to content

Commit

Permalink
Merge pull request home-assistant#622 from happyleavesaoc/s20
Browse files Browse the repository at this point in the history
s20 switch support
  • Loading branch information
balloob committed Nov 15, 2015
2 parents 88f3a5a + 12bdc39 commit e3efce5
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ omit =
homeassistant/components/sensor/glances.py
homeassistant/components/sensor/mysensors.py
homeassistant/components/sensor/openweathermap.py
homeassistant/components/switch/orvibo.py
homeassistant/components/sensor/rest.py
homeassistant/components/sensor/rpi_gpio.py
homeassistant/components/sensor/sabnzbd.py
Expand Down
75 changes: 75 additions & 0 deletions homeassistant/components/switch/orvibo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""
homeassistant.components.switch.orvibo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Orvibo S20 Wifi Smart Switches.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.s20/
"""
import logging

from homeassistant.components.switch import SwitchDevice

from orvibo.s20 import S20, S20Exception

DEFAULT_NAME = "Orvibo S20 Switch"
REQUIREMENTS = ['orvibo==1.0.0']
_LOGGER = logging.getLogger(__name__)


# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Find and return S20 switches. """
if config.get('host') is None:
_LOGGER.error("Missing required variable: host")
return
try:
s20 = S20(config.get('host'))
add_devices_callback([S20Switch(config.get('name', DEFAULT_NAME),
s20)])
except S20Exception:
_LOGGER.exception("S20 couldn't be initialized")


class S20Switch(SwitchDevice):
""" Represents an S20 switch. """
def __init__(self, name, s20):
self._name = name
self._s20 = s20
self._state = False

@property
def should_poll(self):
""" Poll. """
return True

@property
def name(self):
""" The name of the switch. """
return self._name

@property
def is_on(self):
""" True if device is on. """
return self._state

def update(self):
""" Update device state. """
try:
self._state = self._s20.on
except S20Exception:
_LOGGER.exception("Error while fetching S20 state")

def turn_on(self, **kwargs):
""" Turn the device on. """
try:
self._s20.on = True
except S20Exception:
_LOGGER.exception("Error while turning on S20")

def turn_off(self, **kwargs):
""" Turn the device off. """
try:
self._s20.on = False
except S20Exception:
_LOGGER.exception("Error while turning off S20")
3 changes: 3 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,6 @@ evohomeclient==0.2.3

# Pushetta (notify.pushetta)
pushetta==1.0.15

# Orvibo S10
orvibo==1.0.0

0 comments on commit e3efce5

Please sign in to comment.