596
|
1 from invoke import task
|
1717
|
2 from pathlib import Path
|
596
|
3
|
1741
|
4 port = 'usb-1a86_USB_Serial-if00-port0'
|
1701
|
5
|
1741
|
6 tag = 'docker.io/esphome/esphome:2023.2.4'
|
1701
|
7
|
1717
|
8 esphome = (
|
|
9 'docker run --rm ' + #
|
|
10 '-v `pwd`:/config ' + #
|
|
11 '-v /usr/share/fonts:/usr/share/fonts ' + #
|
|
12 '-v /dev:/dev ' + #
|
|
13 '-v /tmp:/tmp ' + #
|
|
14 f'-it {tag}')
|
|
15
|
800
|
16
|
|
17 @task
|
|
18 def get_dev_esphome(ctx):
|
1717
|
19 ctx.run(
|
|
20 f'docker build -t esphome_dev -f docker/Dockerfile https://github.com/MasterTim17/esphome.git#dev'
|
|
21 )
|
|
22
|
686
|
23
|
|
24 @task
|
|
25 def pull_esphome(ctx):
|
|
26 ctx.run(f"docker pull {tag}")
|
|
27
|
1717
|
28
|
596
|
29 @task
|
|
30 def program_board_over_usb(ctx, board):
|
800
|
31 board = board.replace('.yaml', '')
|
1717
|
32 print(
|
|
33 'connect gnd, 3v3, rx/tx per https://randomnerdtutorials.com/esp32-cam-video-streaming-web-server-camera-home-assistant/, '
|
|
34 )
|
|
35 print(
|
|
36 'rts to reset (if possible), dtr to gpio0 per https://github.com/espressif/esptool/wiki/ESP32-Boot-Mode-Selection#automatic-bootloader'
|
|
37 )
|
|
38 ctx.run(f"{esphome} run {board}.yaml --device={port}", pty=True, echo=True)
|
|
39
|
596
|
40
|
|
41 @task
|
|
42 def program_board_over_wifi(ctx, board):
|
1716
|
43 global esphome
|
800
|
44 board = board.replace('.yaml', '')
|
1716
|
45 if board == 'theater_lcd':
|
|
46 tag = 'esphome_dev'
|
|
47 esphome = 'esphome-local/env/bin/esphome'
|
|
48
|
800
|
49 ctx.run(f"{esphome} {board}.yaml run", pty=True)
|
596
|
50
|
1716
|
51
|
596
|
52 @task
|
|
53 def monitor_usb(ctx, board):
|
800
|
54 board = board.replace('.yaml', '')
|
1717
|
55 ctx.run(f"{esphome} logs {board}.yaml --device={port}", pty=True)
|
|
56
|
686
|
57
|
|
58 # device up?
|
|
59 # nmap -Pn -p 3232,6053 10.2.0.21
|
1717
|
60
|
|
61
|
|
62
|
|
63 # -s k v seemed to have no effect
|
|
64 def config_replace(in_file, out_file, repls):
|
|
65 yaml_text = open(in_file, 'rt').read()
|
|
66 for k, v in repls.items():
|
|
67 yaml_text = yaml_text.replace(k, str(v))
|
|
68 with open(out_file, 'wt') as out:
|
|
69 out.write(yaml_text)
|
|
70
|
|
71
|
|
72 def prep_tmp(ctx, project):
|
|
73 tmp = Path(f'/tmp/esphome_build/{project}')
|
|
74 ctx.run(f'mkdir -p {tmp}')
|
1718
|
75 ctx.run(f'rsync -a component secrets.yaml {tmp}')
|
1717
|
76 return tmp
|
|
77
|
|
78
|
1741
|
79 def replace_yaml_for_cam(inPath, outPath, camName):
|
|
80 config_replace(inPath, outPath, {
|
|
81 '$build_path': outPath.parent,
|
|
82 '$addr': '10.2.0.22',
|
|
83 '$name': camName,
|
|
84 })
|
|
85
|
|
86 @task
|
|
87 def program_cam_usb(ctx, name='cam-foo'):
|
|
88 idVendor = '1a86'
|
|
89 port = f'/dev/serial/by-id/usb-{idVendor}_USB_Serial-if00-port0'
|
|
90 tmp = prep_tmp(ctx, 'cam')
|
|
91 tmpyaml = tmp / 'cam.yaml'
|
|
92 replace_yaml_for_cam("cam.yaml", tmpyaml, name)
|
|
93 ctx.run(
|
|
94 f"{esphome} " #
|
|
95 + f" run {tmpyaml} " #
|
|
96 + f'--device={port} ',
|
|
97 pty=True,
|
|
98 echo=True)
|
|
99
|
1717
|
100 @task
|
|
101 def program_cam_ota(ctx, name='0'):
|
|
102 tmp = prep_tmp(ctx, 'cam')
|
|
103 tmpyaml = tmp / 'cam.yaml'
|
1741
|
104 replace_yaml_for_cam("cam.yaml", tmpyaml, name)
|
1717
|
105 ctx.run(
|
|
106 f"{esphome} " #
|
|
107 + f"run {tmpyaml} " #
|
|
108 + "--device=OTA --no-logs" #
|
|
109 ,
|
|
110 pty=True,
|
|
111 echo=True)
|