From 020593d50923511da979cbcd318ab201ab39eac9 Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Wed, 17 Jan 2018 08:52:32 +0000 Subject: [PATCH] Override default name for TP-Link devices (#11710) Fixes #11706 Corrects a bug introduced that prevents the names of TP-LInk devices from being pulled from the devices themselves. --- homeassistant/components/light/tplink.py | 14 ++++++++++---- homeassistant/components/switch/tplink.py | 4 +++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/light/tplink.py b/homeassistant/components/light/tplink.py index 87004f45ea0..30ad3a4d268 100644 --- a/homeassistant/components/light/tplink.py +++ b/homeassistant/components/light/tplink.py @@ -78,9 +78,7 @@ class TPLinkSmartBulb(Light): def __init__(self, smartbulb: 'SmartBulb', name): """Initialize the bulb.""" self.smartbulb = smartbulb - self._name = None - if name is not None: - self._name = name + self._name = name self._state = None self._available = True self._color_temp = None @@ -149,22 +147,30 @@ class TPLinkSmartBulb(Light): from pyHS100 import SmartDeviceException try: self._available = True + if self._supported_features == 0: self.get_features() + self._state = ( self.smartbulb.state == self.smartbulb.BULB_STATE_ON) - if self._name is None: + + # Pull the name from the device if a name was not specified + if self._name == DEFAULT_NAME: self._name = self.smartbulb.alias + if self._supported_features & SUPPORT_BRIGHTNESS: self._brightness = brightness_from_percentage( self.smartbulb.brightness) + if self._supported_features & SUPPORT_COLOR_TEMP: if (self.smartbulb.color_temp is not None and self.smartbulb.color_temp != 0): self._color_temp = kelvin_to_mired( self.smartbulb.color_temp) + if self._supported_features & SUPPORT_RGB_COLOR: self._rgb = hsv_to_rgb(self.smartbulb.hsv) + if self.smartbulb.has_emeter: self._emeter_params[ATTR_CURRENT_POWER_W] = '{:.1f}'.format( self.smartbulb.current_consumption()) diff --git a/homeassistant/components/switch/tplink.py b/homeassistant/components/switch/tplink.py index aa2e70e0020..f67aaec9796 100644 --- a/homeassistant/components/switch/tplink.py +++ b/homeassistant/components/switch/tplink.py @@ -90,10 +90,12 @@ class SmartPlugSwitch(SwitchDevice): from pyHS100 import SmartDeviceException try: self._available = True + self._state = self.smartplug.state == \ self.smartplug.SWITCH_STATE_ON - if self._name is None: + # Pull the name from the device if a name was not specified + if self._name == DEFAULT_NAME: self._name = self.smartplug.alias if self.smartplug.has_emeter: