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

Allow disabling the LEDs on TP-Link smart plugs #10980

Merged
merged 1 commit into from
Dec 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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