Add child devices from hubs to generated list of supported devices (#898)

Updates generate_supported hook to include child devices of hubs in the list of supported devices.
This commit is contained in:
Steven B
2024-05-07 07:48:47 +01:00
committed by GitHub
parent c5d65b624b
commit f063c83378
4 changed files with 53 additions and 12 deletions

View File

@@ -29,10 +29,12 @@ DEVICE_TYPE_TO_PRODUCT_GROUP = {
DeviceType.StripSocket: "Power Strips",
DeviceType.Dimmer: "Wall Switches",
DeviceType.WallSwitch: "Wall Switches",
DeviceType.Fan: "Wall Switches",
DeviceType.Bulb: "Bulbs",
DeviceType.LightStrip: "Light Strips",
DeviceType.Hub: "Hubs",
DeviceType.Sensor: "Sensors",
DeviceType.Sensor: "Hub-Connected Devices",
DeviceType.Thermostat: "Hub-Connected Devices",
}
@@ -106,7 +108,7 @@ def _supported_summary(supported):
return _supported_text(
supported,
"### Supported $brand$auth devices\n\n$types\n",
"- **$type_**: $models\n",
"- **$type_$type_asterix**: $models\n",
)
@@ -136,6 +138,10 @@ def _supported_text(
if brand == "kasa"
else "All Tapo devices require authentication."
)
preamble_text += (
"<br>Hub-Connected Devices may work across TAPO/KASA branded "
+ "hubs even if they don't work across the native apps."
)
brand_text = brand.capitalize()
brand_auth = r"<sup>\*</sup>" if brand == "tapo" else ""
types_text = ""
@@ -177,7 +183,14 @@ def _supported_text(
else:
models_list.append(f"{model}{auth_flag}")
models_text = models_text if models_text else ", ".join(models_list)
types_text += typest.substitute(type_=supported_type, models=models_text)
type_asterix = (
r"<sup>\*\*\*</sup>"
if supported_type == "Hub-Connected Devices"
else ""
)
types_text += typest.substitute(
type_=supported_type, type_asterix=type_asterix, models=models_text
)
brands += brandt.substitute(
brand=brand_text, types=types_text, auth=brand_auth, preamble=preamble_text
)
@@ -185,16 +198,22 @@ def _supported_text(
def _get_smart_supported(supported):
for file in Path(SMART_FOLDER).glob("*.json"):
for file in Path(SMART_FOLDER).glob("**/*.json"):
with file.open() as f:
fixture_data = json.load(f)
model, _, region = fixture_data["discovery_result"]["device_model"].partition(
"("
)
if "discovery_result" in fixture_data:
model, _, region = fixture_data["discovery_result"][
"device_model"
].partition("(")
device_type = fixture_data["discovery_result"]["device_type"]
else: # child devices of hubs do not have discovery result
model = fixture_data["get_device_info"]["model"]
region = fixture_data["get_device_info"].get("specs")
device_type = fixture_data["get_device_info"]["type"]
# P100 doesn't have region HW
region = region.replace(")", "") if region else ""
device_type = fixture_data["discovery_result"]["device_type"]
_protocol, devicetype = device_type.split(".")
brand = devicetype[:4].lower()
components = [