Add transition support for SmartDimmer (#69)

* Adds a transition param to set_brightness(), turn_on(), and turn_off() that specifies the duration in milliseconds that the dimmer switch will take to transition to the new state.
* Fixes bug where set_brightness(0) was allowed even though the dimmer does not support it. Now brightness values of 0 are coerced to 1 to be consistent with bulbs (which do support brightness values of 0).
This commit is contained in:
Connor Proctor
2020-06-14 09:09:28 -07:00
committed by GitHub
parent 9dc0cbaece
commit dd073fa8c8
3 changed files with 222 additions and 10 deletions

View File

@@ -315,6 +315,15 @@ class FakeTransportProtocol(TPLinkSmartHomeProtocol):
_LOGGER.debug("Setting brightness to %s", x)
self.proto["system"]["get_sysinfo"]["brightness"] = x["brightness"]
def set_hs220_dimmer_transition(self, x, *args):
_LOGGER.debug("Setting dimmer transition to %s", x)
brightness = x["brightness"]
if brightness == 0:
self.proto["system"]["get_sysinfo"]["relay_state"] = 0
else:
self.proto["system"]["get_sysinfo"]["relay_state"] = 1
self.proto["system"]["get_sysinfo"]["brightness"] = x["brightness"]
def transition_light_state(self, x, *args):
_LOGGER.debug("Setting light state to %s", x)
light_state = self.proto["system"]["get_sysinfo"]["light_state"]
@@ -392,7 +401,10 @@ class FakeTransportProtocol(TPLinkSmartHomeProtocol):
"set_timezone": None,
},
# HS220 brightness, different setter and getter
"smartlife.iot.dimmer": {"set_brightness": set_hs220_brightness},
"smartlife.iot.dimmer": {
"set_brightness": set_hs220_brightness,
"set_dimmer_transition": set_hs220_dimmer_transition,
},
}
async def query(self, host, request, port=9999):