@jessicaisleep/dsh-mihome 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +141 -78
- package/client.js +1149 -19
- package/cordis.patch.yml +2 -2
- package/docs/REPAIR-VALIDATION.md +62 -0
- package/lib/bridge.js +126 -44
- package/lib/connections.js +46 -0
- package/lib/format.js +148 -0
- package/lib/index.js +274 -31
- package/lib/panel.js +138 -7
- package/locale/en.json +3 -3
- package/locale/zh.json +2 -2
- package/package.json +13 -4
- package/python/app/core/service.py +62 -31
- package/python/mihome_bridge.py +211 -9
- package/python/smart_home/__init__.py +24 -0
- package/python/smart_home/adapters/__init__.py +50 -0
- package/python/smart_home/adapters/base.py +143 -0
- package/python/smart_home/adapters/ble.py +100 -0
- package/python/smart_home/adapters/dlna.py +227 -0
- package/python/smart_home/adapters/home_assistant.py +454 -0
- package/python/smart_home/adapters/hue.py +225 -0
- package/python/smart_home/adapters/kasa.py +239 -0
- package/python/smart_home/adapters/mihome.py +342 -0
- package/python/smart_home/adapters/network.py +250 -0
- package/python/smart_home/adapters/shelly.py +289 -0
- package/python/smart_home/adapters/tuya.py +95 -0
- package/python/smart_home/adapters/tv.py +26 -0
- package/python/smart_home/catalog.py +336 -0
- package/python/smart_home/cloud.py +85 -0
- package/python/smart_home/discovery.py +934 -0
- package/python/smart_home/localize.py +787 -0
- package/python/smart_home/manager.py +672 -0
- package/python/smart_home/oui_table.py +40550 -0
- package/python/smart_home/scan.py +73 -0
- package/python/smart_home/test_discovery_repairs.py +186 -0
- package/python/smart_home/test_localization_repairs.py +229 -0
- package/python/smart_home/test_offline.py +195 -0
- package/python/smart_home/test_repairs.py +107 -0
- package/python/smart_home/util.py +320 -0
- package/python/tests/test_bridge_integration.py +108 -0
- package/python/tests/test_ha_discovery.py +260 -0
- package/python/tests/test_home_assistant.py +365 -0
- package/python/tests/test_manager_integration.py +150 -0
- package/python/tests/test_mihome_repairs.py +117 -0
- package/python/tests/test_network_read_contract.py +50 -0
- package/python/tests/test_power_confirmation.py +95 -0
- package/python/tests/test_protocol_repairs.py +369 -0
- package/python/tests/test_yeelight_repairs.py +70 -0
- package/requirements-optional.txt +4 -0
- package/requirements.txt +5 -0
- package/scripts/update-oui.py +108 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
3
|
+
"""Generate an offline MA-L lookup from a checksum-verified IEEE archive.
|
|
4
|
+
|
|
5
|
+
Download https://standards-oui.ieee.org/oui/oui.txt (or oui.csv), preserve that
|
|
6
|
+
archive, and record its SHA-256 and download date. This command never downloads
|
|
7
|
+
or guesses brands. Run from the repository root, for example:
|
|
8
|
+
|
|
9
|
+
python scripts/update-oui.py --input /archive/oui.txt \
|
|
10
|
+
--sha256 <64-hex-digest> --snapshot-date 2026-11-22 \
|
|
11
|
+
--output python/smart_home/oui_table.py
|
|
12
|
+
|
|
13
|
+
Identical input bytes and arguments produce identical UTF-8/LF output. The
|
|
14
|
+
organization spelling is retained verbatim; an OUI is not a device category.
|
|
15
|
+
"""
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import argparse
|
|
19
|
+
import csv
|
|
20
|
+
import datetime
|
|
21
|
+
import hashlib
|
|
22
|
+
import io
|
|
23
|
+
import json
|
|
24
|
+
import re
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
|
|
27
|
+
IEEE_TXT_URL = "https://standards-oui.ieee.org/oui/oui.txt"
|
|
28
|
+
IEEE_CSV_URL = "https://standards-oui.ieee.org/oui/oui.csv"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def parse_archive(raw: bytes) -> tuple[dict[str, str], str, dict[str, list[str]]]:
|
|
32
|
+
"""Read official MA-L TXT/CSV; ambiguous legacy prefixes stay unknown.
|
|
33
|
+
|
|
34
|
+
IEEE contains historic duplicate assignments (notably 080030). Choosing
|
|
35
|
+
whichever row happens to be first would assign a potentially wrong name.
|
|
36
|
+
See https://seclists.org/nmap-dev/2015/q2/321 and the IEEE archive itself.
|
|
37
|
+
"""
|
|
38
|
+
text = raw.decode("utf-8-sig")
|
|
39
|
+
assignments: dict[str, set[str]] = {}
|
|
40
|
+
|
|
41
|
+
def add(prefix: str, organization: str) -> None:
|
|
42
|
+
prefix, organization = prefix.strip().upper(), organization.strip()
|
|
43
|
+
if not re.fullmatch(r"[0-9A-F]{6}", prefix) or not organization:
|
|
44
|
+
raise ValueError("Invalid MA-L assignment or empty organization")
|
|
45
|
+
assignments.setdefault(prefix, set()).add(organization)
|
|
46
|
+
|
|
47
|
+
if text.startswith("Registry,"):
|
|
48
|
+
for row in csv.DictReader(io.StringIO(text)):
|
|
49
|
+
if row.get("Registry") == "MA-L":
|
|
50
|
+
add(row.get("Assignment", ""), row.get("Organization Name", ""))
|
|
51
|
+
source_url = IEEE_CSV_URL
|
|
52
|
+
else:
|
|
53
|
+
for match in re.finditer(r"(?m)^\s*([0-9A-Fa-f]{6})[ \t]+\(base 16\)[ \t]+([^\r\n]+)", text):
|
|
54
|
+
add(match.group(1), match.group(2))
|
|
55
|
+
source_url = IEEE_TXT_URL
|
|
56
|
+
if not assignments:
|
|
57
|
+
raise ValueError("The input contains no IEEE MA-L assignments")
|
|
58
|
+
entries = {prefix: next(iter(names)) for prefix, names in assignments.items() if len(names) == 1}
|
|
59
|
+
ambiguous = {prefix: sorted(names) for prefix, names in assignments.items() if len(names) > 1}
|
|
60
|
+
return entries, source_url, ambiguous
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def main(argv: list[str] | None = None) -> int:
|
|
64
|
+
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
65
|
+
parser.add_argument("--input", type=Path, required=True, help="Archived IEEE oui.txt or oui.csv")
|
|
66
|
+
parser.add_argument("--output", type=Path, required=True, help="Generated Python module")
|
|
67
|
+
parser.add_argument("--snapshot-date", required=True, help="Archive acquisition date, YYYY-MM-DD")
|
|
68
|
+
parser.add_argument("--sha256", required=True, help="Expected SHA-256 of the original archive bytes")
|
|
69
|
+
args = parser.parse_args(argv)
|
|
70
|
+
if datetime.date.fromisoformat(args.snapshot_date).isoformat() != args.snapshot_date:
|
|
71
|
+
raise ValueError("snapshot-date must use YYYY-MM-DD")
|
|
72
|
+
expected = args.sha256.lower()
|
|
73
|
+
if not re.fullmatch(r"[0-9a-f]{64}", expected):
|
|
74
|
+
raise ValueError("sha256 must contain 64 hexadecimal digits")
|
|
75
|
+
raw = args.input.read_bytes()
|
|
76
|
+
digest = hashlib.sha256(raw).hexdigest()
|
|
77
|
+
if digest != expected:
|
|
78
|
+
raise ValueError(f"IEEE archive SHA-256 mismatch: expected {expected}, got {digest}")
|
|
79
|
+
entries, source_url, ambiguous = parse_archive(raw)
|
|
80
|
+
quote = lambda value: json.dumps(value, ensure_ascii=False)
|
|
81
|
+
lines = [
|
|
82
|
+
"# SPDX-License-Identifier: GPL-3.0-or-later",
|
|
83
|
+
'\"\"\"IEEE MA-L prefix -> registered organization (not brand or category).',
|
|
84
|
+
"",
|
|
85
|
+
"Generated by scripts/update-oui.py from the checksum-verified IEEE archive.",
|
|
86
|
+
"Preserve the source archive to reproduce this module; do not hand-edit names.",
|
|
87
|
+
'\"\"\"',
|
|
88
|
+
"from __future__ import annotations",
|
|
89
|
+
"",
|
|
90
|
+
f"SOURCE_URL = {quote(source_url)}",
|
|
91
|
+
f"SOURCE_SNAPSHOT_DATE = {quote(args.snapshot_date)}",
|
|
92
|
+
f"SOURCE_SHA256 = {quote(digest)}",
|
|
93
|
+
f"SOURCE_ENTRY_COUNT = {len(entries)}",
|
|
94
|
+
"# These legacy assignments have several organizations; lookup returns unknown.",
|
|
95
|
+
f"AMBIGUOUS_ASSIGNMENTS: dict[str, list[str]] = {json.dumps(dict(sorted(ambiguous.items())), ensure_ascii=False)}",
|
|
96
|
+
"",
|
|
97
|
+
"OUI_TABLE: dict[str, str] = {",
|
|
98
|
+
]
|
|
99
|
+
lines.extend(f" {quote(prefix)}: {quote(organization)}," for prefix, organization in sorted(entries.items()))
|
|
100
|
+
lines.extend(["}", ""])
|
|
101
|
+
# write_bytes avoids platform newline conversion, keeping hashes reproducible.
|
|
102
|
+
args.output.write_bytes("\n".join(lines).encode("utf-8"))
|
|
103
|
+
print(f"Generated {len(entries)} IEEE MA-L entries; source SHA-256 {digest}")
|
|
104
|
+
return 0
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
if __name__ == "__main__":
|
|
108
|
+
raise SystemExit(main())
|