mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Migrate to voluptuous (#2907)
This commit is contained in:
parent
3fae4fefbf
commit
502c65ca32
@ -6,42 +6,41 @@ https://home-assistant.io/components/switch.dlink/
|
|||||||
"""
|
"""
|
||||||
import logging
|
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 (
|
from homeassistant.const import (
|
||||||
CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME)
|
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 = ''
|
|
||||||
DEVICE_DEFAULT_NAME = 'D-link Smart Plug W215'
|
|
||||||
REQUIREMENTS = ['https://github.com/LinuxChristian/pyW215/archive/'
|
REQUIREMENTS = ['https://github.com/LinuxChristian/pyW215/archive/'
|
||||||
'v0.1.1.zip#pyW215==0.1.1']
|
'v0.1.1.zip#pyW215==0.1.1']
|
||||||
|
|
||||||
# setup logger
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DEFAULT_NAME = 'D-link Smart Plug W215'
|
||||||
|
DEFAULT_PASSWORD = ''
|
||||||
|
DEFAULT_USERNAME = 'admin'
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_HOST): cv.string,
|
||||||
|
vol.Required(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string,
|
||||||
|
vol.Required(CONF_PASSWORD, default=DEFAULT_PASSWORD): cv.string,
|
||||||
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# 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 D-Link Smart Plugs."""
|
"""Setup a D-Link Smart Plug."""
|
||||||
from pyW215.pyW215 import SmartPlug
|
from pyW215.pyW215 import SmartPlug
|
||||||
|
|
||||||
# check for required values in configuration file
|
|
||||||
if not validate_config({DOMAIN: config},
|
|
||||||
{DOMAIN: [CONF_HOST]},
|
|
||||||
_LOGGER):
|
|
||||||
return False
|
|
||||||
|
|
||||||
host = config.get(CONF_HOST)
|
host = config.get(CONF_HOST)
|
||||||
username = config.get(CONF_USERNAME, DEFAULT_USERNAME)
|
username = config.get(CONF_USERNAME)
|
||||||
password = str(config.get(CONF_PASSWORD, DEFAULT_PASSWORD))
|
password = config.get(CONF_PASSWORD)
|
||||||
name = config.get(CONF_NAME, DEVICE_DEFAULT_NAME)
|
name = config.get(CONF_NAME)
|
||||||
|
|
||||||
add_devices_callback([SmartPlugSwitch(SmartPlug(host,
|
add_devices([SmartPlugSwitch(SmartPlug(host, password, username), name)])
|
||||||
password,
|
|
||||||
username),
|
|
||||||
name)])
|
|
||||||
|
|
||||||
|
|
||||||
class SmartPlugSwitch(SwitchDevice):
|
class SmartPlugSwitch(SwitchDevice):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user