Skip to content

Commit

Permalink
Use voluptuous for Edimax (#3178)
Browse files Browse the repository at this point in the history
🐬
  • Loading branch information
fabaff authored and Teagan42 committed Sep 5, 2016
1 parent 98bdcd3 commit 59cd92c
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions homeassistant/components/switch/edimax.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,40 @@
"""
import logging

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

from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA)
from homeassistant.const import (
CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME)
from homeassistant.helpers import validate_config
import homeassistant.helpers.config_validation as cv

# constants
DEFAULT_USERNAME = 'admin'
DEFAULT_PASSWORD = '1234'
DEVICE_DEFAULT_NAME = 'Edimax Smart Plug'
REQUIREMENTS = ['https://github.com/rkabadi/pyedimax/archive/'
'365301ce3ff26129a7910c501ead09ea625f3700.zip#pyedimax==0.1']

_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = 'Edimax Smart Plug'
DEFAULT_PASSWORD = '1234'
DEFAULT_USERNAME = 'admin'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_PASSWORD, default=DEFAULT_PASSWORD): cv.string,
vol.Optional(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string,
})


# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Find and return Edimax Smart Plugs."""
from pyedimax.smartplug import SmartPlug

# pylint: disable=global-statement
# check for required values in configuration file
if not validate_config({DOMAIN: config},
{DOMAIN: [CONF_HOST]},
_LOGGER):
return False

host = config.get(CONF_HOST)
auth = (config.get(CONF_USERNAME, DEFAULT_USERNAME),
config.get(CONF_PASSWORD, DEFAULT_PASSWORD))
name = config.get(CONF_NAME, DEVICE_DEFAULT_NAME)
auth = (config.get(CONF_USERNAME), config.get(CONF_PASSWORD))
name = config.get(CONF_NAME)

add_devices_callback([SmartPlugSwitch(SmartPlug(host, auth), name)])
add_devices([SmartPlugSwitch(SmartPlug(host, auth), name)])


class SmartPlugSwitch(SwitchDevice):
Expand Down

0 comments on commit 59cd92c

Please sign in to comment.