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

Use voluptuous for Edimax #3178

Merged
merged 2 commits into from
Sep 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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