Change state_information to return feature values (#804)

This changes `state_information` to return the names and values of
all defined features.
It was originally a "temporary" hack to show some extra, device-specific
information in the cli tool, but now that we have device-defined
features we can leverage them.
This commit is contained in:
Teemu R
2024-03-26 19:28:39 +01:00
committed by GitHub
parent d63f43a230
commit 35dbda7049
13 changed files with 70 additions and 115 deletions

View File

@@ -121,6 +121,61 @@ TIME_MODULE = {
"set_timezone": None,
}
CLOUD_MODULE = {
"get_info": {
"username": "",
"server": "devs.tplinkcloud.com",
"binded": 0,
"cld_connection": 0,
"illegalType": -1,
"stopConnect": -1,
"tcspStatus": -1,
"fwDlPage": "",
"tcspInfo": "",
"fwNotifyType": 0,
}
}
AMBIENT_MODULE = {
"get_current_brt": {"value": 26, "err_code": 0},
"get_config": {
"devs": [
{
"hw_id": 0,
"enable": 0,
"dark_index": 1,
"min_adc": 0,
"max_adc": 2450,
"level_array": [
{"name": "cloudy", "adc": 490, "value": 20},
{"name": "overcast", "adc": 294, "value": 12},
{"name": "dawn", "adc": 222, "value": 9},
{"name": "twilight", "adc": 222, "value": 9},
{"name": "total darkness", "adc": 111, "value": 4},
{"name": "custom", "adc": 2400, "value": 97},
],
}
],
"ver": "1.0",
"err_code": 0,
},
}
MOTION_MODULE = {
"get_config": {
"enable": 0,
"version": "1.0",
"trigger_index": 2,
"cold_time": 60000,
"min_adc": 0,
"max_adc": 4095,
"array": [80, 50, 20, 0],
"err_code": 0,
}
}
class FakeIotProtocol(IotProtocol):
def __init__(self, info):
@@ -306,8 +361,10 @@ class FakeIotProtocol(IotProtocol):
"set_brightness": set_hs220_brightness,
"set_dimmer_transition": set_hs220_dimmer_transition,
},
"smartlife.iot.LAS": {},
"smartlife.iot.PIR": {},
"smartlife.iot.LAS": AMBIENT_MODULE,
"smartlife.iot.PIR": MOTION_MODULE,
"cnCloud": CLOUD_MODULE,
"smartlife.iot.common.cloud": CLOUD_MODULE,
}
async def query(self, request, port=9999):

View File

@@ -42,11 +42,8 @@ async def test_bulb_sysinfo(dev: Bulb):
@bulb
async def test_state_attributes(dev: Bulb):
assert "Brightness" in dev.state_information
assert dev.state_information["Brightness"] == dev.brightness
assert "Is dimmable" in dev.state_information
assert dev.state_information["Is dimmable"] == dev.is_dimmable
assert "Cloud connection" in dev.state_information
assert isinstance(dev.state_information["Cloud connection"], bool)
@bulb_iot
@@ -114,6 +111,7 @@ async def test_invalid_hsv(dev: Bulb, turn_on):
@color_bulb
@pytest.mark.skip("requires color feature")
async def test_color_state_information(dev: Bulb):
assert "HSV" in dev.state_information
assert dev.state_information["HSV"] == dev.hsv
@@ -130,6 +128,7 @@ async def test_hsv_on_non_color(dev: Bulb):
@variable_temp
@pytest.mark.skip("requires colortemp module")
async def test_variable_temp_state_information(dev: Bulb):
assert "Color temperature" in dev.state_information
assert dev.state_information["Color temperature"] == dev.color_temp

View File

@@ -28,7 +28,6 @@ async def test_effects_lightstrip_set_effect(dev: IotLightStrip):
await dev.set_effect("Candy Cane")
assert dev.effect["name"] == "Candy Cane"
assert dev.state_information["Effect"] == "Candy Cane"
@lightstrip