Skip to content

Commit 0e6e3de

Browse files
committed
Revive code
1 parent 9797d5e commit 0e6e3de

File tree

7 files changed

+58
-352
lines changed

7 files changed

+58
-352
lines changed

docs/updating.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ ota:
103103
Z2M versions older than v2.0.0 need a different configuration (and we will drop support soon):
104104
```yaml
105105
external_converters:
106-
- switch_custom.js
106+
- switch_custom.mjs
107107
- tuya_with_ota.js
108108
ota:
109109
zigbee_ota_override_index_location: PATH

helper_scripts/make_z2m_custom_converters.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import argparse
2-
from jinja2 import Environment, FileSystemLoader, select_autoescape
32
from pathlib import Path
4-
import yaml
53

4+
import yaml
5+
from jinja2 import Environment, FileSystemLoader, select_autoescape
66

77
env = Environment(
88
loader=FileSystemLoader("helper_scripts/templates"),
@@ -19,9 +19,6 @@
1919
parser.add_argument(
2020
"db_file", metavar="INPUT", type=str, help="File with device db"
2121
)
22-
parser.add_argument(
23-
"--z2m-v1", action=argparse.BooleanOptionalAction, help="Use old z2m"
24-
)
2522

2623
args = parser.parse_args()
2724

@@ -31,11 +28,10 @@
3128
devices = []
3229

3330
for device in db.values():
34-
3531
# Skip if build == no. Defaults to yes
3632
if not device.get("build", True):
3733
continue
38-
34+
3935
config = device["config_str"]
4036
zb_manufacturer, zb_model, *peripherals = config.rstrip(";").split(";")
4137

@@ -46,13 +42,13 @@
4642
for peripheral in peripherals:
4743
if peripheral[0] == "R":
4844
relay_cnt += 1
49-
if peripheral[0] == 'S':
45+
if peripheral[0] == "S":
5046
switch_cnt += 1
51-
if peripheral[0] == 'I':
47+
if peripheral[0] == "I":
5248
indicators_cnt += 1
53-
if peripheral[0] == 'L':
49+
if peripheral[0] == "L":
5450
has_dedicated_net_led = True
55-
51+
5652
if switch_cnt == 1:
5753
switch_names = ["switch"]
5854
elif switch_cnt == 2:
@@ -71,20 +67,20 @@
7167
else:
7268
relay_names = [f"relay_{index}" for index in range(relay_cnt)]
7369

74-
devices.append({
75-
"zb_models": [zb_model] + (device.get("old_zb_models") or []),
76-
"model": device.get("override_z2m_device") or device["stock_converter_model"],
77-
"switchNames": switch_names,
78-
"relayNames": relay_names,
79-
"relayIndicatorNames": relay_names[:indicators_cnt],
80-
"has_dedicated_net_led": has_dedicated_net_led,
81-
})
70+
devices.append(
71+
{
72+
"zb_models": [zb_model] + (device.get("old_zb_models") or []),
73+
"model": device.get("override_z2m_device")
74+
or device["stock_converter_model"],
75+
"switchNames": switch_names,
76+
"relayNames": relay_names,
77+
"relayIndicatorNames": relay_names[:indicators_cnt],
78+
"has_dedicated_net_led": has_dedicated_net_led,
79+
}
80+
)
8281

83-
template = env.get_template("switch_custom.js.jinja")
82+
template = env.get_template("switch_custom.mjs.jinja")
8483

85-
print(template.render(devices=devices, z2m_v1=args.z2m_v1))
84+
print(template.render(devices=devices))
8685

8786
exit(0)
88-
89-
90-
Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
import argparse
2-
from jinja2 import Environment, FileSystemLoader, select_autoescape
32
from pathlib import Path
3+
44
import yaml
5+
from jinja2 import Environment, FileSystemLoader, select_autoescape
56

67
env = Environment(
78
loader=FileSystemLoader("helper_scripts/templates"),
89
autoescape=select_autoescape(),
910
trim_blocks=True,
10-
lstrip_blocks=True
11+
lstrip_blocks=True,
1112
)
1213

1314
if __name__ == "__main__":
14-
parser = argparse.ArgumentParser(description="Create Zigbee2mqtt converter for tuya devices with ota",
15-
epilog="Generates a js file that adds ota support for given tuya models")
16-
parser.add_argument(
17-
"db_file", metavar="INPUT", type=str, help="File with device db"
15+
parser = argparse.ArgumentParser(
16+
description="Create Zigbee2mqtt converter for tuya devices with ota",
17+
epilog="Generates a js file that adds ota support for given tuya models",
1818
)
1919
parser.add_argument(
20-
"--z2m-v1", action=argparse.BooleanOptionalAction, help="Use old z2m"
20+
"db_file", metavar="INPUT", type=str, help="File with device db"
2121
)
2222

23-
2423
args = parser.parse_args()
2524

2625
db_str = Path(args.db_file).read_text()
@@ -29,18 +28,17 @@
2928
manufacturers = {
3029
"Tuya": ["TS0001", "TS0002", "TS0003", "TS0004"],
3130
"Moes": [],
32-
"AVATTO": []
31+
"AVATTO": [],
3332
}
3433

3534
# Prepare containers for multiple pinout models
3635
multiple_pinouts = {key: [] for key in manufacturers}
3736

3837
for entry in db.values():
39-
4038
# Skip if build == no. Defaults to yes
4139
if not entry.get("build", True):
4240
continue
43-
41+
4442
model = entry.get("stock_converter_model")
4543
mfr = entry.get("stock_converter_manufacturer", "Tuya")
4644
if model is None or mfr not in manufacturers:
@@ -61,14 +59,15 @@
6159

6260
template = env.get_template("tuya_with_ota.js.jinja")
6361

64-
print(template.render(
65-
tuyaModels=sorted(list(set(tuyaModels))),
66-
tuyaMultiplePinoutsModels=sorted(list(set(tuyaMultiplePinoutsModels))),
67-
moesModels=sorted(list(set(moesModels))),
68-
moesMultiplePinoutsModels=sorted(list(set(moesMultiplePinoutsModels))),
69-
avattoModels=sorted(list(set(avattoModels))),
70-
avattoMultiplePinoutsModels=sorted(list(set(avattoMultiplePinoutsModels))),
71-
z2m_v1=args.z2m_v1)
62+
print(
63+
template.render(
64+
tuyaModels=sorted(list(set(tuyaModels))),
65+
tuyaMultiplePinoutsModels=sorted(list(set(tuyaMultiplePinoutsModels))),
66+
moesModels=sorted(list(set(moesModels))),
67+
moesMultiplePinoutsModels=sorted(list(set(moesMultiplePinoutsModels))),
68+
avattoModels=sorted(list(set(avattoModels))),
69+
avattoMultiplePinoutsModels=sorted(list(set(avattoMultiplePinoutsModels))),
70+
)
7271
)
73-
74-
exit(0)
72+
73+
exit(0)

0 commit comments

Comments
 (0)