Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

orvibo updates #3006

Merged
merged 2 commits into from
Sep 2, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 36 additions & 14 deletions homeassistant/components/switch/orvibo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,62 @@
"""
import logging

from homeassistant.components.switch import SwitchDevice
import voluptuous as vol

from homeassistant.components.switch import SwitchDevice, PLATFORM_SCHEMA
import homeassistant.helpers.config_validation as cv

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

CONF_SWITCHES = 'switches'
CONF_HOST = 'host'
CONF_NAME = 'name'
CONF_MAC = 'mac'
CONF_DISCOVERY = 'discovery'
DEFAULT_NAME = "Orvibo S20 Switch"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixing ' and "

DEFAULT_DISCOVERY = True

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_DISCOVERY, default=DEFAULT_DISCOVERY): cv.boolean,
vol.Required(CONF_SWITCHES, default=[]):
vol.All(cv.ensure_list, [{
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_MAC): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string
}])
})


# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Find and return S20 switches."""
from orvibo.s20 import S20, S20Exception
from orvibo.s20 import discover, S20, S20Exception

switch_data = {}
switches = []
switch_conf = config.get('switches', [config])
switch_conf = config.get(CONF_SWITCHES, [config])

if config.get(CONF_DISCOVERY):
_LOGGER.info("Discovering S20 switches ...")
switch_data.update(discover())

for switch in switch_conf:
if switch.get('host') is None:
_LOGGER.error("Missing required variable: host")
continue
host = switch.get('host')
mac = switch.get('mac')
switch_data[switch.get(CONF_HOST)] = switch

for host, data in switch_data.items():
try:
switches.append(S20Switch(switch.get('name', DEFAULT_NAME),
S20(host, mac=mac)))
switches.append(S20Switch(data.get(CONF_NAME, DEFAULT_NAME),
S20(host, mac=data.get(CONF_MAC))))
_LOGGER.info("Initialized S20 at %s", host)
except S20Exception:
_LOGGER.exception("S20 at %s couldn't be initialized",
host)
_LOGGER.error("S20 at %s couldn't be initialized", host)

add_devices_callback(switches)


class S20Switch(SwitchDevice):
"""Representsation of an S20 switch."""
"""Representation of an S20 switch."""

def __init__(self, name, s20):
"""Initialize the S20 device."""
Expand Down