"""Управление Hisense VIDAA напрямую (без HA). Использование: tv_hisense.py --state tv_hisense.py --key KEY_HOME tv_hisense.py --app youtube tv_hisense.py --vol-up | --vol-down | --mute tv_hisense.py --on | --off | --power tv_hisense.py --apps """ import asyncio import inspect import sys import vidaa TV_HOST = "192.168.1.145" TV_PORT = 36669 def _maybe_await(value): return value async def _run(action: str, arg: str | None) -> int: tv = vidaa.AsyncVidaaTV(TV_HOST, TV_PORT) try: res = tv.connect() if inspect.isawaitable(res): res = await res if not res: print(" телевизор не отвечает (выключен?)") return 1 if action == "state": st = tv.get_state() if inspect.isawaitable(st): st = await st print(" состояние:", st) elif action == "key": print(" клавиша:", arg, "→", tv.send_key(arg or "KEY_HOME")) elif action == "app": print(" приложение:", arg, "→", tv.launch_app(arg)) elif action == "apps": apps = tv.get_apps() if inspect.isawaitable(apps): apps = await apps print(" приложения:", apps) elif action == "vol-up": print(" громкость + →", tv.send_key("KEY_VOLUMEUP")) elif action == "vol-down": print(" громкость − →", tv.send_key("KEY_VOLUMEDOWN")) elif action == "mute": print(" mute →", tv.send_key("KEY_MUTE")) elif action == "on": print(" включение →", tv.power(on=True)) elif action == "off": print(" выключение →", tv.power(on=False)) elif action == "power": print(" питание →", tv.power()) else: print(" неизвестное действие:", action) return 2 return 0 except Exception as e: print(" ошибка:", type(e).__name__, str(e)[:200]) return 1 finally: try: r = tv.disconnect() if inspect.isawaitable(r): await r except Exception: pass def main() -> int: args = sys.argv[1:] if not args: print(__doc__) return 2 flag = args[0].lstrip("-") arg = args[1] if len(args) > 1 else None return asyncio.run(_run(flag, arg)) if __name__ == "__main__": sys.exit(main())