mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
- Added for smartplug
- Added error check for host param in config.yaml - Fixed SmartPlugSwitch is_on method - Edimax smartplug works now!
This commit is contained in:
parent
6631ebfdfa
commit
fac194f66c
@ -7,7 +7,7 @@ Support for Edimax switches.
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchDevice
|
from homeassistant.components.switch import SwitchDevice
|
||||||
|
from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD
|
||||||
|
|
||||||
# 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_callback, discovery_info=None):
|
||||||
@ -23,14 +23,16 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
host = config.get(CONF_HOST)
|
||||||
|
auth=(config.get(CONF_USERNAME, 'admin'),
|
||||||
|
config.get(CONF_PASSWORD, '1234'))
|
||||||
|
|
||||||
add_devices_callback([
|
if not host:
|
||||||
SmartPlugSwitch(SmartPlug(
|
logging.getLogger(__name__).error('Missing config variable %s', CONF_HOST)
|
||||||
host = config.get('host'),
|
return False
|
||||||
auth=(
|
|
||||||
config.get('user', 'admin'),
|
|
||||||
config.get('password', '1234'))))
|
add_devices_callback([SmartPlugSwitch(SmartPlug(host, auth))])
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
class SmartPlugSwitch(SwitchDevice):
|
class SmartPlugSwitch(SwitchDevice):
|
||||||
@ -38,10 +40,16 @@ class SmartPlugSwitch(SwitchDevice):
|
|||||||
def __init__(self, smartplug):
|
def __init__(self, smartplug):
|
||||||
self.smartplug = smartplug
|
self.smartplug = smartplug
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
""" Returns the name of the Smart Plug, if any. """
|
||||||
|
#TODO: dynamically get name from device using requests
|
||||||
|
return 'Edimax Smart Plug'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
""" True if switch is on. """
|
""" True if switch is on. """
|
||||||
return self.smartplug.get_state()
|
return self.smartplug.state == 'ON'
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
""" Turns the switch on. """
|
""" Turns the switch on. """
|
||||||
|
Loading…
x
Reference in New Issue
Block a user