Whilser / Xiaomi-Universal-IR-Remote-Controller-Domoticz-plugin

Xiaomi Universal IR Remote Controller (Chuangmi IR) plugin for Domoticz
GNU General Public License v3.0
5 stars 0 forks source link

command line #9

Open zon2004 opened 4 years ago

zon2004 commented 4 years ago

Скажите пожалуйста, Возможна ли отправка и получение кодов с командной строки. Использовал скрипт для отправки кода

!/usr/bin/python3

import sys import ipaddress from typing import Any from miio import ChuangmiIr,DeviceException import time ip = '192.168.x.x' token = '6xxxxxxxxxxxxxxxxxxxxxxxxxxc' f=open('codes.txt') codeline=f.readlines() id_aux = codeline[int(sys.argv[1])-1].split(" ") id=id_aux[0] ir = ChuangmiIr(ip,token) ir.play_raw(id,frequency='')

Но пульты от сони он так не берет Возможно что виноват скрипт получения кодов

!/usr/bin/python3

import sys import ipaddress from typing import Any from miio import ChuangmiIr,DeviceException import time import json import os import os.path fichero ='./codes.txt' ip= '192.168.x.x' token = '6xxxxxxxxxxxxxxxxxxxxxxxxxxc' try: os.stat("codes.txt") except: file = open("codes.txt", "w")

num_lines = sum(1 for line in open('codes.txt')) print ('Stored Ir Keys ->'+ str(num_lines) ) id = num_lines + 1 ir = ChuangmiIr(ip,token)

ir.learn(key=1) time.sleep(10) print (ir.read(key=1).get("code"))

with open('codes.txt', 'a') as file: try: file.write(ir.read(key=1).get("code")+ '\n') except: print('error')

Спасибо за любую помощь

Whilser commented 4 years ago

Дело не в скрипте. Есть подозрение, что посылка слишком длинная. Некоторые пользователи с этим сталкиваются. Но обычно родное приложение работает без особых проблем.

zon2004 commented 4 years ago

Может Вы знаете как переделать пронто HEX код для передачи. возможно отослать получиться. Видел такой скрипт, но не могу понять его работу

mport base64 import heatshrink2 import miio

def pronto_convert(pronto): old_raw, freq = miio.ChuangmiIr.pronto_to_raw(pronto) signal = miio.chuangmi_ir.ChuangmiIrSignal.parse(base64.b64decode(old_raw)) times = [] for pair in signal.edge_pairs: times.append(signal.times_index[pair.pulse]) times.append(signal.times_index[pair.gap]) times = '{}\x00'.format(','.join(map(str, times))) return f"raw:{base64.b64encode(heatshrink2.encode(times.encode())).decode()}:{freq}"