Fix tplink HS220 dimmers (round 2) (#33928)
* HS220 dimmers are handled as lights with a limited feature set * Dimmers look up has has_emeter every call so this is cached as well now to resovle the performance issue.
This commit is contained in:
1 parent
f38ff3b622
commit
1b0ccf10e5
2 files changed
+34
-28
No files matched your search
@@ -40,6 +40,7 @@ ATTR_MONTHLY_ENERGY_KWH = "monthly_energy_kwh"
|
||||
|
||||
LIGHT_STATE_DFT_ON = "dft_on_state"
|
||||
LIGHT_STATE_ON_OFF = "on_off"
|
||||
LIGHT_STATE_RELAY_STATE = "relay_state"
|
||||
LIGHT_STATE_BRIGHTNESS = "brightness"
|
||||
LIGHT_STATE_COLOR_TEMP = "color_temp"
|
||||
LIGHT_STATE_HUE = "hue"
|
||||
@@ -128,6 +129,7 @@ class LightFeatures(NamedTuple):
|
||||
supported_features: int
|
||||
min_mireds: float
|
||||
max_mireds: float
|
||||
has_emeter: bool
|
||||
|
||||
|
||||
class TPLinkSmartBulb(Light):
|
||||
@@ -285,8 +287,9 @@ class TPLinkSmartBulb(Light):
|
||||
model = sysinfo[LIGHT_SYSINFO_MODEL]
|
||||
min_mireds = None
|
||||
max_mireds = None
|
||||
has_emeter = self.smartbulb.has_emeter
|
||||
|
||||
if sysinfo.get(LIGHT_SYSINFO_IS_DIMMABLE):
|
||||
if sysinfo.get(LIGHT_SYSINFO_IS_DIMMABLE) or LIGHT_STATE_BRIGHTNESS in sysinfo:
|
||||
supported_features += SUPPORT_BRIGHTNESS
|
||||
if sysinfo.get(LIGHT_SYSINFO_IS_VARIABLE_COLOR_TEMP):
|
||||
supported_features += SUPPORT_COLOR_TEMP
|
||||
@@ -306,6 +309,7 @@ class TPLinkSmartBulb(Light):
|
||||
supported_features=supported_features,
|
||||
min_mireds=min_mireds,
|
||||
max_mireds=max_mireds,
|
||||
has_emeter=has_emeter,
|
||||
)
|
||||
|
||||
def _get_light_state_retry(self) -> LightState:
|
||||
@@ -360,7 +364,7 @@ class TPLinkSmartBulb(Light):
|
||||
return self._light_state_from_params(self._get_device_state())
|
||||
|
||||
def _update_emeter(self):
|
||||
if not self.smartbulb.has_emeter:
|
||||
if not self._light_features.has_emeter:
|
||||
return
|
||||
|
||||
now = dt_util.utcnow()
|
||||
@@ -446,10 +450,11 @@ class TPLinkSmartBulb(Light):
|
||||
if isinstance(self.smartbulb, SmartBulb):
|
||||
return self.smartbulb.get_light_state()
|
||||
|
||||
sysinfo = self.smartbulb.sys_info
|
||||
# Its not really a bulb, its a dimmable SmartPlug (aka Wall Switch)
|
||||
return {
|
||||
LIGHT_STATE_ON_OFF: self.smartbulb.state,
|
||||
LIGHT_STATE_BRIGHTNESS: self.smartbulb.brightness,
|
||||
LIGHT_STATE_ON_OFF: sysinfo[LIGHT_STATE_RELAY_STATE],
|
||||
LIGHT_STATE_BRIGHTNESS: sysinfo.get(LIGHT_STATE_BRIGHTNESS, 0),
|
||||
LIGHT_STATE_COLOR_TEMP: 0,
|
||||
LIGHT_STATE_HUE: 0,
|
||||
LIGHT_STATE_SATURATION: 0,
|
||||
@@ -468,9 +473,12 @@ class TPLinkSmartBulb(Light):
|
||||
if state[LIGHT_STATE_BRIGHTNESS]:
|
||||
self.smartbulb.brightness = state[LIGHT_STATE_BRIGHTNESS]
|
||||
else:
|
||||
self.smartbulb.state = 0
|
||||
self.smartbulb.state = self.smartbulb.SWITCH_STATE_OFF
|
||||
elif LIGHT_STATE_ON_OFF in state:
|
||||
self.smartbulb.state = state[LIGHT_STATE_ON_OFF]
|
||||
if state[LIGHT_STATE_ON_OFF]:
|
||||
self.smartbulb.state = self.smartbulb.SWITCH_STATE_ON
|
||||
else:
|
||||
self.smartbulb.state = self.smartbulb.SWITCH_STATE_OFF
|
||||
|
||||
return self._get_device_state()
|
||||
|
||||
|
||||
Reference in new issue
Block a user