From 6e01c4dc857aa24d8214787efcd9c099d53ecb93 Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Wed, 13 Dec 2023 21:36:52 +0100 Subject: [PATCH] Add remote_receiver/transmitter support (#8) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * generate remote_receiver block * add comment about comments; also handle unquoted comments * add UPK for ty02-1ch-rf-v1 * note IR/RF receivers in frontpage * rename to remote * reformatted with black * remote_receiver: support "ir" and "infrr" * black * simplify to one receiver * typo * handle infre * consistency * Apply suggestions from code review * Update upk2esphome/result.py --------- Co-authored-by: Kuba SzczodrzyƄski --- upk2esphome/generator.py | 4 +- upk2esphome/parts/remote.py | 43 ++++ upk2esphome/result.py | 3 + upk2esphome/tests/ty02-1ch-rf-v1.txt | 284 +++++++++++++++++++++++++++ web/index.html | 2 +- 5 files changed, 333 insertions(+), 3 deletions(-) create mode 100644 upk2esphome/parts/remote.py create mode 100644 upk2esphome/tests/ty02-1ch-rf-v1.txt diff --git a/upk2esphome/generator.py b/upk2esphome/generator.py index 8eed64a..5ffbbc9 100644 --- a/upk2esphome/generator.py +++ b/upk2esphome/generator.py @@ -73,9 +73,9 @@ def upk2esphome( opts: Opts, raw_extras: Union[str, dict] = None, ) -> YamlResult: - from .parts import bulb, module, monitor, netled, static, switch, tuyamcu + from .parts import bulb, module, monitor, netled, remote, static, switch, tuyamcu - parts = [module, static, bulb, switch, netled, monitor, tuyamcu] + parts = [module, static, bulb, switch, netled, remote, monitor, tuyamcu] yr = YamlResult() try: diff --git a/upk2esphome/parts/remote.py b/upk2esphome/parts/remote.py new file mode 100644 index 0000000..484442a --- /dev/null +++ b/upk2esphome/parts/remote.py @@ -0,0 +1,43 @@ +from upk2esphome.config import ConfigData +from upk2esphome.generator import invert, pull +from upk2esphome.opts import Opts +from upk2esphome.result import YamlResult + + +def generate(yr: YamlResult, config: ConfigData, opts: Opts): + config = config.upk or {} + in_keys = ["ir", "infrr"] + out_keys = ["infre"] + + for key in in_keys: + ir_pin = config.get(f"{key}") + + # keys currently not understood: + # irfunc + # irnightt + # irstep + # irk*val, irk*fun - presumably these map ir values received to specific functions (light on, off, colours, etc.) + + if ir_pin is None: + continue + + yr.log(f"Remote receiver: pin P{ir_pin}") + receiver = { + "pin": f"P{ir_pin}", + } + pull(receiver, True) + receiver["_1"] = "dump: all" + yr.data["remote_receiver"] = receiver + + for key in out_keys: + ir_pin = config.get(f"{key}") + + if ir_pin is None: + continue + + yr.log(f"Remote transmitter: pin P{ir_pin}") + transmitter = { + "pin": f"P{ir_pin}", + } + transmitter["carrier_duty_percent"] = "50%" + yr.data["remote_transmitter"] = transmitter diff --git a/upk2esphome/result.py b/upk2esphome/result.py index fac57b1..d0ab44d 100644 --- a/upk2esphome/result.py +++ b/upk2esphome/result.py @@ -36,7 +36,10 @@ def text(self) -> str: text = re.sub(r"'!(\w+) (.+)'", r"!\1 \2", text) text = re.sub(r"\n([a-z])", r"\n\n\1", text) text = text.replace("'", '"') + # generate comments for quoted strings with _\d+ keys text = re.sub(r'_\d+: "(.+?)"', r"# \1", text) + # generate comments for unquoted strings _\d+ keys + text = re.sub(r"_\d+: (.+?)", r"# \1", text) text = text.replace(" {}", "") text = text.replace("{}", "") return text diff --git a/upk2esphome/tests/ty02-1ch-rf-v1.txt b/upk2esphome/tests/ty02-1ch-rf-v1.txt new file mode 100644 index 0000000..2272bca --- /dev/null +++ b/upk2esphome/tests/ty02-1ch-rf-v1.txt @@ -0,0 +1,284 @@ +{ + "gw_bi": { + "uuid": "cx4wsQfa07MC", + "psk_key": null, + "auth_key": "QhPWKB3ffZEuYDRs", + "ap_ssid": "A", + "ap_passwd": null, + "country_code": null, + "bt_mac": null, + "bt_hid": null, + "prod_test": false + }, + "user_param_key": { + "0err": 70, + "1err": 40, + "Jsonver": "1.1.0", + "adclimit": 2400, + "aging": 0, + "bitseq": 0, + "brightmax": 100, + "brightmin": 5, + "brightstep": 10, + "c_lv": 1, + "c_pin": 8, + "category": "0501", + "cmod": "c", + "colormax": 100, + "colormin": 10, + "crc": 94, + "customcode": 58107, + "cwtype": 0, + "defbright": 100, + "defcolor": "c", + "deftemp": 100, + "dmod": 0, + "ir": 7, + "irfunc": 1, + "irk10fun": 28, + "irk10val": 6, + "irk11fun": 29, + "irk11val": 8, + "irk12fun": 30, + "irk12val": 90, + "irk13fun": 31, + "irk13val": 9, + "irk14fun": 32, + "irk14val": 138, + "irk15fun": 33, + "irk15val": 16, + "irk16fun": 34, + "irk16val": 28, + "irk17fun": 35, + "irk17val": 82, + "irk18fun": 36, + "irk18val": 83, + "irk19fun": 37, + "irk19val": 12, + "irk1fun": 2, + "irk1val": 37, + "irk20fun": 54, + "irk20val": 26, + "irk21fun": 79, + "irk21val": 31, + "irk22fun": 108, + "irk22val": 1, + "irk23fun": 109, + "irk23val": 0, + "irk24fun": 110, + "irk24val": 2, + "irk25fun": 86, + "irk25val": 208, + "irk26fun": 87, + "irk26val": 209, + "irk27fun": 60, + "irk27val": 210, + "irk28fun": 61, + "irk28val": 211, + "irk29fun": 0, + "irk29val": 212, + "irk2fun": 1, + "irk2val": 45, + "irk30fun": 0, + "irk30val": 213, + "irk3fun": 3, + "irk3val": 38, + "irk4fun": 81, + "irk4val": 11, + "irk5fun": 84, + "irk5val": 10, + "irk6fun": 58, + "irk6val": 15, + "irk7fun": 80, + "irk7val": 91, + "irk8fun": 85, + "irk8val": 92, + "irk9fun": 59, + "irk9val": 110, + "irnightt": 30, + "irstep": 10, + "ismusic": 0, + "k1dfunc": 5, + "k2dfunc": 0, + "k2lfunc": 0, + "k2pin_lv": 0, + "k2pin_pin": 1, + "k2sdir": 0, + "k2sfunc": 2, + "key_lv": 0, + "key_pin": 14, + "keyfunc": 1, + "keynumber": 30, + "knum": 2, + "ktime": 3, + "leaderr": 15, + "micpin": 23, + "module": "WB3S", + "notdisturb": 0, + "onoffmode": 0, + "pairt": 18, + "pmemory": 1, + "pwmhz": 1000, + "remdmode": 0, + "rstbr": 50, + "rstcor": "c", + "rstmode": 2, + "rstnum": 3, + "rsttemp": 100, + "scenespct": 5, + "scgmod": 0, + "sfunc": 4, + "starterr": 70, + "swgmod": 0, + "tempstep": 25, + "title20": 0, + "wfcfg": "spcl_auto", + "wfct": 3, + "wgmod": 0 + }, + "gw_wsm": { + "nc_tp": 4, + "ssid": null, + "passwd": null, + "md": 0, + "random": 0, + "wfb64": 1, + "stat": 2, + "token": "AAAAAA", + "region": "AA", + "reg_key": null, + "dns_prio": 2 + }, + "is_stride": 0, + "tls_ca_cnt": 0, + "gw_di": { + "abi": 0, + "id": "XP4Ugbn4miTgmzZYQioq", + "swv": "1.1.6", + "bv": "40.00", + "pv": "2.2", + "lpv": "3.3", + "pk": "keys8pj5xkq8cmrm", + "firmk": "keys8pj5xkq8cmrm", + "cadv": "1.0.2", + "cdv": "1.0.0", + "dev_swv": "1.1.6", + "s_id": "000002qmxg", + "dtp": 0, + "sync": 0, + "attr_num": 0, + "mst_tp_0": 0, + "mst_ver_0": null, + "mst_tp_1": 0, + "mst_ver_1": null, + "mst_tp_2": 0, + "mst_ver_2": null, + "mst_tp_3": 0, + "mst_ver_3": null, + "dminfo_name": null, + "dminfo_code": null, + "dminfo_report_code": null, + "dminfo_sn": null + }, + "timer_arr": { + "lastFetchTime": 0, + "cnt": 0 + }, + "gw_ai": { + "key": "KRSBVEH0JQkBkuiw", + "lckey": "eDqiGJUHGc0KkN7z", + "h_url": "http://10.42.42.1/d.json", + "h_ip": "10.42.42.1", + "hs_url": null, + "hs_ip": null, + "hs_psk": "https://a3.tuyacn.com/d.json", + "hs_psk_ip": "121.5.96.248", + "mqs_url": null, + "mqs_ip": null, + "mq_url": "10.42.42.1:1883", + "mq_ip": "10.42.42.1", + "ai_sp": null, + "mq_psk": "m2.tuyacn.com:8886", + "mq_psk_ip": "42.192.30.165", + "time_z": "+01:00", + "s_time_z": "[[1648342800,1667091600],[1679792400,1698541200]]", + "wx_app_id": null, + "wx_uuid": null, + "dy_tls_m": 1, + "cloud_cap": 1025 + }, + "000002qmxg": [ + { + "type": "obj", + "mode": "rw", + "property": { + "type": "bool" + }, + "id": 20 + }, + { + "type": "obj", + "mode": "rw", + "property": { + "range": [ + "white", + "colour", + "scene", + "music" + ], + "type": "enum" + }, + "id": 21 + }, + { + "type": "obj", + "mode": "rw", + "property": { + "min": 10, + "max": 1000, + "scale": 0, + "step": 1, + "type": "value" + }, + "id": 22 + }, + { + "type": "obj", + "mode": "rw", + "property": { + "type": "string", + "maxlen": 255 + }, + "id": 25 + }, + { + "type": "obj", + "mode": "rw", + "property": { + "min": 0, + "max": 86400, + "scale": 0, + "step": 1, + "type": "value" + }, + "id": 26 + }, + { + "type": "obj", + "mode": "wr", + "property": { + "type": "string", + "maxlen": 255 + }, + "id": 28 + }, + { + "mode": "rw", + "id": 33, + "type": "raw" + } + ], + "em_sys_env": "BK7231S_2M" +} + + diff --git a/web/index.html b/web/index.html index 0490320..869bcb8 100644 --- a/web/index.html +++ b/web/index.html @@ -41,7 +41,7 @@

UPK2ESPHome

  • user_param_key JSON (just the object)
  • raw data (JSON-like) extracted from storage, or offset 0x1E5000/0x1D4000 of the flash memory
  • -

    Supported device features are: relays, buttons, LEDs (status, PWM, driver chips), power monitoring chips.

    +

    Supported device features are: relays, buttons, LEDs (status, PWM, driver chips), power monitoring chips, IR/RF receivers.