-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,73 @@ | ||
import re | ||
from custom_components.xiaomi_gateway3.core.devices import DEVICES | ||
|
||
from homeassistant.components.sensor import DOMAIN | ||
|
||
from custom_components.xiaomi_gateway3.core.converters.devices import DEVICES | ||
from custom_components.xiaomi_gateway3.core.converters.mibeacon import MiBeacon | ||
|
||
assert DOMAIN # fix circular import | ||
|
||
columns = ["Brand", "Name", "Model", "Entities", "S"] | ||
columns = ["Brand", "Name", "Model", "Entities"] | ||
header = ["---"] * len(columns) | ||
|
||
devices = { | ||
"Gateways": [ | ||
[ | ||
"Xiaomi", | ||
"Multimode Gateway CN", | ||
"[ZNDMWG03LM](https://home.miot-spec.com/s/lumi.gateway.mgl03)", | ||
"alarm, command, data, gateway", | ||
"4", | ||
], | ||
[ | ||
"Xiaomi", | ||
"Multimode Gateway EU", | ||
"[ZNDMWG02LM](https://home.miot-spec.com/s/lumi.gateway.mgl03)", | ||
"alarm, command, data, gateway", | ||
"4", | ||
], | ||
] | ||
} | ||
devices = {} | ||
models = set() | ||
|
||
for device in DEVICES: | ||
is_ble = True | ||
|
||
for i, device in enumerate(DEVICES): | ||
# skip devices with bad support | ||
if device.get("support", 3) < 3: | ||
if device.pop("support", 3) < 3: | ||
continue | ||
|
||
for k, v in device.items(): | ||
if not isinstance(v, list) or k in ("spec", "lumi.gateway.aqcn03"): | ||
continue | ||
spec = device.pop("spec") | ||
|
||
brand, name, model = v if len(v) == 3 else v + [k] | ||
# skip BLE with unknown spec | ||
if "default" not in device: | ||
spec = ", ".join([conv.attr for conv in spec if conv.domain]) | ||
else: | ||
spec = "*" | ||
|
||
if isinstance(k, str): | ||
if "gateway" in k: | ||
kind = "Gateways" | ||
elif k.startswith("lumi.") or k.startswith("ikea."): | ||
kind = "Xiaomi Zigbee" | ||
else: | ||
kind = "Other Zigbee" | ||
elif MiBeacon in device["spec"]: | ||
kind = "Xiaomi BLE" | ||
else: | ||
kind = "Xiaomi Mesh" | ||
for model, info in device.items(): | ||
if not isinstance(info, list): | ||
continue | ||
|
||
if kind != "Other Zigbee": | ||
link = f"https://home.miot-spec.com/s/{k}" | ||
if model in models: | ||
print("duplicate:", model) | ||
else: | ||
link = f"https://www.zigbee2mqtt.io/supported-devices/#s={model}" | ||
models.add(model) | ||
|
||
items = devices.setdefault(kind, []) | ||
if isinstance(model, str) and model not in info: | ||
info.append(model) | ||
|
||
# skip if model already exists | ||
if any(True for i in items if f"[{model}]" in i[2]): | ||
continue | ||
market_brand = info[0] or "~" | ||
market_name = info[1] | ||
market_model = ", ".join(info[2:]) if len(info) > 2 else "" | ||
|
||
# skip BLE with unknown spec | ||
if "default" not in device: | ||
spec = ", ".join( | ||
[ | ||
conv.attr + "*" if conv.enabled is None else conv.attr | ||
for conv in device["spec"] | ||
if conv.domain | ||
] | ||
) | ||
if isinstance(model, str): | ||
if "gateway" in model: | ||
kind = "Gateways" | ||
elif model.startswith(("lumi.", "ikea.")): | ||
kind = "Xiaomi Zigbee" | ||
elif model.startswith("matter."): | ||
kind = "Matter" | ||
else: | ||
kind = "Other Zigbee" | ||
elif isinstance(model, int): | ||
if is_ble: | ||
kind = "Xiaomi BLE" | ||
else: | ||
kind = "Xiaomi Mesh" | ||
else: | ||
spec = "*" | ||
|
||
support = str(device.get("support", "")) | ||
kind = "Unknown" | ||
|
||
model = f"[{model}]({link})" | ||
devices.setdefault(kind, []).append( | ||
[market_brand, market_name, market_model, spec] | ||
) | ||
|
||
items.append([brand, name, model, spec, support]) | ||
if device.get("default") == "ble": | ||
is_ble = False | ||
|
||
out = "<!--supported-->\n" | ||
out = f"# Supported devices\n\nTotal devices: {len(models)}\n\n" | ||
for k, v in devices.items(): | ||
out += f"### Supported {k}\n\nTotal devices: {len(v)}\n\n" | ||
out += f"## Supported {k}\n\nTotal devices: {len(v)}\n\n" | ||
out += "|" + "|".join(columns) + "|\n" | ||
out += "|" + "|".join(header) + "|\n" | ||
for line in sorted(v): | ||
out += "|" + "|".join(line) + "|\n" | ||
out += "\n" | ||
out += "<!--supported-->" | ||
|
||
raw = open("README.md", "r", encoding="utf-8").read() | ||
raw = re.sub(r"<!--supported-->(.+?)<!--supported-->", out, raw, flags=re.DOTALL) | ||
open("README.md", "w", encoding="utf-8").write(raw) | ||
open("DEVICES.md", "w", encoding="utf-8").write(out) |