New Switch Platform: TPLink Switch (HS100 / HS110) (#2453)
* New Switch Platform: TPLink Switch (HS100 / HS110) ### Information The TPLink switch platform allows you to control the state of your TPLink Wi-Fi Smart Plugs. Supported devices (tested): HS100 (UK) It should also work with the HS110. To use your D-Link smart plugs in your installation, add the following to your configuration.yaml file: """ # Example configuration.yaml entry switch: platform: tplink host: IP_ADRRESS name: TPLink Switch """ ### Configuration variables: host (Required): The IP address of your TPlink plug, eg. http://192.168.1.105 name (Optional): The name to use when displaying this switch. * Update tplink.py Bug fixes * Separate to a standalone library * Removed unnecessary imports * Code cleanup and update reference library link * TPLink switch support (#2453) * updated requirements
This commit is contained in:
1 parent
344fb9c8b4
commit
609458052c
3 files changed
+57
No files matched your search
@@ -0,0 +1,53 @@
|
||||
"""Support for TPLink HS100/HS110 smart switch.
|
||||
|
||||
It is able to monitor current switch status, as well as turn on and off
|
||||
the switch. Will work with both HS100 and HS110 switch models.
|
||||
"""
|
||||
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
from homeassistant.const import (
|
||||
CONF_HOST, CONF_NAME)
|
||||
|
||||
# constants
|
||||
DEVICE_DEFAULT_NAME = 'HS100'
|
||||
REQUIREMENTS = ['https://github.com/gadgetreactor/pyHS100/archive/'
|
||||
'master.zip#pyHS100==0.1.2']
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
"""Setup the TPLink platform in configuration.yaml."""
|
||||
from pyHS100.pyHS100 import SmartPlug
|
||||
host = config.get(CONF_HOST)
|
||||
name = config.get(CONF_NAME, DEVICE_DEFAULT_NAME)
|
||||
|
||||
add_devices_callback([SmartPlugSwitch(SmartPlug(host),
|
||||
name)])
|
||||
|
||||
|
||||
class SmartPlugSwitch(SwitchDevice):
|
||||
"""Representation of a TPLink Smart Plug switch."""
|
||||
|
||||
def __init__(self, smartplug, name):
|
||||
"""Initialize the switch."""
|
||||
self.smartplug = smartplug
|
||||
self._name = name
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the Smart Plug, if any."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if switch is on."""
|
||||
return self.smartplug.state == 'ON'
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the switch on."""
|
||||
self.smartplug.state = 'ON'
|
||||
|
||||
def turn_off(self):
|
||||
"""Turn the switch off."""
|
||||
self.smartplug.state = 'OFF'
|
||||
Reference in new issue
Block a user