Skip to content

Commit

Permalink
Add remote_receiver/transmitter support (#8)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Habbie and kuba2k2 authored Dec 13, 2023
1 parent 4c0804c commit 6e01c4d
Show file tree
Hide file tree
Showing 5 changed files with 333 additions and 3 deletions.
4 changes: 2 additions & 2 deletions upk2esphome/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
43 changes: 43 additions & 0 deletions upk2esphome/parts/remote.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions upk2esphome/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
284 changes: 284 additions & 0 deletions upk2esphome/tests/ty02-1ch-rf-v1.txt
Original file line number Diff line number Diff line change
@@ -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"
}


2 changes: 1 addition & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h1 class="text-body-emphasis">UPK2ESPHome</h1>
<li><code>user_param_key</code> JSON (just the object)</li>
<li>raw data (JSON-like) extracted from storage, or offset 0x1E5000/0x1D4000 of the flash memory</li>
</ul>
<p>Supported device features are: relays, buttons, LEDs (status, PWM, driver chips), power monitoring chips.</p>
<p>Supported device features are: relays, buttons, LEDs (status, PWM, driver chips), power monitoring chips, IR/RF receivers.</p>
<div class="alert alert-dismissible alert-warning fade show" role="alert" id="disclaimer">
<p>While the author has taken care to write the converter as well as possible, keep in mind that this might not
be 100% accurate!</p>
Expand Down

0 comments on commit 6e01c4d

Please sign in to comment.