Skip to content

Commit

Permalink
Allow disabling the LEDs on TP-Link smart plugs (#10980)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanNixon authored and fabaff committed Dec 6, 2017
1 parent 1db7e2c commit 5f4baa6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions homeassistant/components/switch/tplink.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
ATTR_DAILY_CONSUMPTION = 'daily_consumption'
ATTR_CURRENT = 'current'

CONF_LEDS = 'enable_leds'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_LEDS, default=True): cv.boolean,
})


Expand All @@ -34,17 +37,19 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
from pyHS100 import SmartPlug
host = config.get(CONF_HOST)
name = config.get(CONF_NAME)
leds_on = config.get(CONF_LEDS)

add_devices([SmartPlugSwitch(SmartPlug(host), name)], True)
add_devices([SmartPlugSwitch(SmartPlug(host), name, leds_on)], True)


class SmartPlugSwitch(SwitchDevice):
"""Representation of a TPLink Smart Plug switch."""

def __init__(self, smartplug, name):
def __init__(self, smartplug, name, leds_on):
"""Initialize the switch."""
self.smartplug = smartplug
self._name = name
self._leds_on = leds_on
self._state = None
self._available = True
# Set up emeter cache
Expand Down Expand Up @@ -89,6 +94,8 @@ def update(self):
if self._name is None:
self._name = self.smartplug.alias

self.smartplug.led = self._leds_on

if self.smartplug.has_emeter:
emeter_readings = self.smartplug.get_emeter_realtime()

Expand Down

0 comments on commit 5f4baa6

Please sign in to comment.