feat: Add config flow for SmartIR integration with multi-step UI wizard
- Implemented a new config flow in `config_flow.py` for SmartIR, allowing users to select platforms, controllers, and devices through a guided interface. - Added support for new device codes in `codes_index.json` for Apton and Andersson manufacturers. - Enhanced fan, light, and media player components to support setup from config entries. - Introduced `strings.json` and `translations/en.json` for improved localization of the configuration steps. - Created a tool `build_index.py` to rebuild the `codes_index.json` from individual device JSON files. - Updated `smartir_capture.py` to handle single-code modes and excluded modes for better device configuration. - Added `iot_class` and `config_flow` attributes in `manifest.json` to support the new configuration flow.
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Rebuild codes_index.json by scanning all codes/{platform}/*.json files.
|
||||
|
||||
Run from the repo root:
|
||||
python tools/build_index.py
|
||||
|
||||
Outputs: custom_components/smartir/codes_index.json
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
PLATFORMS = ["climate", "fan", "media_player", "light"]
|
||||
|
||||
_TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
REPO_ROOT = os.path.dirname(_TOOLS_DIR)
|
||||
CODES_DIR = os.path.join(REPO_ROOT, "codes")
|
||||
OUTPUT_FILE = os.path.join(
|
||||
REPO_ROOT, "custom_components", "smartir", "codes_index.json"
|
||||
)
|
||||
|
||||
|
||||
def build_index() -> dict:
|
||||
index: dict[str, list] = {}
|
||||
total = 0
|
||||
errors = 0
|
||||
|
||||
for platform in PLATFORMS:
|
||||
platform_dir = os.path.join(CODES_DIR, platform)
|
||||
entries: list[dict] = []
|
||||
|
||||
if not os.path.isdir(platform_dir):
|
||||
print(f" {platform}: directory not found, skipping")
|
||||
index[platform] = entries
|
||||
continue
|
||||
|
||||
files = sorted(f for f in os.listdir(platform_dir) if f.endswith(".json"))
|
||||
|
||||
for filename in files:
|
||||
code_str = filename[:-5] # strip .json
|
||||
try:
|
||||
code = int(code_str)
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
path = os.path.join(platform_dir, filename)
|
||||
try:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
except Exception as exc:
|
||||
print(f" ERROR {filename}: {exc}", file=sys.stderr)
|
||||
errors += 1
|
||||
continue
|
||||
|
||||
entries.append(
|
||||
{
|
||||
"code": code,
|
||||
"manufacturer": data.get("manufacturer", "Unknown"),
|
||||
"models": data.get("supportedModels", []),
|
||||
"controller": data.get("supportedController", "Unknown"),
|
||||
"encoding": data.get("commandsEncoding", "Unknown"),
|
||||
}
|
||||
)
|
||||
total += 1
|
||||
|
||||
index[platform] = entries
|
||||
print(f" {platform}: {len(entries)} devices")
|
||||
|
||||
return index, total, errors
|
||||
|
||||
|
||||
def main() -> None:
|
||||
print(f"Scanning {CODES_DIR} ...")
|
||||
index, total, errors = build_index()
|
||||
|
||||
with open(OUTPUT_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump(index, f, indent=2)
|
||||
|
||||
print(f"\nDone: {total} devices indexed")
|
||||
print(f"Output: {OUTPUT_FILE}")
|
||||
if errors:
|
||||
print(f"Warnings: {errors} files failed to parse", file=sys.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user