Add effect support for light strips (#293)

* Add effect support for KL430

* KL400 supports effects

* Add KL400 fixture

* Comments from review

* actually commit the remove
This commit is contained in:
J. Nick Koston
2022-03-21 11:10:12 -10:00
committed by GitHub
parent b22f6b4eef
commit 58f6517445
8 changed files with 508 additions and 2 deletions

View File

@@ -0,0 +1,57 @@
{
"smartlife.iot.common.emeter": {
"get_realtime": {
"err_code": 0,
"power_mw": 10800,
"total_wh": 1
}
},
"system": {
"get_sysinfo": {
"LEF": 0,
"active_mode": "none",
"alias": "Kl400",
"ctrl_protocols": {
"name": "Linkie",
"version": "1.0"
},
"description": "Kasa Smart Light Strip, Multicolor",
"dev_state": "normal",
"deviceId": "0000000000000000000000000000000000000000",
"disco_ver": "1.0",
"err_code": 0,
"hwId": "00000000000000000000000000000000",
"hw_ver": "1.0",
"is_color": 1,
"is_dimmable": 1,
"is_factory": false,
"is_variable_color_temp": 0,
"latitude_i": 0,
"length": 1,
"light_state": {
"brightness": 100,
"color_temp": 6500,
"hue": 0,
"mode": "normal",
"on_off": 1,
"saturation": 0
},
"lighting_effect_state": {
"brightness": 100,
"custom": 0,
"enable": 1,
"id": "CdLeIgiKcQrLKMINRPTMbylATulQewLD",
"name": "Hanukkah"
},
"longitude_i": 0,
"mic_mac": "00:00:00:00:00:00",
"mic_type": "IOT.SMARTBULB",
"model": "KL400L5(US)",
"oemId": "00000000000000000000000000000000",
"preferred_state": [],
"rssi": -44,
"status": "new",
"sw_ver": "1.0.8 Build 211018 Rel.162056"
}
}
}

View File

@@ -0,0 +1,57 @@
{
"smartlife.iot.common.emeter": {
"get_realtime": {
"err_code": 0,
"power_mw": 11150,
"total_wh": 18
}
},
"system": {
"get_sysinfo": {
"LEF": 1,
"active_mode": "none",
"alias": "kl430 updated",
"ctrl_protocols": {
"name": "Linkie",
"version": "1.0"
},
"description": "Kasa Smart Light Strip, Multicolor",
"dev_state": "normal",
"deviceId": "0000000000000000000000000000000000000000",
"disco_ver": "1.0",
"err_code": 0,
"hwId": "00000000000000000000000000000000",
"hw_ver": "2.0",
"is_color": 1,
"is_dimmable": 1,
"is_factory": false,
"is_variable_color_temp": 1,
"latitude_i": 0,
"length": 16,
"light_state": {
"brightness": 100,
"color_temp": 0,
"hue": 194,
"mode": "normal",
"on_off": 1,
"saturation": 50
},
"lighting_effect_state": {
"brightness": 100,
"custom": 0,
"enable": 1,
"id": "izRhLCQNcDzIKdpMPqSTtBMuAIoreAuT",
"name": "Rainbow"
},
"longitude_i": 0,
"mic_mac": "00:00:00:00:00:00",
"mic_type": "IOT.SMARTBULB",
"model": "KL430(US)",
"oemId": "00000000000000000000000000000000",
"preferred_state": [],
"rssi": -58,
"status": "new",
"sw_ver": "1.0.9 Build 210915 Rel.170534"
}
}
}

View File

@@ -359,6 +359,10 @@ class FakeTransportProtocol(TPLinkSmartHomeProtocol):
self.proto["system"]["get_sysinfo"]["relay_state"] = 1
self.proto["system"]["get_sysinfo"]["brightness"] = x["brightness"]
def set_lighting_effect(self, effect, *args):
_LOGGER.debug("Setting light effect to %s", effect)
self.proto["system"]["get_sysinfo"]["lighting_effect_state"] = dict(effect)
def transition_light_state(self, state_changes, *args):
_LOGGER.debug("Setting light state to %s", state_changes)
light_state = self.proto["system"]["get_sysinfo"]["light_state"]
@@ -422,6 +426,9 @@ class FakeTransportProtocol(TPLinkSmartHomeProtocol):
"get_light_state": light_state,
"transition_light_state": transition_light_state,
},
"smartlife.iot.lighting_effect": {
"set_lighting_effect": set_lighting_effect,
},
# lightstrip follows the same payloads but uses different module & method
"smartlife.iot.lightStrip": {
"set_light_state": transition_light_state,

View File

@@ -1,4 +1,7 @@
import pytest
from kasa import DeviceType, SmartLightStrip
from kasa.exceptions import SmartDeviceException
from .conftest import lightstrip, pytestmark
@@ -15,3 +18,19 @@ async def test_lightstrip_effect(dev: SmartLightStrip):
assert isinstance(dev.effect, dict)
for k in ["brightness", "custom", "enable", "id", "name"]:
assert k in dev.effect
@lightstrip
async def test_effects_lightstrip_set_effect(dev: SmartLightStrip):
with pytest.raises(SmartDeviceException):
await dev.set_effect("Not real")
await dev.set_effect("Candy Cane")
assert dev.effect["name"] == "Candy Cane"
assert dev.state_information["Effect"] == "Candy Cane"
@lightstrip
async def test_effects_lightstrip_has_effects(dev: SmartLightStrip):
assert dev.has_effects is True
assert dev.effect_list