mirror of
https://github.com/esphome/esphome.git
synced 2025-08-20 17:19:27 +00:00
Compare commits
1590 Commits
pre-commit
...
api_memory
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7744b2db79 | ||
![]() |
8fcbcebf84 | ||
![]() |
561ed32b2a | ||
![]() |
5adfb71fe1 | ||
![]() |
dfdec8ec0a | ||
![]() |
f6c12229e5 | ||
![]() |
c80481baab | ||
![]() |
86ceccbb1c | ||
![]() |
628caf63fc | ||
![]() |
1ce5a994d8 | ||
![]() |
2abccce297 | ||
![]() |
0448a66960 | ||
![]() |
f3c0c0c00c | ||
![]() |
231bcb1f7d | ||
![]() |
9cac1c824e | ||
![]() |
b497f11af0 | ||
![]() |
07f16dc065 | ||
![]() |
d2deba6b69 | ||
![]() |
545fa1f1bc | ||
![]() |
c691f01c7f | ||
![]() |
b648944973 | ||
![]() |
40935f7ae4 | ||
![]() |
e152690867 | ||
![]() |
b1c86fe30e | ||
![]() |
b695f13f86 | ||
![]() |
a477249266 | ||
![]() |
b974ccabac | ||
![]() |
ab54a880c1 | ||
![]() |
f745135bdc | ||
![]() |
8f38be0914 | ||
![]() |
30c4b91697 | ||
![]() |
bfaf2547e3 | ||
![]() |
b5be45273f | ||
![]() |
5c2dea79ef | ||
![]() |
e012fd5b32 | ||
![]() |
856cb182fc | ||
![]() |
2b12307b49 | ||
![]() |
e340d61a85 | ||
![]() |
0110a376b7 | ||
![]() |
6486147da1 | ||
![]() |
5480675dd8 | ||
![]() |
6ab3de65a6 | ||
![]() |
5d9cba3dce | ||
![]() |
eb81b8a1c8 | ||
![]() |
de0656a188 | ||
![]() |
90a16ffa89 | ||
![]() |
4182076f64 | ||
![]() |
8c8c08d40c | ||
![]() |
82120bc5d7 | ||
![]() |
9769f8a4cc | ||
![]() |
0f6dad9c62 | ||
![]() |
58541aa739 | ||
![]() |
4c91dead3d | ||
![]() |
78a0fecc08 | ||
![]() |
42e1b1a2c1 | ||
![]() |
0d360938c2 | ||
![]() |
0968338064 | ||
![]() |
18e2f41424 | ||
![]() |
bd0fe34b14 | ||
![]() |
6e90feeccf | ||
![]() |
36ca3546f5 | ||
![]() |
5536bdf0c9 | ||
![]() |
37982290f7 | ||
![]() |
02b7db7311 | ||
![]() |
9bc3ff5f53 | ||
![]() |
786cb7ded5 | ||
![]() |
7f01c25782 | ||
![]() |
321f2f87b0 | ||
![]() |
11a051401f | ||
![]() |
6148dd7e41 | ||
![]() |
42b6939e90 | ||
![]() |
35b3f75f7c | ||
![]() |
78e8001aa8 | ||
![]() |
84fc6ff71a | ||
![]() |
a896190de5 | ||
![]() |
e599ab1a03 | ||
![]() |
5aaa99d0e4 | ||
![]() |
60e9ad2240 | ||
![]() |
d3342d6a1a | ||
![]() |
74b0a29a52 | ||
![]() |
3f492e3b82 | ||
![]() |
909356698c | ||
![]() |
b959baf3d6 | ||
![]() |
63b8a219e6 | ||
![]() |
84349b6d05 | ||
![]() |
0f15250f12 | ||
![]() |
c2f7dcfa6d | ||
![]() |
f34fe95f1c | ||
![]() |
388fde1ee8 | ||
![]() |
b13842f44e | ||
![]() |
1229766436 | ||
![]() |
77a5430f00 | ||
![]() |
778b586d78 | ||
![]() |
d3d1ba553d | ||
![]() |
a572d4eb47 | ||
![]() |
9ae45ba8aa | ||
![]() |
8f58ca3a2a | ||
![]() |
8ac6075321 | ||
![]() |
6e1e8ed321 | ||
![]() |
e3da197adf | ||
![]() |
0826ade69d | ||
![]() |
cf9130f906 | ||
![]() |
b2a8b0a22f | ||
![]() |
d268c14f7e | ||
![]() |
619e2d69c0 | ||
![]() |
3cca7a6161 | ||
![]() |
52d6801618 | ||
![]() |
a714e8da0b | ||
![]() |
1778776b73 | ||
![]() |
d6e05061f8 | ||
![]() |
13ceda899b | ||
![]() |
40d436746c | ||
![]() |
5c59b4fcad | ||
![]() |
4de36ffeb4 | ||
![]() |
f78e71c86a | ||
![]() |
4b3393ce64 | ||
![]() |
4c8bb878bf | ||
![]() |
8a3cb32531 | ||
![]() |
d3ab7f320e | ||
![]() |
85351bb952 | ||
![]() |
b47f9158b2 | ||
![]() |
ee5242ec8d | ||
![]() |
238909c0de | ||
![]() |
fe9316c95d | ||
![]() |
a7e74bb7de | ||
![]() |
b9cb690986 | ||
![]() |
808066f564 | ||
![]() |
f8c45573f3 | ||
![]() |
2057af8396 | ||
![]() |
b95449615f | ||
![]() |
5e8f1d82c3 | ||
![]() |
6afda9d4dc | ||
![]() |
4f10a0ccf7 | ||
![]() |
96d39403f4 | ||
![]() |
aeb56cc3d0 | ||
![]() |
33389f9c7f | ||
![]() |
e231d334a3 | ||
![]() |
55a7926670 | ||
![]() |
f76cba0af6 | ||
![]() |
1dc75f6ffa | ||
![]() |
acb0fdc288 | ||
![]() |
de235b638a | ||
![]() |
ab454e9928 | ||
![]() |
0a8af3ec85 | ||
![]() |
51eecac2de | ||
![]() |
815744b0f6 | ||
![]() |
a1281febe9 | ||
![]() |
9ef982fa4d | ||
![]() |
44f97e2de4 | ||
![]() |
8ad4d3b6f5 | ||
![]() |
d97f473e4a | ||
![]() |
ef072eb655 | ||
![]() |
8040c7cd92 | ||
![]() |
8648acab5d | ||
![]() |
1155e9b88a | ||
![]() |
c069a66625 | ||
![]() |
2a10f58bdd | ||
![]() |
e713b0bd8c | ||
![]() |
e7d819a656 | ||
![]() |
fd13ed78ab | ||
![]() |
221f380ca3 | ||
![]() |
16292a9f13 | ||
![]() |
85fa884382 | ||
![]() |
873f4125c5 | ||
![]() |
90f0ebb22b | ||
![]() |
4153380f99 | ||
![]() |
740c0ef9d7 | ||
![]() |
b4521e1d8c | ||
![]() |
10ca7ed85b | ||
![]() |
e43efdaaec | ||
![]() |
9207bf97f3 | ||
![]() |
c13317f807 | ||
![]() |
77d1d0414d | ||
![]() |
8f42bc6aac | ||
![]() |
9beb4e2cd4 | ||
![]() |
097aac2183 | ||
![]() |
6cd443e9dc | ||
![]() |
c8c1573fbb | ||
![]() |
e7fb069bb3 | ||
![]() |
fe7e5feba7 | ||
![]() |
1abdc23a23 | ||
![]() |
ec3660e8ae | ||
![]() |
f6251cf6e4 | ||
![]() |
77258b5e62 | ||
![]() |
dc7996922b | ||
![]() |
31a6ae00b5 | ||
![]() |
d2569c0f1e | ||
![]() |
d8f786cfdf | ||
![]() |
75ef572a24 | ||
![]() |
f0f30224d3 | ||
![]() |
ec6e61e688 | ||
![]() |
3dd457c471 | ||
![]() |
3b8a34c8d0 | ||
![]() |
fe76955f3e | ||
![]() |
db8767fb05 | ||
![]() |
7dad9c2ab0 | ||
![]() |
4c0c0954a4 | ||
![]() |
f5a486a7da | ||
![]() |
425d57ba7d | ||
![]() |
1965a41725 | ||
![]() |
27f352b7dc | ||
![]() |
e01fb0b677 | ||
![]() |
671f0d62c7 | ||
![]() |
f1b888b309 | ||
![]() |
9cbcd0497a | ||
![]() |
0139de37ba | ||
![]() |
4e7fe88da3 | ||
![]() |
6af4961695 | ||
![]() |
ae78f7798f | ||
![]() |
53295fde7e | ||
![]() |
df461c08a9 | ||
![]() |
bbf9dcc15a | ||
![]() |
a3e7105cb0 | ||
![]() |
10e5400d1f | ||
![]() |
97eb949670 | ||
![]() |
8f484a89f3 | ||
![]() |
1f35c35e2a | ||
![]() |
427560f814 | ||
![]() |
4a3000bcc5 | ||
![]() |
25cac3e04e | ||
![]() |
fc386a2648 | ||
![]() |
3fd9a3507c | ||
![]() |
d92005113a | ||
![]() |
fb2d764c89 | ||
![]() |
0251bb48ec | ||
![]() |
a035db1d11 | ||
![]() |
88049f9801 | ||
![]() |
42a9125ea7 | ||
![]() |
63972ff272 | ||
![]() |
dc53473e7e | ||
![]() |
2c290e3bee | ||
![]() |
c37494ea55 | ||
![]() |
b3e8963a33 | ||
![]() |
e2c77c0c4f | ||
![]() |
139ce4c655 | ||
![]() |
010dc35efc | ||
![]() |
413969300b | ||
![]() |
b67a88027d | ||
![]() |
2384b54ee3 | ||
![]() |
7e3a203f0b | ||
![]() |
054e39316c | ||
![]() |
7ce879521d | ||
![]() |
6f5f378857 | ||
![]() |
773950332b | ||
![]() |
35cd8616a2 | ||
![]() |
95786ce269 | ||
![]() |
c082ee616e | ||
![]() |
869f96f832 | ||
![]() |
504ca09451 | ||
![]() |
90c4b71d3f | ||
![]() |
7e1db7a75c | ||
![]() |
2f298992cf | ||
![]() |
c8c5c26896 | ||
![]() |
d8545ef946 | ||
![]() |
db68f9571b | ||
![]() |
0350471fa9 | ||
![]() |
3ed533d709 | ||
![]() |
e472a345c9 | ||
![]() |
42be5d892a | ||
![]() |
9a0d5019e1 | ||
![]() |
fc8c1ac9dd | ||
![]() |
536134e2b5 | ||
![]() |
005d4354d5 | ||
![]() |
7107b5cfef | ||
![]() |
bb153d42dc | ||
![]() |
a3806e4de2 | ||
![]() |
4dbe19a56e | ||
![]() |
0b74122d6f | ||
![]() |
e148c22f25 | ||
![]() |
1678eb0591 | ||
![]() |
dfa4328604 | ||
![]() |
9dab840c58 | ||
![]() |
29fff967f5 | ||
![]() |
2a35c95718 | ||
![]() |
4a70aa26e8 | ||
![]() |
748604d374 | ||
![]() |
d32db20aa0 | ||
![]() |
ae346bb94e | ||
![]() |
cb67010574 | ||
![]() |
defa452aa1 | ||
![]() |
97a476b475 | ||
![]() |
07a4f6f53c | ||
![]() |
7d2726ab21 | ||
![]() |
3862e3b4e7 | ||
![]() |
be84f12100 | ||
![]() |
0097a55eaa | ||
![]() |
d1609de25a | ||
![]() |
02395c92a1 | ||
![]() |
f2ac6b0af6 | ||
![]() |
a3c8f667a7 | ||
![]() |
d06bab01ac | ||
![]() |
591786a787 | ||
![]() |
5de7b874b0 | ||
![]() |
a27f6c72b9 | ||
![]() |
a80d3012bd | ||
![]() |
1c0a646309 | ||
![]() |
eabb781e5f | ||
![]() |
03c2cda17c | ||
![]() |
26b72ccb10 | ||
![]() |
ab993c6d5a | ||
![]() |
999090fa18 | ||
![]() |
2eed309224 | ||
![]() |
12980847a8 | ||
![]() |
01a6b38b89 | ||
![]() |
73b786c22e | ||
![]() |
c1a6e82322 | ||
![]() |
ec848bc7b4 | ||
![]() |
e5df43b934 | ||
![]() |
d13f87e891 | ||
![]() |
132d56fe1a | ||
![]() |
171e19381f | ||
![]() |
9cc7b060c9 | ||
![]() |
d178e2da6f | ||
![]() |
1e8f961362 | ||
![]() |
166f77610f | ||
![]() |
97dc244d1e | ||
![]() |
085ddebf7d | ||
![]() |
bccc3d79d8 | ||
![]() |
4df3bfe85d | ||
![]() |
99345574e4 | ||
![]() |
80c66b0742 | ||
![]() |
17d820570b | ||
![]() |
c979d5c9b1 | ||
![]() |
13ac6df1dd | ||
![]() |
98d091fbc3 | ||
![]() |
22e67f9754 | ||
![]() |
515a97de76 | ||
![]() |
68b5337ed3 | ||
![]() |
8ee86c717b | ||
![]() |
10530cdef3 | ||
![]() |
5de0f9efc9 | ||
![]() |
6d1d7f137f | ||
![]() |
38e16efa11 | ||
![]() |
5e2f0f7f5e | ||
![]() |
83c7afc46f | ||
![]() |
10753f0f99 | ||
![]() |
34a852d433 | ||
![]() |
3922fbdef7 | ||
![]() |
e5415abf20 | ||
![]() |
67e1a92cce | ||
![]() |
4c64511a15 | ||
![]() |
75f3e0900e | ||
![]() |
abd33c21bf | ||
![]() |
d592ba2c5e | ||
![]() |
321eba5184 | ||
![]() |
82b9ec53fd | ||
![]() |
b9262f967b | ||
![]() |
949fb9a890 | ||
![]() |
99952a701f | ||
![]() |
88878adb6c | ||
![]() |
17e3b49ebb | ||
![]() |
a217747f5d | ||
![]() |
790c9cbb84 | ||
![]() |
da5fb6e24f | ||
![]() |
a77439b4b7 | ||
![]() |
1a049bdcbb | ||
![]() |
79686239d3 | ||
![]() |
c934e84e21 | ||
![]() |
5e2f8cb018 | ||
![]() |
6bd0af6d85 | ||
![]() |
0f28a49822 | ||
![]() |
66d96646b1 | ||
![]() |
be4cf6505f | ||
![]() |
e8ea7825a9 | ||
![]() |
8c13eab731 | ||
![]() |
bf4cbb0aee | ||
![]() |
aaec4b7bd3 | ||
![]() |
7bddcd4f64 | ||
![]() |
af205a5267 | ||
![]() |
c2599d7719 | ||
![]() |
4ea6f23d9e | ||
![]() |
f23fd52a26 | ||
![]() |
cfd43c81fb | ||
![]() |
3dcba675b4 | ||
![]() |
bb51031ec6 | ||
![]() |
ecb99cbcce | ||
![]() |
0a514821c6 | ||
![]() |
074fbb522c | ||
![]() |
71d6ba242e | ||
![]() |
37ffd64b48 | ||
![]() |
ec65652567 | ||
![]() |
731613421d | ||
![]() |
58dfad4ed0 | ||
![]() |
7eb029f4b9 | ||
![]() |
8da8d938f0 | ||
![]() |
64ac0d2bde | ||
![]() |
7d3cdd15ad | ||
![]() |
53baf02087 | ||
![]() |
a0d2392344 | ||
![]() |
fb3c092eaa | ||
![]() |
c169cf1e77 | ||
![]() |
fa4d8e083a | ||
![]() |
2cfeccfd71 | ||
![]() |
f36ca93752 | ||
![]() |
dc8714c277 | ||
![]() |
90fcb5fbcd | ||
![]() |
932d0a5d8b | ||
![]() |
4cafa18fa4 | ||
![]() |
b12d7db5a7 | ||
![]() |
e84345594d | ||
![]() |
add7bec7f2 | ||
![]() |
db84d8e8dc | ||
![]() |
ad51e647af | ||
![]() |
c45901746b | ||
![]() |
033c469250 | ||
![]() |
0900fd3cea | ||
![]() |
ba8f3d3f63 | ||
![]() |
2759f3828e | ||
![]() |
f395767766 | ||
![]() |
2dc222aea6 | ||
![]() |
82d68c87e2 | ||
![]() |
f213657753 | ||
![]() |
e077e6cec7 | ||
![]() |
339a3270f6 | ||
![]() |
462b44ee23 | ||
![]() |
52d3dba89c | ||
![]() |
939d01dd99 | ||
![]() |
4900f7c7ca | ||
![]() |
48957aee8b | ||
![]() |
e355ce04f7 | ||
![]() |
758e5b89bb | ||
![]() |
3ffdd1d451 | ||
![]() |
4c1b8c8b96 | ||
![]() |
3ca956cd6a | ||
![]() |
2e24a11a1d | ||
![]() |
10a03ad538 | ||
![]() |
69839ec4dc | ||
![]() |
28a66d4bf0 | ||
![]() |
782d894801 | ||
![]() |
06dd731c78 | ||
![]() |
6af74302dc | ||
![]() |
03380a6ecd | ||
![]() |
8d8db11dd9 | ||
![]() |
28886a896b | ||
![]() |
05253991c2 | ||
![]() |
96f0fda477 | ||
![]() |
023fa4d220 | ||
![]() |
a1f63c0dfc | ||
![]() |
ef98f42e7e | ||
![]() |
737e1284af | ||
![]() |
8677918157 | ||
![]() |
629c891dfc | ||
![]() |
8e8ef83780 | ||
![]() |
2a15f35e9d | ||
![]() |
9bfa942cf2 | ||
![]() |
b00adbddce | ||
![]() |
a71030c4de | ||
![]() |
6bb32c2e61 | ||
![]() |
7bc2c685e0 | ||
![]() |
9205338cc8 | ||
![]() |
04336f7ba3 | ||
![]() |
6f64312d08 | ||
![]() |
79dfb86830 | ||
![]() |
453dc29540 | ||
![]() |
f4260d370c | ||
![]() |
655f9489a8 | ||
![]() |
4b3cc52afe | ||
![]() |
fd3f15637a | ||
![]() |
1311e1b8b0 | ||
![]() |
64e84872da | ||
![]() |
bc7379030e | ||
![]() |
ecfb6dc8ed | ||
![]() |
75d67af932 | ||
![]() |
845dad6ee7 | ||
![]() |
e2e86da64b | ||
![]() |
90ec63589f | ||
![]() |
ea308eaaa2 | ||
![]() |
87f1fac2bf | ||
![]() |
c23651527f | ||
![]() |
2cc263a707 | ||
![]() |
fb336718de | ||
![]() |
e2e35bf965 | ||
![]() |
bdd25c7268 | ||
![]() |
82c788d6ce | ||
![]() |
5167184cc7 | ||
![]() |
a5d1b11204 | ||
![]() |
dc8f2fd37e | ||
![]() |
7c85886ce8 | ||
![]() |
12f172436d | ||
![]() |
e69ac0478e | ||
![]() |
a45743c2b7 | ||
![]() |
ebe1531927 | ||
![]() |
a88a059c6a | ||
![]() |
d314cbb0d5 | ||
![]() |
4d75758eb2 | ||
![]() |
0eecc29039 | ||
![]() |
294fb67410 | ||
![]() |
2f1f098b47 | ||
![]() |
77be414261 | ||
![]() |
c34fc3c4c7 | ||
![]() |
8aac2f525e | ||
![]() |
f85dcdca4e | ||
![]() |
e7a1ef7aa1 | ||
![]() |
7c2d2ef5a3 | ||
![]() |
1449001747 | ||
![]() |
f245c74520 | ||
![]() |
da1658e4f9 | ||
![]() |
80f9352a79 | ||
![]() |
9ded501402 | ||
![]() |
3d6a1811c5 | ||
![]() |
a5ee047efb | ||
![]() |
fb0090dcdc | ||
![]() |
294bd4d042 | ||
![]() |
e99b8d2daf | ||
![]() |
6dbdeeb59b | ||
![]() |
82fd62e9dd | ||
![]() |
70f935d323 | ||
![]() |
0f3e6cccd9 | ||
![]() |
6ff323c56d | ||
![]() |
096ec79ef9 | ||
![]() |
bf5ba65558 | ||
![]() |
62088dfaed | ||
![]() |
dfcc3206f7 | ||
![]() |
e173b7f0c2 | ||
![]() |
f98e28a8a2 | ||
![]() |
f63557f2e7 | ||
![]() |
a353598961 | ||
![]() |
bc33b44648 | ||
![]() |
1579779967 | ||
![]() |
cc6ea4cd14 | ||
![]() |
303a8ff87a | ||
![]() |
7d3a11a735 | ||
![]() |
94b6344820 | ||
![]() |
40307c079c | ||
![]() |
debef6fde4 | ||
![]() |
0cda83d29c | ||
![]() |
32729c7ca7 | ||
![]() |
b7fca5488a | ||
![]() |
9c22772758 | ||
![]() |
1e72f07fdf | ||
![]() |
a592e96709 | ||
![]() |
3980339868 | ||
![]() |
afa66c17bd | ||
![]() |
be2988b1d7 | ||
![]() |
cf647f0c36 | ||
![]() |
385ed4ca0c | ||
![]() |
9188a8e326 | ||
![]() |
0efb6d55c8 | ||
![]() |
f748047b7b | ||
![]() |
49bc767bf4 | ||
![]() |
e12cc9a9a7 | ||
![]() |
8e4470cdff | ||
![]() |
bdb7e19fd0 | ||
![]() |
0fc3f0e162 | ||
![]() |
6fac66e63b | ||
![]() |
71e06ea1b6 | ||
![]() |
3df434fd55 | ||
![]() |
729b2b2873 | ||
![]() |
bc2adb6b5a | ||
![]() |
aaff086aeb | ||
![]() |
e4c0f18ee3 | ||
![]() |
9c09a271f2 | ||
![]() |
37578f3e22 | ||
![]() |
4649599592 | ||
![]() |
71f78e3a81 | ||
![]() |
f7ca26eef8 | ||
![]() |
0665fcea9e | ||
![]() |
cd2b50c27f | ||
![]() |
ca70f17b3b | ||
![]() |
a5e08aaf74 | ||
![]() |
947db4605a | ||
![]() |
481a00a0b5 | ||
![]() |
465019e510 | ||
![]() |
a4d5f39fb6 | ||
![]() |
5dd76966c3 | ||
![]() |
db86f87fc3 | ||
![]() |
e21334b7fa | ||
![]() |
ba4c268956 | ||
![]() |
068594be5e | ||
![]() |
0fd45fc86e | ||
![]() |
257fb98113 | ||
![]() |
f8922b3cca | ||
![]() |
b0b08f317b | ||
![]() |
2c4667fb46 | ||
![]() |
9eadfa21d8 | ||
![]() |
953fd24458 | ||
![]() |
1be171e084 | ||
![]() |
5c83b99e0c | ||
![]() |
743e611735 | ||
![]() |
35ff850894 | ||
![]() |
b666295b53 | ||
![]() |
96cf8d97ab | ||
![]() |
3c1a781a1c | ||
![]() |
00bd1b0a02 | ||
![]() |
b8482da421 | ||
![]() |
756ece9ff3 | ||
![]() |
4bb016fec3 | ||
![]() |
32f0322dec | ||
![]() |
1a1c13b722 | ||
![]() |
139453822b | ||
![]() |
7a33994666 | ||
![]() |
f381d9011b | ||
![]() |
96352f047d | ||
![]() |
5e7a1fea8c | ||
![]() |
64eb70444d | ||
![]() |
0f39b1c49a | ||
![]() |
e2d6363c68 | ||
![]() |
cdeef700c2 | ||
![]() |
86fd702841 | ||
![]() |
6c62d4a923 | ||
![]() |
6e42d009fb | ||
![]() |
7d7769ea5d | ||
![]() |
3908677fe2 | ||
![]() |
9799a2b636 | ||
![]() |
55c8129423 | ||
![]() |
099474053e | ||
![]() |
efafabed97 | ||
![]() |
d209739f85 | ||
![]() |
d463dd0f57 | ||
![]() |
c33c14a46f | ||
![]() |
2d0c109dc1 | ||
![]() |
825d0bed88 | ||
![]() |
cd1390916c | ||
![]() |
149bdaf146 | ||
![]() |
ad628c9cba | ||
![]() |
b88f87799e | ||
![]() |
1ff7cf1125 | ||
![]() |
31db6e51eb | ||
![]() |
681d9236f9 | ||
![]() |
8aa8af735d | ||
![]() |
943d0f103d | ||
![]() |
8b195d7f63 | ||
![]() |
649ad47e62 | ||
![]() |
93dc5765bb | ||
![]() |
b000b1b70c | ||
![]() |
8707b6e01a | ||
![]() |
34abd67f3e | ||
![]() |
45f1db9233 | ||
![]() |
beb4d1511a | ||
![]() |
adeceee71f | ||
![]() |
7d4b11d112 | ||
![]() |
6733cd4ed1 | ||
![]() |
07f361a404 | ||
![]() |
ae981ea7f2 | ||
![]() |
b7d0f5e36b | ||
![]() |
3cbce4df42 | ||
![]() |
7e77e40bda | ||
![]() |
305805256d | ||
![]() |
e36c669dc0 | ||
![]() |
71aff9bc60 | ||
![]() |
36d11c969f | ||
![]() |
f76ce5d3bb | ||
![]() |
0df454481e | ||
![]() |
83c1a30cfb | ||
![]() |
6cbd1479c6 | ||
![]() |
3e6e438920 | ||
![]() |
560886eb90 | ||
![]() |
340bb5cef6 | ||
![]() |
44a7c1d4a5 | ||
![]() |
519c49f175 | ||
![]() |
c96ffefa42 | ||
![]() |
490ca8ad5a | ||
![]() |
e385f87d6c | ||
![]() |
58de53123a | ||
![]() |
4f365c1716 | ||
![]() |
981177da23 | ||
![]() |
088bea9ccd | ||
![]() |
36350f179e | ||
![]() |
902f08c1bc | ||
![]() |
47ad206ccd | ||
![]() |
9f51546023 | ||
![]() |
f6d679f056 | ||
![]() |
93c45e88e7 | ||
![]() |
da189da9ae | ||
![]() |
c40a33cb48 | ||
![]() |
9846beee7d | ||
![]() |
81685f9132 | ||
![]() |
14123d25c2 | ||
![]() |
928819ffbd | ||
![]() |
7f2f9636f5 | ||
![]() |
b49fe146ad | ||
![]() |
98bbd4136b | ||
![]() |
d8d02f71ba | ||
![]() |
26980df2b9 | ||
![]() |
ffe39473d0 | ||
![]() |
6af8d152ee | ||
![]() |
de846a8f7a | ||
![]() |
8e31316e3d | ||
![]() |
fb6edb3243 | ||
![]() |
244bd9256f | ||
![]() |
1f61fd383c | ||
![]() |
ce294ce0c1 | ||
![]() |
dcbdc0ac51 | ||
![]() |
daea06586d | ||
![]() |
9c8bf2587b | ||
![]() |
9871cb04ea | ||
![]() |
7dc093815f | ||
![]() |
087697106c | ||
![]() |
9beebc7bfe | ||
![]() |
4a948b7aae | ||
![]() |
0d3bc21e97 | ||
![]() |
7496894ae6 | ||
![]() |
918d7217a9 | ||
![]() |
2103d583f9 | ||
![]() |
837c446926 | ||
![]() |
480ea54ee0 | ||
![]() |
97e7c34cb6 | ||
![]() |
fe65b149f5 | ||
![]() |
4106b97174 | ||
![]() |
8648954b94 | ||
![]() |
9f1fae0955 | ||
![]() |
1d631c3c6d | ||
![]() |
727161f1db | ||
![]() |
bf5f628769 | ||
![]() |
8563a5785f | ||
![]() |
4082634e6d | ||
![]() |
a74adb5865 | ||
![]() |
2e4d7301f2 | ||
![]() |
94845222ad | ||
![]() |
7f6ac2deee | ||
![]() |
a054aa9c52 | ||
![]() |
22cb59b88c | ||
![]() |
6968772a31 | ||
![]() |
004f4b51d1 | ||
![]() |
8c8dd7b4bc | ||
![]() |
9778289d33 | ||
![]() |
a43caf08a6 | ||
![]() |
01e550fac9 | ||
![]() |
ad4dd6a060 | ||
![]() |
849d99b0dc | ||
![]() |
f5df5f71a3 | ||
![]() |
429be0a5ae | ||
![]() |
148e4ec555 | ||
![]() |
bb22f4d6a3 | ||
![]() |
f94703360b | ||
![]() |
f26bec1a5a | ||
![]() |
d065f4ae62 | ||
![]() |
ed2c3e626b | ||
![]() |
1927f92358 | ||
![]() |
939144174c | ||
![]() |
59bcbe7fef | ||
![]() |
8e00fedc67 | ||
![]() |
0ac879ae0b | ||
![]() |
22d1a18d22 | ||
![]() |
ca203bff9b | ||
![]() |
e01d16ce82 | ||
![]() |
93b6b9835c | ||
![]() |
d0ac5388d9 | ||
![]() |
9097d646ca | ||
![]() |
596a28e1fb | ||
![]() |
5205ff5c43 | ||
![]() |
c420bf5f4f | ||
![]() |
18844e15dc | ||
![]() |
af2f5b7348 | ||
![]() |
bcbf0f0e26 | ||
![]() |
4d460d4bc3 | ||
![]() |
92f6f3ac0d | ||
![]() |
bc63d246c8 | ||
![]() |
b25f272d72 | ||
![]() |
e3a3305adb | ||
![]() |
c655c4e106 | ||
![]() |
7fe8cdaa34 | ||
![]() |
df97985048 | ||
![]() |
3779675816 | ||
![]() |
0005aad5b5 | ||
![]() |
98c18517e2 | ||
![]() |
e4dee935ce | ||
![]() |
f8cb44fb3c | ||
![]() |
101901fdb8 | ||
![]() |
b8579d2040 | ||
![]() |
3fca3df756 | ||
![]() |
2f5db85997 | ||
![]() |
e0d4361875 | ||
![]() |
30bafc43bd | ||
![]() |
3530437b48 | ||
![]() |
81db42942c | ||
![]() |
6cb0d9e0b5 | ||
![]() |
19f7e36753 | ||
![]() |
a963f97520 | ||
![]() |
ad2d48e9b7 | ||
![]() |
5c0d67ca14 | ||
![]() |
3467329a7c | ||
![]() |
d73fa370f3 | ||
![]() |
78fd0a4870 | ||
![]() |
3162bb475d | ||
![]() |
c17503abd5 | ||
![]() |
3433ee8171 | ||
![]() |
344297b0a7 | ||
![]() |
947456628e | ||
![]() |
80dd6c111d | ||
![]() |
b70188ba4b | ||
![]() |
c6064aa2b4 | ||
![]() |
6596f864be | ||
![]() |
f61a40efb8 | ||
![]() |
b049f0b480 | ||
![]() |
b2641d29c1 | ||
![]() |
7b8cfc768d | ||
![]() |
04860567f7 | ||
![]() |
b16edb5a99 | ||
![]() |
15a995b2e7 | ||
![]() |
f57e26c54e | ||
![]() |
2b7bc1cd9f | ||
![]() |
614a2f66a3 | ||
![]() |
9047b02c92 | ||
![]() |
e73d0477bb | ||
![]() |
2b1e623eb4 | ||
![]() |
c366d555e9 | ||
![]() |
7efbd62730 | ||
![]() |
b77c1d0af8 | ||
![]() |
f8810ea6a8 | ||
![]() |
40dd667211 | ||
![]() |
848b572864 | ||
![]() |
7c858fbccd | ||
![]() |
a1814ea37d | ||
![]() |
5892a1dbe2 | ||
![]() |
29f524f432 | ||
![]() |
4ec588ebd7 | ||
![]() |
efdef61477 | ||
![]() |
fe2b9f8c12 | ||
![]() |
c6be55eb55 | ||
![]() |
4c69925b84 | ||
![]() |
bc6407df0a | ||
![]() |
01982a8d0a | ||
![]() |
b995cd6257 | ||
![]() |
b16d7b7a95 | ||
![]() |
42aea701d3 | ||
![]() |
5f56c85182 | ||
![]() |
52b4eb8950 | ||
![]() |
eeb2b42a0f | ||
![]() |
90772033d1 | ||
![]() |
dadeb4d2a9 | ||
![]() |
60a5029c88 | ||
![]() |
d7ba16b48b | ||
![]() |
fca9befa63 | ||
![]() |
187cbde0db | ||
![]() |
f5ae5cade8 | ||
![]() |
3e66c28aff | ||
![]() |
89703a1aef | ||
![]() |
cba31617e9 | ||
![]() |
a3eeb46961 | ||
![]() |
128bd76f20 | ||
![]() |
c0355fd2c6 | ||
![]() |
a5fd440e25 | ||
![]() |
592ef8be2a | ||
![]() |
3bcc1c7297 | ||
![]() |
3b44c3acd1 | ||
![]() |
ec4911643a | ||
![]() |
f4fedbab44 | ||
![]() |
553d441ecc | ||
![]() |
1946116438 | ||
![]() |
ab28515fba | ||
![]() |
4dc11fb95e | ||
![]() |
e27094e0f3 | ||
![]() |
88302201eb | ||
![]() |
8afb172e83 | ||
![]() |
562d024623 | ||
![]() |
50b094547c | ||
![]() |
a6c1e50985 | ||
![]() |
96772bdfc6 | ||
![]() |
ed154d373c | ||
![]() |
a5e862ce36 | ||
![]() |
ae55964bd9 | ||
![]() |
c162309f41 | ||
![]() |
62c667f1a0 | ||
![]() |
3d08eae8e4 | ||
![]() |
2af5a0a6dd | ||
![]() |
6d24b04235 | ||
![]() |
3ee8103353 | ||
![]() |
1296165fce | ||
![]() |
7100c22dc4 | ||
![]() |
5718c0f5b8 | ||
![]() |
25ebddfa1c | ||
![]() |
2c0558fe23 | ||
![]() |
7192108fc1 | ||
![]() |
847696c342 | ||
![]() |
912ae1fc87 | ||
![]() |
a86f75d31d | ||
![]() |
fe1e25b5c7 | ||
![]() |
9b241b596a | ||
![]() |
53b9c8d5bb | ||
![]() |
2946bc9d72 | ||
![]() |
67a20e212d | ||
![]() |
a9ace366eb | ||
![]() |
df3469efba | ||
![]() |
0a3bbb8554 | ||
![]() |
a15b9f5d3b | ||
![]() |
e6334b0716 | ||
![]() |
7a835baa5a | ||
![]() |
c9c21a5728 | ||
![]() |
956959fc32 | ||
![]() |
6f67f74638 | ||
![]() |
b3dd4543b7 | ||
![]() |
4f17a28ac5 | ||
![]() |
90736f367a | ||
![]() |
9af88bd482 | ||
![]() |
13b89f4934 | ||
![]() |
d00a00d142 | ||
![]() |
e662c39e16 | ||
![]() |
95ef131285 | ||
![]() |
7476f170f6 | ||
![]() |
3b6bd55d1e | ||
![]() |
10dbc9e884 | ||
![]() |
860f619dfe | ||
![]() |
17ddc9ee0c | ||
![]() |
949689c318 | ||
![]() |
86a2aac011 | ||
![]() |
d0a402f201 | ||
![]() |
05772d5365 | ||
![]() |
c2a68f5147 | ||
![]() |
697ca1c7be | ||
![]() |
409346952f | ||
![]() |
f4b3539d77 | ||
![]() |
c12166c1a1 | ||
![]() |
8d20f003cb | ||
![]() |
88f857a2f0 | ||
![]() |
fb7faadd99 | ||
![]() |
5c8d6752fb | ||
![]() |
dda81fbc2c | ||
![]() |
c40dff5d63 | ||
![]() |
6f07b54772 | ||
![]() |
ce0f1dfcb6 | ||
![]() |
9a3a5d48eb | ||
![]() |
4a759eda02 | ||
![]() |
26badf201d | ||
![]() |
384f27cd6d | ||
![]() |
ac1c5f9f58 | ||
![]() |
8ad058fdf4 | ||
![]() |
9024c3c67a | ||
![]() |
fc81a47499 | ||
![]() |
a331452076 | ||
![]() |
b1c6e8168e | ||
![]() |
b41cc0226e | ||
![]() |
450429ddd5 | ||
![]() |
f7b24f4b4b | ||
![]() |
294c985380 | ||
![]() |
720964b901 | ||
![]() |
8895c8a987 | ||
![]() |
740dcd72a2 | ||
![]() |
ffd442624f | ||
![]() |
088fd85694 | ||
![]() |
d5b68d69d3 | ||
![]() |
bb0f7bb393 | ||
![]() |
d86a108f18 | ||
![]() |
7828ed2d9e | ||
![]() |
ebf14f50fb | ||
![]() |
1546ff615b | ||
![]() |
46cf1fb597 | ||
![]() |
8bf8655054 | ||
![]() |
a6d84948e2 | ||
![]() |
fac20a1f97 | ||
![]() |
c65586b5e1 | ||
![]() |
b27b018b06 | ||
![]() |
403da1e632 | ||
![]() |
2371ec1f9e | ||
![]() |
5e3ec2d34b | ||
![]() |
78d84644c9 | ||
![]() |
0cd0f8015a | ||
![]() |
4b5424f695 | ||
![]() |
a1d59040f7 | ||
![]() |
0306398072 | ||
![]() |
a7e0bf9013 | ||
![]() |
ddb988cd83 | ||
![]() |
04b54353f1 | ||
![]() |
f058107c05 | ||
![]() |
6b5b0815d7 | ||
![]() |
8388497038 | ||
![]() |
825b1113b6 | ||
![]() |
9074ef792f | ||
![]() |
0946f28511 | ||
![]() |
23765cd4f5 | ||
![]() |
e20c6468d0 | ||
![]() |
b90516de1d | ||
![]() |
ec5cc0f00f | ||
![]() |
5dda5a976e | ||
![]() |
915da9ae13 | ||
![]() |
8652464f4e | ||
![]() |
ce6ce1c1f8 | ||
![]() |
39efe67e55 | ||
![]() |
748ffa00f3 | ||
![]() |
e8d9df2b0e | ||
![]() |
17396d67de | ||
![]() |
edd6a86714 | ||
![]() |
85b4012c56 | ||
![]() |
7d98433502 | ||
![]() |
23774ae03b | ||
![]() |
0dedbcdd71 | ||
![]() |
4bdd08887e | ||
![]() |
1fd8ebf386 | ||
![]() |
d2fc3e749c | ||
![]() |
71fbcbceaf | ||
![]() |
27347b2088 | ||
![]() |
599993d1a5 | ||
![]() |
bf359cb8e3 | ||
![]() |
509a704410 | ||
![]() |
1f48e2b01f | ||
![]() |
8b25b1eee6 | ||
![]() |
3bbf30ff5f | ||
![]() |
83613726d1 | ||
![]() |
254b6a17f3 | ||
![]() |
796e12bd70 | ||
![]() |
ddbe17d3f6 | ||
![]() |
591ec36f4a | ||
![]() |
41eceb72ef | ||
![]() |
0a5f094025 | ||
![]() |
ca0f3ba262 | ||
![]() |
30f4e782db | ||
![]() |
192158ef1a | ||
![]() |
602456db40 | ||
![]() |
536e45668f | ||
![]() |
10bf05ab0d | ||
![]() |
5ad1af69e4 | ||
![]() |
48f2911434 | ||
![]() |
dbb0d6349a | ||
![]() |
ac3598f12a | ||
![]() |
66201be5ca | ||
![]() |
ac0b0b652e | ||
![]() |
d89ee2df42 | ||
![]() |
418e248e5e | ||
![]() |
8c2b141049 | ||
![]() |
2f8e07302b | ||
![]() |
c3776240b6 | ||
![]() |
e370872ec1 | ||
![]() |
d4e978369a | ||
![]() |
8d5d7f5237 | ||
![]() |
5cd498fbe9 | ||
![]() |
250f515f08 | ||
![]() |
0ec0a9e313 | ||
![]() |
184f42ef03 | ||
![]() |
499517418d | ||
![]() |
606b9c1a6d | ||
![]() |
971e954a54 | ||
![]() |
e3aaf3219d | ||
![]() |
0eea1c0e40 | ||
![]() |
0773819778 | ||
![]() |
170869b7db | ||
![]() |
5dc54782e5 | ||
![]() |
97b26fbefe | ||
![]() |
686cc58d6c | ||
![]() |
76a59759b2 | ||
![]() |
93245a24b5 | ||
![]() |
6a22ea1c7d | ||
![]() |
56a02409c8 | ||
![]() |
edeafd5a53 | ||
![]() |
f67490b69b | ||
![]() |
b76e34fb7b | ||
![]() |
ddbda5032b | ||
![]() |
5898d34b0a | ||
![]() |
b0c02341ff | ||
![]() |
19cbc8c33b | ||
![]() |
02e61ef5d3 | ||
![]() |
8d5d18064d | ||
![]() |
c5ef7ebd27 | ||
![]() |
047a3e0e8c | ||
![]() |
13b23f840b | ||
![]() |
147f6012b2 | ||
![]() |
2c315595f0 | ||
![]() |
20405c84ac | ||
![]() |
0bc59b97de | ||
![]() |
a3a3bdc7eb | ||
![]() |
e767f30886 | ||
![]() |
e8c250a03c | ||
![]() |
d6725fc1ca | ||
![]() |
8ec998ff30 | ||
![]() |
23cc0c7f39 | ||
![]() |
19b8bd6aa8 | ||
![]() |
ed57e7c6b0 | ||
![]() |
9f489c9f27 | ||
![]() |
f036989361 | ||
![]() |
6afa8141c0 | ||
![]() |
587964c6f1 | ||
![]() |
7aea82a273 | ||
![]() |
20f946ccaf | ||
![]() |
e5e972231c | ||
![]() |
bfa80157f2 | ||
![]() |
99b1b079d0 | ||
![]() |
5697d549a8 | ||
![]() |
754d2874e7 | ||
![]() |
06de58ff8b | ||
![]() |
a0b3527710 | ||
![]() |
df24f48fa1 | ||
![]() |
13d53590b2 | ||
![]() |
5857f7b9a7 | ||
![]() |
a5ea0cd41f | ||
![]() |
d677934417 | ||
![]() |
ba87a0b63c | ||
![]() |
b725bb3dd1 | ||
![]() |
c34ba3deb5 | ||
![]() |
68b13340fb | ||
![]() |
8831999ea6 | ||
![]() |
c1853f8b84 | ||
![]() |
2b9b7e2853 | ||
![]() |
d3b18debf9 | ||
![]() |
b01eb28d42 | ||
![]() |
02019dd16c | ||
![]() |
7be12f5ff6 | ||
![]() |
a90d59b6ba | ||
![]() |
e7fa156254 | ||
![]() |
a8ab6b1c43 | ||
![]() |
25ed7c890b | ||
![]() |
85e3b63f05 | ||
![]() |
a37bac1956 | ||
![]() |
818a978dfc | ||
![]() |
180aeb7d8e | ||
![]() |
0764fa7292 | ||
![]() |
17bf533ed7 | ||
![]() |
d7eae1c1a0 | ||
![]() |
7f2d979255 | ||
![]() |
46b419ea8b | ||
![]() |
b30b527ff9 | ||
![]() |
41b1bfc504 | ||
![]() |
f4f14a7507 | ||
![]() |
61c29213a7 | ||
![]() |
e6d7639209 | ||
![]() |
3c07a186b2 | ||
![]() |
8a725250a9 | ||
![]() |
502b8a6073 | ||
![]() |
6212c6f80f | ||
![]() |
b03e3b8d4a | ||
![]() |
a98e34d190 | ||
![]() |
bf8d8b6e63 | ||
![]() |
57599f7a98 | ||
![]() |
ffccce7ffc | ||
![]() |
bbd5d050a9 | ||
![]() |
71a96fdcbf | ||
![]() |
221e3c6c9c | ||
![]() |
fb1679d572 | ||
![]() |
c19065f112 | ||
![]() |
f2b04a077e | ||
![]() |
8e7841c880 | ||
![]() |
1873490b24 | ||
![]() |
4d231953f4 | ||
![]() |
aa4c399657 | ||
![]() |
1f99d18982 | ||
![]() |
be37178ef8 | ||
![]() |
fad86c655e | ||
![]() |
4a7958586e | ||
![]() |
f44ecd0891 | ||
![]() |
3d0392d668 | ||
![]() |
d300d2605b | ||
![]() |
66cce6a2f2 | ||
![]() |
65e3c6bfbb | ||
![]() |
2a39060912 | ||
![]() |
8714e80978 | ||
![]() |
98de53f60b | ||
![]() |
41e11e9a0e | ||
![]() |
e7a4eac8bd | ||
![]() |
1589a131db | ||
![]() |
7d84f0e650 | ||
![]() |
86fb0e317f | ||
![]() |
32088d5ef7 | ||
![]() |
63de88dd57 | ||
![]() |
153a6440dc | ||
![]() |
8937ed2269 | ||
![]() |
02e922b56f | ||
![]() |
bf9e901ab9 | ||
![]() |
1234ef8de2 | ||
![]() |
41697a7b1b | ||
![]() |
912e265bc0 | ||
![]() |
96ee6fb064 | ||
![]() |
788dba8ef3 | ||
![]() |
fdde9c4681 | ||
![]() |
f195e73d38 | ||
![]() |
b0d9ffc6a1 | ||
![]() |
e17619841d | ||
![]() |
eb6a7cf3b9 | ||
![]() |
9901e2d72e | ||
![]() |
1be4e23b68 | ||
![]() |
e78094cc0a | ||
![]() |
bcf961c0b0 | ||
![]() |
f84a4c9753 | ||
![]() |
df56ca0236 | ||
![]() |
de0cd0ec67 | ||
![]() |
67c30245c4 | ||
![]() |
1f72757591 | ||
![]() |
35c2fdf6af | ||
![]() |
d1ecd841be | ||
![]() |
828a49697c | ||
![]() |
0551495501 | ||
![]() |
2bbffe4a68 | ||
![]() |
281ad90e39 | ||
![]() |
ed50976a07 | ||
![]() |
a3400037d9 | ||
![]() |
f0d82f75bc | ||
![]() |
349cb80e90 | ||
![]() |
c263ee39af | ||
![]() |
e99bc52756 | ||
![]() |
7944b2b8e9 | ||
![]() |
ca6ae746c1 | ||
![]() |
deabac18b2 | ||
![]() |
5cf8681c61 | ||
![]() |
ca7ede8f96 | ||
![]() |
4969682d52 | ||
![]() |
8002fe0dd5 | ||
![]() |
7dfdf965b7 | ||
![]() |
b408795dd6 | ||
![]() |
a5a099336b | ||
![]() |
4ae56fc004 | ||
![]() |
3f71c09b7b | ||
![]() |
bd50a7f1ab | ||
![]() |
51e4c45e5c | ||
![]() |
e3fae49add | ||
![]() |
610215ab60 | ||
![]() |
74acbda435 | ||
![]() |
25c4af777c | ||
![]() |
ec186e6324 | ||
![]() |
150b7a98f3 | ||
![]() |
8ae7c1cff0 | ||
![]() |
7f1d0eef98 | ||
![]() |
1179ab33f2 | ||
![]() |
a09faa1c10 | ||
![]() |
c0319d9b2f | ||
![]() |
4870cd2921 | ||
![]() |
d4280ec68b | ||
![]() |
52cdc11927 | ||
![]() |
8345b8c9ce | ||
![]() |
c56f0677c3 | ||
![]() |
00e9e1421e | ||
![]() |
93c72c6e6c | ||
![]() |
9cea930dbd | ||
![]() |
7b9bd70729 | ||
![]() |
5115c7a100 | ||
![]() |
5634494e64 | ||
![]() |
aa8bd4abf1 | ||
![]() |
17fd69dd7f | ||
![]() |
1d9dae374b | ||
![]() |
cb2241ad91 | ||
![]() |
d8a7e9abc8 | ||
![]() |
969abc3f29 | ||
![]() |
766fdc8a1f | ||
![]() |
4c37c20d76 | ||
![]() |
7d314398e1 | ||
![]() |
b69191e3a8 | ||
![]() |
b27c6b3596 | ||
![]() |
5453835963 | ||
![]() |
4d55ba057c | ||
![]() |
325c01242c | ||
![]() |
45b32bca89 | ||
![]() |
7620049214 | ||
![]() |
3553495a60 | ||
![]() |
3ce6db61d5 | ||
![]() |
798ff32c40 | ||
![]() |
430cee8bda | ||
![]() |
1fe3fb25a6 | ||
![]() |
685ed87581 | ||
![]() |
ea3ea1eee7 | ||
![]() |
c9edcb909b | ||
![]() |
35bfc9f069 | ||
![]() |
c4aec194b9 | ||
![]() |
e8547b16f6 | ||
![]() |
2bbe08cee0 | ||
![]() |
0a0c369b88 | ||
![]() |
5d2f454a94 | ||
![]() |
04bcc5c879 | ||
![]() |
d4db16665f | ||
![]() |
20b7a494f6 | ||
![]() |
fbdce3ad89 | ||
![]() |
4fc8807f02 | ||
![]() |
83075bfb5c | ||
![]() |
4074ec0425 | ||
![]() |
8e1694dd0f | ||
![]() |
911df18855 | ||
![]() |
6b049e93f8 | ||
![]() |
a335dcc379 | ||
![]() |
c6478c8a79 | ||
![]() |
cc9d40cb60 | ||
![]() |
0a6b7f9a1b | ||
![]() |
daa1fb9a7a | ||
![]() |
b7d543290b | ||
![]() |
ea852b60ac | ||
![]() |
ed341988ea | ||
![]() |
057b6c8e30 | ||
![]() |
44444fe071 | ||
![]() |
797330d6ab | ||
![]() |
a630d5b5f5 | ||
![]() |
eb3dc82b5d | ||
![]() |
34ed18d562 | ||
![]() |
1ce02ee313 | ||
![]() |
2a26a0188c | ||
![]() |
50cb05d1b1 | ||
![]() |
6e739ac453 | ||
![]() |
7aa2fd9f0e | ||
![]() |
8e254e1b03 | ||
![]() |
1ad9d717ff | ||
![]() |
104658e43a | ||
![]() |
e7e4b995bf | ||
![]() |
b35b54f2c2 | ||
![]() |
f80aeb1d1d | ||
![]() |
6a756ab3b6 | ||
![]() |
58a697bed1 | ||
![]() |
280960ac18 | ||
![]() |
0640ff13aa | ||
![]() |
545505691f | ||
![]() |
11fcf81321 | ||
![]() |
c565b37dc8 | ||
![]() |
3d18495270 | ||
![]() |
419e4e63e9 | ||
![]() |
724aa2bf65 | ||
![]() |
573fa8aeb3 | ||
![]() |
8a672e34c5 | ||
![]() |
bc49211dab | ||
![]() |
4ef9c3667e | ||
![]() |
6babe516ac | ||
![]() |
e0b258ef7e | ||
![]() |
ff0c3a89b1 | ||
![]() |
2511b81048 | ||
![]() |
6ffcd94edc | ||
![]() |
2fcf73c812 | ||
![]() |
dee0608af9 | ||
![]() |
d11860a383 | ||
![]() |
1c05115bf5 | ||
![]() |
d7e7382d0b | ||
![]() |
872388f6e3 | ||
![]() |
1215ef920b | ||
![]() |
d19d5a23ea | ||
![]() |
f49a779f1d | ||
![]() |
d8bf5b80e1 | ||
![]() |
69483b9353 | ||
![]() |
14e8548989 | ||
![]() |
4abd93b661 | ||
![]() |
5d925af76f | ||
![]() |
b999c6064a | ||
![]() |
94e3576978 | ||
![]() |
7a22406a2d | ||
![]() |
e60684494f | ||
![]() |
9db28ed779 | ||
![]() |
6fd8c5cee7 | ||
![]() |
787ec43266 | ||
![]() |
a4efc63bf2 | ||
![]() |
80a8f1437e | ||
![]() |
fcca94169d | ||
![]() |
d1924088e3 | ||
![]() |
fd31afe09c | ||
![]() |
7a763712c5 | ||
![]() |
7216be5da7 | ||
![]() |
711b0a291b | ||
![]() |
dfc96496c8 | ||
![]() |
2a1c5ef333 | ||
![]() |
9755209499 | ||
![]() |
0b26e537d4 | ||
![]() |
98c6233ec3 | ||
![]() |
f711706b1a | ||
![]() |
cee7789ab6 | ||
![]() |
8a06c4380d | ||
![]() |
72ecf7a288 | ||
![]() |
ef98c7502d | ||
![]() |
03d0e74b65 | ||
![]() |
5b8fdc0364 | ||
![]() |
593b4bd137 | ||
![]() |
267e12d058 | ||
![]() |
4a5e39b651 | ||
![]() |
ea24fa5b78 | ||
![]() |
bb2bb128f7 | ||
![]() |
94e8a856d7 | ||
![]() |
4c19fbf98e | ||
![]() |
60f8938bfa | ||
![]() |
55679662b5 | ||
![]() |
53df959e49 | ||
![]() |
8e6ef9966f | ||
![]() |
1d52fceafa | ||
![]() |
99186ed864 | ||
![]() |
383931d484 | ||
![]() |
0b49a54cb3 | ||
![]() |
705c0f1891 | ||
![]() |
544c3ffc95 | ||
![]() |
33f252a45d | ||
![]() |
f55d82a015 | ||
![]() |
8cf33fdef0 | ||
![]() |
f858d98811 | ||
![]() |
2a6165d440 | ||
![]() |
4586528c40 | ||
![]() |
23a07baa19 | ||
![]() |
f9040ca932 | ||
![]() |
4cea7f0237 | ||
![]() |
b1847d5e98 | ||
![]() |
9ce4d2e952 | ||
![]() |
247078e06d | ||
![]() |
a0cd72de28 | ||
![]() |
e467f569f0 | ||
![]() |
e31c7b7dfc | ||
![]() |
dc2e0c832b | ||
![]() |
7ddf51bb51 | ||
![]() |
8fb3856665 | ||
![]() |
183dd74f3e | ||
![]() |
4f29039b41 | ||
![]() |
102fcbec20 | ||
![]() |
d00e5212c7 | ||
![]() |
0e6bfb62cd | ||
![]() |
f576e8f635 | ||
![]() |
e6dc10a440 | ||
![]() |
aa930fb6b6 | ||
![]() |
f327ed87e9 | ||
![]() |
2de9be0589 | ||
![]() |
345cde8645 | ||
![]() |
cf152af9ae | ||
![]() |
d6333dcfd9 | ||
![]() |
0121f799f0 | ||
![]() |
82c39580df | ||
![]() |
53a578a46f | ||
![]() |
62612ef80b | ||
![]() |
61ac874c4c | ||
![]() |
976b200ff6 | ||
![]() |
852343b6d8 | ||
![]() |
c56af9d52b | ||
![]() |
05f18e2828 | ||
![]() |
72804caab2 | ||
![]() |
80cbe5c7c9 | ||
![]() |
21892d1236 | ||
![]() |
13824624f8 | ||
![]() |
0fd72ecbab | ||
![]() |
f848cb1546 | ||
![]() |
633854081a | ||
![]() |
4fed9a581b | ||
![]() |
e9c1202aaa | ||
![]() |
0a7ae279d0 | ||
![]() |
0de2696543 | ||
![]() |
a7dc239b71 | ||
![]() |
fe0e6990f5 | ||
![]() |
5ba65e92d9 | ||
![]() |
a1452b52c9 | ||
![]() |
dd2aa23a5f | ||
![]() |
0e0359ba7d | ||
![]() |
93b1b7aded | ||
![]() |
9472dc6a53 | ||
![]() |
67b681854e | ||
![]() |
7b5990833e | ||
![]() |
b6d5d04589 | ||
![]() |
fdfbb3e944 | ||
![]() |
faa7a3e37f | ||
![]() |
23748b82bb | ||
![]() |
bccb6f578a | ||
![]() |
de8a5d6e9e | ||
![]() |
a8eb3f7961 | ||
![]() |
2dc85f5a42 | ||
![]() |
82518b351d | ||
![]() |
68f34a1683 | ||
![]() |
bc6b72a422 | ||
![]() |
599e28e1cb | ||
![]() |
ee6b2ba6c6 | ||
![]() |
0877b3e2af | ||
![]() |
d1edb1e32a | ||
![]() |
d1e6b8dd10 | ||
![]() |
b32fc3bfdd | ||
![]() |
1e24417db0 | ||
![]() |
fb9387ecc5 | ||
![]() |
6c5f4cdb70 | ||
![]() |
aabacb7454 | ||
![]() |
b5da84479e | ||
![]() |
88d9361050 | ||
![]() |
1d90388ffc | ||
![]() |
b3c43ce31f | ||
![]() |
6d9d22d422 | ||
![]() |
86be1f56d0 | ||
![]() |
a0c81ffd7a | ||
![]() |
ec1dc42e58 | ||
![]() |
866eaed73d | ||
![]() |
a18374e1ad | ||
![]() |
f7afcb3b24 | ||
![]() |
3adcae783c | ||
![]() |
73b40dd2e7 | ||
![]() |
1e12614f9a | ||
![]() |
aeaa7c699a | ||
![]() |
f1c56b7254 | ||
![]() |
e72e0d0646 | ||
![]() |
5719d334aa | ||
![]() |
bcb6b85333 | ||
![]() |
5d765413ef | ||
![]() |
efb2e5e7a8 | ||
![]() |
5d5e346199 | ||
![]() |
08a74890da | ||
![]() |
0545b9c7f2 | ||
![]() |
bbf7d32676 | ||
![]() |
e83f4ae974 | ||
![]() |
9b0d01e03f | ||
![]() |
eae0d90a1e | ||
![]() |
90c09a7650 | ||
![]() |
aecf080211 | ||
![]() |
8517420356 | ||
![]() |
376be1f009 | ||
![]() |
0021e76649 | ||
![]() |
d440c4bc43 | ||
![]() |
50840b2105 | ||
![]() |
7502c6b6c0 | ||
![]() |
919c32f0cc | ||
![]() |
a28c951272 | ||
![]() |
13d7c5a9a9 | ||
![]() |
5f1383344d | ||
![]() |
48f43d3eb1 | ||
![]() |
4ac2141307 | ||
![]() |
719d8cac97 | ||
![]() |
99cbe53a8e | ||
![]() |
a36af1bfac | ||
![]() |
8b6aa319bf | ||
![]() |
a16d321e1a | ||
![]() |
74e70278e2 | ||
![]() |
1332e24a2c | ||
![]() |
5ab78ec461 | ||
![]() |
ce701d3c31 | ||
![]() |
5fca1be44d | ||
![]() |
0bd4c333bd | ||
![]() |
c6ed880732 | ||
![]() |
da0f3c6cce | ||
![]() |
e5d12d346a | ||
![]() |
478e2e726b | ||
![]() |
dbdac3707b | ||
![]() |
bd89a88e34 | ||
![]() |
d322d83745 | ||
![]() |
463a581ab9 | ||
![]() |
eae4bd222a | ||
![]() |
a7bb7fc14d | ||
![]() |
c047aa47eb | ||
![]() |
61bca56316 | ||
![]() |
9a37323eb8 | ||
![]() |
99a54369bf | ||
![]() |
f7533dfc5c | ||
![]() |
ee7d95272d | ||
![]() |
2b9b1d12e6 | ||
![]() |
2cbb5c7d8e | ||
![]() |
9686c7babe | ||
![]() |
66bd4c96c4 | ||
![]() |
dc47faa4b6 | ||
![]() |
55ee0b116d | ||
![]() |
c6957c08bc | ||
![]() |
8fe6a323d8 | ||
![]() |
8e51590c32 | ||
![]() |
ae066d5627 | ||
![]() |
6760279916 | ||
![]() |
3c208050b0 | ||
![]() |
bbc7c9fb37 | ||
![]() |
e1c3862586 | ||
![]() |
c24b7cb7bd | ||
![]() |
c91e16549d | ||
![]() |
6e70aca458 | ||
![]() |
d9ffd0ac8e | ||
![]() |
4641f73d19 | ||
![]() |
9f0051c21f | ||
![]() |
0331cb09e8 | ||
![]() |
2f8946f86c | ||
![]() |
88a3df4008 | ||
![]() |
0adf514bd6 | ||
![]() |
a1b5a2abcb | ||
![]() |
068c62c6fe | ||
![]() |
0e9f14f969 | ||
![]() |
78315fd388 | ||
![]() |
0ab69002df | ||
![]() |
1eec1239ec | ||
![]() |
60cc4c4ed0 | ||
![]() |
34c100e997 | ||
![]() |
57f4067fbf | ||
![]() |
f4a9221232 | ||
![]() |
3d4a75148d | ||
![]() |
c2c5bd844d | ||
![]() |
98a2f23024 | ||
![]() |
c955897d1b | ||
![]() |
9624efa21e | ||
![]() |
831638210d | ||
![]() |
cfdb0925ce | ||
![]() |
83db3eddd9 | ||
![]() |
cc2c5a544e | ||
![]() |
8fba8c2800 | ||
![]() |
51d1da8460 | ||
![]() |
2f1257056d | ||
![]() |
2f8f6967bf | ||
![]() |
246527e618 | ||
![]() |
3857cc9c83 | ||
![]() |
a59a8c563e | ||
![]() |
856829bcbb | ||
![]() |
dd2b931f61 | ||
![]() |
39beccbbb0 | ||
![]() |
ff626b428f | ||
![]() |
3915e1f012 | ||
![]() |
7b460b6224 | ||
![]() |
8fb8e79730 | ||
![]() |
79bbc475f4 | ||
![]() |
cef023283b | ||
![]() |
d4fda79ada | ||
![]() |
ff0bdcf4cd | ||
![]() |
bfbc313144 | ||
![]() |
31f2376f15 | ||
![]() |
f76ecb6604 | ||
![]() |
298cc58433 | ||
![]() |
825c0593e1 | ||
![]() |
87ed1dc3e3 | ||
![]() |
67e9db021c | ||
![]() |
3922950951 | ||
![]() |
9c4aa0ba53 | ||
![]() |
f5f1651b31 | ||
![]() |
32f4e4ca13 | ||
![]() |
962e0c4c33 | ||
![]() |
2c01bc5795 | ||
![]() |
0651f7cb3c | ||
![]() |
01ac59ce2a | ||
![]() |
c1fd597757 | ||
![]() |
e79e244eee | ||
![]() |
68ecc08111 | ||
![]() |
3b5fbc359f | ||
![]() |
583e5ea47f | ||
![]() |
7b647c3fae | ||
![]() |
a8b76c617c | ||
![]() |
1bd8985dff | ||
![]() |
25b5a6c4ae |
@@ -1 +1 @@
|
||||
a3cdfc378d28b53b416a1d5bf0ab9077ee18867f0d39436ea8013cf5a4ead87a
|
||||
07f621354fe1350ba51953c80273cd44a04aa44f15cc30bd7b8fe2a641427b7a
|
||||
|
92
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
92
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
name: Report an issue with ESPHome
|
||||
description: Report an issue with ESPHome.
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
This issue form is for reporting bugs only!
|
||||
|
||||
If you have a feature request or enhancement, please [request them here instead][fr].
|
||||
|
||||
[fr]: https://github.com/orgs/esphome/discussions
|
||||
- type: textarea
|
||||
validations:
|
||||
required: true
|
||||
id: problem
|
||||
attributes:
|
||||
label: The problem
|
||||
description: >-
|
||||
Describe the issue you are experiencing here to communicate to the
|
||||
maintainers. Tell us what you were trying to do and what happened.
|
||||
|
||||
Provide a clear and concise description of what the problem is.
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
## Environment
|
||||
- type: input
|
||||
id: version
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: Which version of ESPHome has the issue?
|
||||
description: >
|
||||
ESPHome version like 1.19, 2025.6.0 or 2025.XX.X-dev.
|
||||
- type: dropdown
|
||||
validations:
|
||||
required: true
|
||||
id: installation
|
||||
attributes:
|
||||
label: What type of installation are you using?
|
||||
options:
|
||||
- Home Assistant Add-on
|
||||
- Docker
|
||||
- pip
|
||||
- type: dropdown
|
||||
validations:
|
||||
required: true
|
||||
id: platform
|
||||
attributes:
|
||||
label: What platform are you using?
|
||||
options:
|
||||
- ESP8266
|
||||
- ESP32
|
||||
- RP2040
|
||||
- BK72XX
|
||||
- RTL87XX
|
||||
- LN882X
|
||||
- Host
|
||||
- Other
|
||||
- type: input
|
||||
id: component_name
|
||||
attributes:
|
||||
label: Component causing the issue
|
||||
description: >
|
||||
The name of the component or platform. For example, api/i2c or ultrasonic.
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
# Details
|
||||
- type: textarea
|
||||
id: config
|
||||
attributes:
|
||||
label: YAML Config
|
||||
description: |
|
||||
Include a complete YAML configuration file demonstrating the problem here. Preferably post the *entire* file - don't make assumptions about what is unimportant. However, if it's a large or complicated config then you will need to reduce it to the smallest possible file *that still demonstrates the problem*. If you don't provide enough information to *easily* reproduce the problem, it's unlikely your bug report will get any attention. Logs do not belong here, attach them below.
|
||||
render: yaml
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: Anything in the logs that might be useful for us?
|
||||
description: For example, error message, or stack traces. Serial or USB logs are much more useful than WiFi logs.
|
||||
render: txt
|
||||
- type: textarea
|
||||
id: additional
|
||||
attributes:
|
||||
label: Additional information
|
||||
description: >
|
||||
If you have any additional information for us, use the field below.
|
||||
Please note, you can attach screenshots or screen recordings here, by
|
||||
dragging and dropping files in the field below.
|
26
.github/ISSUE_TEMPLATE/config.yml
vendored
26
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1,15 +1,21 @@
|
||||
---
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Issue Tracker
|
||||
url: https://github.com/esphome/issues
|
||||
about: Please create bug reports in the dedicated issue tracker.
|
||||
- name: Feature Request Tracker
|
||||
url: https://github.com/esphome/feature-requests
|
||||
about: |
|
||||
Please create feature requests in the dedicated feature request tracker.
|
||||
- name: Report an issue with the ESPHome documentation
|
||||
url: https://github.com/esphome/esphome-docs/issues/new/choose
|
||||
about: Report an issue with the ESPHome documentation.
|
||||
- name: Report an issue with the ESPHome web server
|
||||
url: https://github.com/esphome/esphome-webserver/issues/new/choose
|
||||
about: Report an issue with the ESPHome web server.
|
||||
- name: Report an issue with the ESPHome Builder / Dashboard
|
||||
url: https://github.com/esphome/dashboard/issues/new/choose
|
||||
about: Report an issue with the ESPHome Builder / Dashboard.
|
||||
- name: Report an issue with the ESPHome API client
|
||||
url: https://github.com/esphome/aioesphomeapi/issues/new/choose
|
||||
about: Report an issue with the ESPHome API client.
|
||||
- name: Make a Feature Request
|
||||
url: https://github.com/orgs/esphome/discussions
|
||||
about: Please create feature requests in the dedicated feature request tracker.
|
||||
- name: Frequently Asked Question
|
||||
url: https://esphome.io/guides/faq.html
|
||||
about: |
|
||||
Please view the FAQ for common questions and what
|
||||
to include in a bug report.
|
||||
about: Please view the FAQ for common questions and what to include in a bug report.
|
||||
|
1
.github/workflows/ci-clang-tidy-hash.yml
vendored
1
.github/workflows/ci-clang-tidy-hash.yml
vendored
@@ -73,4 +73,3 @@ jobs:
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
2
.github/workflows/ci-docker.yml
vendored
2
.github/workflows/ci-docker.yml
vendored
@@ -47,7 +47,7 @@ jobs:
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5.6.0
|
||||
with:
|
||||
python-version: "3.10"
|
||||
python-version: "3.11"
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3.11.1
|
||||
|
||||
|
57
.github/workflows/ci.yml
vendored
57
.github/workflows/ci.yml
vendored
@@ -20,8 +20,8 @@ permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
DEFAULT_PYTHON: "3.10"
|
||||
PYUPGRADE_TARGET: "--py310-plus"
|
||||
DEFAULT_PYTHON: "3.11"
|
||||
PYUPGRADE_TARGET: "--py311-plus"
|
||||
|
||||
concurrency:
|
||||
# yamllint disable-line rule:line-length
|
||||
@@ -84,29 +84,6 @@ jobs:
|
||||
run: script/ci-suggest-changes
|
||||
if: always()
|
||||
|
||||
pyupgrade:
|
||||
name: Check pyupgrade
|
||||
runs-on: ubuntu-24.04
|
||||
needs:
|
||||
- common
|
||||
- determine-jobs
|
||||
if: needs.determine-jobs.outputs.python-linters == 'true'
|
||||
steps:
|
||||
- name: Check out code from GitHub
|
||||
uses: actions/checkout@v4.2.2
|
||||
- name: Restore Python
|
||||
uses: ./.github/actions/restore-python
|
||||
with:
|
||||
python-version: ${{ env.DEFAULT_PYTHON }}
|
||||
cache-key: ${{ needs.common.outputs.cache-key }}
|
||||
- name: Run pyupgrade
|
||||
run: |
|
||||
. venv/bin/activate
|
||||
pyupgrade ${{ env.PYUPGRADE_TARGET }} `find esphome -name "*.py" -type f`
|
||||
- name: Suggested changes
|
||||
run: script/ci-suggest-changes
|
||||
if: always()
|
||||
|
||||
ci-custom:
|
||||
name: Run script/ci-custom
|
||||
runs-on: ubuntu-24.04
|
||||
@@ -135,7 +112,6 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version:
|
||||
- "3.10"
|
||||
- "3.11"
|
||||
- "3.12"
|
||||
- "3.13"
|
||||
@@ -151,14 +127,10 @@ jobs:
|
||||
os: windows-latest
|
||||
- python-version: "3.12"
|
||||
os: windows-latest
|
||||
- python-version: "3.10"
|
||||
os: windows-latest
|
||||
- python-version: "3.13"
|
||||
os: macOS-latest
|
||||
- python-version: "3.12"
|
||||
os: macOS-latest
|
||||
- python-version: "3.10"
|
||||
os: macOS-latest
|
||||
runs-on: ${{ matrix.os }}
|
||||
needs:
|
||||
- common
|
||||
@@ -269,30 +241,13 @@ jobs:
|
||||
. venv/bin/activate
|
||||
pytest -vv --no-cov --tb=native -n auto tests/integration/
|
||||
|
||||
clang-tidy-deps:
|
||||
name: Clang-tidy dependencies
|
||||
runs-on: ubuntu-24.04
|
||||
needs:
|
||||
- common
|
||||
- ci-custom
|
||||
- pytest
|
||||
- determine-jobs
|
||||
if: |
|
||||
always() &&
|
||||
needs.determine-jobs.outputs.clang-tidy == 'true'
|
||||
steps:
|
||||
- run: echo "All clang-tidy dependencies ready"
|
||||
|
||||
clang-tidy:
|
||||
name: ${{ matrix.name }}
|
||||
runs-on: ubuntu-24.04
|
||||
needs:
|
||||
- clang-tidy-deps
|
||||
- common
|
||||
- determine-jobs
|
||||
if: |
|
||||
always() &&
|
||||
needs.determine-jobs.outputs.clang-tidy == 'true' &&
|
||||
needs.clang-tidy-deps.result == 'success'
|
||||
if: needs.determine-jobs.outputs.clang-tidy == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
strategy:
|
||||
@@ -512,7 +467,7 @@ jobs:
|
||||
cache-key: ${{ needs.common.outputs.cache-key }}
|
||||
- uses: pre-commit/action@v3.0.1
|
||||
env:
|
||||
SKIP: pylint,clang-tidy-hash,yamllint
|
||||
SKIP: pylint,clang-tidy-hash
|
||||
- uses: pre-commit-ci/lite-action@v1.1.0
|
||||
if: always()
|
||||
|
||||
@@ -525,8 +480,6 @@ jobs:
|
||||
- pylint
|
||||
- pytest
|
||||
- integration-tests
|
||||
- pyupgrade
|
||||
- clang-tidy-deps
|
||||
- clang-tidy
|
||||
- determine-jobs
|
||||
- test-build-components
|
||||
|
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -96,7 +96,7 @@ jobs:
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5.6.0
|
||||
with:
|
||||
python-version: "3.10"
|
||||
python-version: "3.11"
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3.11.1
|
||||
|
25
.github/workflows/yaml-lint.yml
vendored
25
.github/workflows/yaml-lint.yml
vendored
@@ -1,25 +0,0 @@
|
||||
---
|
||||
name: YAML lint
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [dev, beta, release]
|
||||
paths:
|
||||
- "**.yaml"
|
||||
- "**.yml"
|
||||
pull_request:
|
||||
paths:
|
||||
- "**.yaml"
|
||||
- "**.yml"
|
||||
|
||||
jobs:
|
||||
yamllint:
|
||||
name: yamllint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code from GitHub
|
||||
uses: actions/checkout@v4.2.2
|
||||
- name: Run yamllint
|
||||
uses: frenck/action-yamllint@v1.5.0
|
||||
with:
|
||||
strict: true
|
@@ -6,7 +6,7 @@ ci:
|
||||
autoupdate_commit_msg: 'pre-commit: autoupdate'
|
||||
autoupdate_schedule: off # Disabled until ruff versions are synced between deps and pre-commit
|
||||
# Skip hooks that have issues in pre-commit CI environment
|
||||
skip: [pylint, clang-tidy-hash, yamllint]
|
||||
skip: [pylint, clang-tidy-hash]
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
@@ -27,22 +27,25 @@ repos:
|
||||
- pydocstyle==5.1.1
|
||||
files: ^(esphome|tests)/.+\.py$
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v3.4.0
|
||||
rev: v5.0.0
|
||||
hooks:
|
||||
- id: no-commit-to-branch
|
||||
args:
|
||||
- --branch=dev
|
||||
- --branch=release
|
||||
- --branch=beta
|
||||
- id: end-of-file-fixer
|
||||
- id: trailing-whitespace
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v3.20.0
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: [--py310-plus]
|
||||
args: [--py311-plus]
|
||||
- repo: https://github.com/adrienverge/yamllint.git
|
||||
rev: v1.37.1
|
||||
hooks:
|
||||
- id: yamllint
|
||||
exclude: ^(\.clang-format|\.clang-tidy)$
|
||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||
rev: v13.0.1
|
||||
hooks:
|
||||
|
@@ -324,6 +324,7 @@ esphome/components/nextion/text_sensor/* @senexcrenshaw
|
||||
esphome/components/nfc/* @jesserockz @kbx81
|
||||
esphome/components/noblex/* @AGalfra
|
||||
esphome/components/npi19/* @bakerkj
|
||||
esphome/components/nrf52/* @tomaszduda23
|
||||
esphome/components/number/* @esphome/core
|
||||
esphome/components/one_wire/* @ssieb
|
||||
esphome/components/online_image/* @clydebarrow @guillempages
|
||||
@@ -378,6 +379,7 @@ esphome/components/rp2040_pwm/* @jesserockz
|
||||
esphome/components/rpi_dpi_rgb/* @clydebarrow
|
||||
esphome/components/rtl87xx/* @kuba2k2
|
||||
esphome/components/rtttl/* @glmnet
|
||||
esphome/components/runtime_stats/* @bdraco
|
||||
esphome/components/safe_mode/* @jsuanet @kbx81 @paulmonigatti
|
||||
esphome/components/scd4x/* @martgras @sjtrny
|
||||
esphome/components/script/* @esphome/core
|
||||
@@ -535,5 +537,6 @@ esphome/components/xiaomi_xmwsdj04mmc/* @medusalix
|
||||
esphome/components/xl9535/* @mreditor97
|
||||
esphome/components/xpt2046/touchscreen/* @nielsnl68 @numo68
|
||||
esphome/components/xxtea/* @clydebarrow
|
||||
esphome/components/zephyr/* @tomaszduda23
|
||||
esphome/components/zhlt01/* @cfeenstra1024
|
||||
esphome/components/zio_ultrasonic/* @kahrendt
|
||||
|
@@ -51,82 +51,83 @@ SAMPLING_MODES = {
|
||||
"max": sampling_mode.MAX,
|
||||
}
|
||||
|
||||
adc1_channel_t = cg.global_ns.enum("adc1_channel_t")
|
||||
adc2_channel_t = cg.global_ns.enum("adc2_channel_t")
|
||||
adc_unit_t = cg.global_ns.enum("adc_unit_t", is_class=True)
|
||||
|
||||
adc_channel_t = cg.global_ns.enum("adc_channel_t", is_class=True)
|
||||
|
||||
# pin to adc1 channel mapping
|
||||
# https://github.com/espressif/esp-idf/blob/v4.4.8/components/driver/include/driver/adc.h
|
||||
ESP32_VARIANT_ADC1_PIN_TO_CHANNEL = {
|
||||
# https://github.com/espressif/esp-idf/blob/master/components/soc/esp32/include/soc/adc_channel.h
|
||||
VARIANT_ESP32: {
|
||||
36: adc1_channel_t.ADC1_CHANNEL_0,
|
||||
37: adc1_channel_t.ADC1_CHANNEL_1,
|
||||
38: adc1_channel_t.ADC1_CHANNEL_2,
|
||||
39: adc1_channel_t.ADC1_CHANNEL_3,
|
||||
32: adc1_channel_t.ADC1_CHANNEL_4,
|
||||
33: adc1_channel_t.ADC1_CHANNEL_5,
|
||||
34: adc1_channel_t.ADC1_CHANNEL_6,
|
||||
35: adc1_channel_t.ADC1_CHANNEL_7,
|
||||
36: adc_channel_t.ADC_CHANNEL_0,
|
||||
37: adc_channel_t.ADC_CHANNEL_1,
|
||||
38: adc_channel_t.ADC_CHANNEL_2,
|
||||
39: adc_channel_t.ADC_CHANNEL_3,
|
||||
32: adc_channel_t.ADC_CHANNEL_4,
|
||||
33: adc_channel_t.ADC_CHANNEL_5,
|
||||
34: adc_channel_t.ADC_CHANNEL_6,
|
||||
35: adc_channel_t.ADC_CHANNEL_7,
|
||||
},
|
||||
# https://github.com/espressif/esp-idf/blob/master/components/soc/esp32c2/include/soc/adc_channel.h
|
||||
VARIANT_ESP32C2: {
|
||||
0: adc1_channel_t.ADC1_CHANNEL_0,
|
||||
1: adc1_channel_t.ADC1_CHANNEL_1,
|
||||
2: adc1_channel_t.ADC1_CHANNEL_2,
|
||||
3: adc1_channel_t.ADC1_CHANNEL_3,
|
||||
4: adc1_channel_t.ADC1_CHANNEL_4,
|
||||
0: adc_channel_t.ADC_CHANNEL_0,
|
||||
1: adc_channel_t.ADC_CHANNEL_1,
|
||||
2: adc_channel_t.ADC_CHANNEL_2,
|
||||
3: adc_channel_t.ADC_CHANNEL_3,
|
||||
4: adc_channel_t.ADC_CHANNEL_4,
|
||||
},
|
||||
# https://github.com/espressif/esp-idf/blob/master/components/soc/esp32c3/include/soc/adc_channel.h
|
||||
VARIANT_ESP32C3: {
|
||||
0: adc1_channel_t.ADC1_CHANNEL_0,
|
||||
1: adc1_channel_t.ADC1_CHANNEL_1,
|
||||
2: adc1_channel_t.ADC1_CHANNEL_2,
|
||||
3: adc1_channel_t.ADC1_CHANNEL_3,
|
||||
4: adc1_channel_t.ADC1_CHANNEL_4,
|
||||
0: adc_channel_t.ADC_CHANNEL_0,
|
||||
1: adc_channel_t.ADC_CHANNEL_1,
|
||||
2: adc_channel_t.ADC_CHANNEL_2,
|
||||
3: adc_channel_t.ADC_CHANNEL_3,
|
||||
4: adc_channel_t.ADC_CHANNEL_4,
|
||||
},
|
||||
# https://github.com/espressif/esp-idf/blob/master/components/soc/esp32c6/include/soc/adc_channel.h
|
||||
VARIANT_ESP32C6: {
|
||||
0: adc1_channel_t.ADC1_CHANNEL_0,
|
||||
1: adc1_channel_t.ADC1_CHANNEL_1,
|
||||
2: adc1_channel_t.ADC1_CHANNEL_2,
|
||||
3: adc1_channel_t.ADC1_CHANNEL_3,
|
||||
4: adc1_channel_t.ADC1_CHANNEL_4,
|
||||
5: adc1_channel_t.ADC1_CHANNEL_5,
|
||||
6: adc1_channel_t.ADC1_CHANNEL_6,
|
||||
0: adc_channel_t.ADC_CHANNEL_0,
|
||||
1: adc_channel_t.ADC_CHANNEL_1,
|
||||
2: adc_channel_t.ADC_CHANNEL_2,
|
||||
3: adc_channel_t.ADC_CHANNEL_3,
|
||||
4: adc_channel_t.ADC_CHANNEL_4,
|
||||
5: adc_channel_t.ADC_CHANNEL_5,
|
||||
6: adc_channel_t.ADC_CHANNEL_6,
|
||||
},
|
||||
# https://github.com/espressif/esp-idf/blob/master/components/soc/esp32h2/include/soc/adc_channel.h
|
||||
VARIANT_ESP32H2: {
|
||||
1: adc1_channel_t.ADC1_CHANNEL_0,
|
||||
2: adc1_channel_t.ADC1_CHANNEL_1,
|
||||
3: adc1_channel_t.ADC1_CHANNEL_2,
|
||||
4: adc1_channel_t.ADC1_CHANNEL_3,
|
||||
5: adc1_channel_t.ADC1_CHANNEL_4,
|
||||
1: adc_channel_t.ADC_CHANNEL_0,
|
||||
2: adc_channel_t.ADC_CHANNEL_1,
|
||||
3: adc_channel_t.ADC_CHANNEL_2,
|
||||
4: adc_channel_t.ADC_CHANNEL_3,
|
||||
5: adc_channel_t.ADC_CHANNEL_4,
|
||||
},
|
||||
# https://github.com/espressif/esp-idf/blob/master/components/soc/esp32s2/include/soc/adc_channel.h
|
||||
VARIANT_ESP32S2: {
|
||||
1: adc1_channel_t.ADC1_CHANNEL_0,
|
||||
2: adc1_channel_t.ADC1_CHANNEL_1,
|
||||
3: adc1_channel_t.ADC1_CHANNEL_2,
|
||||
4: adc1_channel_t.ADC1_CHANNEL_3,
|
||||
5: adc1_channel_t.ADC1_CHANNEL_4,
|
||||
6: adc1_channel_t.ADC1_CHANNEL_5,
|
||||
7: adc1_channel_t.ADC1_CHANNEL_6,
|
||||
8: adc1_channel_t.ADC1_CHANNEL_7,
|
||||
9: adc1_channel_t.ADC1_CHANNEL_8,
|
||||
10: adc1_channel_t.ADC1_CHANNEL_9,
|
||||
1: adc_channel_t.ADC_CHANNEL_0,
|
||||
2: adc_channel_t.ADC_CHANNEL_1,
|
||||
3: adc_channel_t.ADC_CHANNEL_2,
|
||||
4: adc_channel_t.ADC_CHANNEL_3,
|
||||
5: adc_channel_t.ADC_CHANNEL_4,
|
||||
6: adc_channel_t.ADC_CHANNEL_5,
|
||||
7: adc_channel_t.ADC_CHANNEL_6,
|
||||
8: adc_channel_t.ADC_CHANNEL_7,
|
||||
9: adc_channel_t.ADC_CHANNEL_8,
|
||||
10: adc_channel_t.ADC_CHANNEL_9,
|
||||
},
|
||||
# https://github.com/espressif/esp-idf/blob/master/components/soc/esp32s3/include/soc/adc_channel.h
|
||||
VARIANT_ESP32S3: {
|
||||
1: adc1_channel_t.ADC1_CHANNEL_0,
|
||||
2: adc1_channel_t.ADC1_CHANNEL_1,
|
||||
3: adc1_channel_t.ADC1_CHANNEL_2,
|
||||
4: adc1_channel_t.ADC1_CHANNEL_3,
|
||||
5: adc1_channel_t.ADC1_CHANNEL_4,
|
||||
6: adc1_channel_t.ADC1_CHANNEL_5,
|
||||
7: adc1_channel_t.ADC1_CHANNEL_6,
|
||||
8: adc1_channel_t.ADC1_CHANNEL_7,
|
||||
9: adc1_channel_t.ADC1_CHANNEL_8,
|
||||
10: adc1_channel_t.ADC1_CHANNEL_9,
|
||||
1: adc_channel_t.ADC_CHANNEL_0,
|
||||
2: adc_channel_t.ADC_CHANNEL_1,
|
||||
3: adc_channel_t.ADC_CHANNEL_2,
|
||||
4: adc_channel_t.ADC_CHANNEL_3,
|
||||
5: adc_channel_t.ADC_CHANNEL_4,
|
||||
6: adc_channel_t.ADC_CHANNEL_5,
|
||||
7: adc_channel_t.ADC_CHANNEL_6,
|
||||
8: adc_channel_t.ADC_CHANNEL_7,
|
||||
9: adc_channel_t.ADC_CHANNEL_8,
|
||||
10: adc_channel_t.ADC_CHANNEL_9,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -135,24 +136,24 @@ ESP32_VARIANT_ADC1_PIN_TO_CHANNEL = {
|
||||
ESP32_VARIANT_ADC2_PIN_TO_CHANNEL = {
|
||||
# https://github.com/espressif/esp-idf/blob/master/components/soc/esp32/include/soc/adc_channel.h
|
||||
VARIANT_ESP32: {
|
||||
4: adc2_channel_t.ADC2_CHANNEL_0,
|
||||
0: adc2_channel_t.ADC2_CHANNEL_1,
|
||||
2: adc2_channel_t.ADC2_CHANNEL_2,
|
||||
15: adc2_channel_t.ADC2_CHANNEL_3,
|
||||
13: adc2_channel_t.ADC2_CHANNEL_4,
|
||||
12: adc2_channel_t.ADC2_CHANNEL_5,
|
||||
14: adc2_channel_t.ADC2_CHANNEL_6,
|
||||
27: adc2_channel_t.ADC2_CHANNEL_7,
|
||||
25: adc2_channel_t.ADC2_CHANNEL_8,
|
||||
26: adc2_channel_t.ADC2_CHANNEL_9,
|
||||
4: adc_channel_t.ADC_CHANNEL_0,
|
||||
0: adc_channel_t.ADC_CHANNEL_1,
|
||||
2: adc_channel_t.ADC_CHANNEL_2,
|
||||
15: adc_channel_t.ADC_CHANNEL_3,
|
||||
13: adc_channel_t.ADC_CHANNEL_4,
|
||||
12: adc_channel_t.ADC_CHANNEL_5,
|
||||
14: adc_channel_t.ADC_CHANNEL_6,
|
||||
27: adc_channel_t.ADC_CHANNEL_7,
|
||||
25: adc_channel_t.ADC_CHANNEL_8,
|
||||
26: adc_channel_t.ADC_CHANNEL_9,
|
||||
},
|
||||
# https://github.com/espressif/esp-idf/blob/master/components/soc/esp32c2/include/soc/adc_channel.h
|
||||
VARIANT_ESP32C2: {
|
||||
5: adc2_channel_t.ADC2_CHANNEL_0,
|
||||
5: adc_channel_t.ADC_CHANNEL_0,
|
||||
},
|
||||
# https://github.com/espressif/esp-idf/blob/master/components/soc/esp32c3/include/soc/adc_channel.h
|
||||
VARIANT_ESP32C3: {
|
||||
5: adc2_channel_t.ADC2_CHANNEL_0,
|
||||
5: adc_channel_t.ADC_CHANNEL_0,
|
||||
},
|
||||
# https://github.com/espressif/esp-idf/blob/master/components/soc/esp32c6/include/soc/adc_channel.h
|
||||
VARIANT_ESP32C6: {}, # no ADC2
|
||||
@@ -160,29 +161,29 @@ ESP32_VARIANT_ADC2_PIN_TO_CHANNEL = {
|
||||
VARIANT_ESP32H2: {}, # no ADC2
|
||||
# https://github.com/espressif/esp-idf/blob/master/components/soc/esp32s2/include/soc/adc_channel.h
|
||||
VARIANT_ESP32S2: {
|
||||
11: adc2_channel_t.ADC2_CHANNEL_0,
|
||||
12: adc2_channel_t.ADC2_CHANNEL_1,
|
||||
13: adc2_channel_t.ADC2_CHANNEL_2,
|
||||
14: adc2_channel_t.ADC2_CHANNEL_3,
|
||||
15: adc2_channel_t.ADC2_CHANNEL_4,
|
||||
16: adc2_channel_t.ADC2_CHANNEL_5,
|
||||
17: adc2_channel_t.ADC2_CHANNEL_6,
|
||||
18: adc2_channel_t.ADC2_CHANNEL_7,
|
||||
19: adc2_channel_t.ADC2_CHANNEL_8,
|
||||
20: adc2_channel_t.ADC2_CHANNEL_9,
|
||||
11: adc_channel_t.ADC_CHANNEL_0,
|
||||
12: adc_channel_t.ADC_CHANNEL_1,
|
||||
13: adc_channel_t.ADC_CHANNEL_2,
|
||||
14: adc_channel_t.ADC_CHANNEL_3,
|
||||
15: adc_channel_t.ADC_CHANNEL_4,
|
||||
16: adc_channel_t.ADC_CHANNEL_5,
|
||||
17: adc_channel_t.ADC_CHANNEL_6,
|
||||
18: adc_channel_t.ADC_CHANNEL_7,
|
||||
19: adc_channel_t.ADC_CHANNEL_8,
|
||||
20: adc_channel_t.ADC_CHANNEL_9,
|
||||
},
|
||||
# https://github.com/espressif/esp-idf/blob/master/components/soc/esp32s3/include/soc/adc_channel.h
|
||||
VARIANT_ESP32S3: {
|
||||
11: adc2_channel_t.ADC2_CHANNEL_0,
|
||||
12: adc2_channel_t.ADC2_CHANNEL_1,
|
||||
13: adc2_channel_t.ADC2_CHANNEL_2,
|
||||
14: adc2_channel_t.ADC2_CHANNEL_3,
|
||||
15: adc2_channel_t.ADC2_CHANNEL_4,
|
||||
16: adc2_channel_t.ADC2_CHANNEL_5,
|
||||
17: adc2_channel_t.ADC2_CHANNEL_6,
|
||||
18: adc2_channel_t.ADC2_CHANNEL_7,
|
||||
19: adc2_channel_t.ADC2_CHANNEL_8,
|
||||
20: adc2_channel_t.ADC2_CHANNEL_9,
|
||||
11: adc_channel_t.ADC_CHANNEL_0,
|
||||
12: adc_channel_t.ADC_CHANNEL_1,
|
||||
13: adc_channel_t.ADC_CHANNEL_2,
|
||||
14: adc_channel_t.ADC_CHANNEL_3,
|
||||
15: adc_channel_t.ADC_CHANNEL_4,
|
||||
16: adc_channel_t.ADC_CHANNEL_5,
|
||||
17: adc_channel_t.ADC_CHANNEL_6,
|
||||
18: adc_channel_t.ADC_CHANNEL_7,
|
||||
19: adc_channel_t.ADC_CHANNEL_8,
|
||||
20: adc_channel_t.ADC_CHANNEL_9,
|
||||
},
|
||||
}
|
||||
|
||||
|
@@ -3,11 +3,14 @@
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/voltage_sampler/voltage_sampler.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/hal.h"
|
||||
|
||||
#ifdef USE_ESP32
|
||||
#include <esp_adc_cal.h>
|
||||
#include "driver/adc.h"
|
||||
#include "esp_adc/adc_cali.h"
|
||||
#include "esp_adc/adc_cali_scheme.h"
|
||||
#include "esp_adc/adc_oneshot.h"
|
||||
#include "hal/adc_types.h" // This defines ADC_CHANNEL_MAX
|
||||
#endif // USE_ESP32
|
||||
|
||||
namespace esphome {
|
||||
@@ -49,36 +52,71 @@ class Aggregator {
|
||||
|
||||
class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage_sampler::VoltageSampler {
|
||||
public:
|
||||
#ifdef USE_ESP32
|
||||
/// Set the attenuation for this pin. Only available on the ESP32.
|
||||
void set_attenuation(adc_atten_t attenuation) { this->attenuation_ = attenuation; }
|
||||
void set_channel1(adc1_channel_t channel) {
|
||||
this->channel1_ = channel;
|
||||
this->channel2_ = ADC2_CHANNEL_MAX;
|
||||
}
|
||||
void set_channel2(adc2_channel_t channel) {
|
||||
this->channel2_ = channel;
|
||||
this->channel1_ = ADC1_CHANNEL_MAX;
|
||||
}
|
||||
void set_autorange(bool autorange) { this->autorange_ = autorange; }
|
||||
#endif // USE_ESP32
|
||||
|
||||
/// Update ADC values
|
||||
/// Update the sensor's state by reading the current ADC value.
|
||||
/// This method is called periodically based on the update interval.
|
||||
void update() override;
|
||||
/// Setup ADC
|
||||
|
||||
/// Set up the ADC sensor by initializing hardware and calibration parameters.
|
||||
/// This method is called once during device initialization.
|
||||
void setup() override;
|
||||
|
||||
/// Output the configuration details of the ADC sensor for debugging purposes.
|
||||
/// This method is called during the ESPHome setup process to log the configuration.
|
||||
void dump_config() override;
|
||||
/// `HARDWARE_LATE` setup priority
|
||||
|
||||
/// Return the setup priority for this component.
|
||||
/// Components with higher priority are initialized earlier during setup.
|
||||
/// @return A float representing the setup priority.
|
||||
float get_setup_priority() const override;
|
||||
|
||||
/// Set the GPIO pin to be used by the ADC sensor.
|
||||
/// @param pin Pointer to an InternalGPIOPin representing the ADC input pin.
|
||||
void set_pin(InternalGPIOPin *pin) { this->pin_ = pin; }
|
||||
|
||||
/// Enable or disable the output of raw ADC values (unprocessed data).
|
||||
/// @param output_raw Boolean indicating whether to output raw ADC values (true) or processed values (false).
|
||||
void set_output_raw(bool output_raw) { this->output_raw_ = output_raw; }
|
||||
|
||||
/// Set the number of samples to be taken for ADC readings to improve accuracy.
|
||||
/// A higher sample count reduces noise but increases the reading time.
|
||||
/// @param sample_count The number of samples (e.g., 1, 4, 8).
|
||||
void set_sample_count(uint8_t sample_count);
|
||||
|
||||
/// Set the sampling mode for how multiple ADC samples are combined into a single measurement.
|
||||
///
|
||||
/// When multiple samples are taken (controlled by set_sample_count), they can be combined
|
||||
/// in one of three ways:
|
||||
/// - SamplingMode::AVG: Compute the average (default)
|
||||
/// - SamplingMode::MIN: Use the lowest sample value
|
||||
/// - SamplingMode::MAX: Use the highest sample value
|
||||
/// @param sampling_mode The desired sampling mode to use for aggregating ADC samples.
|
||||
void set_sampling_mode(SamplingMode sampling_mode);
|
||||
|
||||
/// Perform a single ADC sampling operation and return the measured value.
|
||||
/// This function handles raw readings, calibration, and averaging as needed.
|
||||
/// @return The sampled value as a float.
|
||||
float sample() override;
|
||||
|
||||
#ifdef USE_ESP8266
|
||||
std::string unique_id() override;
|
||||
#endif // USE_ESP8266
|
||||
#ifdef USE_ESP32
|
||||
/// Set the ADC attenuation level to adjust the input voltage range.
|
||||
/// This determines how the ADC interprets input voltages, allowing for greater precision
|
||||
/// or the ability to measure higher voltages depending on the chosen attenuation level.
|
||||
/// @param attenuation The desired ADC attenuation level (e.g., ADC_ATTEN_DB_0, ADC_ATTEN_DB_11).
|
||||
void set_attenuation(adc_atten_t attenuation) { this->attenuation_ = attenuation; }
|
||||
|
||||
/// Configure the ADC to use a specific channel on ADC1.
|
||||
/// This sets the channel for single-shot or continuous ADC measurements.
|
||||
/// @param channel The ADC1 channel to configure, such as ADC_CHANNEL_0, ADC_CHANNEL_3, etc.
|
||||
void set_channel(adc_unit_t unit, adc_channel_t channel) {
|
||||
this->adc_unit_ = unit;
|
||||
this->channel_ = channel;
|
||||
}
|
||||
|
||||
/// Set whether autoranging should be enabled for the ADC.
|
||||
/// Autoranging automatically adjusts the attenuation level to handle a wide range of input voltages.
|
||||
/// @param autorange Boolean indicating whether to enable autoranging.
|
||||
void set_autorange(bool autorange) { this->autorange_ = autorange; }
|
||||
#endif // USE_ESP32
|
||||
|
||||
#ifdef USE_RP2040
|
||||
void set_is_temperature() { this->is_temperature_ = true; }
|
||||
@@ -90,17 +128,28 @@ class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage
|
||||
InternalGPIOPin *pin_;
|
||||
SamplingMode sampling_mode_{SamplingMode::AVG};
|
||||
|
||||
#ifdef USE_ESP32
|
||||
float sample_autorange_();
|
||||
float sample_fixed_attenuation_();
|
||||
bool autorange_{false};
|
||||
adc_oneshot_unit_handle_t adc_handle_{nullptr};
|
||||
adc_cali_handle_t calibration_handle_{nullptr};
|
||||
adc_atten_t attenuation_{ADC_ATTEN_DB_0};
|
||||
adc_channel_t channel_;
|
||||
adc_unit_t adc_unit_;
|
||||
struct SetupFlags {
|
||||
uint8_t init_complete : 1;
|
||||
uint8_t config_complete : 1;
|
||||
uint8_t handle_init_complete : 1;
|
||||
uint8_t calibration_complete : 1;
|
||||
uint8_t reserved : 4;
|
||||
} setup_flags_{};
|
||||
static adc_oneshot_unit_handle_t shared_adc_handles[2];
|
||||
#endif // USE_ESP32
|
||||
|
||||
#ifdef USE_RP2040
|
||||
bool is_temperature_{false};
|
||||
#endif // USE_RP2040
|
||||
|
||||
#ifdef USE_ESP32
|
||||
adc_atten_t attenuation_{ADC_ATTEN_DB_0};
|
||||
adc1_channel_t channel1_{ADC1_CHANNEL_MAX};
|
||||
adc2_channel_t channel2_{ADC2_CHANNEL_MAX};
|
||||
bool autorange_{false};
|
||||
esp_adc_cal_characteristics_t cal_characteristics_[SOC_ADC_ATTEN_NUM] = {};
|
||||
#endif // USE_ESP32
|
||||
};
|
||||
|
||||
} // namespace adc
|
||||
|
@@ -8,145 +8,308 @@ namespace adc {
|
||||
|
||||
static const char *const TAG = "adc.esp32";
|
||||
|
||||
static const adc_bits_width_t ADC_WIDTH_MAX_SOC_BITS = static_cast<adc_bits_width_t>(ADC_WIDTH_MAX - 1);
|
||||
adc_oneshot_unit_handle_t ADCSensor::shared_adc_handles[2] = {nullptr, nullptr};
|
||||
|
||||
#ifndef SOC_ADC_RTC_MAX_BITWIDTH
|
||||
#if USE_ESP32_VARIANT_ESP32S2
|
||||
static const int32_t SOC_ADC_RTC_MAX_BITWIDTH = 13;
|
||||
#else
|
||||
static const int32_t SOC_ADC_RTC_MAX_BITWIDTH = 12;
|
||||
#endif // USE_ESP32_VARIANT_ESP32S2
|
||||
#endif // SOC_ADC_RTC_MAX_BITWIDTH
|
||||
|
||||
static const int ADC_MAX = (1 << SOC_ADC_RTC_MAX_BITWIDTH) - 1;
|
||||
static const int ADC_HALF = (1 << SOC_ADC_RTC_MAX_BITWIDTH) >> 1;
|
||||
|
||||
void ADCSensor::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->get_name().c_str());
|
||||
|
||||
if (this->channel1_ != ADC1_CHANNEL_MAX) {
|
||||
adc1_config_width(ADC_WIDTH_MAX_SOC_BITS);
|
||||
if (!this->autorange_) {
|
||||
adc1_config_channel_atten(this->channel1_, this->attenuation_);
|
||||
}
|
||||
} else if (this->channel2_ != ADC2_CHANNEL_MAX) {
|
||||
if (!this->autorange_) {
|
||||
adc2_config_channel_atten(this->channel2_, this->attenuation_);
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i <= ADC_ATTEN_DB_12_COMPAT; i++) {
|
||||
auto adc_unit = this->channel1_ != ADC1_CHANNEL_MAX ? ADC_UNIT_1 : ADC_UNIT_2;
|
||||
auto cal_value = esp_adc_cal_characterize(adc_unit, (adc_atten_t) i, ADC_WIDTH_MAX_SOC_BITS,
|
||||
1100, // default vref
|
||||
&this->cal_characteristics_[i]);
|
||||
switch (cal_value) {
|
||||
case ESP_ADC_CAL_VAL_EFUSE_VREF:
|
||||
ESP_LOGV(TAG, "Using eFuse Vref for calibration");
|
||||
break;
|
||||
case ESP_ADC_CAL_VAL_EFUSE_TP:
|
||||
ESP_LOGV(TAG, "Using two-point eFuse Vref for calibration");
|
||||
break;
|
||||
case ESP_ADC_CAL_VAL_DEFAULT_VREF:
|
||||
const LogString *attenuation_to_str(adc_atten_t attenuation) {
|
||||
switch (attenuation) {
|
||||
case ADC_ATTEN_DB_0:
|
||||
return LOG_STR("0 dB");
|
||||
case ADC_ATTEN_DB_2_5:
|
||||
return LOG_STR("2.5 dB");
|
||||
case ADC_ATTEN_DB_6:
|
||||
return LOG_STR("6 dB");
|
||||
case ADC_ATTEN_DB_12_COMPAT:
|
||||
return LOG_STR("12 dB");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return LOG_STR("Unknown Attenuation");
|
||||
}
|
||||
}
|
||||
|
||||
void ADCSensor::dump_config() {
|
||||
static const char *const ATTEN_AUTO_STR = "auto";
|
||||
static const char *const ATTEN_0DB_STR = "0 db";
|
||||
static const char *const ATTEN_2_5DB_STR = "2.5 db";
|
||||
static const char *const ATTEN_6DB_STR = "6 db";
|
||||
static const char *const ATTEN_12DB_STR = "12 db";
|
||||
const char *atten_str = ATTEN_AUTO_STR;
|
||||
const LogString *adc_unit_to_str(adc_unit_t unit) {
|
||||
switch (unit) {
|
||||
case ADC_UNIT_1:
|
||||
return LOG_STR("ADC1");
|
||||
case ADC_UNIT_2:
|
||||
return LOG_STR("ADC2");
|
||||
default:
|
||||
return LOG_STR("Unknown ADC Unit");
|
||||
}
|
||||
}
|
||||
|
||||
void ADCSensor::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->get_name().c_str());
|
||||
// Check if another sensor already initialized this ADC unit
|
||||
if (ADCSensor::shared_adc_handles[this->adc_unit_] == nullptr) {
|
||||
adc_oneshot_unit_init_cfg_t init_config = {}; // Zero initialize
|
||||
init_config.unit_id = this->adc_unit_;
|
||||
init_config.ulp_mode = ADC_ULP_MODE_DISABLE;
|
||||
#if USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32C6 || USE_ESP32_VARIANT_ESP32H2
|
||||
init_config.clk_src = ADC_DIGI_CLK_SRC_DEFAULT;
|
||||
#endif // USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32C6 || USE_ESP32_VARIANT_ESP32H2
|
||||
esp_err_t err = adc_oneshot_new_unit(&init_config, &ADCSensor::shared_adc_handles[this->adc_unit_]);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Error initializing %s: %d", LOG_STR_ARG(adc_unit_to_str(this->adc_unit_)), err);
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
this->adc_handle_ = ADCSensor::shared_adc_handles[this->adc_unit_];
|
||||
|
||||
this->setup_flags_.handle_init_complete = true;
|
||||
|
||||
adc_oneshot_chan_cfg_t config = {
|
||||
.atten = this->attenuation_,
|
||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||
};
|
||||
esp_err_t err = adc_oneshot_config_channel(this->adc_handle_, this->channel_, &config);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Error configuring channel: %d", err);
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
this->setup_flags_.config_complete = true;
|
||||
|
||||
// Initialize ADC calibration
|
||||
if (this->calibration_handle_ == nullptr) {
|
||||
adc_cali_handle_t handle = nullptr;
|
||||
esp_err_t err;
|
||||
|
||||
#if USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32C6 || USE_ESP32_VARIANT_ESP32S3 || USE_ESP32_VARIANT_ESP32H2
|
||||
// RISC-V variants and S3 use curve fitting calibration
|
||||
adc_cali_curve_fitting_config_t cali_config = {}; // Zero initialize first
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
|
||||
cali_config.chan = this->channel_;
|
||||
#endif // ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
|
||||
cali_config.unit_id = this->adc_unit_;
|
||||
cali_config.atten = this->attenuation_;
|
||||
cali_config.bitwidth = ADC_BITWIDTH_DEFAULT;
|
||||
|
||||
err = adc_cali_create_scheme_curve_fitting(&cali_config, &handle);
|
||||
if (err == ESP_OK) {
|
||||
this->calibration_handle_ = handle;
|
||||
this->setup_flags_.calibration_complete = true;
|
||||
ESP_LOGV(TAG, "Using curve fitting calibration");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Curve fitting calibration failed with error %d, will use uncalibrated readings", err);
|
||||
this->setup_flags_.calibration_complete = false;
|
||||
}
|
||||
#else // Other ESP32 variants use line fitting calibration
|
||||
adc_cali_line_fitting_config_t cali_config = {
|
||||
.unit_id = this->adc_unit_,
|
||||
.atten = this->attenuation_,
|
||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||
#if !defined(USE_ESP32_VARIANT_ESP32S2)
|
||||
.default_vref = 1100, // Default reference voltage in mV
|
||||
#endif // !defined(USE_ESP32_VARIANT_ESP32S2)
|
||||
};
|
||||
err = adc_cali_create_scheme_line_fitting(&cali_config, &handle);
|
||||
if (err == ESP_OK) {
|
||||
this->calibration_handle_ = handle;
|
||||
this->setup_flags_.calibration_complete = true;
|
||||
ESP_LOGV(TAG, "Using line fitting calibration");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Line fitting calibration failed with error %d, will use uncalibrated readings", err);
|
||||
this->setup_flags_.calibration_complete = false;
|
||||
}
|
||||
#endif // USE_ESP32_VARIANT_ESP32C3 || ESP32C6 || ESP32S3 || ESP32H2
|
||||
}
|
||||
|
||||
this->setup_flags_.init_complete = true;
|
||||
}
|
||||
|
||||
void ADCSensor::dump_config() {
|
||||
LOG_SENSOR("", "ADC Sensor", this);
|
||||
LOG_PIN(" Pin: ", this->pin_);
|
||||
|
||||
if (!this->autorange_) {
|
||||
switch (this->attenuation_) {
|
||||
case ADC_ATTEN_DB_0:
|
||||
atten_str = ATTEN_0DB_STR;
|
||||
break;
|
||||
case ADC_ATTEN_DB_2_5:
|
||||
atten_str = ATTEN_2_5DB_STR;
|
||||
break;
|
||||
case ADC_ATTEN_DB_6:
|
||||
atten_str = ATTEN_6DB_STR;
|
||||
break;
|
||||
case ADC_ATTEN_DB_12_COMPAT:
|
||||
atten_str = ATTEN_12DB_STR;
|
||||
break;
|
||||
default: // This is to satisfy the unused ADC_ATTEN_MAX
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ESP_LOGCONFIG(TAG,
|
||||
" Channel: %d\n"
|
||||
" Unit: %s\n"
|
||||
" Attenuation: %s\n"
|
||||
" Samples: %i\n"
|
||||
" Sampling mode: %s",
|
||||
atten_str, this->sample_count_, LOG_STR_ARG(sampling_mode_to_str(this->sampling_mode_)));
|
||||
this->channel_, LOG_STR_ARG(adc_unit_to_str(this->adc_unit_)),
|
||||
this->autorange_ ? "Auto" : LOG_STR_ARG(attenuation_to_str(this->attenuation_)), this->sample_count_,
|
||||
LOG_STR_ARG(sampling_mode_to_str(this->sampling_mode_)));
|
||||
|
||||
ESP_LOGCONFIG(
|
||||
TAG,
|
||||
" Setup Status:\n"
|
||||
" Handle Init: %s\n"
|
||||
" Config: %s\n"
|
||||
" Calibration: %s\n"
|
||||
" Overall Init: %s",
|
||||
this->setup_flags_.handle_init_complete ? "OK" : "FAILED", this->setup_flags_.config_complete ? "OK" : "FAILED",
|
||||
this->setup_flags_.calibration_complete ? "OK" : "FAILED", this->setup_flags_.init_complete ? "OK" : "FAILED");
|
||||
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
}
|
||||
|
||||
float ADCSensor::sample() {
|
||||
if (!this->autorange_) {
|
||||
if (this->autorange_) {
|
||||
return this->sample_autorange_();
|
||||
} else {
|
||||
return this->sample_fixed_attenuation_();
|
||||
}
|
||||
}
|
||||
|
||||
float ADCSensor::sample_fixed_attenuation_() {
|
||||
auto aggr = Aggregator(this->sampling_mode_);
|
||||
|
||||
for (uint8_t sample = 0; sample < this->sample_count_; sample++) {
|
||||
int raw = -1;
|
||||
if (this->channel1_ != ADC1_CHANNEL_MAX) {
|
||||
raw = adc1_get_raw(this->channel1_);
|
||||
} else if (this->channel2_ != ADC2_CHANNEL_MAX) {
|
||||
adc2_get_raw(this->channel2_, ADC_WIDTH_MAX_SOC_BITS, &raw);
|
||||
int raw;
|
||||
esp_err_t err = adc_oneshot_read(this->adc_handle_, this->channel_, &raw);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "ADC read failed with error %d", err);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (raw == -1) {
|
||||
return NAN;
|
||||
ESP_LOGW(TAG, "Invalid ADC reading");
|
||||
continue;
|
||||
}
|
||||
|
||||
aggr.add_sample(raw);
|
||||
}
|
||||
|
||||
uint32_t final_value = aggr.aggregate();
|
||||
|
||||
if (this->output_raw_) {
|
||||
return aggr.aggregate();
|
||||
}
|
||||
uint32_t mv =
|
||||
esp_adc_cal_raw_to_voltage(aggr.aggregate(), &this->cal_characteristics_[(int32_t) this->attenuation_]);
|
||||
return mv / 1000.0f;
|
||||
return final_value;
|
||||
}
|
||||
|
||||
int raw12 = ADC_MAX, raw6 = ADC_MAX, raw2 = ADC_MAX, raw0 = ADC_MAX;
|
||||
if (this->calibration_handle_ != nullptr) {
|
||||
int voltage_mv;
|
||||
esp_err_t err = adc_cali_raw_to_voltage(this->calibration_handle_, final_value, &voltage_mv);
|
||||
if (err == ESP_OK) {
|
||||
return voltage_mv / 1000.0f;
|
||||
} else {
|
||||
ESP_LOGW(TAG, "ADC calibration conversion failed with error %d, disabling calibration", err);
|
||||
if (this->calibration_handle_ != nullptr) {
|
||||
#if USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32C6 || USE_ESP32_VARIANT_ESP32S3 || USE_ESP32_VARIANT_ESP32H2
|
||||
adc_cali_delete_scheme_curve_fitting(this->calibration_handle_);
|
||||
#else // Other ESP32 variants use line fitting calibration
|
||||
adc_cali_delete_scheme_line_fitting(this->calibration_handle_);
|
||||
#endif // USE_ESP32_VARIANT_ESP32C3 || ESP32C6 || ESP32S3 || ESP32H2
|
||||
this->calibration_handle_ = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this->channel1_ != ADC1_CHANNEL_MAX) {
|
||||
adc1_config_channel_atten(this->channel1_, ADC_ATTEN_DB_12_COMPAT);
|
||||
raw12 = adc1_get_raw(this->channel1_);
|
||||
if (raw12 < ADC_MAX) {
|
||||
adc1_config_channel_atten(this->channel1_, ADC_ATTEN_DB_6);
|
||||
raw6 = adc1_get_raw(this->channel1_);
|
||||
if (raw6 < ADC_MAX) {
|
||||
adc1_config_channel_atten(this->channel1_, ADC_ATTEN_DB_2_5);
|
||||
raw2 = adc1_get_raw(this->channel1_);
|
||||
if (raw2 < ADC_MAX) {
|
||||
adc1_config_channel_atten(this->channel1_, ADC_ATTEN_DB_0);
|
||||
raw0 = adc1_get_raw(this->channel1_);
|
||||
return final_value * 3.3f / 4095.0f;
|
||||
}
|
||||
|
||||
float ADCSensor::sample_autorange_() {
|
||||
// Auto-range mode
|
||||
auto read_atten = [this](adc_atten_t atten) -> std::pair<int, float> {
|
||||
// First reconfigure the attenuation for this reading
|
||||
adc_oneshot_chan_cfg_t config = {
|
||||
.atten = atten,
|
||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||
};
|
||||
|
||||
esp_err_t err = adc_oneshot_config_channel(this->adc_handle_, this->channel_, &config);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Error configuring ADC channel for autorange: %d", err);
|
||||
return {-1, 0.0f};
|
||||
}
|
||||
|
||||
// Need to recalibrate for the new attenuation
|
||||
if (this->calibration_handle_ != nullptr) {
|
||||
// Delete old calibration handle
|
||||
#if USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32C6 || USE_ESP32_VARIANT_ESP32S3 || USE_ESP32_VARIANT_ESP32H2
|
||||
adc_cali_delete_scheme_curve_fitting(this->calibration_handle_);
|
||||
#else
|
||||
adc_cali_delete_scheme_line_fitting(this->calibration_handle_);
|
||||
#endif
|
||||
this->calibration_handle_ = nullptr;
|
||||
}
|
||||
|
||||
// Create new calibration handle for this attenuation
|
||||
adc_cali_handle_t handle = nullptr;
|
||||
|
||||
#if USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32C6 || USE_ESP32_VARIANT_ESP32S3 || USE_ESP32_VARIANT_ESP32H2
|
||||
adc_cali_curve_fitting_config_t cali_config = {};
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
|
||||
cali_config.chan = this->channel_;
|
||||
#endif
|
||||
cali_config.unit_id = this->adc_unit_;
|
||||
cali_config.atten = atten;
|
||||
cali_config.bitwidth = ADC_BITWIDTH_DEFAULT;
|
||||
|
||||
err = adc_cali_create_scheme_curve_fitting(&cali_config, &handle);
|
||||
#else
|
||||
adc_cali_line_fitting_config_t cali_config = {
|
||||
.unit_id = this->adc_unit_,
|
||||
.atten = atten,
|
||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||
#if !defined(USE_ESP32_VARIANT_ESP32S2)
|
||||
.default_vref = 1100,
|
||||
#endif
|
||||
};
|
||||
err = adc_cali_create_scheme_line_fitting(&cali_config, &handle);
|
||||
#endif
|
||||
|
||||
int raw;
|
||||
err = adc_oneshot_read(this->adc_handle_, this->channel_, &raw);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "ADC read failed in autorange with error %d", err);
|
||||
if (handle != nullptr) {
|
||||
#if USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32C6 || USE_ESP32_VARIANT_ESP32S3 || USE_ESP32_VARIANT_ESP32H2
|
||||
adc_cali_delete_scheme_curve_fitting(handle);
|
||||
#else
|
||||
adc_cali_delete_scheme_line_fitting(handle);
|
||||
#endif
|
||||
}
|
||||
} else if (this->channel2_ != ADC2_CHANNEL_MAX) {
|
||||
adc2_config_channel_atten(this->channel2_, ADC_ATTEN_DB_12_COMPAT);
|
||||
adc2_get_raw(this->channel2_, ADC_WIDTH_MAX_SOC_BITS, &raw12);
|
||||
if (raw12 < ADC_MAX) {
|
||||
adc2_config_channel_atten(this->channel2_, ADC_ATTEN_DB_6);
|
||||
adc2_get_raw(this->channel2_, ADC_WIDTH_MAX_SOC_BITS, &raw6);
|
||||
if (raw6 < ADC_MAX) {
|
||||
adc2_config_channel_atten(this->channel2_, ADC_ATTEN_DB_2_5);
|
||||
adc2_get_raw(this->channel2_, ADC_WIDTH_MAX_SOC_BITS, &raw2);
|
||||
if (raw2 < ADC_MAX) {
|
||||
adc2_config_channel_atten(this->channel2_, ADC_ATTEN_DB_0);
|
||||
adc2_get_raw(this->channel2_, ADC_WIDTH_MAX_SOC_BITS, &raw0);
|
||||
return {-1, 0.0f};
|
||||
}
|
||||
|
||||
float voltage = 0.0f;
|
||||
if (handle != nullptr) {
|
||||
int voltage_mv;
|
||||
err = adc_cali_raw_to_voltage(handle, raw, &voltage_mv);
|
||||
if (err == ESP_OK) {
|
||||
voltage = voltage_mv / 1000.0f;
|
||||
} else {
|
||||
voltage = raw * 3.3f / 4095.0f;
|
||||
}
|
||||
// Clean up calibration handle
|
||||
#if USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32C6 || USE_ESP32_VARIANT_ESP32S3 || USE_ESP32_VARIANT_ESP32H2
|
||||
adc_cali_delete_scheme_curve_fitting(handle);
|
||||
#else
|
||||
adc_cali_delete_scheme_line_fitting(handle);
|
||||
#endif
|
||||
} else {
|
||||
voltage = raw * 3.3f / 4095.0f;
|
||||
}
|
||||
|
||||
return {raw, voltage};
|
||||
};
|
||||
|
||||
auto [raw12, mv12] = read_atten(ADC_ATTEN_DB_12);
|
||||
if (raw12 == -1) {
|
||||
ESP_LOGE(TAG, "Failed to read ADC in autorange mode");
|
||||
return NAN;
|
||||
}
|
||||
|
||||
int raw6 = 4095, raw2 = 4095, raw0 = 4095;
|
||||
float mv6 = 0, mv2 = 0, mv0 = 0;
|
||||
|
||||
if (raw12 < 4095) {
|
||||
auto [raw6_val, mv6_val] = read_atten(ADC_ATTEN_DB_6);
|
||||
raw6 = raw6_val;
|
||||
mv6 = mv6_val;
|
||||
|
||||
if (raw6 < 4095 && raw6 != -1) {
|
||||
auto [raw2_val, mv2_val] = read_atten(ADC_ATTEN_DB_2_5);
|
||||
raw2 = raw2_val;
|
||||
mv2 = mv2_val;
|
||||
|
||||
if (raw2 < 4095 && raw2 != -1) {
|
||||
auto [raw0_val, mv0_val] = read_atten(ADC_ATTEN_DB_0);
|
||||
raw0 = raw0_val;
|
||||
mv0 = mv0_val;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -155,19 +318,19 @@ float ADCSensor::sample() {
|
||||
return NAN;
|
||||
}
|
||||
|
||||
uint32_t mv12 = esp_adc_cal_raw_to_voltage(raw12, &this->cal_characteristics_[(int32_t) ADC_ATTEN_DB_12_COMPAT]);
|
||||
uint32_t mv6 = esp_adc_cal_raw_to_voltage(raw6, &this->cal_characteristics_[(int32_t) ADC_ATTEN_DB_6]);
|
||||
uint32_t mv2 = esp_adc_cal_raw_to_voltage(raw2, &this->cal_characteristics_[(int32_t) ADC_ATTEN_DB_2_5]);
|
||||
uint32_t mv0 = esp_adc_cal_raw_to_voltage(raw0, &this->cal_characteristics_[(int32_t) ADC_ATTEN_DB_0]);
|
||||
|
||||
uint32_t c12 = std::min(raw12, ADC_HALF);
|
||||
uint32_t c6 = ADC_HALF - std::abs(raw6 - ADC_HALF);
|
||||
uint32_t c2 = ADC_HALF - std::abs(raw2 - ADC_HALF);
|
||||
uint32_t c0 = std::min(ADC_MAX - raw0, ADC_HALF);
|
||||
const int adc_half = 2048;
|
||||
uint32_t c12 = std::min(raw12, adc_half);
|
||||
uint32_t c6 = adc_half - std::abs(raw6 - adc_half);
|
||||
uint32_t c2 = adc_half - std::abs(raw2 - adc_half);
|
||||
uint32_t c0 = std::min(4095 - raw0, adc_half);
|
||||
uint32_t csum = c12 + c6 + c2 + c0;
|
||||
|
||||
uint32_t mv_scaled = (mv12 * c12) + (mv6 * c6) + (mv2 * c2) + (mv0 * c0);
|
||||
return mv_scaled / (float) (csum * 1000U);
|
||||
if (csum == 0) {
|
||||
ESP_LOGE(TAG, "Invalid weight sum in autorange calculation");
|
||||
return NAN;
|
||||
}
|
||||
|
||||
return (mv12 * c12 + mv6 * c6 + mv2 * c2 + mv0 * c0) / csum;
|
||||
}
|
||||
|
||||
} // namespace adc
|
||||
|
@@ -56,8 +56,6 @@ float ADCSensor::sample() {
|
||||
return aggr.aggregate() / 1024.0f;
|
||||
}
|
||||
|
||||
std::string ADCSensor::unique_id() { return get_mac_address() + "-adc"; }
|
||||
|
||||
} // namespace adc
|
||||
} // namespace esphome
|
||||
|
||||
|
@@ -10,13 +10,11 @@ from esphome.const import (
|
||||
CONF_NUMBER,
|
||||
CONF_PIN,
|
||||
CONF_RAW,
|
||||
CONF_WIFI,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
UNIT_VOLT,
|
||||
)
|
||||
from esphome.core import CORE
|
||||
import esphome.final_validate as fv
|
||||
|
||||
from . import (
|
||||
ATTENUATION_MODES,
|
||||
@@ -24,6 +22,7 @@ from . import (
|
||||
ESP32_VARIANT_ADC2_PIN_TO_CHANNEL,
|
||||
SAMPLING_MODES,
|
||||
adc_ns,
|
||||
adc_unit_t,
|
||||
validate_adc_pin,
|
||||
)
|
||||
|
||||
@@ -57,21 +56,6 @@ def validate_config(config):
|
||||
return config
|
||||
|
||||
|
||||
def final_validate_config(config):
|
||||
if CORE.is_esp32:
|
||||
variant = get_esp32_variant()
|
||||
if (
|
||||
CONF_WIFI in fv.full_config.get()
|
||||
and config[CONF_PIN][CONF_NUMBER]
|
||||
in ESP32_VARIANT_ADC2_PIN_TO_CHANNEL[variant]
|
||||
):
|
||||
raise cv.Invalid(
|
||||
f"{variant} doesn't support ADC on this pin when Wi-Fi is configured"
|
||||
)
|
||||
|
||||
return config
|
||||
|
||||
|
||||
ADCSensor = adc_ns.class_(
|
||||
"ADCSensor", sensor.Sensor, cg.PollingComponent, voltage_sampler.VoltageSampler
|
||||
)
|
||||
@@ -99,8 +83,6 @@ CONFIG_SCHEMA = cv.All(
|
||||
validate_config,
|
||||
)
|
||||
|
||||
FINAL_VALIDATE_SCHEMA = final_validate_config
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
@@ -119,13 +101,13 @@ async def to_code(config):
|
||||
cg.add(var.set_sample_count(config[CONF_SAMPLES]))
|
||||
cg.add(var.set_sampling_mode(config[CONF_SAMPLING_MODE]))
|
||||
|
||||
if CORE.is_esp32:
|
||||
if attenuation := config.get(CONF_ATTENUATION):
|
||||
if attenuation == "auto":
|
||||
cg.add(var.set_autorange(cg.global_ns.true))
|
||||
else:
|
||||
cg.add(var.set_attenuation(attenuation))
|
||||
|
||||
if CORE.is_esp32:
|
||||
variant = get_esp32_variant()
|
||||
pin_num = config[CONF_PIN][CONF_NUMBER]
|
||||
if (
|
||||
@@ -133,10 +115,10 @@ async def to_code(config):
|
||||
and pin_num in ESP32_VARIANT_ADC1_PIN_TO_CHANNEL[variant]
|
||||
):
|
||||
chan = ESP32_VARIANT_ADC1_PIN_TO_CHANNEL[variant][pin_num]
|
||||
cg.add(var.set_channel1(chan))
|
||||
cg.add(var.set_channel(adc_unit_t.ADC_UNIT_1, chan))
|
||||
elif (
|
||||
variant in ESP32_VARIANT_ADC2_PIN_TO_CHANNEL
|
||||
and pin_num in ESP32_VARIANT_ADC2_PIN_TO_CHANNEL[variant]
|
||||
):
|
||||
chan = ESP32_VARIANT_ADC2_PIN_TO_CHANNEL[variant][pin_num]
|
||||
cg.add(var.set_channel2(chan))
|
||||
cg.add(var.set_channel(adc_unit_t.ADC_UNIT_2, chan))
|
||||
|
@@ -222,37 +222,37 @@ message DeviceInfoResponse {
|
||||
// The model of the board. For example NodeMCU
|
||||
string model = 6;
|
||||
|
||||
bool has_deep_sleep = 7;
|
||||
bool has_deep_sleep = 7 [(field_ifdef) = "USE_DEEP_SLEEP"];
|
||||
|
||||
// The esphome project details if set
|
||||
string project_name = 8;
|
||||
string project_version = 9;
|
||||
string project_name = 8 [(field_ifdef) = "ESPHOME_PROJECT_NAME"];
|
||||
string project_version = 9 [(field_ifdef) = "ESPHOME_PROJECT_NAME"];
|
||||
|
||||
uint32 webserver_port = 10;
|
||||
uint32 webserver_port = 10 [(field_ifdef) = "USE_WEBSERVER"];
|
||||
|
||||
uint32 legacy_bluetooth_proxy_version = 11;
|
||||
uint32 bluetooth_proxy_feature_flags = 15;
|
||||
uint32 legacy_bluetooth_proxy_version = 11 [(field_ifdef) = "USE_BLUETOOTH_PROXY"];
|
||||
uint32 bluetooth_proxy_feature_flags = 15 [(field_ifdef) = "USE_BLUETOOTH_PROXY"];
|
||||
|
||||
string manufacturer = 12;
|
||||
|
||||
string friendly_name = 13;
|
||||
|
||||
uint32 legacy_voice_assistant_version = 14;
|
||||
uint32 voice_assistant_feature_flags = 17;
|
||||
uint32 legacy_voice_assistant_version = 14 [(field_ifdef) = "USE_VOICE_ASSISTANT"];
|
||||
uint32 voice_assistant_feature_flags = 17 [(field_ifdef) = "USE_VOICE_ASSISTANT"];
|
||||
|
||||
string suggested_area = 16;
|
||||
string suggested_area = 16 [(field_ifdef) = "USE_AREAS"];
|
||||
|
||||
// The Bluetooth mac address of the device. For example "AC:BC:32:89:0E:AA"
|
||||
string bluetooth_mac_address = 18;
|
||||
string bluetooth_mac_address = 18 [(field_ifdef) = "USE_BLUETOOTH_PROXY"];
|
||||
|
||||
// Supports receiving and saving api encryption key
|
||||
bool api_encryption_supported = 19;
|
||||
bool api_encryption_supported = 19 [(field_ifdef) = "USE_API_NOISE"];
|
||||
|
||||
repeated DeviceInfo devices = 20;
|
||||
repeated AreaInfo areas = 21;
|
||||
repeated DeviceInfo devices = 20 [(field_ifdef) = "USE_DEVICES"];
|
||||
repeated AreaInfo areas = 21 [(field_ifdef) = "USE_AREAS"];
|
||||
|
||||
// Top-level area info to phase out suggested_area
|
||||
AreaInfo area = 22;
|
||||
AreaInfo area = 22 [(field_ifdef) = "USE_AREAS"];
|
||||
}
|
||||
|
||||
message ListEntitiesRequest {
|
||||
@@ -290,14 +290,14 @@ message ListEntitiesBinarySensorResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
string device_class = 5;
|
||||
bool is_status_binary_sensor = 6;
|
||||
bool disabled_by_default = 7;
|
||||
string icon = 8;
|
||||
string icon = 8 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
EntityCategory entity_category = 9;
|
||||
uint32 device_id = 10;
|
||||
uint32 device_id = 10 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message BinarySensorStateResponse {
|
||||
option (id) = 21;
|
||||
@@ -311,7 +311,7 @@ message BinarySensorStateResponse {
|
||||
// If the binary sensor does not have a valid state yet.
|
||||
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
|
||||
bool missing_state = 3;
|
||||
uint32 device_id = 4;
|
||||
uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== COVER ====================
|
||||
@@ -324,17 +324,17 @@ message ListEntitiesCoverResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
bool assumed_state = 5;
|
||||
bool supports_position = 6;
|
||||
bool supports_tilt = 7;
|
||||
string device_class = 8;
|
||||
bool disabled_by_default = 9;
|
||||
string icon = 10;
|
||||
string icon = 10 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
EntityCategory entity_category = 11;
|
||||
bool supports_stop = 12;
|
||||
uint32 device_id = 13;
|
||||
uint32 device_id = 13 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
enum LegacyCoverState {
|
||||
@@ -361,7 +361,7 @@ message CoverStateResponse {
|
||||
float position = 3;
|
||||
float tilt = 4;
|
||||
CoverOperation current_operation = 5;
|
||||
uint32 device_id = 6;
|
||||
uint32 device_id = 6 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
enum LegacyCoverCommand {
|
||||
@@ -388,7 +388,7 @@ message CoverCommandRequest {
|
||||
bool has_tilt = 6;
|
||||
float tilt = 7;
|
||||
bool stop = 8;
|
||||
uint32 device_id = 9;
|
||||
uint32 device_id = 9 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== FAN ====================
|
||||
@@ -401,17 +401,17 @@ message ListEntitiesFanResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
bool supports_oscillation = 5;
|
||||
bool supports_speed = 6;
|
||||
bool supports_direction = 7;
|
||||
int32 supported_speed_count = 8;
|
||||
bool disabled_by_default = 9;
|
||||
string icon = 10;
|
||||
string icon = 10 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
EntityCategory entity_category = 11;
|
||||
repeated string supported_preset_modes = 12;
|
||||
uint32 device_id = 13;
|
||||
uint32 device_id = 13 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
enum FanSpeed {
|
||||
FAN_SPEED_LOW = 0;
|
||||
@@ -436,7 +436,7 @@ message FanStateResponse {
|
||||
FanDirection direction = 5;
|
||||
int32 speed_level = 6;
|
||||
string preset_mode = 7;
|
||||
uint32 device_id = 8;
|
||||
uint32 device_id = 8 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message FanCommandRequest {
|
||||
option (id) = 31;
|
||||
@@ -458,7 +458,7 @@ message FanCommandRequest {
|
||||
int32 speed_level = 11;
|
||||
bool has_preset_mode = 12;
|
||||
string preset_mode = 13;
|
||||
uint32 device_id = 14;
|
||||
uint32 device_id = 14 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== LIGHT ====================
|
||||
@@ -484,7 +484,7 @@ message ListEntitiesLightResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
repeated ColorMode supported_color_modes = 12;
|
||||
// next four supports_* are for legacy clients, newer clients should use color modes
|
||||
@@ -496,9 +496,9 @@ message ListEntitiesLightResponse {
|
||||
float max_mireds = 10;
|
||||
repeated string effects = 11;
|
||||
bool disabled_by_default = 13;
|
||||
string icon = 14;
|
||||
string icon = 14 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
EntityCategory entity_category = 15;
|
||||
uint32 device_id = 16;
|
||||
uint32 device_id = 16 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message LightStateResponse {
|
||||
option (id) = 24;
|
||||
@@ -520,7 +520,7 @@ message LightStateResponse {
|
||||
float cold_white = 12;
|
||||
float warm_white = 13;
|
||||
string effect = 9;
|
||||
uint32 device_id = 14;
|
||||
uint32 device_id = 14 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message LightCommandRequest {
|
||||
option (id) = 32;
|
||||
@@ -556,7 +556,7 @@ message LightCommandRequest {
|
||||
uint32 flash_length = 17;
|
||||
bool has_effect = 18;
|
||||
string effect = 19;
|
||||
uint32 device_id = 28;
|
||||
uint32 device_id = 28 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== SENSOR ====================
|
||||
@@ -582,9 +582,9 @@ message ListEntitiesSensorResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
string icon = 5;
|
||||
string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
string unit_of_measurement = 6;
|
||||
int32 accuracy_decimals = 7;
|
||||
bool force_update = 8;
|
||||
@@ -594,7 +594,7 @@ message ListEntitiesSensorResponse {
|
||||
SensorLastResetType legacy_last_reset_type = 11;
|
||||
bool disabled_by_default = 12;
|
||||
EntityCategory entity_category = 13;
|
||||
uint32 device_id = 14;
|
||||
uint32 device_id = 14 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message SensorStateResponse {
|
||||
option (id) = 25;
|
||||
@@ -608,7 +608,7 @@ message SensorStateResponse {
|
||||
// If the sensor does not have a valid state yet.
|
||||
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
|
||||
bool missing_state = 3;
|
||||
uint32 device_id = 4;
|
||||
uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== SWITCH ====================
|
||||
@@ -621,14 +621,14 @@ message ListEntitiesSwitchResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
string icon = 5;
|
||||
string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
bool assumed_state = 6;
|
||||
bool disabled_by_default = 7;
|
||||
EntityCategory entity_category = 8;
|
||||
string device_class = 9;
|
||||
uint32 device_id = 10;
|
||||
uint32 device_id = 10 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message SwitchStateResponse {
|
||||
option (id) = 26;
|
||||
@@ -639,7 +639,7 @@ message SwitchStateResponse {
|
||||
|
||||
fixed32 key = 1;
|
||||
bool state = 2;
|
||||
uint32 device_id = 3;
|
||||
uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message SwitchCommandRequest {
|
||||
option (id) = 33;
|
||||
@@ -650,7 +650,7 @@ message SwitchCommandRequest {
|
||||
|
||||
fixed32 key = 1;
|
||||
bool state = 2;
|
||||
uint32 device_id = 3;
|
||||
uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== TEXT SENSOR ====================
|
||||
@@ -663,13 +663,13 @@ message ListEntitiesTextSensorResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
string icon = 5;
|
||||
string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
bool disabled_by_default = 6;
|
||||
EntityCategory entity_category = 7;
|
||||
string device_class = 8;
|
||||
uint32 device_id = 9;
|
||||
uint32 device_id = 9 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message TextSensorStateResponse {
|
||||
option (id) = 27;
|
||||
@@ -683,7 +683,7 @@ message TextSensorStateResponse {
|
||||
// If the text sensor does not have a valid state yet.
|
||||
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
|
||||
bool missing_state = 3;
|
||||
uint32 device_id = 4;
|
||||
uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== SUBSCRIBE LOGS ====================
|
||||
@@ -853,11 +853,11 @@ message ListEntitiesCameraResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
bool disabled_by_default = 5;
|
||||
string icon = 6;
|
||||
string icon = 6 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
EntityCategory entity_category = 7;
|
||||
uint32 device_id = 8;
|
||||
uint32 device_id = 8 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
message CameraImageResponse {
|
||||
@@ -869,7 +869,7 @@ message CameraImageResponse {
|
||||
fixed32 key = 1;
|
||||
bytes data = 2;
|
||||
bool done = 3;
|
||||
uint32 device_id = 4;
|
||||
uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message CameraImageRequest {
|
||||
option (id) = 45;
|
||||
@@ -937,7 +937,7 @@ message ListEntitiesClimateResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
bool supports_current_temperature = 5;
|
||||
bool supports_two_point_target_temperature = 6;
|
||||
@@ -955,14 +955,14 @@ message ListEntitiesClimateResponse {
|
||||
repeated ClimatePreset supported_presets = 16;
|
||||
repeated string supported_custom_presets = 17;
|
||||
bool disabled_by_default = 18;
|
||||
string icon = 19;
|
||||
string icon = 19 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
EntityCategory entity_category = 20;
|
||||
float visual_current_temperature_step = 21;
|
||||
bool supports_current_humidity = 22;
|
||||
bool supports_target_humidity = 23;
|
||||
float visual_min_humidity = 24;
|
||||
float visual_max_humidity = 25;
|
||||
uint32 device_id = 26;
|
||||
uint32 device_id = 26 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message ClimateStateResponse {
|
||||
option (id) = 47;
|
||||
@@ -987,7 +987,7 @@ message ClimateStateResponse {
|
||||
string custom_preset = 13;
|
||||
float current_humidity = 14;
|
||||
float target_humidity = 15;
|
||||
uint32 device_id = 16;
|
||||
uint32 device_id = 16 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message ClimateCommandRequest {
|
||||
option (id) = 48;
|
||||
@@ -1020,7 +1020,7 @@ message ClimateCommandRequest {
|
||||
string custom_preset = 21;
|
||||
bool has_target_humidity = 22;
|
||||
float target_humidity = 23;
|
||||
uint32 device_id = 24;
|
||||
uint32 device_id = 24 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== NUMBER ====================
|
||||
@@ -1038,9 +1038,9 @@ message ListEntitiesNumberResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
string icon = 5;
|
||||
string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
float min_value = 6;
|
||||
float max_value = 7;
|
||||
float step = 8;
|
||||
@@ -1049,7 +1049,7 @@ message ListEntitiesNumberResponse {
|
||||
string unit_of_measurement = 11;
|
||||
NumberMode mode = 12;
|
||||
string device_class = 13;
|
||||
uint32 device_id = 14;
|
||||
uint32 device_id = 14 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message NumberStateResponse {
|
||||
option (id) = 50;
|
||||
@@ -1063,7 +1063,7 @@ message NumberStateResponse {
|
||||
// If the number does not have a valid state yet.
|
||||
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
|
||||
bool missing_state = 3;
|
||||
uint32 device_id = 4;
|
||||
uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message NumberCommandRequest {
|
||||
option (id) = 51;
|
||||
@@ -1074,7 +1074,7 @@ message NumberCommandRequest {
|
||||
|
||||
fixed32 key = 1;
|
||||
float state = 2;
|
||||
uint32 device_id = 3;
|
||||
uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== SELECT ====================
|
||||
@@ -1087,13 +1087,13 @@ message ListEntitiesSelectResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
string icon = 5;
|
||||
string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
repeated string options = 6;
|
||||
bool disabled_by_default = 7;
|
||||
EntityCategory entity_category = 8;
|
||||
uint32 device_id = 9;
|
||||
uint32 device_id = 9 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message SelectStateResponse {
|
||||
option (id) = 53;
|
||||
@@ -1107,7 +1107,7 @@ message SelectStateResponse {
|
||||
// If the select does not have a valid state yet.
|
||||
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
|
||||
bool missing_state = 3;
|
||||
uint32 device_id = 4;
|
||||
uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message SelectCommandRequest {
|
||||
option (id) = 54;
|
||||
@@ -1118,7 +1118,7 @@ message SelectCommandRequest {
|
||||
|
||||
fixed32 key = 1;
|
||||
string state = 2;
|
||||
uint32 device_id = 3;
|
||||
uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== SIREN ====================
|
||||
@@ -1131,15 +1131,15 @@ message ListEntitiesSirenResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
string icon = 5;
|
||||
string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
bool disabled_by_default = 6;
|
||||
repeated string tones = 7;
|
||||
bool supports_duration = 8;
|
||||
bool supports_volume = 9;
|
||||
EntityCategory entity_category = 10;
|
||||
uint32 device_id = 11;
|
||||
uint32 device_id = 11 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message SirenStateResponse {
|
||||
option (id) = 56;
|
||||
@@ -1150,7 +1150,7 @@ message SirenStateResponse {
|
||||
|
||||
fixed32 key = 1;
|
||||
bool state = 2;
|
||||
uint32 device_id = 3;
|
||||
uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message SirenCommandRequest {
|
||||
option (id) = 57;
|
||||
@@ -1168,7 +1168,7 @@ message SirenCommandRequest {
|
||||
uint32 duration = 7;
|
||||
bool has_volume = 8;
|
||||
float volume = 9;
|
||||
uint32 device_id = 10;
|
||||
uint32 device_id = 10 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== LOCK ====================
|
||||
@@ -1194,9 +1194,9 @@ message ListEntitiesLockResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
string icon = 5;
|
||||
string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
bool disabled_by_default = 6;
|
||||
EntityCategory entity_category = 7;
|
||||
bool assumed_state = 8;
|
||||
@@ -1206,7 +1206,7 @@ message ListEntitiesLockResponse {
|
||||
|
||||
// Not yet implemented:
|
||||
string code_format = 11;
|
||||
uint32 device_id = 12;
|
||||
uint32 device_id = 12 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message LockStateResponse {
|
||||
option (id) = 59;
|
||||
@@ -1216,7 +1216,7 @@ message LockStateResponse {
|
||||
option (no_delay) = true;
|
||||
fixed32 key = 1;
|
||||
LockState state = 2;
|
||||
uint32 device_id = 3;
|
||||
uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message LockCommandRequest {
|
||||
option (id) = 60;
|
||||
@@ -1230,7 +1230,7 @@ message LockCommandRequest {
|
||||
// Not yet implemented:
|
||||
bool has_code = 3;
|
||||
string code = 4;
|
||||
uint32 device_id = 5;
|
||||
uint32 device_id = 5 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== BUTTON ====================
|
||||
@@ -1243,13 +1243,13 @@ message ListEntitiesButtonResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
string icon = 5;
|
||||
string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
bool disabled_by_default = 6;
|
||||
EntityCategory entity_category = 7;
|
||||
string device_class = 8;
|
||||
uint32 device_id = 9;
|
||||
uint32 device_id = 9 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message ButtonCommandRequest {
|
||||
option (id) = 62;
|
||||
@@ -1259,7 +1259,7 @@ message ButtonCommandRequest {
|
||||
option (base_class) = "CommandProtoMessage";
|
||||
|
||||
fixed32 key = 1;
|
||||
uint32 device_id = 2;
|
||||
uint32 device_id = 2 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== MEDIA PLAYER ====================
|
||||
@@ -1298,9 +1298,9 @@ message ListEntitiesMediaPlayerResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
string icon = 5;
|
||||
string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
bool disabled_by_default = 6;
|
||||
EntityCategory entity_category = 7;
|
||||
|
||||
@@ -1308,7 +1308,7 @@ message ListEntitiesMediaPlayerResponse {
|
||||
|
||||
repeated MediaPlayerSupportedFormat supported_formats = 9;
|
||||
|
||||
uint32 device_id = 10;
|
||||
uint32 device_id = 10 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message MediaPlayerStateResponse {
|
||||
option (id) = 64;
|
||||
@@ -1320,7 +1320,7 @@ message MediaPlayerStateResponse {
|
||||
MediaPlayerState state = 2;
|
||||
float volume = 3;
|
||||
bool muted = 4;
|
||||
uint32 device_id = 5;
|
||||
uint32 device_id = 5 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message MediaPlayerCommandRequest {
|
||||
option (id) = 65;
|
||||
@@ -1342,7 +1342,7 @@ message MediaPlayerCommandRequest {
|
||||
|
||||
bool has_announcement = 8;
|
||||
bool announcement = 9;
|
||||
uint32 device_id = 10;
|
||||
uint32 device_id = 10 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== BLUETOOTH ====================
|
||||
@@ -1845,14 +1845,14 @@ message ListEntitiesAlarmControlPanelResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
string icon = 5;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
bool disabled_by_default = 6;
|
||||
EntityCategory entity_category = 7;
|
||||
uint32 supported_features = 8;
|
||||
bool requires_code = 9;
|
||||
bool requires_code_to_arm = 10;
|
||||
uint32 device_id = 11;
|
||||
uint32 device_id = 11 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
message AlarmControlPanelStateResponse {
|
||||
@@ -1863,7 +1863,7 @@ message AlarmControlPanelStateResponse {
|
||||
option (no_delay) = true;
|
||||
fixed32 key = 1;
|
||||
AlarmControlPanelState state = 2;
|
||||
uint32 device_id = 3;
|
||||
uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
message AlarmControlPanelCommandRequest {
|
||||
@@ -1875,7 +1875,7 @@ message AlarmControlPanelCommandRequest {
|
||||
fixed32 key = 1;
|
||||
AlarmControlPanelStateCommand command = 2;
|
||||
string code = 3;
|
||||
uint32 device_id = 4;
|
||||
uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ===================== TEXT =====================
|
||||
@@ -1892,8 +1892,8 @@ message ListEntitiesTextResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
string icon = 5;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
bool disabled_by_default = 6;
|
||||
EntityCategory entity_category = 7;
|
||||
|
||||
@@ -1901,7 +1901,7 @@ message ListEntitiesTextResponse {
|
||||
uint32 max_length = 9;
|
||||
string pattern = 10;
|
||||
TextMode mode = 11;
|
||||
uint32 device_id = 12;
|
||||
uint32 device_id = 12 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message TextStateResponse {
|
||||
option (id) = 98;
|
||||
@@ -1915,7 +1915,7 @@ message TextStateResponse {
|
||||
// If the Text does not have a valid state yet.
|
||||
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
|
||||
bool missing_state = 3;
|
||||
uint32 device_id = 4;
|
||||
uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message TextCommandRequest {
|
||||
option (id) = 99;
|
||||
@@ -1926,7 +1926,7 @@ message TextCommandRequest {
|
||||
|
||||
fixed32 key = 1;
|
||||
string state = 2;
|
||||
uint32 device_id = 3;
|
||||
uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
|
||||
@@ -1940,12 +1940,12 @@ message ListEntitiesDateResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
string icon = 5;
|
||||
string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
bool disabled_by_default = 6;
|
||||
EntityCategory entity_category = 7;
|
||||
uint32 device_id = 8;
|
||||
uint32 device_id = 8 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message DateStateResponse {
|
||||
option (id) = 101;
|
||||
@@ -1961,7 +1961,7 @@ message DateStateResponse {
|
||||
uint32 year = 3;
|
||||
uint32 month = 4;
|
||||
uint32 day = 5;
|
||||
uint32 device_id = 6;
|
||||
uint32 device_id = 6 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message DateCommandRequest {
|
||||
option (id) = 102;
|
||||
@@ -1974,7 +1974,7 @@ message DateCommandRequest {
|
||||
uint32 year = 2;
|
||||
uint32 month = 3;
|
||||
uint32 day = 4;
|
||||
uint32 device_id = 5;
|
||||
uint32 device_id = 5 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== DATETIME TIME ====================
|
||||
@@ -1987,12 +1987,12 @@ message ListEntitiesTimeResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
string icon = 5;
|
||||
string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
bool disabled_by_default = 6;
|
||||
EntityCategory entity_category = 7;
|
||||
uint32 device_id = 8;
|
||||
uint32 device_id = 8 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message TimeStateResponse {
|
||||
option (id) = 104;
|
||||
@@ -2008,7 +2008,7 @@ message TimeStateResponse {
|
||||
uint32 hour = 3;
|
||||
uint32 minute = 4;
|
||||
uint32 second = 5;
|
||||
uint32 device_id = 6;
|
||||
uint32 device_id = 6 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message TimeCommandRequest {
|
||||
option (id) = 105;
|
||||
@@ -2021,7 +2021,7 @@ message TimeCommandRequest {
|
||||
uint32 hour = 2;
|
||||
uint32 minute = 3;
|
||||
uint32 second = 4;
|
||||
uint32 device_id = 5;
|
||||
uint32 device_id = 5 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== EVENT ====================
|
||||
@@ -2034,15 +2034,15 @@ message ListEntitiesEventResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
string icon = 5;
|
||||
string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
bool disabled_by_default = 6;
|
||||
EntityCategory entity_category = 7;
|
||||
string device_class = 8;
|
||||
|
||||
repeated string event_types = 9;
|
||||
uint32 device_id = 10;
|
||||
uint32 device_id = 10 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message EventResponse {
|
||||
option (id) = 108;
|
||||
@@ -2052,7 +2052,7 @@ message EventResponse {
|
||||
|
||||
fixed32 key = 1;
|
||||
string event_type = 2;
|
||||
uint32 device_id = 3;
|
||||
uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== VALVE ====================
|
||||
@@ -2065,9 +2065,9 @@ message ListEntitiesValveResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
string icon = 5;
|
||||
string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
bool disabled_by_default = 6;
|
||||
EntityCategory entity_category = 7;
|
||||
string device_class = 8;
|
||||
@@ -2075,7 +2075,7 @@ message ListEntitiesValveResponse {
|
||||
bool assumed_state = 9;
|
||||
bool supports_position = 10;
|
||||
bool supports_stop = 11;
|
||||
uint32 device_id = 12;
|
||||
uint32 device_id = 12 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
enum ValveOperation {
|
||||
@@ -2093,7 +2093,7 @@ message ValveStateResponse {
|
||||
fixed32 key = 1;
|
||||
float position = 2;
|
||||
ValveOperation current_operation = 3;
|
||||
uint32 device_id = 4;
|
||||
uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
message ValveCommandRequest {
|
||||
@@ -2107,7 +2107,7 @@ message ValveCommandRequest {
|
||||
bool has_position = 2;
|
||||
float position = 3;
|
||||
bool stop = 4;
|
||||
uint32 device_id = 5;
|
||||
uint32 device_id = 5 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== DATETIME DATETIME ====================
|
||||
@@ -2120,12 +2120,12 @@ message ListEntitiesDateTimeResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
string icon = 5;
|
||||
string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
bool disabled_by_default = 6;
|
||||
EntityCategory entity_category = 7;
|
||||
uint32 device_id = 8;
|
||||
uint32 device_id = 8 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message DateTimeStateResponse {
|
||||
option (id) = 113;
|
||||
@@ -2139,7 +2139,7 @@ message DateTimeStateResponse {
|
||||
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
|
||||
bool missing_state = 2;
|
||||
fixed32 epoch_seconds = 3;
|
||||
uint32 device_id = 4;
|
||||
uint32 device_id = 4 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message DateTimeCommandRequest {
|
||||
option (id) = 114;
|
||||
@@ -2150,7 +2150,7 @@ message DateTimeCommandRequest {
|
||||
|
||||
fixed32 key = 1;
|
||||
fixed32 epoch_seconds = 2;
|
||||
uint32 device_id = 3;
|
||||
uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
||||
// ==================== UPDATE ====================
|
||||
@@ -2163,13 +2163,13 @@ message ListEntitiesUpdateResponse {
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
reserved 4; // Deprecated: was string unique_id
|
||||
|
||||
string icon = 5;
|
||||
string icon = 5 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
bool disabled_by_default = 6;
|
||||
EntityCategory entity_category = 7;
|
||||
string device_class = 8;
|
||||
uint32 device_id = 9;
|
||||
uint32 device_id = 9 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
message UpdateStateResponse {
|
||||
option (id) = 117;
|
||||
@@ -2188,7 +2188,7 @@ message UpdateStateResponse {
|
||||
string title = 8;
|
||||
string release_summary = 9;
|
||||
string release_url = 10;
|
||||
uint32 device_id = 11;
|
||||
uint32 device_id = 11 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
enum UpdateCommand {
|
||||
UPDATE_COMMAND_NONE = 0;
|
||||
@@ -2204,5 +2204,5 @@ message UpdateCommandRequest {
|
||||
|
||||
fixed32 key = 1;
|
||||
UpdateCommand command = 2;
|
||||
uint32 device_id = 3;
|
||||
uint32 device_id = 3 [(field_ifdef) = "USE_DEVICES"];
|
||||
}
|
||||
|
@@ -86,8 +86,8 @@ void APIConnection::start() {
|
||||
APIError err = this->helper_->init();
|
||||
if (err != APIError::OK) {
|
||||
on_fatal_error();
|
||||
ESP_LOGW(TAG, "%s: Helper init failed: %s errno=%d", this->get_client_combined_info().c_str(),
|
||||
api_error_to_str(err), errno);
|
||||
ESP_LOGW(TAG, "%s: Helper init failed %s errno=%d", this->get_client_combined_info().c_str(), api_error_to_str(err),
|
||||
errno);
|
||||
return;
|
||||
}
|
||||
this->client_info_ = helper_->getpeername();
|
||||
@@ -119,7 +119,7 @@ void APIConnection::loop() {
|
||||
APIError err = this->helper_->loop();
|
||||
if (err != APIError::OK) {
|
||||
on_fatal_error();
|
||||
ESP_LOGW(TAG, "%s: Socket operation failed: %s errno=%d", this->get_client_combined_info().c_str(),
|
||||
ESP_LOGW(TAG, "%s: Socket operation failed %s errno=%d", this->get_client_combined_info().c_str(),
|
||||
api_error_to_str(err), errno);
|
||||
return;
|
||||
}
|
||||
@@ -136,14 +136,8 @@ void APIConnection::loop() {
|
||||
break;
|
||||
} else if (err != APIError::OK) {
|
||||
on_fatal_error();
|
||||
if (err == APIError::SOCKET_READ_FAILED && errno == ECONNRESET) {
|
||||
ESP_LOGW(TAG, "%s: Connection reset", this->get_client_combined_info().c_str());
|
||||
} else if (err == APIError::CONNECTION_CLOSED) {
|
||||
ESP_LOGW(TAG, "%s: Connection closed", this->get_client_combined_info().c_str());
|
||||
} else {
|
||||
ESP_LOGW(TAG, "%s: Reading failed: %s errno=%d", this->get_client_combined_info().c_str(),
|
||||
api_error_to_str(err), errno);
|
||||
}
|
||||
ESP_LOGW(TAG, "%s: Reading failed %s errno=%d", this->get_client_combined_info().c_str(), api_error_to_str(err),
|
||||
errno);
|
||||
return;
|
||||
} else {
|
||||
this->last_traffic_ = now;
|
||||
@@ -186,7 +180,8 @@ void APIConnection::loop() {
|
||||
on_fatal_error();
|
||||
ESP_LOGW(TAG, "%s is unresponsive; disconnecting", this->get_client_combined_info().c_str());
|
||||
}
|
||||
} else if (now - this->last_traffic_ > KEEPALIVE_TIMEOUT_MS) {
|
||||
} else if (now - this->last_traffic_ > KEEPALIVE_TIMEOUT_MS && !this->flags_.remove) {
|
||||
// Only send ping if we're not disconnecting
|
||||
ESP_LOGVV(TAG, "Sending keepalive PING");
|
||||
this->flags_.sent_ping = this->send_message(PingRequest());
|
||||
if (!this->flags_.sent_ping) {
|
||||
@@ -246,10 +241,6 @@ void APIConnection::loop() {
|
||||
}
|
||||
}
|
||||
|
||||
std::string get_default_unique_id(const std::string &component_type, EntityBase *entity) {
|
||||
return App.get_name() + component_type + entity->get_object_id();
|
||||
}
|
||||
|
||||
DisconnectResponse APIConnection::disconnect(const DisconnectRequest &msg) {
|
||||
// remote initiated disconnect_client
|
||||
// don't close yet, we still need to send the disconnect response
|
||||
@@ -326,8 +317,8 @@ uint16_t APIConnection::try_send_binary_sensor_state(EntityBase *entity, APIConn
|
||||
BinarySensorStateResponse resp;
|
||||
resp.state = binary_sensor->state;
|
||||
resp.missing_state = !binary_sensor->has_state();
|
||||
fill_entity_state_base(binary_sensor, resp);
|
||||
return encode_message_to_buffer(resp, BinarySensorStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(binary_sensor, resp, BinarySensorStateResponse::MESSAGE_TYPE, conn,
|
||||
remaining_size, is_single);
|
||||
}
|
||||
|
||||
uint16_t APIConnection::try_send_binary_sensor_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
@@ -336,9 +327,8 @@ uint16_t APIConnection::try_send_binary_sensor_info(EntityBase *entity, APIConne
|
||||
ListEntitiesBinarySensorResponse msg;
|
||||
msg.device_class = binary_sensor->get_device_class();
|
||||
msg.is_status_binary_sensor = binary_sensor->is_status_binary_sensor();
|
||||
msg.unique_id = get_default_unique_id("binary_sensor", binary_sensor);
|
||||
fill_entity_info_base(binary_sensor, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesBinarySensorResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(binary_sensor, msg, ListEntitiesBinarySensorResponse::MESSAGE_TYPE, conn,
|
||||
remaining_size, is_single);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -358,8 +348,7 @@ uint16_t APIConnection::try_send_cover_state(EntityBase *entity, APIConnection *
|
||||
if (traits.get_supports_tilt())
|
||||
msg.tilt = cover->tilt;
|
||||
msg.current_operation = static_cast<enums::CoverOperation>(cover->current_operation);
|
||||
fill_entity_state_base(cover, msg);
|
||||
return encode_message_to_buffer(msg, CoverStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(cover, msg, CoverStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
uint16_t APIConnection::try_send_cover_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
bool is_single) {
|
||||
@@ -371,9 +360,8 @@ uint16_t APIConnection::try_send_cover_info(EntityBase *entity, APIConnection *c
|
||||
msg.supports_tilt = traits.get_supports_tilt();
|
||||
msg.supports_stop = traits.get_supports_stop();
|
||||
msg.device_class = cover->get_device_class();
|
||||
msg.unique_id = get_default_unique_id("cover", cover);
|
||||
fill_entity_info_base(cover, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesCoverResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(cover, msg, ListEntitiesCoverResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
void APIConnection::cover_command(const CoverCommandRequest &msg) {
|
||||
ENTITY_COMMAND_MAKE_CALL(cover::Cover, cover, cover)
|
||||
@@ -420,8 +408,7 @@ uint16_t APIConnection::try_send_fan_state(EntityBase *entity, APIConnection *co
|
||||
msg.direction = static_cast<enums::FanDirection>(fan->direction);
|
||||
if (traits.supports_preset_modes())
|
||||
msg.preset_mode = fan->preset_mode;
|
||||
fill_entity_state_base(fan, msg);
|
||||
return encode_message_to_buffer(msg, FanStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(fan, msg, FanStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
uint16_t APIConnection::try_send_fan_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
bool is_single) {
|
||||
@@ -434,9 +421,7 @@ uint16_t APIConnection::try_send_fan_info(EntityBase *entity, APIConnection *con
|
||||
msg.supported_speed_count = traits.supported_speed_count();
|
||||
for (auto const &preset : traits.supported_preset_modes())
|
||||
msg.supported_preset_modes.push_back(preset);
|
||||
msg.unique_id = get_default_unique_id("fan", fan);
|
||||
fill_entity_info_base(fan, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesFanResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(fan, msg, ListEntitiesFanResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
void APIConnection::fan_command(const FanCommandRequest &msg) {
|
||||
ENTITY_COMMAND_MAKE_CALL(fan::Fan, fan, fan)
|
||||
@@ -481,8 +466,7 @@ uint16_t APIConnection::try_send_light_state(EntityBase *entity, APIConnection *
|
||||
resp.warm_white = values.get_warm_white();
|
||||
if (light->supports_effects())
|
||||
resp.effect = light->get_effect_name();
|
||||
fill_entity_state_base(light, resp);
|
||||
return encode_message_to_buffer(resp, LightStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(light, resp, LightStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
uint16_t APIConnection::try_send_light_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
bool is_single) {
|
||||
@@ -508,9 +492,8 @@ uint16_t APIConnection::try_send_light_info(EntityBase *entity, APIConnection *c
|
||||
msg.effects.push_back(effect->get_name());
|
||||
}
|
||||
}
|
||||
msg.unique_id = get_default_unique_id("light", light);
|
||||
fill_entity_info_base(light, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesLightResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(light, msg, ListEntitiesLightResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
void APIConnection::light_command(const LightCommandRequest &msg) {
|
||||
ENTITY_COMMAND_MAKE_CALL(light::LightState, light, light)
|
||||
@@ -557,8 +540,7 @@ uint16_t APIConnection::try_send_sensor_state(EntityBase *entity, APIConnection
|
||||
SensorStateResponse resp;
|
||||
resp.state = sensor->state;
|
||||
resp.missing_state = !sensor->has_state();
|
||||
fill_entity_state_base(sensor, resp);
|
||||
return encode_message_to_buffer(resp, SensorStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(sensor, resp, SensorStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
|
||||
uint16_t APIConnection::try_send_sensor_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
@@ -570,11 +552,8 @@ uint16_t APIConnection::try_send_sensor_info(EntityBase *entity, APIConnection *
|
||||
msg.force_update = sensor->get_force_update();
|
||||
msg.device_class = sensor->get_device_class();
|
||||
msg.state_class = static_cast<enums::SensorStateClass>(sensor->get_state_class());
|
||||
msg.unique_id = sensor->unique_id();
|
||||
if (msg.unique_id.empty())
|
||||
msg.unique_id = get_default_unique_id("sensor", sensor);
|
||||
fill_entity_info_base(sensor, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesSensorResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(sensor, msg, ListEntitiesSensorResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -589,8 +568,8 @@ uint16_t APIConnection::try_send_switch_state(EntityBase *entity, APIConnection
|
||||
auto *a_switch = static_cast<switch_::Switch *>(entity);
|
||||
SwitchStateResponse resp;
|
||||
resp.state = a_switch->state;
|
||||
fill_entity_state_base(a_switch, resp);
|
||||
return encode_message_to_buffer(resp, SwitchStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(a_switch, resp, SwitchStateResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
|
||||
uint16_t APIConnection::try_send_switch_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
@@ -599,9 +578,8 @@ uint16_t APIConnection::try_send_switch_info(EntityBase *entity, APIConnection *
|
||||
ListEntitiesSwitchResponse msg;
|
||||
msg.assumed_state = a_switch->assumed_state();
|
||||
msg.device_class = a_switch->get_device_class();
|
||||
msg.unique_id = get_default_unique_id("switch", a_switch);
|
||||
fill_entity_info_base(a_switch, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesSwitchResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(a_switch, msg, ListEntitiesSwitchResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
void APIConnection::switch_command(const SwitchCommandRequest &msg) {
|
||||
ENTITY_COMMAND_GET(switch_::Switch, a_switch, switch)
|
||||
@@ -626,19 +604,16 @@ uint16_t APIConnection::try_send_text_sensor_state(EntityBase *entity, APIConnec
|
||||
TextSensorStateResponse resp;
|
||||
resp.state = text_sensor->state;
|
||||
resp.missing_state = !text_sensor->has_state();
|
||||
fill_entity_state_base(text_sensor, resp);
|
||||
return encode_message_to_buffer(resp, TextSensorStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(text_sensor, resp, TextSensorStateResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
uint16_t APIConnection::try_send_text_sensor_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
bool is_single) {
|
||||
auto *text_sensor = static_cast<text_sensor::TextSensor *>(entity);
|
||||
ListEntitiesTextSensorResponse msg;
|
||||
msg.device_class = text_sensor->get_device_class();
|
||||
msg.unique_id = text_sensor->unique_id();
|
||||
if (msg.unique_id.empty())
|
||||
msg.unique_id = get_default_unique_id("text_sensor", text_sensor);
|
||||
fill_entity_info_base(text_sensor, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesTextSensorResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(text_sensor, msg, ListEntitiesTextSensorResponse::MESSAGE_TYPE, conn,
|
||||
remaining_size, is_single);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -651,7 +626,6 @@ uint16_t APIConnection::try_send_climate_state(EntityBase *entity, APIConnection
|
||||
bool is_single) {
|
||||
auto *climate = static_cast<climate::Climate *>(entity);
|
||||
ClimateStateResponse resp;
|
||||
fill_entity_state_base(climate, resp);
|
||||
auto traits = climate->get_traits();
|
||||
resp.mode = static_cast<enums::ClimateMode>(climate->mode);
|
||||
resp.action = static_cast<enums::ClimateAction>(climate->action);
|
||||
@@ -678,7 +652,8 @@ uint16_t APIConnection::try_send_climate_state(EntityBase *entity, APIConnection
|
||||
resp.current_humidity = climate->current_humidity;
|
||||
if (traits.get_supports_target_humidity())
|
||||
resp.target_humidity = climate->target_humidity;
|
||||
return encode_message_to_buffer(resp, ClimateStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(climate, resp, ClimateStateResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
uint16_t APIConnection::try_send_climate_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
bool is_single) {
|
||||
@@ -709,9 +684,8 @@ uint16_t APIConnection::try_send_climate_info(EntityBase *entity, APIConnection
|
||||
msg.supported_custom_presets.push_back(custom_preset);
|
||||
for (auto swing_mode : traits.get_supported_swing_modes())
|
||||
msg.supported_swing_modes.push_back(static_cast<enums::ClimateSwingMode>(swing_mode));
|
||||
msg.unique_id = get_default_unique_id("climate", climate);
|
||||
fill_entity_info_base(climate, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesClimateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(climate, msg, ListEntitiesClimateResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
void APIConnection::climate_command(const ClimateCommandRequest &msg) {
|
||||
ENTITY_COMMAND_MAKE_CALL(climate::Climate, climate, climate)
|
||||
@@ -751,8 +725,7 @@ uint16_t APIConnection::try_send_number_state(EntityBase *entity, APIConnection
|
||||
NumberStateResponse resp;
|
||||
resp.state = number->state;
|
||||
resp.missing_state = !number->has_state();
|
||||
fill_entity_state_base(number, resp);
|
||||
return encode_message_to_buffer(resp, NumberStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(number, resp, NumberStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
|
||||
uint16_t APIConnection::try_send_number_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
@@ -765,9 +738,8 @@ uint16_t APIConnection::try_send_number_info(EntityBase *entity, APIConnection *
|
||||
msg.min_value = number->traits.get_min_value();
|
||||
msg.max_value = number->traits.get_max_value();
|
||||
msg.step = number->traits.get_step();
|
||||
msg.unique_id = get_default_unique_id("number", number);
|
||||
fill_entity_info_base(number, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesNumberResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(number, msg, ListEntitiesNumberResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
void APIConnection::number_command(const NumberCommandRequest &msg) {
|
||||
ENTITY_COMMAND_MAKE_CALL(number::Number, number, number)
|
||||
@@ -789,16 +761,14 @@ uint16_t APIConnection::try_send_date_state(EntityBase *entity, APIConnection *c
|
||||
resp.year = date->year;
|
||||
resp.month = date->month;
|
||||
resp.day = date->day;
|
||||
fill_entity_state_base(date, resp);
|
||||
return encode_message_to_buffer(resp, DateStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(date, resp, DateStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
uint16_t APIConnection::try_send_date_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
bool is_single) {
|
||||
auto *date = static_cast<datetime::DateEntity *>(entity);
|
||||
ListEntitiesDateResponse msg;
|
||||
msg.unique_id = get_default_unique_id("date", date);
|
||||
fill_entity_info_base(date, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesDateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(date, msg, ListEntitiesDateResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
void APIConnection::date_command(const DateCommandRequest &msg) {
|
||||
ENTITY_COMMAND_MAKE_CALL(datetime::DateEntity, date, date)
|
||||
@@ -820,16 +790,14 @@ uint16_t APIConnection::try_send_time_state(EntityBase *entity, APIConnection *c
|
||||
resp.hour = time->hour;
|
||||
resp.minute = time->minute;
|
||||
resp.second = time->second;
|
||||
fill_entity_state_base(time, resp);
|
||||
return encode_message_to_buffer(resp, TimeStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(time, resp, TimeStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
uint16_t APIConnection::try_send_time_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
bool is_single) {
|
||||
auto *time = static_cast<datetime::TimeEntity *>(entity);
|
||||
ListEntitiesTimeResponse msg;
|
||||
msg.unique_id = get_default_unique_id("time", time);
|
||||
fill_entity_info_base(time, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesTimeResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(time, msg, ListEntitiesTimeResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
void APIConnection::time_command(const TimeCommandRequest &msg) {
|
||||
ENTITY_COMMAND_MAKE_CALL(datetime::TimeEntity, time, time)
|
||||
@@ -852,16 +820,15 @@ uint16_t APIConnection::try_send_datetime_state(EntityBase *entity, APIConnectio
|
||||
ESPTime state = datetime->state_as_esptime();
|
||||
resp.epoch_seconds = state.timestamp;
|
||||
}
|
||||
fill_entity_state_base(datetime, resp);
|
||||
return encode_message_to_buffer(resp, DateTimeStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(datetime, resp, DateTimeStateResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
uint16_t APIConnection::try_send_datetime_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
bool is_single) {
|
||||
auto *datetime = static_cast<datetime::DateTimeEntity *>(entity);
|
||||
ListEntitiesDateTimeResponse msg;
|
||||
msg.unique_id = get_default_unique_id("datetime", datetime);
|
||||
fill_entity_info_base(datetime, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesDateTimeResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(datetime, msg, ListEntitiesDateTimeResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
void APIConnection::datetime_command(const DateTimeCommandRequest &msg) {
|
||||
ENTITY_COMMAND_MAKE_CALL(datetime::DateTimeEntity, datetime, datetime)
|
||||
@@ -882,8 +849,7 @@ uint16_t APIConnection::try_send_text_state(EntityBase *entity, APIConnection *c
|
||||
TextStateResponse resp;
|
||||
resp.state = text->state;
|
||||
resp.missing_state = !text->has_state();
|
||||
fill_entity_state_base(text, resp);
|
||||
return encode_message_to_buffer(resp, TextStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(text, resp, TextStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
|
||||
uint16_t APIConnection::try_send_text_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
@@ -894,9 +860,8 @@ uint16_t APIConnection::try_send_text_info(EntityBase *entity, APIConnection *co
|
||||
msg.min_length = text->traits.get_min_length();
|
||||
msg.max_length = text->traits.get_max_length();
|
||||
msg.pattern = text->traits.get_pattern();
|
||||
msg.unique_id = get_default_unique_id("text", text);
|
||||
fill_entity_info_base(text, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesTextResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(text, msg, ListEntitiesTextResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
void APIConnection::text_command(const TextCommandRequest &msg) {
|
||||
ENTITY_COMMAND_MAKE_CALL(text::Text, text, text)
|
||||
@@ -917,8 +882,7 @@ uint16_t APIConnection::try_send_select_state(EntityBase *entity, APIConnection
|
||||
SelectStateResponse resp;
|
||||
resp.state = select->state;
|
||||
resp.missing_state = !select->has_state();
|
||||
fill_entity_state_base(select, resp);
|
||||
return encode_message_to_buffer(resp, SelectStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(select, resp, SelectStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
|
||||
uint16_t APIConnection::try_send_select_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
@@ -927,9 +891,8 @@ uint16_t APIConnection::try_send_select_info(EntityBase *entity, APIConnection *
|
||||
ListEntitiesSelectResponse msg;
|
||||
for (const auto &option : select->traits.get_options())
|
||||
msg.options.push_back(option);
|
||||
msg.unique_id = get_default_unique_id("select", select);
|
||||
fill_entity_info_base(select, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesSelectResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(select, msg, ListEntitiesSelectResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
void APIConnection::select_command(const SelectCommandRequest &msg) {
|
||||
ENTITY_COMMAND_MAKE_CALL(select::Select, select, select)
|
||||
@@ -944,9 +907,8 @@ uint16_t APIConnection::try_send_button_info(EntityBase *entity, APIConnection *
|
||||
auto *button = static_cast<button::Button *>(entity);
|
||||
ListEntitiesButtonResponse msg;
|
||||
msg.device_class = button->get_device_class();
|
||||
msg.unique_id = get_default_unique_id("button", button);
|
||||
fill_entity_info_base(button, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesButtonResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(button, msg, ListEntitiesButtonResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
void esphome::api::APIConnection::button_command(const ButtonCommandRequest &msg) {
|
||||
ENTITY_COMMAND_GET(button::Button, button, button)
|
||||
@@ -965,8 +927,7 @@ uint16_t APIConnection::try_send_lock_state(EntityBase *entity, APIConnection *c
|
||||
auto *a_lock = static_cast<lock::Lock *>(entity);
|
||||
LockStateResponse resp;
|
||||
resp.state = static_cast<enums::LockState>(a_lock->state);
|
||||
fill_entity_state_base(a_lock, resp);
|
||||
return encode_message_to_buffer(resp, LockStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(a_lock, resp, LockStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
|
||||
uint16_t APIConnection::try_send_lock_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
@@ -976,9 +937,8 @@ uint16_t APIConnection::try_send_lock_info(EntityBase *entity, APIConnection *co
|
||||
msg.assumed_state = a_lock->traits.get_assumed_state();
|
||||
msg.supports_open = a_lock->traits.get_supports_open();
|
||||
msg.requires_code = a_lock->traits.get_requires_code();
|
||||
msg.unique_id = get_default_unique_id("lock", a_lock);
|
||||
fill_entity_info_base(a_lock, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesLockResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(a_lock, msg, ListEntitiesLockResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
void APIConnection::lock_command(const LockCommandRequest &msg) {
|
||||
ENTITY_COMMAND_GET(lock::Lock, a_lock, lock)
|
||||
@@ -1008,8 +968,7 @@ uint16_t APIConnection::try_send_valve_state(EntityBase *entity, APIConnection *
|
||||
ValveStateResponse resp;
|
||||
resp.position = valve->position;
|
||||
resp.current_operation = static_cast<enums::ValveOperation>(valve->current_operation);
|
||||
fill_entity_state_base(valve, resp);
|
||||
return encode_message_to_buffer(resp, ValveStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(valve, resp, ValveStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
uint16_t APIConnection::try_send_valve_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
bool is_single) {
|
||||
@@ -1020,9 +979,8 @@ uint16_t APIConnection::try_send_valve_info(EntityBase *entity, APIConnection *c
|
||||
msg.assumed_state = traits.get_is_assumed_state();
|
||||
msg.supports_position = traits.get_supports_position();
|
||||
msg.supports_stop = traits.get_supports_stop();
|
||||
msg.unique_id = get_default_unique_id("valve", valve);
|
||||
fill_entity_info_base(valve, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesValveResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(valve, msg, ListEntitiesValveResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
void APIConnection::valve_command(const ValveCommandRequest &msg) {
|
||||
ENTITY_COMMAND_MAKE_CALL(valve::Valve, valve, valve)
|
||||
@@ -1049,8 +1007,8 @@ uint16_t APIConnection::try_send_media_player_state(EntityBase *entity, APIConne
|
||||
resp.state = static_cast<enums::MediaPlayerState>(report_state);
|
||||
resp.volume = media_player->volume;
|
||||
resp.muted = media_player->is_muted();
|
||||
fill_entity_state_base(media_player, resp);
|
||||
return encode_message_to_buffer(resp, MediaPlayerStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(media_player, resp, MediaPlayerStateResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
uint16_t APIConnection::try_send_media_player_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
bool is_single) {
|
||||
@@ -1067,9 +1025,8 @@ uint16_t APIConnection::try_send_media_player_info(EntityBase *entity, APIConnec
|
||||
media_format.sample_bytes = supported_format.sample_bytes;
|
||||
msg.supported_formats.push_back(media_format);
|
||||
}
|
||||
msg.unique_id = get_default_unique_id("media_player", media_player);
|
||||
fill_entity_info_base(media_player, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesMediaPlayerResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(media_player, msg, ListEntitiesMediaPlayerResponse::MESSAGE_TYPE, conn,
|
||||
remaining_size, is_single);
|
||||
}
|
||||
void APIConnection::media_player_command(const MediaPlayerCommandRequest &msg) {
|
||||
ENTITY_COMMAND_MAKE_CALL(media_player::MediaPlayer, media_player, media_player)
|
||||
@@ -1104,9 +1061,8 @@ uint16_t APIConnection::try_send_camera_info(EntityBase *entity, APIConnection *
|
||||
bool is_single) {
|
||||
auto *camera = static_cast<camera::Camera *>(entity);
|
||||
ListEntitiesCameraResponse msg;
|
||||
msg.unique_id = get_default_unique_id("camera", camera);
|
||||
fill_entity_info_base(camera, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesCameraResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(camera, msg, ListEntitiesCameraResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
void APIConnection::camera_image(const CameraImageRequest &msg) {
|
||||
if (camera::Camera::instance() == nullptr)
|
||||
@@ -1284,8 +1240,8 @@ uint16_t APIConnection::try_send_alarm_control_panel_state(EntityBase *entity, A
|
||||
auto *a_alarm_control_panel = static_cast<alarm_control_panel::AlarmControlPanel *>(entity);
|
||||
AlarmControlPanelStateResponse resp;
|
||||
resp.state = static_cast<enums::AlarmControlPanelState>(a_alarm_control_panel->get_state());
|
||||
fill_entity_state_base(a_alarm_control_panel, resp);
|
||||
return encode_message_to_buffer(resp, AlarmControlPanelStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(a_alarm_control_panel, resp, AlarmControlPanelStateResponse::MESSAGE_TYPE, conn,
|
||||
remaining_size, is_single);
|
||||
}
|
||||
uint16_t APIConnection::try_send_alarm_control_panel_info(EntityBase *entity, APIConnection *conn,
|
||||
uint32_t remaining_size, bool is_single) {
|
||||
@@ -1294,10 +1250,8 @@ uint16_t APIConnection::try_send_alarm_control_panel_info(EntityBase *entity, AP
|
||||
msg.supported_features = a_alarm_control_panel->get_supported_features();
|
||||
msg.requires_code = a_alarm_control_panel->get_requires_code();
|
||||
msg.requires_code_to_arm = a_alarm_control_panel->get_requires_code_to_arm();
|
||||
msg.unique_id = get_default_unique_id("alarm_control_panel", a_alarm_control_panel);
|
||||
fill_entity_info_base(a_alarm_control_panel, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesAlarmControlPanelResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
return fill_and_encode_entity_info(a_alarm_control_panel, msg, ListEntitiesAlarmControlPanelResponse::MESSAGE_TYPE,
|
||||
conn, remaining_size, is_single);
|
||||
}
|
||||
void APIConnection::alarm_control_panel_command(const AlarmControlPanelCommandRequest &msg) {
|
||||
ENTITY_COMMAND_MAKE_CALL(alarm_control_panel::AlarmControlPanel, a_alarm_control_panel, alarm_control_panel)
|
||||
@@ -1338,8 +1292,7 @@ uint16_t APIConnection::try_send_event_response(event::Event *event, const std::
|
||||
uint32_t remaining_size, bool is_single) {
|
||||
EventResponse resp;
|
||||
resp.event_type = event_type;
|
||||
fill_entity_state_base(event, resp);
|
||||
return encode_message_to_buffer(resp, EventResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(event, resp, EventResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
|
||||
uint16_t APIConnection::try_send_event_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
@@ -1349,9 +1302,8 @@ uint16_t APIConnection::try_send_event_info(EntityBase *entity, APIConnection *c
|
||||
msg.device_class = event->get_device_class();
|
||||
for (const auto &event_type : event->get_event_types())
|
||||
msg.event_types.push_back(event_type);
|
||||
msg.unique_id = get_default_unique_id("event", event);
|
||||
fill_entity_info_base(event, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesEventResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(event, msg, ListEntitiesEventResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1377,17 +1329,15 @@ uint16_t APIConnection::try_send_update_state(EntityBase *entity, APIConnection
|
||||
resp.release_summary = update->update_info.summary;
|
||||
resp.release_url = update->update_info.release_url;
|
||||
}
|
||||
fill_entity_state_base(update, resp);
|
||||
return encode_message_to_buffer(resp, UpdateStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_state(update, resp, UpdateStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
uint16_t APIConnection::try_send_update_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
bool is_single) {
|
||||
auto *update = static_cast<update::UpdateEntity *>(entity);
|
||||
ListEntitiesUpdateResponse msg;
|
||||
msg.device_class = update->get_device_class();
|
||||
msg.unique_id = get_default_unique_id("update", update);
|
||||
fill_entity_info_base(update, msg);
|
||||
return encode_message_to_buffer(msg, ListEntitiesUpdateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
return fill_and_encode_entity_info(update, msg, ListEntitiesUpdateResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
void APIConnection::update_command(const UpdateCommandRequest &msg) {
|
||||
ENTITY_COMMAND_GET(update::UpdateEntity, update, update)
|
||||
@@ -1410,9 +1360,6 @@ void APIConnection::update_command(const UpdateCommandRequest &msg) {
|
||||
#endif
|
||||
|
||||
bool APIConnection::try_send_log_message(int level, const char *tag, const char *line, size_t message_len) {
|
||||
if (this->flags_.log_subscription < level)
|
||||
return false;
|
||||
|
||||
// Pre-calculate message size to avoid reallocations
|
||||
uint32_t msg_size = 0;
|
||||
|
||||
@@ -1435,6 +1382,24 @@ bool APIConnection::try_send_log_message(int level, const char *tag, const char
|
||||
return this->send_buffer(buffer, SubscribeLogsResponse::MESSAGE_TYPE);
|
||||
}
|
||||
|
||||
void APIConnection::complete_authentication_() {
|
||||
// Early return if already authenticated
|
||||
if (this->flags_.connection_state == static_cast<uint8_t>(ConnectionState::AUTHENTICATED)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->flags_.connection_state = static_cast<uint8_t>(ConnectionState::AUTHENTICATED);
|
||||
ESP_LOGD(TAG, "%s connected", this->get_client_combined_info().c_str());
|
||||
#ifdef USE_API_CLIENT_CONNECTED_TRIGGER
|
||||
this->parent_->get_client_connected_trigger()->trigger(this->client_info_, this->client_peername_);
|
||||
#endif
|
||||
#ifdef USE_HOMEASSISTANT_TIME
|
||||
if (homeassistant::global_homeassistant_time != nullptr) {
|
||||
this->send_time_request();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
HelloResponse APIConnection::hello(const HelloRequest &msg) {
|
||||
this->client_info_ = msg.client_info;
|
||||
this->client_peername_ = this->helper_->getpeername();
|
||||
@@ -1450,7 +1415,14 @@ HelloResponse APIConnection::hello(const HelloRequest &msg) {
|
||||
resp.server_info = App.get_name() + " (esphome v" ESPHOME_VERSION ")";
|
||||
resp.name = App.get_name();
|
||||
|
||||
#ifdef USE_API_PASSWORD
|
||||
// Password required - wait for authentication
|
||||
this->flags_.connection_state = static_cast<uint8_t>(ConnectionState::CONNECTED);
|
||||
#else
|
||||
// No password configured - auto-authenticate
|
||||
this->complete_authentication_();
|
||||
#endif
|
||||
|
||||
return resp;
|
||||
}
|
||||
ConnectResponse APIConnection::connect(const ConnectRequest &msg) {
|
||||
@@ -1463,29 +1435,22 @@ ConnectResponse APIConnection::connect(const ConnectRequest &msg) {
|
||||
// bool invalid_password = 1;
|
||||
resp.invalid_password = !correct;
|
||||
if (correct) {
|
||||
ESP_LOGD(TAG, "%s connected", this->get_client_combined_info().c_str());
|
||||
this->flags_.connection_state = static_cast<uint8_t>(ConnectionState::AUTHENTICATED);
|
||||
#ifdef USE_API_CLIENT_CONNECTED_TRIGGER
|
||||
this->parent_->get_client_connected_trigger()->trigger(this->client_info_, this->client_peername_);
|
||||
#endif
|
||||
#ifdef USE_HOMEASSISTANT_TIME
|
||||
if (homeassistant::global_homeassistant_time != nullptr) {
|
||||
this->send_time_request();
|
||||
}
|
||||
#endif
|
||||
this->complete_authentication_();
|
||||
}
|
||||
return resp;
|
||||
}
|
||||
DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) {
|
||||
DeviceInfoResponse resp{};
|
||||
#ifdef USE_API_PASSWORD
|
||||
resp.uses_password = this->parent_->uses_password();
|
||||
resp.uses_password = true;
|
||||
#else
|
||||
resp.uses_password = false;
|
||||
#endif
|
||||
resp.name = App.get_name();
|
||||
resp.friendly_name = App.get_friendly_name();
|
||||
#ifdef USE_AREAS
|
||||
resp.suggested_area = App.get_area();
|
||||
#endif
|
||||
resp.mac_address = get_mac_address_pretty();
|
||||
resp.esphome_version = ESPHOME_VERSION;
|
||||
resp.compilation_time = App.get_compilation_time();
|
||||
@@ -1596,7 +1561,7 @@ bool APIConnection::try_to_clear_buffer(bool log_out_of_space) {
|
||||
APIError err = this->helper_->loop();
|
||||
if (err != APIError::OK) {
|
||||
on_fatal_error();
|
||||
ESP_LOGW(TAG, "%s: Socket operation failed: %s errno=%d", this->get_client_combined_info().c_str(),
|
||||
ESP_LOGW(TAG, "%s: Socket operation failed %s errno=%d", this->get_client_combined_info().c_str(),
|
||||
api_error_to_str(err), errno);
|
||||
return false;
|
||||
}
|
||||
@@ -1617,12 +1582,8 @@ bool APIConnection::send_buffer(ProtoWriteBuffer buffer, uint8_t message_type) {
|
||||
return false;
|
||||
if (err != APIError::OK) {
|
||||
on_fatal_error();
|
||||
if (err == APIError::SOCKET_WRITE_FAILED && errno == ECONNRESET) {
|
||||
ESP_LOGW(TAG, "%s: Connection reset", this->get_client_combined_info().c_str());
|
||||
} else {
|
||||
ESP_LOGW(TAG, "%s: Packet write failed %s errno=%d", this->get_client_combined_info().c_str(),
|
||||
api_error_to_str(err), errno);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// Do not set last_traffic_ on send
|
||||
@@ -1630,11 +1591,11 @@ bool APIConnection::send_buffer(ProtoWriteBuffer buffer, uint8_t message_type) {
|
||||
}
|
||||
void APIConnection::on_unauthenticated_access() {
|
||||
this->on_fatal_error();
|
||||
ESP_LOGD(TAG, "%s requested access without authentication", this->get_client_combined_info().c_str());
|
||||
ESP_LOGD(TAG, "%s access without authentication", this->get_client_combined_info().c_str());
|
||||
}
|
||||
void APIConnection::on_no_setup_connection() {
|
||||
this->on_fatal_error();
|
||||
ESP_LOGD(TAG, "%s requested access without full connection", this->get_client_combined_info().c_str());
|
||||
ESP_LOGD(TAG, "%s access without full connection", this->get_client_combined_info().c_str());
|
||||
}
|
||||
void APIConnection::on_fatal_error() {
|
||||
this->helper_->close();
|
||||
@@ -1662,8 +1623,15 @@ void APIConnection::DeferredBatch::add_item(EntityBase *entity, MessageCreator c
|
||||
|
||||
void APIConnection::DeferredBatch::add_item_front(EntityBase *entity, MessageCreator creator, uint8_t message_type,
|
||||
uint8_t estimated_size) {
|
||||
// Insert at front for high priority messages (no deduplication check)
|
||||
items.insert(items.begin(), BatchItem(entity, std::move(creator), message_type, estimated_size));
|
||||
// Add high priority message and swap to front
|
||||
// This avoids expensive vector::insert which shifts all elements
|
||||
// Note: We only ever have one high-priority message at a time (ping OR disconnect)
|
||||
// If we're disconnecting, pings are blocked, so this simple swap is sufficient
|
||||
items.emplace_back(entity, std::move(creator), message_type, estimated_size);
|
||||
if (items.size() > 1) {
|
||||
// Swap the new high-priority item to the front
|
||||
std::swap(items.front(), items.back());
|
||||
}
|
||||
}
|
||||
|
||||
bool APIConnection::schedule_batch_() {
|
||||
@@ -1799,12 +1767,8 @@ void APIConnection::process_batch_() {
|
||||
this->helper_->write_protobuf_packets(ProtoWriteBuffer{&this->parent_->get_shared_buffer_ref()}, packet_info);
|
||||
if (err != APIError::OK && err != APIError::WOULD_BLOCK) {
|
||||
on_fatal_error();
|
||||
if (err == APIError::SOCKET_WRITE_FAILED && errno == ECONNRESET) {
|
||||
ESP_LOGW(TAG, "%s: Connection reset during batch write", this->get_client_combined_info().c_str());
|
||||
} else {
|
||||
ESP_LOGW(TAG, "%s: Batch write failed %s errno=%d", this->get_client_combined_info().c_str(),
|
||||
api_error_to_str(err), errno);
|
||||
}
|
||||
ESP_LOGW(TAG, "%s: Batch write failed %s errno=%d", this->get_client_combined_info().c_str(), api_error_to_str(err),
|
||||
errno);
|
||||
}
|
||||
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
|
@@ -209,6 +209,7 @@ class APIConnection : public APIServerConnection {
|
||||
return static_cast<ConnectionState>(this->flags_.connection_state) == ConnectionState::CONNECTED ||
|
||||
this->is_authenticated();
|
||||
}
|
||||
uint8_t get_log_subscription_level() const { return this->flags_.log_subscription; }
|
||||
void on_fatal_error() override;
|
||||
void on_unauthenticated_access() override;
|
||||
void on_no_setup_connection() override;
|
||||
@@ -273,36 +274,45 @@ class APIConnection : public APIServerConnection {
|
||||
ProtoWriteBuffer allocate_batch_message_buffer(uint16_t size);
|
||||
|
||||
protected:
|
||||
// Helper function to fill common entity info fields
|
||||
static void fill_entity_info_base(esphome::EntityBase *entity, InfoResponseProtoMessage &response) {
|
||||
// Set common fields that are shared by all entity types
|
||||
response.key = entity->get_object_id_hash();
|
||||
response.object_id = entity->get_object_id();
|
||||
|
||||
if (entity->has_own_name())
|
||||
response.name = entity->get_name();
|
||||
|
||||
// Set common EntityBase properties
|
||||
response.icon = entity->get_icon();
|
||||
response.disabled_by_default = entity->is_disabled_by_default();
|
||||
response.entity_category = static_cast<enums::EntityCategory>(entity->get_entity_category());
|
||||
#ifdef USE_DEVICES
|
||||
response.device_id = entity->get_device_id();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Helper function to fill common entity state fields
|
||||
static void fill_entity_state_base(esphome::EntityBase *entity, StateResponseProtoMessage &response) {
|
||||
response.key = entity->get_object_id_hash();
|
||||
#ifdef USE_DEVICES
|
||||
response.device_id = entity->get_device_id();
|
||||
#endif
|
||||
}
|
||||
// Helper function to handle authentication completion
|
||||
void complete_authentication_();
|
||||
|
||||
// Non-template helper to encode any ProtoMessage
|
||||
static uint16_t encode_message_to_buffer(ProtoMessage &msg, uint8_t message_type, APIConnection *conn,
|
||||
uint32_t remaining_size, bool is_single);
|
||||
|
||||
// Helper to fill entity state base and encode message
|
||||
static uint16_t fill_and_encode_entity_state(EntityBase *entity, StateResponseProtoMessage &msg, uint8_t message_type,
|
||||
APIConnection *conn, uint32_t remaining_size, bool is_single) {
|
||||
msg.key = entity->get_object_id_hash();
|
||||
#ifdef USE_DEVICES
|
||||
msg.device_id = entity->get_device_id();
|
||||
#endif
|
||||
return encode_message_to_buffer(msg, message_type, conn, remaining_size, is_single);
|
||||
}
|
||||
|
||||
// Helper to fill entity info base and encode message
|
||||
static uint16_t fill_and_encode_entity_info(EntityBase *entity, InfoResponseProtoMessage &msg, uint8_t message_type,
|
||||
APIConnection *conn, uint32_t remaining_size, bool is_single) {
|
||||
// Set common fields that are shared by all entity types
|
||||
msg.key = entity->get_object_id_hash();
|
||||
msg.object_id = entity->get_object_id();
|
||||
|
||||
if (entity->has_own_name())
|
||||
msg.name = entity->get_name();
|
||||
|
||||
// Set common EntityBase properties
|
||||
#ifdef USE_ENTITY_ICON
|
||||
msg.icon = entity->get_icon();
|
||||
#endif
|
||||
msg.disabled_by_default = entity->is_disabled_by_default();
|
||||
msg.entity_category = static_cast<enums::EntityCategory>(entity->get_entity_category());
|
||||
#ifdef USE_DEVICES
|
||||
msg.device_id = entity->get_device_id();
|
||||
#endif
|
||||
return encode_message_to_buffer(msg, message_type, conn, remaining_size, is_single);
|
||||
}
|
||||
|
||||
#ifdef USE_VOICE_ASSISTANT
|
||||
// Helper to check voice assistant validity and connection ownership
|
||||
inline bool check_voice_assistant_api_connection_() const;
|
||||
|
@@ -23,3 +23,7 @@ extend google.protobuf.MessageOptions {
|
||||
optional bool no_delay = 1040 [default=false];
|
||||
optional string base_class = 1041;
|
||||
}
|
||||
|
||||
extend google.protobuf.FieldOptions {
|
||||
optional string field_ifdef = 1042;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -291,7 +291,6 @@ class InfoResponseProtoMessage : public ProtoMessage {
|
||||
std::string object_id{};
|
||||
uint32_t key{0};
|
||||
std::string name{};
|
||||
std::string unique_id{};
|
||||
bool disabled_by_default{false};
|
||||
std::string icon{};
|
||||
enums::EntityCategory entity_category{};
|
||||
@@ -492,22 +491,50 @@ class DeviceInfoResponse : public ProtoMessage {
|
||||
std::string esphome_version{};
|
||||
std::string compilation_time{};
|
||||
std::string model{};
|
||||
#ifdef USE_DEEP_SLEEP
|
||||
bool has_deep_sleep{false};
|
||||
#endif
|
||||
#ifdef ESPHOME_PROJECT_NAME
|
||||
std::string project_name{};
|
||||
#endif
|
||||
#ifdef ESPHOME_PROJECT_NAME
|
||||
std::string project_version{};
|
||||
#endif
|
||||
#ifdef USE_WEBSERVER
|
||||
uint32_t webserver_port{0};
|
||||
#endif
|
||||
#ifdef USE_BLUETOOTH_PROXY
|
||||
uint32_t legacy_bluetooth_proxy_version{0};
|
||||
#endif
|
||||
#ifdef USE_BLUETOOTH_PROXY
|
||||
uint32_t bluetooth_proxy_feature_flags{0};
|
||||
#endif
|
||||
std::string manufacturer{};
|
||||
std::string friendly_name{};
|
||||
#ifdef USE_VOICE_ASSISTANT
|
||||
uint32_t legacy_voice_assistant_version{0};
|
||||
#endif
|
||||
#ifdef USE_VOICE_ASSISTANT
|
||||
uint32_t voice_assistant_feature_flags{0};
|
||||
#endif
|
||||
#ifdef USE_AREAS
|
||||
std::string suggested_area{};
|
||||
#endif
|
||||
#ifdef USE_BLUETOOTH_PROXY
|
||||
std::string bluetooth_mac_address{};
|
||||
#endif
|
||||
#ifdef USE_API_NOISE
|
||||
bool api_encryption_supported{false};
|
||||
#endif
|
||||
#ifdef USE_DEVICES
|
||||
std::vector<DeviceInfo> devices{};
|
||||
#endif
|
||||
#ifdef USE_AREAS
|
||||
std::vector<AreaInfo> areas{};
|
||||
#endif
|
||||
#ifdef USE_AREAS
|
||||
AreaInfo area{};
|
||||
#endif
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
@@ -559,7 +586,7 @@ class SubscribeStatesRequest : public ProtoMessage {
|
||||
class ListEntitiesBinarySensorResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 12;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 60;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 51;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_binary_sensor_response"; }
|
||||
#endif
|
||||
@@ -595,7 +622,7 @@ class BinarySensorStateResponse : public StateResponseProtoMessage {
|
||||
class ListEntitiesCoverResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 13;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 66;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 57;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_cover_response"; }
|
||||
#endif
|
||||
@@ -658,7 +685,7 @@ class CoverCommandRequest : public CommandProtoMessage {
|
||||
class ListEntitiesFanResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 14;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 77;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 68;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_fan_response"; }
|
||||
#endif
|
||||
@@ -729,7 +756,7 @@ class FanCommandRequest : public CommandProtoMessage {
|
||||
class ListEntitiesLightResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 15;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 90;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 81;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_light_response"; }
|
||||
#endif
|
||||
@@ -823,7 +850,7 @@ class LightCommandRequest : public CommandProtoMessage {
|
||||
class ListEntitiesSensorResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 16;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 77;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 68;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_sensor_response"; }
|
||||
#endif
|
||||
@@ -863,7 +890,7 @@ class SensorStateResponse : public StateResponseProtoMessage {
|
||||
class ListEntitiesSwitchResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 17;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 60;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 51;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_switch_response"; }
|
||||
#endif
|
||||
@@ -914,7 +941,7 @@ class SwitchCommandRequest : public CommandProtoMessage {
|
||||
class ListEntitiesTextSensorResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 18;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 58;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 49;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_text_sensor_response"; }
|
||||
#endif
|
||||
@@ -1213,7 +1240,7 @@ class ExecuteServiceRequest : public ProtoMessage {
|
||||
class ListEntitiesCameraResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 43;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 49;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 40;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_camera_response"; }
|
||||
#endif
|
||||
@@ -1263,7 +1290,7 @@ class CameraImageRequest : public ProtoMessage {
|
||||
class ListEntitiesClimateResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 46;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 156;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 147;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_climate_response"; }
|
||||
#endif
|
||||
@@ -1365,7 +1392,7 @@ class ClimateCommandRequest : public CommandProtoMessage {
|
||||
class ListEntitiesNumberResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 49;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 84;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 75;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_number_response"; }
|
||||
#endif
|
||||
@@ -1421,7 +1448,7 @@ class NumberCommandRequest : public CommandProtoMessage {
|
||||
class ListEntitiesSelectResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 52;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 67;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 58;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_select_response"; }
|
||||
#endif
|
||||
@@ -1473,7 +1500,7 @@ class SelectCommandRequest : public CommandProtoMessage {
|
||||
class ListEntitiesSirenResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 55;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 71;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 62;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_siren_response"; }
|
||||
#endif
|
||||
@@ -1533,7 +1560,7 @@ class SirenCommandRequest : public CommandProtoMessage {
|
||||
class ListEntitiesLockResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 58;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 64;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 55;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_lock_response"; }
|
||||
#endif
|
||||
@@ -1589,7 +1616,7 @@ class LockCommandRequest : public CommandProtoMessage {
|
||||
class ListEntitiesButtonResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 61;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 58;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 49;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_button_response"; }
|
||||
#endif
|
||||
@@ -1639,7 +1666,7 @@ class MediaPlayerSupportedFormat : public ProtoMessage {
|
||||
class ListEntitiesMediaPlayerResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 63;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 85;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 76;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_media_player_response"; }
|
||||
#endif
|
||||
@@ -2453,7 +2480,7 @@ class VoiceAssistantSetConfiguration : public ProtoMessage {
|
||||
class ListEntitiesAlarmControlPanelResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 94;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 57;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 48;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_alarm_control_panel_response"; }
|
||||
#endif
|
||||
@@ -2507,7 +2534,7 @@ class AlarmControlPanelCommandRequest : public CommandProtoMessage {
|
||||
class ListEntitiesTextResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 97;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 68;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 59;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_text_response"; }
|
||||
#endif
|
||||
@@ -2562,7 +2589,7 @@ class TextCommandRequest : public CommandProtoMessage {
|
||||
class ListEntitiesDateResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 100;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 49;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 40;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_date_response"; }
|
||||
#endif
|
||||
@@ -2616,7 +2643,7 @@ class DateCommandRequest : public CommandProtoMessage {
|
||||
class ListEntitiesTimeResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 103;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 49;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 40;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_time_response"; }
|
||||
#endif
|
||||
@@ -2670,7 +2697,7 @@ class TimeCommandRequest : public CommandProtoMessage {
|
||||
class ListEntitiesEventResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 107;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 76;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 67;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_event_response"; }
|
||||
#endif
|
||||
@@ -2705,7 +2732,7 @@ class EventResponse : public StateResponseProtoMessage {
|
||||
class ListEntitiesValveResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 109;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 64;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 55;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_valve_response"; }
|
||||
#endif
|
||||
@@ -2761,7 +2788,7 @@ class ValveCommandRequest : public CommandProtoMessage {
|
||||
class ListEntitiesDateTimeResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 112;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 49;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 40;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_date_time_response"; }
|
||||
#endif
|
||||
@@ -2811,7 +2838,7 @@ class DateTimeCommandRequest : public CommandProtoMessage {
|
||||
class ListEntitiesUpdateResponse : public InfoResponseProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 116;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 58;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 49;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_update_response"; }
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -31,7 +31,6 @@ APIServer::APIServer() {
|
||||
}
|
||||
|
||||
void APIServer::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
this->setup_controller();
|
||||
|
||||
#ifdef USE_API_NOISE
|
||||
@@ -105,7 +104,7 @@ void APIServer::setup() {
|
||||
return;
|
||||
}
|
||||
for (auto &c : this->clients_) {
|
||||
if (!c->flags_.remove)
|
||||
if (!c->flags_.remove && c->get_log_subscription_level() >= level)
|
||||
c->try_send_log_message(level, tag, message, message_len);
|
||||
}
|
||||
});
|
||||
@@ -205,22 +204,20 @@ void APIServer::loop() {
|
||||
|
||||
void APIServer::dump_config() {
|
||||
ESP_LOGCONFIG(TAG,
|
||||
"API Server:\n"
|
||||
"Server:\n"
|
||||
" Address: %s:%u",
|
||||
network::get_use_address().c_str(), this->port_);
|
||||
#ifdef USE_API_NOISE
|
||||
ESP_LOGCONFIG(TAG, " Using noise encryption: %s", YESNO(this->noise_ctx_->has_psk()));
|
||||
ESP_LOGCONFIG(TAG, " Noise encryption: %s", YESNO(this->noise_ctx_->has_psk()));
|
||||
if (!this->noise_ctx_->has_psk()) {
|
||||
ESP_LOGCONFIG(TAG, " Supports noise encryption: YES");
|
||||
ESP_LOGCONFIG(TAG, " Supports encryption: YES");
|
||||
}
|
||||
#else
|
||||
ESP_LOGCONFIG(TAG, " Using noise encryption: NO");
|
||||
ESP_LOGCONFIG(TAG, " Noise encryption: NO");
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_API_PASSWORD
|
||||
bool APIServer::uses_password() const { return !this->password_.empty(); }
|
||||
|
||||
bool APIServer::check_password(const std::string &password) const {
|
||||
// depend only on input password length
|
||||
const char *a = this->password_.c_str();
|
||||
@@ -428,7 +425,7 @@ bool APIServer::save_noise_psk(psk_t psk, bool make_active) {
|
||||
ESP_LOGD(TAG, "Noise PSK saved");
|
||||
if (make_active) {
|
||||
this->set_timeout(100, [this, psk]() {
|
||||
ESP_LOGW(TAG, "Disconnecting all clients to reset connections");
|
||||
ESP_LOGW(TAG, "Disconnecting all clients to reset PSK");
|
||||
this->set_noise_psk(psk);
|
||||
for (auto &c : this->clients_) {
|
||||
c->send_message(DisconnectRequest());
|
||||
|
@@ -39,7 +39,6 @@ class APIServer : public Component, public Controller {
|
||||
bool teardown() override;
|
||||
#ifdef USE_API_PASSWORD
|
||||
bool check_password(const std::string &password) const;
|
||||
bool uses_password() const;
|
||||
void set_password(const std::string &password);
|
||||
#endif
|
||||
void set_port(uint16_t port);
|
||||
|
@@ -175,23 +175,7 @@ class Proto32Bit {
|
||||
const uint32_t value_;
|
||||
};
|
||||
|
||||
class Proto64Bit {
|
||||
public:
|
||||
explicit Proto64Bit(uint64_t value) : value_(value) {}
|
||||
uint64_t as_fixed64() const { return this->value_; }
|
||||
int64_t as_sfixed64() const { return static_cast<int64_t>(this->value_); }
|
||||
double as_double() const {
|
||||
union {
|
||||
uint64_t raw;
|
||||
double value;
|
||||
} s{};
|
||||
s.raw = this->value_;
|
||||
return s.value;
|
||||
}
|
||||
|
||||
protected:
|
||||
const uint64_t value_;
|
||||
};
|
||||
// NOTE: Proto64Bit class removed - wire type 1 (64-bit fixed) not supported
|
||||
|
||||
class ProtoWriteBuffer {
|
||||
public:
|
||||
@@ -205,9 +189,9 @@ class ProtoWriteBuffer {
|
||||
* @param field_id Field number (tag) in the protobuf message
|
||||
* @param type Wire type value:
|
||||
* - 0: Varint (int32, int64, uint32, uint64, sint32, sint64, bool, enum)
|
||||
* - 1: 64-bit (fixed64, sfixed64, double)
|
||||
* - 2: Length-delimited (string, bytes, embedded messages, packed repeated fields)
|
||||
* - 5: 32-bit (fixed32, sfixed32, float)
|
||||
* - Note: Wire type 1 (64-bit fixed) is not supported
|
||||
*
|
||||
* Following https://protobuf.dev/programming-guides/encoding/#structure
|
||||
*/
|
||||
@@ -258,20 +242,10 @@ class ProtoWriteBuffer {
|
||||
this->write((value >> 16) & 0xFF);
|
||||
this->write((value >> 24) & 0xFF);
|
||||
}
|
||||
void encode_fixed64(uint32_t field_id, uint64_t value, bool force = false) {
|
||||
if (value == 0 && !force)
|
||||
return;
|
||||
|
||||
this->encode_field_raw(field_id, 1); // type 1: 64-bit fixed64
|
||||
this->write((value >> 0) & 0xFF);
|
||||
this->write((value >> 8) & 0xFF);
|
||||
this->write((value >> 16) & 0xFF);
|
||||
this->write((value >> 24) & 0xFF);
|
||||
this->write((value >> 32) & 0xFF);
|
||||
this->write((value >> 40) & 0xFF);
|
||||
this->write((value >> 48) & 0xFF);
|
||||
this->write((value >> 56) & 0xFF);
|
||||
}
|
||||
// NOTE: Wire type 1 (64-bit fixed: double, fixed64, sfixed64) is intentionally
|
||||
// not supported to reduce overhead on embedded systems. All ESPHome devices are
|
||||
// 32-bit microcontrollers where 64-bit operations are expensive. If 64-bit support
|
||||
// is needed in the future, the necessary encoding/decoding functions must be added.
|
||||
void encode_float(uint32_t field_id, float value, bool force = false) {
|
||||
if (value == 0.0f && !force)
|
||||
return;
|
||||
@@ -337,7 +311,7 @@ class ProtoMessage {
|
||||
virtual bool decode_varint(uint32_t field_id, ProtoVarInt value) { return false; }
|
||||
virtual bool decode_length(uint32_t field_id, ProtoLengthDelimited value) { return false; }
|
||||
virtual bool decode_32bit(uint32_t field_id, Proto32Bit value) { return false; }
|
||||
virtual bool decode_64bit(uint32_t field_id, Proto64Bit value) { return false; }
|
||||
// NOTE: decode_64bit removed - wire type 1 not supported
|
||||
};
|
||||
|
||||
class ProtoSize {
|
||||
@@ -566,6 +540,42 @@ class ProtoSize {
|
||||
total_size += field_id_size + NumBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculates and adds the size of a float field to the total message size
|
||||
*/
|
||||
static inline void add_float_field(uint32_t &total_size, uint32_t field_id_size, float value) {
|
||||
if (value != 0.0f) {
|
||||
total_size += field_id_size + 4;
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: add_double_field removed - wire type 1 (64-bit: double) not supported
|
||||
// to reduce overhead on embedded systems
|
||||
|
||||
/**
|
||||
* @brief Calculates and adds the size of a fixed32 field to the total message size
|
||||
*/
|
||||
static inline void add_fixed32_field(uint32_t &total_size, uint32_t field_id_size, uint32_t value) {
|
||||
if (value != 0) {
|
||||
total_size += field_id_size + 4;
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: add_fixed64_field removed - wire type 1 (64-bit: fixed64) not supported
|
||||
// to reduce overhead on embedded systems
|
||||
|
||||
/**
|
||||
* @brief Calculates and adds the size of a sfixed32 field to the total message size
|
||||
*/
|
||||
static inline void add_sfixed32_field(uint32_t &total_size, uint32_t field_id_size, int32_t value) {
|
||||
if (value != 0) {
|
||||
total_size += field_id_size + 4;
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: add_sfixed64_field removed - wire type 1 (64-bit: sfixed64) not supported
|
||||
// to reduce overhead on embedded systems
|
||||
|
||||
/**
|
||||
* @brief Calculates and adds the size of an enum field to the total message size
|
||||
*
|
||||
@@ -662,33 +672,8 @@ class ProtoSize {
|
||||
total_size += field_id_size + varint(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculates and adds the size of a sint64 field to the total message size
|
||||
*
|
||||
* Sint64 fields use ZigZag encoding, which is more efficient for negative values.
|
||||
*/
|
||||
static inline void add_sint64_field(uint32_t &total_size, uint32_t field_id_size, int64_t value) {
|
||||
// Skip calculation if value is zero
|
||||
if (value == 0) {
|
||||
return; // No need to update total_size
|
||||
}
|
||||
|
||||
// ZigZag encoding for sint64: (n << 1) ^ (n >> 63)
|
||||
uint64_t zigzag = (static_cast<uint64_t>(value) << 1) ^ (static_cast<uint64_t>(value >> 63));
|
||||
total_size += field_id_size + varint(zigzag);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculates and adds the size of a sint64 field to the total message size (repeated field version)
|
||||
*
|
||||
* Sint64 fields use ZigZag encoding, which is more efficient for negative values.
|
||||
*/
|
||||
static inline void add_sint64_field_repeated(uint32_t &total_size, uint32_t field_id_size, int64_t value) {
|
||||
// Always calculate size for repeated fields
|
||||
// ZigZag encoding for sint64: (n << 1) ^ (n >> 63)
|
||||
uint64_t zigzag = (static_cast<uint64_t>(value) << 1) ^ (static_cast<uint64_t>(value >> 63));
|
||||
total_size += field_id_size + varint(zigzag);
|
||||
}
|
||||
// NOTE: sint64 support functions (add_sint64_field, add_sint64_field_repeated) removed
|
||||
// sint64 type is not supported by ESPHome API to reduce overhead on embedded systems
|
||||
|
||||
/**
|
||||
* @brief Calculates and adds the size of a string/bytes field to the total message size
|
||||
|
@@ -16,6 +16,8 @@ class UserServiceDescriptor {
|
||||
virtual ListEntitiesServicesResponse encode_list_service_response() = 0;
|
||||
|
||||
virtual bool execute_service(const ExecuteServiceRequest &req) = 0;
|
||||
|
||||
bool is_internal() { return false; }
|
||||
};
|
||||
|
||||
template<typename T> T get_execute_arg_value(const ExecuteServiceArgument &arg);
|
||||
|
@@ -3,8 +3,6 @@
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/as3935/as3935.h"
|
||||
#include "esphome/components/spi/spi.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace as3935_spi {
|
||||
|
@@ -31,7 +31,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
async def to_code(config):
|
||||
if CORE.is_esp32 or CORE.is_libretiny:
|
||||
# https://github.com/ESP32Async/AsyncTCP
|
||||
cg.add_library("ESP32Async/AsyncTCP", "3.4.4")
|
||||
cg.add_library("ESP32Async/AsyncTCP", "3.4.5")
|
||||
elif CORE.is_esp8266:
|
||||
# https://github.com/ESP32Async/ESPAsyncTCP
|
||||
cg.add_library("ESP32Async/ESPAsyncTCP", "2.0.0")
|
||||
|
@@ -85,13 +85,13 @@ async def to_code(config):
|
||||
await cg.register_component(var, config)
|
||||
|
||||
cg.add(var.set_active(config[CONF_ACTIVE]))
|
||||
await esp32_ble_tracker.register_ble_device(var, config)
|
||||
await esp32_ble_tracker.register_raw_ble_device(var, config)
|
||||
|
||||
for connection_conf in config.get(CONF_CONNECTIONS, []):
|
||||
connection_var = cg.new_Pvariable(connection_conf[CONF_ID])
|
||||
await cg.register_component(connection_var, connection_conf)
|
||||
cg.add(var.register_connection(connection_var))
|
||||
await esp32_ble_tracker.register_client(connection_var, connection_conf)
|
||||
await esp32_ble_tracker.register_raw_client(connection_var, connection_conf)
|
||||
|
||||
if config.get(CONF_CACHE_SERVICES):
|
||||
add_idf_sdkconfig_option("CONFIG_BT_GATTC_CACHE_NVS_FLASH", True)
|
||||
|
@@ -42,15 +42,13 @@ void BluetoothProxy::send_bluetooth_scanner_state_(esp32_ble_tracker::ScannerSta
|
||||
this->api_connection_->send_message(resp);
|
||||
}
|
||||
|
||||
#ifdef USE_ESP32_BLE_DEVICE
|
||||
bool BluetoothProxy::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
|
||||
if (!api::global_api_server->is_connected() || this->api_connection_ == nullptr || this->raw_advertisements_)
|
||||
// This method should never be called since bluetooth_proxy always uses raw advertisements
|
||||
// but we need to provide an implementation to satisfy the virtual method requirement
|
||||
return false;
|
||||
|
||||
ESP_LOGV(TAG, "Proxying packet from %s - %s. RSSI: %d dB", device.get_name().c_str(), device.address_str().c_str(),
|
||||
device.get_rssi());
|
||||
this->send_api_packet_(device);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Batch size for BLE advertisements to maximize WiFi efficiency
|
||||
// Each advertisement is up to 80 bytes when packaged (including protocol overhead)
|
||||
@@ -69,7 +67,7 @@ std::vector<api::BluetoothLERawAdvertisement> batch_buffer;
|
||||
static std::vector<api::BluetoothLERawAdvertisement> &get_batch_buffer() { return batch_buffer; }
|
||||
|
||||
bool BluetoothProxy::parse_devices(const esp32_ble::BLEScanResult *scan_results, size_t count) {
|
||||
if (!api::global_api_server->is_connected() || this->api_connection_ == nullptr || !this->raw_advertisements_)
|
||||
if (!api::global_api_server->is_connected() || this->api_connection_ == nullptr)
|
||||
return false;
|
||||
|
||||
// Get the batch buffer reference
|
||||
@@ -116,6 +114,7 @@ void BluetoothProxy::flush_pending_advertisements() {
|
||||
this->api_connection_->send_message(resp);
|
||||
}
|
||||
|
||||
#ifdef USE_ESP32_BLE_DEVICE
|
||||
void BluetoothProxy::send_api_packet_(const esp32_ble_tracker::ESPBTDevice &device) {
|
||||
api::BluetoothLEAdvertisementResponse resp;
|
||||
resp.address = device.address_uint64();
|
||||
@@ -153,14 +152,14 @@ void BluetoothProxy::send_api_packet_(const esp32_ble_tracker::ESPBTDevice &devi
|
||||
|
||||
this->api_connection_->send_message(resp);
|
||||
}
|
||||
#endif // USE_ESP32_BLE_DEVICE
|
||||
|
||||
void BluetoothProxy::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "Bluetooth Proxy:");
|
||||
ESP_LOGCONFIG(TAG,
|
||||
" Active: %s\n"
|
||||
" Connections: %d\n"
|
||||
" Raw advertisements: %s",
|
||||
YESNO(this->active_), this->connections_.size(), YESNO(this->raw_advertisements_));
|
||||
" Connections: %d",
|
||||
YESNO(this->active_), this->connections_.size());
|
||||
}
|
||||
|
||||
int BluetoothProxy::get_bluetooth_connections_free() {
|
||||
@@ -188,7 +187,6 @@ void BluetoothProxy::loop() {
|
||||
}
|
||||
|
||||
// Flush any pending BLE advertisements that have been accumulated but not yet sent
|
||||
if (this->raw_advertisements_) {
|
||||
static uint32_t last_flush_time = 0;
|
||||
uint32_t now = App.get_loop_component_start_time();
|
||||
|
||||
@@ -197,7 +195,6 @@ void BluetoothProxy::loop() {
|
||||
this->flush_pending_advertisements();
|
||||
last_flush_time = now;
|
||||
}
|
||||
}
|
||||
for (auto *connection : this->connections_) {
|
||||
if (connection->send_service_ == connection->service_count_) {
|
||||
connection->send_service_ = DONE_SENDING_SERVICES;
|
||||
@@ -318,9 +315,7 @@ void BluetoothProxy::loop() {
|
||||
}
|
||||
|
||||
esp32_ble_tracker::AdvertisementParserType BluetoothProxy::get_advertisement_parser_type() {
|
||||
if (this->raw_advertisements_)
|
||||
return esp32_ble_tracker::AdvertisementParserType::RAW_ADVERTISEMENTS;
|
||||
return esp32_ble_tracker::AdvertisementParserType::PARSED_ADVERTISEMENTS;
|
||||
}
|
||||
|
||||
BluetoothConnection *BluetoothProxy::get_connection_(uint64_t address, bool reserve) {
|
||||
@@ -565,7 +560,6 @@ void BluetoothProxy::subscribe_api_connection(api::APIConnection *api_connection
|
||||
return;
|
||||
}
|
||||
this->api_connection_ = api_connection;
|
||||
this->raw_advertisements_ = flags & BluetoothProxySubscriptionFlag::SUBSCRIPTION_RAW_ADVERTISEMENTS;
|
||||
this->parent_->recalculate_advertisement_parser_types();
|
||||
|
||||
this->send_bluetooth_scanner_state_(this->parent_->get_scanner_state());
|
||||
@@ -577,7 +571,6 @@ void BluetoothProxy::unsubscribe_api_connection(api::APIConnection *api_connecti
|
||||
return;
|
||||
}
|
||||
this->api_connection_ = nullptr;
|
||||
this->raw_advertisements_ = false;
|
||||
this->parent_->recalculate_advertisement_parser_types();
|
||||
}
|
||||
|
||||
|
@@ -51,7 +51,9 @@ enum BluetoothProxySubscriptionFlag : uint32_t {
|
||||
class BluetoothProxy : public esp32_ble_tracker::ESPBTDeviceListener, public Component {
|
||||
public:
|
||||
BluetoothProxy();
|
||||
#ifdef USE_ESP32_BLE_DEVICE
|
||||
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override;
|
||||
#endif
|
||||
bool parse_devices(const esp32_ble::BLEScanResult *scan_results, size_t count) override;
|
||||
void dump_config() override;
|
||||
void setup() override;
|
||||
@@ -129,7 +131,9 @@ class BluetoothProxy : public esp32_ble_tracker::ESPBTDeviceListener, public Com
|
||||
}
|
||||
|
||||
protected:
|
||||
#ifdef USE_ESP32_BLE_DEVICE
|
||||
void send_api_packet_(const esp32_ble_tracker::ESPBTDevice &device);
|
||||
#endif
|
||||
void send_bluetooth_scanner_state_(esp32_ble_tracker::ScannerState state);
|
||||
|
||||
BluetoothConnection *get_connection_(uint64_t address, bool reserve);
|
||||
@@ -143,8 +147,7 @@ class BluetoothProxy : public esp32_ble_tracker::ESPBTDeviceListener, public Com
|
||||
|
||||
// Group 3: 1-byte types grouped together
|
||||
bool active_;
|
||||
bool raw_advertisements_{false};
|
||||
// 2 bytes used, 2 bytes padding
|
||||
// 1 byte used, 3 bytes padding
|
||||
};
|
||||
|
||||
extern BluetoothProxy *global_bluetooth_proxy; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
|
@@ -3,6 +3,7 @@
|
||||
CODEOWNERS = ["@esphome/core"]
|
||||
|
||||
CONF_BYTE_ORDER = "byte_order"
|
||||
CONF_COLOR_DEPTH = "color_depth"
|
||||
CONF_DRAW_ROUNDING = "draw_rounding"
|
||||
CONF_ON_STATE_CHANGE = "on_state_change"
|
||||
CONF_REQUEST_HEADERS = "request_headers"
|
||||
|
@@ -105,6 +105,7 @@ void BLEClientBase::dump_config() {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_ESP32_BLE_DEVICE
|
||||
bool BLEClientBase::parse_device(const espbt::ESPBTDevice &device) {
|
||||
if (!this->auto_connect_)
|
||||
return false;
|
||||
@@ -122,6 +123,7 @@ bool BLEClientBase::parse_device(const espbt::ESPBTDevice &device) {
|
||||
this->remote_addr_type_ = device.get_address_type();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void BLEClientBase::connect() {
|
||||
ESP_LOGI(TAG, "[%d] [%s] 0x%02x Attempting BLE connection", this->connection_index_, this->address_str_.c_str(),
|
||||
|
@@ -31,7 +31,9 @@ class BLEClientBase : public espbt::ESPBTClient, public Component {
|
||||
void dump_config() override;
|
||||
|
||||
void run_later(std::function<void()> &&f); // NOLINT
|
||||
#ifdef USE_ESP32_BLE_DEVICE
|
||||
bool parse_device(const espbt::ESPBTDevice &device) override;
|
||||
#endif
|
||||
void on_scan_end() override {}
|
||||
bool gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
|
||||
esp_ble_gattc_cb_param_t *param) override;
|
||||
|
@@ -31,6 +31,8 @@ from esphome.const import (
|
||||
CONF_TRIGGER_ID,
|
||||
)
|
||||
from esphome.core import CORE
|
||||
from esphome.enum import StrEnum
|
||||
from esphome.types import ConfigType
|
||||
|
||||
AUTO_LOAD = ["esp32_ble"]
|
||||
DEPENDENCIES = ["esp32"]
|
||||
@@ -50,6 +52,25 @@ IDF_MAX_CONNECTIONS = 9
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Enum for BLE features
|
||||
class BLEFeatures(StrEnum):
|
||||
ESP_BT_DEVICE = "ESP_BT_DEVICE"
|
||||
|
||||
|
||||
# Set to track which features are needed by components
|
||||
_required_features: set[BLEFeatures] = set()
|
||||
|
||||
|
||||
def register_ble_features(features: set[BLEFeatures]) -> None:
|
||||
"""Register BLE features that a component needs.
|
||||
|
||||
Args:
|
||||
features: Set of BLEFeatures enum members
|
||||
"""
|
||||
_required_features.update(features)
|
||||
|
||||
|
||||
esp32_ble_tracker_ns = cg.esphome_ns.namespace("esp32_ble_tracker")
|
||||
ESP32BLETracker = esp32_ble_tracker_ns.class_(
|
||||
"ESP32BLETracker",
|
||||
@@ -277,6 +298,15 @@ async def to_code(config):
|
||||
cg.add(var.set_scan_window(int(params[CONF_WINDOW].total_milliseconds / 0.625)))
|
||||
cg.add(var.set_scan_active(params[CONF_ACTIVE]))
|
||||
cg.add(var.set_scan_continuous(params[CONF_CONTINUOUS]))
|
||||
|
||||
# Register ESP_BT_DEVICE feature if any of the automation triggers are used
|
||||
if (
|
||||
config.get(CONF_ON_BLE_ADVERTISE)
|
||||
or config.get(CONF_ON_BLE_SERVICE_DATA_ADVERTISE)
|
||||
or config.get(CONF_ON_BLE_MANUFACTURER_DATA_ADVERTISE)
|
||||
):
|
||||
register_ble_features({BLEFeatures.ESP_BT_DEVICE})
|
||||
|
||||
for conf in config.get(CONF_ON_BLE_ADVERTISE, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||
if CONF_MAC_ADDRESS in conf:
|
||||
@@ -334,6 +364,11 @@ async def to_code(config):
|
||||
|
||||
cg.add_define("USE_OTA_STATE_CALLBACK") # To be notified when an OTA update starts
|
||||
cg.add_define("USE_ESP32_BLE_CLIENT")
|
||||
|
||||
# Add feature-specific defines based on what's needed
|
||||
if BLEFeatures.ESP_BT_DEVICE in _required_features:
|
||||
cg.add_define("USE_ESP32_BLE_DEVICE")
|
||||
|
||||
if config.get(CONF_SOFTWARE_COEXISTENCE):
|
||||
cg.add_define("USE_ESP32_BLE_SOFTWARE_COEXISTENCE")
|
||||
|
||||
@@ -382,13 +417,43 @@ async def esp32_ble_tracker_stop_scan_action_to_code(
|
||||
return var
|
||||
|
||||
|
||||
async def register_ble_device(var, config):
|
||||
async def register_ble_device(
|
||||
var: cg.SafeExpType, config: ConfigType
|
||||
) -> cg.SafeExpType:
|
||||
register_ble_features({BLEFeatures.ESP_BT_DEVICE})
|
||||
paren = await cg.get_variable(config[CONF_ESP32_BLE_ID])
|
||||
cg.add(paren.register_listener(var))
|
||||
return var
|
||||
|
||||
|
||||
async def register_client(var, config):
|
||||
async def register_client(var: cg.SafeExpType, config: ConfigType) -> cg.SafeExpType:
|
||||
register_ble_features({BLEFeatures.ESP_BT_DEVICE})
|
||||
paren = await cg.get_variable(config[CONF_ESP32_BLE_ID])
|
||||
cg.add(paren.register_client(var))
|
||||
return var
|
||||
|
||||
|
||||
async def register_raw_ble_device(
|
||||
var: cg.SafeExpType, config: ConfigType
|
||||
) -> cg.SafeExpType:
|
||||
"""Register a BLE device listener that only needs raw advertisement data.
|
||||
|
||||
This does NOT register the ESP_BT_DEVICE feature, meaning ESPBTDevice
|
||||
will not be compiled in if this is the only registration method used.
|
||||
"""
|
||||
paren = await cg.get_variable(config[CONF_ESP32_BLE_ID])
|
||||
cg.add(paren.register_listener(var))
|
||||
return var
|
||||
|
||||
|
||||
async def register_raw_client(
|
||||
var: cg.SafeExpType, config: ConfigType
|
||||
) -> cg.SafeExpType:
|
||||
"""Register a BLE client that only needs raw advertisement data.
|
||||
|
||||
This does NOT register the ESP_BT_DEVICE feature, meaning ESPBTDevice
|
||||
will not be compiled in if this is the only registration method used.
|
||||
"""
|
||||
paren = await cg.get_variable(config[CONF_ESP32_BLE_ID])
|
||||
cg.add(paren.register_client(var))
|
||||
return var
|
||||
|
@@ -7,6 +7,7 @@
|
||||
|
||||
namespace esphome {
|
||||
namespace esp32_ble_tracker {
|
||||
#ifdef USE_ESP32_BLE_DEVICE
|
||||
class ESPBTAdvertiseTrigger : public Trigger<const ESPBTDevice &>, public ESPBTDeviceListener {
|
||||
public:
|
||||
explicit ESPBTAdvertiseTrigger(ESP32BLETracker *parent) { parent->register_listener(this); }
|
||||
@@ -87,6 +88,7 @@ class BLEEndOfScanTrigger : public Trigger<>, public ESPBTDeviceListener {
|
||||
bool parse_device(const ESPBTDevice &device) override { return false; }
|
||||
void on_scan_end() override { this->trigger(); }
|
||||
};
|
||||
#endif // USE_ESP32_BLE_DEVICE
|
||||
|
||||
template<typename... Ts> class ESP32BLEStartScanAction : public Action<Ts...> {
|
||||
public:
|
||||
|
@@ -141,6 +141,7 @@ void ESP32BLETracker::loop() {
|
||||
}
|
||||
|
||||
if (this->parse_advertisements_) {
|
||||
#ifdef USE_ESP32_BLE_DEVICE
|
||||
ESPBTDevice device;
|
||||
device.parse_scan_rst(scan_result);
|
||||
|
||||
@@ -162,6 +163,7 @@ void ESP32BLETracker::loop() {
|
||||
if (!found && !this->scan_continuous_) {
|
||||
this->print_bt_device_info(device);
|
||||
}
|
||||
#endif // USE_ESP32_BLE_DEVICE
|
||||
}
|
||||
|
||||
// Move to next entry in ring buffer
|
||||
@@ -511,6 +513,7 @@ void ESP32BLETracker::set_scanner_state_(ScannerState state) {
|
||||
this->scanner_state_callbacks_.call(state);
|
||||
}
|
||||
|
||||
#ifdef USE_ESP32_BLE_DEVICE
|
||||
ESPBLEiBeacon::ESPBLEiBeacon(const uint8_t *data) { memcpy(&this->beacon_data_, data, sizeof(beacon_data_)); }
|
||||
optional<ESPBLEiBeacon> ESPBLEiBeacon::from_manufacturer_data(const ServiceData &data) {
|
||||
if (!data.uuid.contains(0x4C, 0x00))
|
||||
@@ -751,13 +754,16 @@ void ESPBTDevice::parse_adv_(const uint8_t *payload, uint8_t len) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string ESPBTDevice::address_str() const {
|
||||
char mac[24];
|
||||
snprintf(mac, sizeof(mac), "%02X:%02X:%02X:%02X:%02X:%02X", this->address_[0], this->address_[1], this->address_[2],
|
||||
this->address_[3], this->address_[4], this->address_[5]);
|
||||
return mac;
|
||||
}
|
||||
|
||||
uint64_t ESPBTDevice::address_uint64() const { return esp32_ble::ble_addr_to_uint64(this->address_); }
|
||||
#endif // USE_ESP32_BLE_DEVICE
|
||||
|
||||
void ESP32BLETracker::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "BLE Tracker:");
|
||||
@@ -796,6 +802,7 @@ void ESP32BLETracker::dump_config() {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_ESP32_BLE_DEVICE
|
||||
void ESP32BLETracker::print_bt_device_info(const ESPBTDevice &device) {
|
||||
const uint64_t address = device.address_uint64();
|
||||
for (auto &disc : this->already_discovered_) {
|
||||
@@ -866,8 +873,9 @@ bool ESPBTDevice::resolve_irk(const uint8_t *irk) const {
|
||||
return ecb_ciphertext[15] == (addr64 & 0xff) && ecb_ciphertext[14] == ((addr64 >> 8) & 0xff) &&
|
||||
ecb_ciphertext[13] == ((addr64 >> 16) & 0xff);
|
||||
}
|
||||
#endif // USE_ESP32_BLE_DEVICE
|
||||
|
||||
} // namespace esp32_ble_tracker
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
||||
#endif // USE_ESP32
|
||||
|
@@ -39,6 +39,7 @@ struct ServiceData {
|
||||
adv_data_t data;
|
||||
};
|
||||
|
||||
#ifdef USE_ESP32_BLE_DEVICE
|
||||
class ESPBLEiBeacon {
|
||||
public:
|
||||
ESPBLEiBeacon() { memset(&this->beacon_data_, 0, sizeof(this->beacon_data_)); }
|
||||
@@ -116,13 +117,16 @@ class ESPBTDevice {
|
||||
std::vector<ServiceData> service_datas_{};
|
||||
const BLEScanResult *scan_result_{nullptr};
|
||||
};
|
||||
#endif // USE_ESP32_BLE_DEVICE
|
||||
|
||||
class ESP32BLETracker;
|
||||
|
||||
class ESPBTDeviceListener {
|
||||
public:
|
||||
virtual void on_scan_end() {}
|
||||
#ifdef USE_ESP32_BLE_DEVICE
|
||||
virtual bool parse_device(const ESPBTDevice &device) = 0;
|
||||
#endif
|
||||
virtual bool parse_devices(const BLEScanResult *scan_results, size_t count) { return false; };
|
||||
virtual AdvertisementParserType get_advertisement_parser_type() {
|
||||
return AdvertisementParserType::PARSED_ADVERTISEMENTS;
|
||||
@@ -237,7 +241,9 @@ class ESP32BLETracker : public Component,
|
||||
void register_client(ESPBTClient *client);
|
||||
void recalculate_advertisement_parser_types();
|
||||
|
||||
#ifdef USE_ESP32_BLE_DEVICE
|
||||
void print_bt_device_info(const ESPBTDevice &device);
|
||||
#endif
|
||||
|
||||
void start_scan();
|
||||
void stop_scan();
|
||||
|
@@ -29,7 +29,6 @@ class IPAddressEthernetInfo : public PollingComponent, public text_sensor::TextS
|
||||
}
|
||||
|
||||
float get_setup_priority() const override { return setup_priority::ETHERNET; }
|
||||
std::string unique_id() override { return get_mac_address() + "-ethernetinfo"; }
|
||||
void dump_config() override;
|
||||
void add_ip_sensors(uint8_t index, text_sensor::TextSensor *s) { this->ip_sensors_[index] = s; }
|
||||
|
||||
@@ -52,7 +51,6 @@ class DNSAddressEthernetInfo : public PollingComponent, public text_sensor::Text
|
||||
}
|
||||
}
|
||||
float get_setup_priority() const override { return setup_priority::ETHERNET; }
|
||||
std::string unique_id() override { return get_mac_address() + "-ethernetinfo-dns"; }
|
||||
void dump_config() override;
|
||||
|
||||
protected:
|
||||
@@ -63,7 +61,6 @@ class MACAddressEthernetInfo : public Component, public text_sensor::TextSensor
|
||||
public:
|
||||
void setup() override { this->publish_state(ethernet::global_eth_component->get_eth_mac_address_pretty()); }
|
||||
float get_setup_priority() const override { return setup_priority::ETHERNET; }
|
||||
std::string unique_id() override { return get_mac_address() + "-ethernetinfo-mac"; }
|
||||
void dump_config() override;
|
||||
};
|
||||
|
||||
|
@@ -177,6 +177,10 @@ optional<FanRestoreState> Fan::restore_state_() {
|
||||
return {};
|
||||
}
|
||||
void Fan::save_state_() {
|
||||
if (this->restore_mode_ == FanRestoreMode::NO_RESTORE) {
|
||||
return;
|
||||
}
|
||||
|
||||
FanRestoreState state{};
|
||||
state.state = this->state;
|
||||
state.oscillating = this->oscillating;
|
||||
|
@@ -83,7 +83,7 @@ void HttpRequestUpdate::update_task(void *params) {
|
||||
container.reset(); // Release ownership of the container's shared_ptr
|
||||
|
||||
valid = json::parse_json(response, [this_update](JsonObject root) -> bool {
|
||||
if (!root.containsKey("name") || !root.containsKey("version") || !root.containsKey("builds")) {
|
||||
if (!root["name"].is<const char *>() || !root["version"].is<const char *>() || !root["builds"].is<JsonArray>()) {
|
||||
ESP_LOGE(TAG, "Manifest does not contain required fields");
|
||||
return false;
|
||||
}
|
||||
@@ -91,26 +91,26 @@ void HttpRequestUpdate::update_task(void *params) {
|
||||
this_update->update_info_.latest_version = root["version"].as<std::string>();
|
||||
|
||||
for (auto build : root["builds"].as<JsonArray>()) {
|
||||
if (!build.containsKey("chipFamily")) {
|
||||
if (!build["chipFamily"].is<const char *>()) {
|
||||
ESP_LOGE(TAG, "Manifest does not contain required fields");
|
||||
return false;
|
||||
}
|
||||
if (build["chipFamily"] == ESPHOME_VARIANT) {
|
||||
if (!build.containsKey("ota")) {
|
||||
if (!build["ota"].is<JsonObject>()) {
|
||||
ESP_LOGE(TAG, "Manifest does not contain required fields");
|
||||
return false;
|
||||
}
|
||||
auto ota = build["ota"];
|
||||
if (!ota.containsKey("path") || !ota.containsKey("md5")) {
|
||||
JsonObject ota = build["ota"].as<JsonObject>();
|
||||
if (!ota["path"].is<const char *>() || !ota["md5"].is<const char *>()) {
|
||||
ESP_LOGE(TAG, "Manifest does not contain required fields");
|
||||
return false;
|
||||
}
|
||||
this_update->update_info_.firmware_url = ota["path"].as<std::string>();
|
||||
this_update->update_info_.md5 = ota["md5"].as<std::string>();
|
||||
|
||||
if (ota.containsKey("summary"))
|
||||
if (ota["summary"].is<const char *>())
|
||||
this_update->update_info_.summary = ota["summary"].as<std::string>();
|
||||
if (ota.containsKey("release_url"))
|
||||
if (ota["release_url"].is<const char *>())
|
||||
this_update->update_info_.release_url = ota["release_url"].as<std::string>();
|
||||
|
||||
return true;
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include <driver/gpio.h>
|
||||
|
||||
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 0)
|
||||
#define SOC_HP_I2C_NUM SOC_I2C_NUM
|
||||
@@ -20,21 +21,72 @@ static const char *const TAG = "i2c.idf";
|
||||
void IDFI2CBus::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
static i2c_port_t next_port = I2C_NUM_0;
|
||||
port_ = next_port;
|
||||
this->port_ = next_port;
|
||||
if (this->port_ == I2C_NUM_MAX) {
|
||||
ESP_LOGE(TAG, "No more than %u buses supported", I2C_NUM_MAX);
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->timeout_ > 13000) {
|
||||
ESP_LOGW(TAG, "Using max allowed timeout: 13 ms");
|
||||
this->timeout_ = 13000;
|
||||
}
|
||||
|
||||
this->recover_();
|
||||
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 2)
|
||||
next_port = (i2c_port_t) (next_port + 1);
|
||||
|
||||
i2c_master_bus_config_t bus_conf{};
|
||||
memset(&bus_conf, 0, sizeof(bus_conf));
|
||||
bus_conf.sda_io_num = gpio_num_t(sda_pin_);
|
||||
bus_conf.scl_io_num = gpio_num_t(scl_pin_);
|
||||
bus_conf.i2c_port = this->port_;
|
||||
bus_conf.glitch_ignore_cnt = 7;
|
||||
#if SOC_LP_I2C_SUPPORTED
|
||||
if (this->port_ < SOC_HP_I2C_NUM) {
|
||||
bus_conf.clk_source = I2C_CLK_SRC_DEFAULT;
|
||||
} else {
|
||||
bus_conf.lp_source_clk = LP_I2C_SCLK_DEFAULT;
|
||||
}
|
||||
#else
|
||||
bus_conf.clk_source = I2C_CLK_SRC_DEFAULT;
|
||||
#endif
|
||||
bus_conf.flags.enable_internal_pullup = sda_pullup_enabled_ || scl_pullup_enabled_;
|
||||
esp_err_t err = i2c_new_master_bus(&bus_conf, &this->bus_);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "i2c_new_master_bus failed: %s", esp_err_to_name(err));
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
|
||||
i2c_device_config_t dev_conf{};
|
||||
memset(&dev_conf, 0, sizeof(dev_conf));
|
||||
dev_conf.dev_addr_length = I2C_ADDR_BIT_LEN_7;
|
||||
dev_conf.device_address = I2C_DEVICE_ADDRESS_NOT_USED;
|
||||
dev_conf.scl_speed_hz = this->frequency_;
|
||||
dev_conf.scl_wait_us = this->timeout_;
|
||||
err = i2c_master_bus_add_device(this->bus_, &dev_conf, &this->dev_);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "i2c_master_bus_add_device failed: %s", esp_err_to_name(err));
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
|
||||
this->initialized_ = true;
|
||||
|
||||
if (this->scan_) {
|
||||
ESP_LOGV(TAG, "Scanning for devices");
|
||||
this->i2c_scan_();
|
||||
}
|
||||
#else
|
||||
#if SOC_HP_I2C_NUM > 1
|
||||
next_port = (next_port == I2C_NUM_0) ? I2C_NUM_1 : I2C_NUM_MAX;
|
||||
#else
|
||||
next_port = I2C_NUM_MAX;
|
||||
#endif
|
||||
|
||||
if (port_ == I2C_NUM_MAX) {
|
||||
ESP_LOGE(TAG, "No more than %u buses supported", SOC_HP_I2C_NUM);
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
|
||||
recover_();
|
||||
|
||||
i2c_config_t conf{};
|
||||
memset(&conf, 0, sizeof(conf));
|
||||
conf.mode = I2C_MODE_MASTER;
|
||||
@@ -53,11 +105,7 @@ void IDFI2CBus::setup() {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
if (timeout_ > 0) { // if timeout specified in yaml:
|
||||
if (timeout_ > 13000) {
|
||||
ESP_LOGW(TAG, "i2c timeout of %" PRIu32 "us greater than max of 13ms on esp-idf, setting to max", timeout_);
|
||||
timeout_ = 13000;
|
||||
}
|
||||
if (timeout_ > 0) {
|
||||
err = i2c_set_timeout(port_, timeout_ * 80); // unit: APB 80MHz clock cycle
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "i2c_set_timeout failed: %s", esp_err_to_name(err));
|
||||
@@ -73,12 +121,15 @@ void IDFI2CBus::setup() {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
|
||||
initialized_ = true;
|
||||
if (this->scan_) {
|
||||
ESP_LOGV(TAG, "Scanning bus for active devices");
|
||||
this->i2c_scan_();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void IDFI2CBus::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "I2C Bus:");
|
||||
ESP_LOGCONFIG(TAG,
|
||||
@@ -123,6 +174,74 @@ ErrorCode IDFI2CBus::readv(uint8_t address, ReadBuffer *buffers, size_t cnt) {
|
||||
ESP_LOGVV(TAG, "i2c bus not initialized!");
|
||||
return ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 2)
|
||||
i2c_operation_job_t jobs[cnt + 4];
|
||||
uint8_t read = (address << 1) | I2C_MASTER_READ;
|
||||
size_t last = 0, num = 0;
|
||||
|
||||
jobs[num].command = I2C_MASTER_CMD_START;
|
||||
num++;
|
||||
|
||||
jobs[num].command = I2C_MASTER_CMD_WRITE;
|
||||
jobs[num].write.ack_check = true;
|
||||
jobs[num].write.data = &read;
|
||||
jobs[num].write.total_bytes = 1;
|
||||
num++;
|
||||
|
||||
// find the last valid index
|
||||
for (size_t i = 0; i < cnt; i++) {
|
||||
const auto &buf = buffers[i];
|
||||
if (buf.len == 0) {
|
||||
continue;
|
||||
}
|
||||
last = i;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < cnt; i++) {
|
||||
const auto &buf = buffers[i];
|
||||
if (buf.len == 0) {
|
||||
continue;
|
||||
}
|
||||
if (i == last) {
|
||||
// the last byte read before stop should always be a nack,
|
||||
// split the last read if len is larger than 1
|
||||
if (buf.len > 1) {
|
||||
jobs[num].command = I2C_MASTER_CMD_READ;
|
||||
jobs[num].read.ack_value = I2C_ACK_VAL;
|
||||
jobs[num].read.data = (uint8_t *) buf.data;
|
||||
jobs[num].read.total_bytes = buf.len - 1;
|
||||
num++;
|
||||
}
|
||||
jobs[num].command = I2C_MASTER_CMD_READ;
|
||||
jobs[num].read.ack_value = I2C_NACK_VAL;
|
||||
jobs[num].read.data = (uint8_t *) buf.data + buf.len - 1;
|
||||
jobs[num].read.total_bytes = 1;
|
||||
num++;
|
||||
} else {
|
||||
jobs[num].command = I2C_MASTER_CMD_READ;
|
||||
jobs[num].read.ack_value = I2C_ACK_VAL;
|
||||
jobs[num].read.data = (uint8_t *) buf.data;
|
||||
jobs[num].read.total_bytes = buf.len;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
jobs[num].command = I2C_MASTER_CMD_STOP;
|
||||
num++;
|
||||
|
||||
esp_err_t err = i2c_master_execute_defined_operations(this->dev_, jobs, num, 20);
|
||||
if (err == ESP_ERR_INVALID_STATE) {
|
||||
ESP_LOGVV(TAG, "RX from %02X failed: not acked", address);
|
||||
return ERROR_NOT_ACKNOWLEDGED;
|
||||
} else if (err == ESP_ERR_TIMEOUT) {
|
||||
ESP_LOGVV(TAG, "RX from %02X failed: timeout", address);
|
||||
return ERROR_TIMEOUT;
|
||||
} else if (err != ESP_OK) {
|
||||
ESP_LOGVV(TAG, "RX from %02X failed: %s", address, esp_err_to_name(err));
|
||||
return ERROR_UNKNOWN;
|
||||
}
|
||||
#else
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
esp_err_t err = i2c_master_start(cmd);
|
||||
if (err != ESP_OK) {
|
||||
@@ -168,6 +287,7 @@ ErrorCode IDFI2CBus::readv(uint8_t address, ReadBuffer *buffers, size_t cnt) {
|
||||
ESP_LOGVV(TAG, "RX from %02X failed: %s", address, esp_err_to_name(err));
|
||||
return ERROR_UNKNOWN;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ESPHOME_LOG_HAS_VERY_VERBOSE
|
||||
char debug_buf[4];
|
||||
@@ -185,6 +305,7 @@ ErrorCode IDFI2CBus::readv(uint8_t address, ReadBuffer *buffers, size_t cnt) {
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
ErrorCode IDFI2CBus::writev(uint8_t address, WriteBuffer *buffers, size_t cnt, bool stop) {
|
||||
// logging is only enabled with vv level, if warnings are shown the caller
|
||||
// should log them
|
||||
@@ -207,6 +328,49 @@ ErrorCode IDFI2CBus::writev(uint8_t address, WriteBuffer *buffers, size_t cnt, b
|
||||
ESP_LOGVV(TAG, "0x%02X TX %s", address, debug_hex.c_str());
|
||||
#endif
|
||||
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 2)
|
||||
i2c_operation_job_t jobs[cnt + 3];
|
||||
uint8_t write = (address << 1) | I2C_MASTER_WRITE;
|
||||
size_t num = 0;
|
||||
|
||||
jobs[num].command = I2C_MASTER_CMD_START;
|
||||
num++;
|
||||
|
||||
jobs[num].command = I2C_MASTER_CMD_WRITE;
|
||||
jobs[num].write.ack_check = true;
|
||||
jobs[num].write.data = &write;
|
||||
jobs[num].write.total_bytes = 1;
|
||||
num++;
|
||||
|
||||
for (size_t i = 0; i < cnt; i++) {
|
||||
const auto &buf = buffers[i];
|
||||
if (buf.len == 0) {
|
||||
continue;
|
||||
}
|
||||
jobs[num].command = I2C_MASTER_CMD_WRITE;
|
||||
jobs[num].write.ack_check = true;
|
||||
jobs[num].write.data = (uint8_t *) buf.data;
|
||||
jobs[num].write.total_bytes = buf.len;
|
||||
num++;
|
||||
}
|
||||
|
||||
if (stop) {
|
||||
jobs[num].command = I2C_MASTER_CMD_STOP;
|
||||
num++;
|
||||
}
|
||||
|
||||
esp_err_t err = i2c_master_execute_defined_operations(this->dev_, jobs, num, 20);
|
||||
if (err == ESP_ERR_INVALID_STATE) {
|
||||
ESP_LOGVV(TAG, "TX to %02X failed: not acked", address);
|
||||
return ERROR_NOT_ACKNOWLEDGED;
|
||||
} else if (err == ESP_ERR_TIMEOUT) {
|
||||
ESP_LOGVV(TAG, "TX to %02X failed: timeout", address);
|
||||
return ERROR_TIMEOUT;
|
||||
} else if (err != ESP_OK) {
|
||||
ESP_LOGVV(TAG, "TX to %02X failed: %s", address, esp_err_to_name(err));
|
||||
return ERROR_UNKNOWN;
|
||||
}
|
||||
#else
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
esp_err_t err = i2c_master_start(cmd);
|
||||
if (err != ESP_OK) {
|
||||
@@ -252,6 +416,7 @@ ErrorCode IDFI2CBus::writev(uint8_t address, WriteBuffer *buffers, size_t cnt, b
|
||||
ESP_LOGVV(TAG, "TX to %02X failed: %s", address, esp_err_to_name(err));
|
||||
return ERROR_UNKNOWN;
|
||||
}
|
||||
#endif
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
|
@@ -2,9 +2,14 @@
|
||||
|
||||
#ifdef USE_ESP_IDF
|
||||
|
||||
#include <driver/i2c.h>
|
||||
#include "esphome/core/component.h"
|
||||
#include "i2c_bus.h"
|
||||
#include "esp_idf_version.h"
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 2)
|
||||
#include <driver/i2c_master.h>
|
||||
#else
|
||||
#include <driver/i2c.h>
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
namespace i2c {
|
||||
@@ -38,6 +43,10 @@ class IDFI2CBus : public InternalI2CBus, public Component {
|
||||
RecoveryCode recovery_result_;
|
||||
|
||||
protected:
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 2)
|
||||
i2c_master_dev_handle_t dev_;
|
||||
i2c_master_bus_handle_t bus_;
|
||||
#endif
|
||||
i2c_port_t port_;
|
||||
uint8_t sda_pin_;
|
||||
bool sda_pullup_enabled_;
|
||||
|
@@ -12,6 +12,6 @@ CONFIG_SCHEMA = cv.All(
|
||||
|
||||
@coroutine_with_priority(1.0)
|
||||
async def to_code(config):
|
||||
cg.add_library("bblanchon/ArduinoJson", "6.18.5")
|
||||
cg.add_library("bblanchon/ArduinoJson", "7.4.2")
|
||||
cg.add_define("USE_JSON")
|
||||
cg.add_global(json_ns.using)
|
||||
|
@@ -1,83 +1,76 @@
|
||||
#include "json_util.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
// ArduinoJson::Allocator is included via ArduinoJson.h in json_util.h
|
||||
|
||||
namespace esphome {
|
||||
namespace json {
|
||||
|
||||
static const char *const TAG = "json";
|
||||
|
||||
static std::vector<char> global_json_build_buffer; // NOLINT
|
||||
static const auto ALLOCATOR = RAMAllocator<uint8_t>(RAMAllocator<uint8_t>::ALLOC_INTERNAL);
|
||||
// Build an allocator for the JSON Library using the RAMAllocator class
|
||||
struct SpiRamAllocator : ArduinoJson::Allocator {
|
||||
void *allocate(size_t size) override { return this->allocator_.allocate(size); }
|
||||
|
||||
void deallocate(void *pointer) override {
|
||||
// ArduinoJson's Allocator interface doesn't provide the size parameter in deallocate.
|
||||
// RAMAllocator::deallocate() requires the size, which we don't have access to here.
|
||||
// RAMAllocator::deallocate implementation just calls free() regardless of whether
|
||||
// the memory was allocated with heap_caps_malloc or malloc.
|
||||
// This is safe because ESP-IDF's heap implementation internally tracks the memory region
|
||||
// and routes free() to the appropriate heap.
|
||||
free(pointer); // NOLINT(cppcoreguidelines-owning-memory,cppcoreguidelines-no-malloc)
|
||||
}
|
||||
|
||||
void *reallocate(void *ptr, size_t new_size) override {
|
||||
return this->allocator_.reallocate(static_cast<uint8_t *>(ptr), new_size);
|
||||
}
|
||||
|
||||
protected:
|
||||
RAMAllocator<uint8_t> allocator_{RAMAllocator<uint8_t>(RAMAllocator<uint8_t>::NONE)};
|
||||
};
|
||||
|
||||
std::string build_json(const json_build_t &f) {
|
||||
// Here we are allocating up to 5kb of memory,
|
||||
// with the heap size minus 2kb to be safe if less than 5kb
|
||||
// as we can not have a true dynamic sized document.
|
||||
// The excess memory is freed below with `shrinkToFit()`
|
||||
auto free_heap = ALLOCATOR.get_max_free_block_size();
|
||||
size_t request_size = std::min(free_heap, (size_t) 512);
|
||||
while (true) {
|
||||
ESP_LOGV(TAG, "Attempting to allocate %zu bytes for JSON serialization", request_size);
|
||||
DynamicJsonDocument json_document(request_size);
|
||||
if (json_document.capacity() == 0) {
|
||||
ESP_LOGE(TAG, "Could not allocate memory for document! Requested %zu bytes, largest free heap block: %zu bytes",
|
||||
request_size, free_heap);
|
||||
// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
auto doc_allocator = SpiRamAllocator();
|
||||
JsonDocument json_document(&doc_allocator);
|
||||
if (json_document.overflowed()) {
|
||||
ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
|
||||
return "{}";
|
||||
}
|
||||
JsonObject root = json_document.to<JsonObject>();
|
||||
f(root);
|
||||
if (json_document.overflowed()) {
|
||||
if (request_size == free_heap) {
|
||||
ESP_LOGE(TAG, "Could not allocate memory for document! Overflowed largest free heap block: %zu bytes",
|
||||
free_heap);
|
||||
ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
|
||||
return "{}";
|
||||
}
|
||||
request_size = std::min(request_size * 2, free_heap);
|
||||
continue;
|
||||
}
|
||||
json_document.shrinkToFit();
|
||||
ESP_LOGV(TAG, "Size after shrink %zu bytes", json_document.capacity());
|
||||
std::string output;
|
||||
serializeJson(json_document, output);
|
||||
return output;
|
||||
}
|
||||
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
|
||||
}
|
||||
|
||||
bool parse_json(const std::string &data, const json_parse_t &f) {
|
||||
// Here we are allocating 1.5 times the data size,
|
||||
// with the heap size minus 2kb to be safe if less than that
|
||||
// as we can not have a true dynamic sized document.
|
||||
// The excess memory is freed below with `shrinkToFit()`
|
||||
auto free_heap = ALLOCATOR.get_max_free_block_size();
|
||||
size_t request_size = std::min(free_heap, (size_t) (data.size() * 1.5));
|
||||
while (true) {
|
||||
DynamicJsonDocument json_document(request_size);
|
||||
if (json_document.capacity() == 0) {
|
||||
ESP_LOGE(TAG, "Could not allocate memory for document! Requested %zu bytes, free heap: %zu", request_size,
|
||||
free_heap);
|
||||
// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
auto doc_allocator = SpiRamAllocator();
|
||||
JsonDocument json_document(&doc_allocator);
|
||||
if (json_document.overflowed()) {
|
||||
ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
|
||||
return false;
|
||||
}
|
||||
DeserializationError err = deserializeJson(json_document, data);
|
||||
json_document.shrinkToFit();
|
||||
|
||||
JsonObject root = json_document.as<JsonObject>();
|
||||
|
||||
if (err == DeserializationError::Ok) {
|
||||
return f(root);
|
||||
} else if (err == DeserializationError::NoMemory) {
|
||||
if (request_size * 2 >= free_heap) {
|
||||
ESP_LOGE(TAG, "Can not allocate more memory for deserialization. Consider making source string smaller");
|
||||
return false;
|
||||
}
|
||||
ESP_LOGV(TAG, "Increasing memory allocation.");
|
||||
request_size *= 2;
|
||||
continue;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Parse error: %s", err.c_str());
|
||||
return false;
|
||||
}
|
||||
};
|
||||
return false;
|
||||
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
|
||||
}
|
||||
|
||||
} // namespace json
|
||||
|
@@ -9,6 +9,7 @@ namespace light {
|
||||
// See https://www.home-assistant.io/integrations/light.mqtt/#json-schema for documentation on the schema
|
||||
|
||||
void LightJSONSchema::dump_json(LightState &state, JsonObject root) {
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
if (state.supports_effects())
|
||||
root["effect"] = state.get_effect_name();
|
||||
|
||||
@@ -52,7 +53,7 @@ void LightJSONSchema::dump_json(LightState &state, JsonObject root) {
|
||||
if (values.get_color_mode() & ColorCapability::BRIGHTNESS)
|
||||
root["brightness"] = uint8_t(values.get_brightness() * 255);
|
||||
|
||||
JsonObject color = root.createNestedObject("color");
|
||||
JsonObject color = root["color"].to<JsonObject>();
|
||||
if (values.get_color_mode() & ColorCapability::RGB) {
|
||||
color["r"] = uint8_t(values.get_color_brightness() * values.get_red() * 255);
|
||||
color["g"] = uint8_t(values.get_color_brightness() * values.get_green() * 255);
|
||||
@@ -73,7 +74,7 @@ void LightJSONSchema::dump_json(LightState &state, JsonObject root) {
|
||||
}
|
||||
|
||||
void LightJSONSchema::parse_color_json(LightState &state, LightCall &call, JsonObject root) {
|
||||
if (root.containsKey("state")) {
|
||||
if (root["state"].is<const char *>()) {
|
||||
auto val = parse_on_off(root["state"]);
|
||||
switch (val) {
|
||||
case PARSE_ON:
|
||||
@@ -90,40 +91,40 @@ void LightJSONSchema::parse_color_json(LightState &state, LightCall &call, JsonO
|
||||
}
|
||||
}
|
||||
|
||||
if (root.containsKey("brightness")) {
|
||||
if (root["brightness"].is<uint8_t>()) {
|
||||
call.set_brightness(float(root["brightness"]) / 255.0f);
|
||||
}
|
||||
|
||||
if (root.containsKey("color")) {
|
||||
if (root["color"].is<JsonObject>()) {
|
||||
JsonObject color = root["color"];
|
||||
// HA also encodes brightness information in the r, g, b values, so extract that and set it as color brightness.
|
||||
float max_rgb = 0.0f;
|
||||
if (color.containsKey("r")) {
|
||||
if (color["r"].is<uint8_t>()) {
|
||||
float r = float(color["r"]) / 255.0f;
|
||||
max_rgb = fmaxf(max_rgb, r);
|
||||
call.set_red(r);
|
||||
}
|
||||
if (color.containsKey("g")) {
|
||||
if (color["g"].is<uint8_t>()) {
|
||||
float g = float(color["g"]) / 255.0f;
|
||||
max_rgb = fmaxf(max_rgb, g);
|
||||
call.set_green(g);
|
||||
}
|
||||
if (color.containsKey("b")) {
|
||||
if (color["b"].is<uint8_t>()) {
|
||||
float b = float(color["b"]) / 255.0f;
|
||||
max_rgb = fmaxf(max_rgb, b);
|
||||
call.set_blue(b);
|
||||
}
|
||||
if (color.containsKey("r") || color.containsKey("g") || color.containsKey("b")) {
|
||||
if (color["r"].is<uint8_t>() || color["g"].is<uint8_t>() || color["b"].is<uint8_t>()) {
|
||||
call.set_color_brightness(max_rgb);
|
||||
}
|
||||
|
||||
if (color.containsKey("c")) {
|
||||
if (color["c"].is<uint8_t>()) {
|
||||
call.set_cold_white(float(color["c"]) / 255.0f);
|
||||
}
|
||||
if (color.containsKey("w")) {
|
||||
if (color["w"].is<uint8_t>()) {
|
||||
// the HA scheme is ambiguous here, the same key is used for white channel in RGBW and warm
|
||||
// white channel in RGBWW.
|
||||
if (color.containsKey("c")) {
|
||||
if (color["c"].is<uint8_t>()) {
|
||||
call.set_warm_white(float(color["w"]) / 255.0f);
|
||||
} else {
|
||||
call.set_white(float(color["w"]) / 255.0f);
|
||||
@@ -131,11 +132,11 @@ void LightJSONSchema::parse_color_json(LightState &state, LightCall &call, JsonO
|
||||
}
|
||||
}
|
||||
|
||||
if (root.containsKey("white_value")) { // legacy API
|
||||
if (root["white_value"].is<uint8_t>()) { // legacy API
|
||||
call.set_white(float(root["white_value"]) / 255.0f);
|
||||
}
|
||||
|
||||
if (root.containsKey("color_temp")) {
|
||||
if (root["color_temp"].is<uint16_t>()) {
|
||||
call.set_color_temperature(float(root["color_temp"]));
|
||||
}
|
||||
}
|
||||
@@ -143,17 +144,17 @@ void LightJSONSchema::parse_color_json(LightState &state, LightCall &call, JsonO
|
||||
void LightJSONSchema::parse_json(LightState &state, LightCall &call, JsonObject root) {
|
||||
LightJSONSchema::parse_color_json(state, call, root);
|
||||
|
||||
if (root.containsKey("flash")) {
|
||||
if (root["flash"].is<uint32_t>()) {
|
||||
auto length = uint32_t(float(root["flash"]) * 1000);
|
||||
call.set_flash_length(length);
|
||||
}
|
||||
|
||||
if (root.containsKey("transition")) {
|
||||
if (root["transition"].is<uint16_t>()) {
|
||||
auto length = uint32_t(float(root["transition"]) * 1000);
|
||||
call.set_transition_length(length);
|
||||
}
|
||||
|
||||
if (root.containsKey("effect")) {
|
||||
if (root["effect"].is<const char *>()) {
|
||||
const char *effect = root["effect"];
|
||||
call.set_effect(effect);
|
||||
}
|
||||
|
@@ -21,6 +21,11 @@ from esphome.components.libretiny.const import (
|
||||
COMPONENT_LN882X,
|
||||
COMPONENT_RTL87XX,
|
||||
)
|
||||
from esphome.components.zephyr import (
|
||||
zephyr_add_cdc_acm,
|
||||
zephyr_add_overlay,
|
||||
zephyr_add_prj_conf,
|
||||
)
|
||||
from esphome.config_helpers import filter_source_files_from_platform
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
@@ -41,6 +46,7 @@ from esphome.const import (
|
||||
PLATFORM_ESP32,
|
||||
PLATFORM_ESP8266,
|
||||
PLATFORM_LN882X,
|
||||
PLATFORM_NRF52,
|
||||
PLATFORM_RP2040,
|
||||
PLATFORM_RTL87XX,
|
||||
PlatformFramework,
|
||||
@@ -115,6 +121,8 @@ ESP_ARDUINO_UNSUPPORTED_USB_UARTS = [USB_SERIAL_JTAG]
|
||||
|
||||
UART_SELECTION_RP2040 = [USB_CDC, UART0, UART1]
|
||||
|
||||
UART_SELECTION_NRF52 = [USB_CDC, UART0]
|
||||
|
||||
HARDWARE_UART_TO_UART_SELECTION = {
|
||||
UART0: logger_ns.UART_SELECTION_UART0,
|
||||
UART0_SWAP: logger_ns.UART_SELECTION_UART0_SWAP,
|
||||
@@ -167,6 +175,8 @@ def uart_selection(value):
|
||||
return cv.one_of(*UART_SELECTION_LIBRETINY[component], upper=True)(value)
|
||||
if CORE.is_host:
|
||||
raise cv.Invalid("Uart selection not valid for host platform")
|
||||
if CORE.is_nrf52:
|
||||
return cv.one_of(*UART_SELECTION_NRF52, upper=True)(value)
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@@ -186,6 +196,7 @@ LoggerMessageTrigger = logger_ns.class_(
|
||||
automation.Trigger.template(cg.int_, cg.const_char_ptr, cg.const_char_ptr),
|
||||
)
|
||||
|
||||
|
||||
CONF_ESP8266_STORE_LOG_STRINGS_IN_FLASH = "esp8266_store_log_strings_in_flash"
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
cv.Schema(
|
||||
@@ -227,6 +238,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
bk72xx=DEFAULT,
|
||||
ln882x=DEFAULT,
|
||||
rtl87xx=DEFAULT,
|
||||
nrf52=USB_CDC,
|
||||
): cv.All(
|
||||
cv.only_on(
|
||||
[
|
||||
@@ -236,6 +248,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
PLATFORM_BK72XX,
|
||||
PLATFORM_LN882X,
|
||||
PLATFORM_RTL87XX,
|
||||
PLATFORM_NRF52,
|
||||
]
|
||||
),
|
||||
uart_selection,
|
||||
@@ -358,6 +371,15 @@ async def to_code(config):
|
||||
except cv.Invalid:
|
||||
pass
|
||||
|
||||
if CORE.using_zephyr:
|
||||
if config[CONF_HARDWARE_UART] == UART0:
|
||||
zephyr_add_overlay("""&uart0 { status = "okay";};""")
|
||||
if config[CONF_HARDWARE_UART] == UART1:
|
||||
zephyr_add_overlay("""&uart1 { status = "okay";};""")
|
||||
if config[CONF_HARDWARE_UART] == USB_CDC:
|
||||
zephyr_add_prj_conf("UART_LINE_CTRL", True)
|
||||
zephyr_add_cdc_acm(config, 0)
|
||||
|
||||
# Register at end for safe mode
|
||||
await cg.register_component(log, config)
|
||||
|
||||
@@ -462,6 +484,7 @@ FILTER_SOURCE_FILES = filter_source_files_from_platform(
|
||||
PlatformFramework.RTL87XX_ARDUINO,
|
||||
PlatformFramework.LN882X_ARDUINO,
|
||||
},
|
||||
"logger_zephyr.cpp": {PlatformFramework.NRF52_ZEPHYR},
|
||||
"task_log_buffer.cpp": {
|
||||
PlatformFramework.ESP32_ARDUINO,
|
||||
PlatformFramework.ESP32_IDF,
|
||||
|
@@ -4,9 +4,9 @@
|
||||
#include <memory> // For unique_ptr
|
||||
#endif
|
||||
|
||||
#include "esphome/core/application.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/application.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace logger {
|
||||
@@ -160,6 +160,8 @@ Logger::Logger(uint32_t baud_rate, size_t tx_buffer_size) : baud_rate_(baud_rate
|
||||
this->tx_buffer_ = new char[this->tx_buffer_size_ + 1]; // NOLINT
|
||||
#if defined(USE_ESP32) || defined(USE_LIBRETINY)
|
||||
this->main_task_ = xTaskGetCurrentTaskHandle();
|
||||
#elif defined(USE_ZEPHYR)
|
||||
this->main_task_ = k_current_get();
|
||||
#endif
|
||||
}
|
||||
#ifdef USE_ESPHOME_TASK_LOG_BUFFER
|
||||
@@ -172,6 +174,7 @@ void Logger::init_log_buffer(size_t total_buffer_size) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef USE_ZEPHYR
|
||||
#if defined(USE_LOGGER_USB_CDC) || defined(USE_ESP32)
|
||||
void Logger::loop() {
|
||||
#if defined(USE_LOGGER_USB_CDC) && defined(USE_ARDUINO)
|
||||
@@ -185,8 +188,13 @@ void Logger::loop() {
|
||||
}
|
||||
opened = !opened;
|
||||
}
|
||||
#endif
|
||||
this->process_messages_();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void Logger::process_messages_() {
|
||||
#ifdef USE_ESPHOME_TASK_LOG_BUFFER
|
||||
// Process any buffered messages when available
|
||||
if (this->log_buffer_->has_messages()) {
|
||||
@@ -227,12 +235,11 @@ void Logger::loop() {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void Logger::set_baud_rate(uint32_t baud_rate) { this->baud_rate_ = baud_rate; }
|
||||
void Logger::set_log_level(const std::string &tag, uint8_t log_level) { this->log_levels_[tag] = log_level; }
|
||||
|
||||
#if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040) || defined(USE_LIBRETINY)
|
||||
#if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040) || defined(USE_LIBRETINY) || defined(USE_ZEPHYR)
|
||||
UARTSelection Logger::get_uart() const { return this->uart_; }
|
||||
#endif
|
||||
|
||||
|
@@ -29,6 +29,11 @@
|
||||
#include <driver/uart.h>
|
||||
#endif // USE_ESP_IDF
|
||||
|
||||
#ifdef USE_ZEPHYR
|
||||
#include <zephyr/kernel.h>
|
||||
struct device;
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
|
||||
namespace logger {
|
||||
@@ -56,7 +61,7 @@ static const char *const LOG_LEVEL_LETTERS[] = {
|
||||
"VV", // VERY_VERBOSE
|
||||
};
|
||||
|
||||
#if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040) || defined(USE_LIBRETINY)
|
||||
#if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040) || defined(USE_LIBRETINY) || defined(USE_ZEPHYR)
|
||||
/** Enum for logging UART selection
|
||||
*
|
||||
* Advanced configuration (pin selection, etc) is not supported.
|
||||
@@ -82,7 +87,7 @@ enum UARTSelection : uint8_t {
|
||||
UART_SELECTION_UART0_SWAP,
|
||||
#endif // USE_ESP8266
|
||||
};
|
||||
#endif // USE_ESP32 || USE_ESP8266 || USE_RP2040 || USE_LIBRETINY
|
||||
#endif // USE_ESP32 || USE_ESP8266 || USE_RP2040 || USE_LIBRETINY || USE_ZEPHYR
|
||||
|
||||
/**
|
||||
* @brief Logger component for all ESPHome logging.
|
||||
@@ -107,7 +112,7 @@ class Logger : public Component {
|
||||
#ifdef USE_ESPHOME_TASK_LOG_BUFFER
|
||||
void init_log_buffer(size_t total_buffer_size);
|
||||
#endif
|
||||
#if defined(USE_LOGGER_USB_CDC) || defined(USE_ESP32)
|
||||
#if defined(USE_LOGGER_USB_CDC) || defined(USE_ESP32) || defined(USE_ZEPHYR)
|
||||
void loop() override;
|
||||
#endif
|
||||
/// Manually set the baud rate for serial, set to 0 to disable.
|
||||
@@ -122,7 +127,7 @@ class Logger : public Component {
|
||||
#ifdef USE_ESP32
|
||||
void create_pthread_key() { pthread_key_create(&log_recursion_key_, nullptr); }
|
||||
#endif
|
||||
#if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040) || defined(USE_LIBRETINY)
|
||||
#if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040) || defined(USE_LIBRETINY) || defined(USE_ZEPHYR)
|
||||
void set_uart_selection(UARTSelection uart_selection) { uart_ = uart_selection; }
|
||||
/// Get the UART used by the logger.
|
||||
UARTSelection get_uart() const;
|
||||
@@ -157,6 +162,7 @@ class Logger : public Component {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void process_messages_();
|
||||
void write_msg_(const char *msg);
|
||||
|
||||
// Format a log message with printf-style arguments and write it to a buffer with header, footer, and null terminator
|
||||
@@ -164,7 +170,7 @@ class Logger : public Component {
|
||||
inline void HOT format_log_to_buffer_with_terminator_(uint8_t level, const char *tag, int line, const char *format,
|
||||
va_list args, char *buffer, uint16_t *buffer_at,
|
||||
uint16_t buffer_size) {
|
||||
#if defined(USE_ESP32) || defined(USE_LIBRETINY)
|
||||
#if defined(USE_ESP32) || defined(USE_LIBRETINY) || defined(USE_ZEPHYR)
|
||||
this->write_header_to_buffer_(level, tag, line, this->get_thread_name_(), buffer, buffer_at, buffer_size);
|
||||
#else
|
||||
this->write_header_to_buffer_(level, tag, line, nullptr, buffer, buffer_at, buffer_size);
|
||||
@@ -231,7 +237,10 @@ class Logger : public Component {
|
||||
#ifdef USE_ARDUINO
|
||||
Stream *hw_serial_{nullptr};
|
||||
#endif
|
||||
#if defined(USE_ESP32) || defined(USE_LIBRETINY)
|
||||
#if defined(USE_ZEPHYR)
|
||||
const device *uart_dev_{nullptr};
|
||||
#endif
|
||||
#if defined(USE_ESP32) || defined(USE_LIBRETINY) || defined(USE_ZEPHYR)
|
||||
void *main_task_ = nullptr; // Only used for thread name identification
|
||||
#endif
|
||||
#ifdef USE_ESP32
|
||||
@@ -256,7 +265,7 @@ class Logger : public Component {
|
||||
uint16_t tx_buffer_at_{0};
|
||||
uint16_t tx_buffer_size_{0};
|
||||
uint8_t current_level_{ESPHOME_LOG_LEVEL_VERY_VERBOSE};
|
||||
#if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040)
|
||||
#if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040) || defined(USE_ZEPHYR)
|
||||
UARTSelection uart_{UART_SELECTION_UART0};
|
||||
#endif
|
||||
#ifdef USE_LIBRETINY
|
||||
@@ -268,9 +277,13 @@ class Logger : public Component {
|
||||
bool global_recursion_guard_{false}; // Simple global recursion guard for single-task platforms
|
||||
#endif
|
||||
|
||||
#if defined(USE_ESP32) || defined(USE_LIBRETINY)
|
||||
#if defined(USE_ESP32) || defined(USE_LIBRETINY) || defined(USE_ZEPHYR)
|
||||
const char *HOT get_thread_name_() {
|
||||
#ifdef USE_ZEPHYR
|
||||
k_tid_t current_task = k_current_get();
|
||||
#else
|
||||
TaskHandle_t current_task = xTaskGetCurrentTaskHandle();
|
||||
#endif
|
||||
if (current_task == main_task_) {
|
||||
return nullptr; // Main task
|
||||
} else {
|
||||
@@ -278,6 +291,8 @@ class Logger : public Component {
|
||||
return pcTaskGetName(current_task);
|
||||
#elif defined(USE_LIBRETINY)
|
||||
return pcTaskGetTaskName(current_task);
|
||||
#elif defined(USE_ZEPHYR)
|
||||
return k_thread_name_get(current_task);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -319,7 +334,7 @@ class Logger : public Component {
|
||||
const char *color = esphome::logger::LOG_LEVEL_COLORS[level];
|
||||
const char *letter = esphome::logger::LOG_LEVEL_LETTERS[level];
|
||||
|
||||
#if defined(USE_ESP32) || defined(USE_LIBRETINY)
|
||||
#if defined(USE_ESP32) || defined(USE_LIBRETINY) || defined(USE_ZEPHYR)
|
||||
if (thread_name != nullptr) {
|
||||
// Non-main task with thread name
|
||||
this->printf_to_buffer_(buffer, buffer_at, buffer_size, "%s[%s][%s:%03u]%s[%s]%s: ", color, letter, tag, line,
|
||||
|
88
esphome/components/logger/logger_zephyr.cpp
Normal file
88
esphome/components/logger/logger_zephyr.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#ifdef USE_ZEPHYR
|
||||
|
||||
#include "esphome/core/application.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/uart.h>
|
||||
#include <zephyr/usb/usb_device.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace logger {
|
||||
|
||||
static const char *const TAG = "logger";
|
||||
|
||||
void Logger::loop() {
|
||||
#ifdef USE_LOGGER_USB_CDC
|
||||
if (this->uart_ != UART_SELECTION_USB_CDC || nullptr == this->uart_dev_) {
|
||||
return;
|
||||
}
|
||||
static bool opened = false;
|
||||
uint32_t dtr = 0;
|
||||
uart_line_ctrl_get(this->uart_dev_, UART_LINE_CTRL_DTR, &dtr);
|
||||
|
||||
/* Poll if the DTR flag was set, optional */
|
||||
if (opened == dtr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!opened) {
|
||||
App.schedule_dump_config();
|
||||
}
|
||||
opened = !opened;
|
||||
#endif
|
||||
this->process_messages_();
|
||||
}
|
||||
|
||||
void Logger::pre_setup() {
|
||||
if (this->baud_rate_ > 0) {
|
||||
static const struct device *uart_dev = nullptr;
|
||||
switch (this->uart_) {
|
||||
case UART_SELECTION_UART0:
|
||||
uart_dev = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(uart0));
|
||||
break;
|
||||
case UART_SELECTION_UART1:
|
||||
uart_dev = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(uart1));
|
||||
break;
|
||||
#ifdef USE_LOGGER_USB_CDC
|
||||
case UART_SELECTION_USB_CDC:
|
||||
uart_dev = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(cdc_acm_uart0));
|
||||
if (device_is_ready(uart_dev)) {
|
||||
usb_enable(nullptr);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
if (!device_is_ready(uart_dev)) {
|
||||
ESP_LOGE(TAG, "%s is not ready.", get_uart_selection_());
|
||||
} else {
|
||||
this->uart_dev_ = uart_dev;
|
||||
}
|
||||
}
|
||||
global_logger = this;
|
||||
ESP_LOGI(TAG, "Log initialized");
|
||||
}
|
||||
|
||||
void HOT Logger::write_msg_(const char *msg) {
|
||||
#ifdef CONFIG_PRINTK
|
||||
printk("%s\n", msg);
|
||||
#endif
|
||||
if (nullptr == this->uart_dev_) {
|
||||
return;
|
||||
}
|
||||
while (*msg) {
|
||||
uart_poll_out(this->uart_dev_, *msg);
|
||||
++msg;
|
||||
}
|
||||
uart_poll_out(this->uart_dev_, '\n');
|
||||
}
|
||||
|
||||
const char *const UART_SELECTIONS[] = {"UART0", "UART1", "USB_CDC"};
|
||||
|
||||
const char *Logger::get_uart_selection_() { return UART_SELECTIONS[this->uart_]; }
|
||||
|
||||
} // namespace logger
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
@@ -76,6 +76,7 @@ async def theme_to_code(config):
|
||||
for w_name, style in theme.items():
|
||||
# Work around Python 3.10 bug with nested async comprehensions
|
||||
# With Python 3.11 this could be simplified
|
||||
# TODO: Now that we require Python 3.11+, this can be updated to use nested comprehensions
|
||||
styles = {}
|
||||
for part, states in collect_parts(style).items():
|
||||
styles[part] = {
|
||||
|
@@ -2,10 +2,8 @@ CODEOWNERS = ["@clydebarrow"]
|
||||
|
||||
DOMAIN = "mipi_spi"
|
||||
|
||||
CONF_DRAW_FROM_ORIGIN = "draw_from_origin"
|
||||
CONF_SPI_16 = "spi_16"
|
||||
CONF_PIXEL_MODE = "pixel_mode"
|
||||
CONF_COLOR_DEPTH = "color_depth"
|
||||
CONF_BUS_MODE = "bus_mode"
|
||||
CONF_USE_AXIS_FLIPS = "use_axis_flips"
|
||||
CONF_NATIVE_WIDTH = "native_width"
|
||||
|
@@ -3,11 +3,18 @@ import logging
|
||||
from esphome import pins
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import display, spi
|
||||
from esphome.components.const import (
|
||||
CONF_BYTE_ORDER,
|
||||
CONF_COLOR_DEPTH,
|
||||
CONF_DRAW_ROUNDING,
|
||||
)
|
||||
from esphome.components.display import CONF_SHOW_TEST_CARD, DISPLAY_ROTATIONS
|
||||
from esphome.components.spi import TYPE_OCTAL, TYPE_QUAD, TYPE_SINGLE
|
||||
import esphome.config_validation as cv
|
||||
from esphome.config_validation import ALLOW_EXTRA
|
||||
from esphome.const import (
|
||||
CONF_BRIGHTNESS,
|
||||
CONF_BUFFER_SIZE,
|
||||
CONF_COLOR_ORDER,
|
||||
CONF_CS_PIN,
|
||||
CONF_DATA_RATE,
|
||||
@@ -24,19 +31,19 @@ from esphome.const import (
|
||||
CONF_MODEL,
|
||||
CONF_OFFSET_HEIGHT,
|
||||
CONF_OFFSET_WIDTH,
|
||||
CONF_PAGES,
|
||||
CONF_RESET_PIN,
|
||||
CONF_ROTATION,
|
||||
CONF_SWAP_XY,
|
||||
CONF_TRANSFORM,
|
||||
CONF_WIDTH,
|
||||
)
|
||||
from esphome.core import TimePeriod
|
||||
from esphome.core import CORE, TimePeriod
|
||||
from esphome.cpp_generator import TemplateArguments
|
||||
from esphome.final_validate import full_config
|
||||
|
||||
from ..const import CONF_DRAW_ROUNDING
|
||||
from ..lvgl.defines import CONF_COLOR_DEPTH
|
||||
from . import (
|
||||
CONF_BUS_MODE,
|
||||
CONF_DRAW_FROM_ORIGIN,
|
||||
CONF_NATIVE_HEIGHT,
|
||||
CONF_NATIVE_WIDTH,
|
||||
CONF_PIXEL_MODE,
|
||||
@@ -55,6 +62,7 @@ from .models import (
|
||||
MADCTL_XFLIP,
|
||||
MADCTL_YFLIP,
|
||||
DriverChip,
|
||||
adafruit,
|
||||
amoled,
|
||||
cyd,
|
||||
ili,
|
||||
@@ -69,43 +77,112 @@ DEPENDENCIES = ["spi"]
|
||||
|
||||
LOGGER = logging.getLogger(DOMAIN)
|
||||
mipi_spi_ns = cg.esphome_ns.namespace("mipi_spi")
|
||||
MipiSpi = mipi_spi_ns.class_(
|
||||
"MipiSpi", display.Display, display.DisplayBuffer, cg.Component, spi.SPIDevice
|
||||
MipiSpi = mipi_spi_ns.class_("MipiSpi", display.Display, cg.Component, spi.SPIDevice)
|
||||
MipiSpiBuffer = mipi_spi_ns.class_(
|
||||
"MipiSpiBuffer", MipiSpi, display.Display, cg.Component, spi.SPIDevice
|
||||
)
|
||||
ColorOrder = display.display_ns.enum("ColorMode")
|
||||
ColorBitness = display.display_ns.enum("ColorBitness")
|
||||
Model = mipi_spi_ns.enum("Model")
|
||||
|
||||
PixelMode = mipi_spi_ns.enum("PixelMode")
|
||||
BusType = mipi_spi_ns.enum("BusType")
|
||||
|
||||
COLOR_ORDERS = {
|
||||
MODE_RGB: ColorOrder.COLOR_ORDER_RGB,
|
||||
MODE_BGR: ColorOrder.COLOR_ORDER_BGR,
|
||||
}
|
||||
|
||||
COLOR_DEPTHS = {
|
||||
8: ColorBitness.COLOR_BITNESS_332,
|
||||
16: ColorBitness.COLOR_BITNESS_565,
|
||||
8: PixelMode.PIXEL_MODE_8,
|
||||
16: PixelMode.PIXEL_MODE_16,
|
||||
18: PixelMode.PIXEL_MODE_18,
|
||||
}
|
||||
|
||||
DATA_PIN_SCHEMA = pins.internal_gpio_output_pin_schema
|
||||
|
||||
BusTypes = {
|
||||
TYPE_SINGLE: BusType.BUS_TYPE_SINGLE,
|
||||
TYPE_QUAD: BusType.BUS_TYPE_QUAD,
|
||||
TYPE_OCTAL: BusType.BUS_TYPE_OCTAL,
|
||||
}
|
||||
|
||||
DriverChip("CUSTOM", initsequence={})
|
||||
DriverChip("CUSTOM")
|
||||
|
||||
MODELS = DriverChip.models
|
||||
# These statements are noops, but serve to suppress linting of side-effect-only imports
|
||||
for _ in (ili, jc, amoled, lilygo, lanbon, cyd, waveshare):
|
||||
# This loop is a noop, but suppresses linting of side-effect-only imports
|
||||
for _ in (ili, jc, amoled, lilygo, lanbon, cyd, waveshare, adafruit):
|
||||
pass
|
||||
|
||||
PixelMode = mipi_spi_ns.enum("PixelMode")
|
||||
|
||||
PIXEL_MODE_18BIT = "18bit"
|
||||
PIXEL_MODE_16BIT = "16bit"
|
||||
DISPLAY_18BIT = "18bit"
|
||||
DISPLAY_16BIT = "16bit"
|
||||
|
||||
PIXEL_MODES = {
|
||||
PIXEL_MODE_16BIT: 0x55,
|
||||
PIXEL_MODE_18BIT: 0x66,
|
||||
DISPLAY_PIXEL_MODES = {
|
||||
DISPLAY_16BIT: (0x55, PixelMode.PIXEL_MODE_16),
|
||||
DISPLAY_18BIT: (0x66, PixelMode.PIXEL_MODE_18),
|
||||
}
|
||||
|
||||
|
||||
def get_dimensions(config):
|
||||
if CONF_DIMENSIONS in config:
|
||||
# Explicit dimensions, just use as is
|
||||
dimensions = config[CONF_DIMENSIONS]
|
||||
if isinstance(dimensions, dict):
|
||||
width = dimensions[CONF_WIDTH]
|
||||
height = dimensions[CONF_HEIGHT]
|
||||
offset_width = dimensions[CONF_OFFSET_WIDTH]
|
||||
offset_height = dimensions[CONF_OFFSET_HEIGHT]
|
||||
return width, height, offset_width, offset_height
|
||||
(width, height) = dimensions
|
||||
return width, height, 0, 0
|
||||
|
||||
# Default dimensions, use model defaults
|
||||
transform = get_transform(config)
|
||||
|
||||
model = MODELS[config[CONF_MODEL]]
|
||||
width = model.get_default(CONF_WIDTH)
|
||||
height = model.get_default(CONF_HEIGHT)
|
||||
offset_width = model.get_default(CONF_OFFSET_WIDTH, 0)
|
||||
offset_height = model.get_default(CONF_OFFSET_HEIGHT, 0)
|
||||
|
||||
# if mirroring axes and there are offsets, also mirror the offsets to cater for situations where
|
||||
# the offset is asymmetric
|
||||
if transform[CONF_MIRROR_X]:
|
||||
native_width = model.get_default(CONF_NATIVE_WIDTH, width + offset_width * 2)
|
||||
offset_width = native_width - width - offset_width
|
||||
if transform[CONF_MIRROR_Y]:
|
||||
native_height = model.get_default(
|
||||
CONF_NATIVE_HEIGHT, height + offset_height * 2
|
||||
)
|
||||
offset_height = native_height - height - offset_height
|
||||
# Swap default dimensions if swap_xy is set
|
||||
if transform[CONF_SWAP_XY] is True:
|
||||
width, height = height, width
|
||||
offset_height, offset_width = offset_width, offset_height
|
||||
return width, height, offset_width, offset_height
|
||||
|
||||
|
||||
def denominator(config):
|
||||
"""
|
||||
Calculate the best denominator for a buffer size fraction.
|
||||
The denominator must be a number between 2 and 16 that divides the display height evenly,
|
||||
and the fraction represented by the denominator must be less than or equal to the given fraction.
|
||||
:config: The configuration dictionary containing the buffer size fraction and display dimensions
|
||||
:return: The denominator to use for the buffer size fraction
|
||||
"""
|
||||
frac = config.get(CONF_BUFFER_SIZE)
|
||||
if frac is None or frac > 0.75:
|
||||
return 1
|
||||
height, _width, _offset_width, _offset_height = get_dimensions(config)
|
||||
try:
|
||||
return next(x for x in range(2, 17) if frac >= 1 / x and height % x == 0)
|
||||
except StopIteration:
|
||||
raise cv.Invalid(
|
||||
f"Buffer size fraction {frac} is not compatible with display height {height}"
|
||||
) from StopIteration
|
||||
|
||||
|
||||
def validate_dimension(rounding):
|
||||
def validator(value):
|
||||
value = cv.positive_int(value)
|
||||
@@ -158,25 +235,27 @@ def dimension_schema(rounding):
|
||||
)
|
||||
|
||||
|
||||
def model_schema(bus_mode, model: DriverChip, swapsies: bool):
|
||||
def swap_xy_schema(model):
|
||||
uses_swap = model.get_default(CONF_SWAP_XY, None) != cv.UNDEFINED
|
||||
|
||||
def validator(value):
|
||||
if value:
|
||||
raise cv.Invalid("Axis swapping not supported by this model")
|
||||
return cv.boolean(value)
|
||||
|
||||
if uses_swap:
|
||||
return {cv.Required(CONF_SWAP_XY): cv.boolean}
|
||||
return {cv.Optional(CONF_SWAP_XY, default=False): validator}
|
||||
|
||||
|
||||
def model_schema(config):
|
||||
model = MODELS[config[CONF_MODEL]]
|
||||
bus_mode = config.get(CONF_BUS_MODE, model.modes[0])
|
||||
transform = cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_MIRROR_X): cv.boolean,
|
||||
cv.Required(CONF_MIRROR_Y): cv.boolean,
|
||||
}
|
||||
)
|
||||
if model.get_default(CONF_SWAP_XY, False) == cv.UNDEFINED:
|
||||
transform = transform.extend(
|
||||
{
|
||||
cv.Optional(CONF_SWAP_XY): cv.invalid(
|
||||
"Axis swapping not supported by this model"
|
||||
)
|
||||
}
|
||||
)
|
||||
else:
|
||||
transform = transform.extend(
|
||||
{
|
||||
cv.Required(CONF_SWAP_XY): cv.boolean,
|
||||
**swap_xy_schema(model),
|
||||
}
|
||||
)
|
||||
# CUSTOM model will need to provide a custom init sequence
|
||||
@@ -185,14 +264,21 @@ def model_schema(bus_mode, model: DriverChip, swapsies: bool):
|
||||
if model.initsequence is None
|
||||
else cv.Optional(CONF_INIT_SEQUENCE)
|
||||
)
|
||||
# Dimensions are optional if the model has a default width and the transform is not overridden
|
||||
# Dimensions are optional if the model has a default width and the x-y transform is not overridden
|
||||
is_swapped = config.get(CONF_TRANSFORM, {}).get(CONF_SWAP_XY) is True
|
||||
cv_dimensions = (
|
||||
cv.Optional if model.get_default(CONF_WIDTH) and not swapsies else cv.Required
|
||||
cv.Optional if model.get_default(CONF_WIDTH) and not is_swapped else cv.Required
|
||||
)
|
||||
pixel_modes = PIXEL_MODES if bus_mode == TYPE_SINGLE else (PIXEL_MODE_16BIT,)
|
||||
pixel_modes = DISPLAY_PIXEL_MODES if bus_mode == TYPE_SINGLE else (DISPLAY_16BIT,)
|
||||
color_depth = (
|
||||
("16", "8", "16bit", "8bit") if bus_mode == TYPE_SINGLE else ("16", "16bit")
|
||||
)
|
||||
other_options = [
|
||||
CONF_INVERT_COLORS,
|
||||
CONF_USE_AXIS_FLIPS,
|
||||
]
|
||||
if bus_mode == TYPE_SINGLE:
|
||||
other_options.append(CONF_SPI_16)
|
||||
schema = (
|
||||
display.FULL_DISPLAY_SCHEMA.extend(
|
||||
spi.spi_device_schema(
|
||||
@@ -220,11 +306,13 @@ def model_schema(bus_mode, model: DriverChip, swapsies: bool):
|
||||
model.option(CONF_COLOR_ORDER, MODE_BGR): cv.enum(
|
||||
COLOR_ORDERS, upper=True
|
||||
),
|
||||
model.option(CONF_BYTE_ORDER, "big_endian"): cv.one_of(
|
||||
"big_endian", "little_endian", lower=True
|
||||
),
|
||||
model.option(CONF_COLOR_DEPTH, 16): cv.one_of(*color_depth, lower=True),
|
||||
model.option(CONF_DRAW_ROUNDING, 2): power_of_two,
|
||||
model.option(CONF_PIXEL_MODE, PIXEL_MODE_16BIT): cv.Any(
|
||||
cv.one_of(*pixel_modes, lower=True),
|
||||
cv.int_range(0, 255, min_included=True, max_included=True),
|
||||
model.option(CONF_PIXEL_MODE, DISPLAY_16BIT): cv.one_of(
|
||||
*pixel_modes, lower=True
|
||||
),
|
||||
cv.Optional(CONF_TRANSFORM): transform,
|
||||
cv.Optional(CONF_BUS_MODE, default=bus_mode): cv.one_of(
|
||||
@@ -232,19 +320,12 @@ def model_schema(bus_mode, model: DriverChip, swapsies: bool):
|
||||
),
|
||||
cv.Required(CONF_MODEL): cv.one_of(model.name, upper=True),
|
||||
iseqconf: cv.ensure_list(map_sequence),
|
||||
cv.Optional(CONF_BUFFER_SIZE): cv.All(
|
||||
cv.percentage, cv.Range(0.12, 1.0)
|
||||
),
|
||||
}
|
||||
)
|
||||
.extend(
|
||||
{
|
||||
model.option(x): cv.boolean
|
||||
for x in [
|
||||
CONF_DRAW_FROM_ORIGIN,
|
||||
CONF_SPI_16,
|
||||
CONF_INVERT_COLORS,
|
||||
CONF_USE_AXIS_FLIPS,
|
||||
]
|
||||
}
|
||||
)
|
||||
.extend({model.option(x): cv.boolean for x in other_options})
|
||||
)
|
||||
if brightness := model.get_default(CONF_BRIGHTNESS):
|
||||
schema = schema.extend(
|
||||
@@ -259,18 +340,25 @@ def model_schema(bus_mode, model: DriverChip, swapsies: bool):
|
||||
return schema
|
||||
|
||||
|
||||
def rotation_as_transform(model, config):
|
||||
def is_rotation_transformable(config):
|
||||
"""
|
||||
Check if a rotation can be implemented in hardware using the MADCTL register.
|
||||
A rotation of 180 is always possible, 90 and 270 are possible if the model supports swapping X and Y.
|
||||
"""
|
||||
model = MODELS[config[CONF_MODEL]]
|
||||
rotation = config.get(CONF_ROTATION, 0)
|
||||
return rotation and (
|
||||
model.get_default(CONF_SWAP_XY) != cv.UNDEFINED or rotation == 180
|
||||
)
|
||||
|
||||
|
||||
def config_schema(config):
|
||||
def customise_schema(config):
|
||||
"""
|
||||
Create a customised config schema for a specific model and validate the configuration.
|
||||
:param config: The configuration dictionary to validate
|
||||
:return: The validated configuration dictionary
|
||||
:raises cv.Invalid: If the configuration is invalid
|
||||
"""
|
||||
# First get the model and bus mode
|
||||
config = cv.Schema(
|
||||
{
|
||||
@@ -288,29 +376,94 @@ def config_schema(config):
|
||||
extra=ALLOW_EXTRA,
|
||||
)(config)
|
||||
bus_mode = config.get(CONF_BUS_MODE, model.modes[0])
|
||||
swapsies = config.get(CONF_TRANSFORM, {}).get(CONF_SWAP_XY) is True
|
||||
config = model_schema(bus_mode, model, swapsies)(config)
|
||||
config = model_schema(config)(config)
|
||||
# Check for invalid combinations of MADCTL config
|
||||
if init_sequence := config.get(CONF_INIT_SEQUENCE):
|
||||
if MADCTL in [x[0] for x in init_sequence] and CONF_TRANSFORM in config:
|
||||
commands = [x[0] for x in init_sequence]
|
||||
if MADCTL in commands and CONF_TRANSFORM in config:
|
||||
raise cv.Invalid(
|
||||
f"transform is not supported when MADCTL ({MADCTL:#X}) is in the init sequence"
|
||||
)
|
||||
if PIXFMT in commands:
|
||||
raise cv.Invalid(
|
||||
f"PIXFMT ({PIXFMT:#X}) should not be in the init sequence, it will be set automatically"
|
||||
)
|
||||
|
||||
if bus_mode == TYPE_QUAD and CONF_DC_PIN in config:
|
||||
raise cv.Invalid("DC pin is not supported in quad mode")
|
||||
if config[CONF_PIXEL_MODE] == PIXEL_MODE_18BIT and bus_mode != TYPE_SINGLE:
|
||||
raise cv.Invalid("18-bit pixel mode is not supported on a quad or octal bus")
|
||||
if bus_mode != TYPE_QUAD and CONF_DC_PIN not in config:
|
||||
raise cv.Invalid(f"DC pin is required in {bus_mode} mode")
|
||||
denominator(config)
|
||||
return config
|
||||
|
||||
|
||||
CONFIG_SCHEMA = config_schema
|
||||
CONFIG_SCHEMA = customise_schema
|
||||
|
||||
|
||||
def get_transform(model, config):
|
||||
can_transform = rotation_as_transform(model, config)
|
||||
def requires_buffer(config):
|
||||
"""
|
||||
Check if the display configuration requires a buffer. It will do so if any drawing methods are configured.
|
||||
:param config:
|
||||
:return: True if a buffer is required, False otherwise
|
||||
"""
|
||||
return any(
|
||||
config.get(key) for key in (CONF_LAMBDA, CONF_PAGES, CONF_SHOW_TEST_CARD)
|
||||
)
|
||||
|
||||
|
||||
def get_color_depth(config):
|
||||
return int(config[CONF_COLOR_DEPTH].removesuffix("bit"))
|
||||
|
||||
|
||||
def _final_validate(config):
|
||||
global_config = full_config.get()
|
||||
|
||||
from esphome.components.lvgl import DOMAIN as LVGL_DOMAIN
|
||||
|
||||
if not requires_buffer(config) and LVGL_DOMAIN not in global_config:
|
||||
# If no drawing methods are configured, and LVGL is not enabled, show a test card
|
||||
config[CONF_SHOW_TEST_CARD] = True
|
||||
|
||||
if "psram" not in global_config and CONF_BUFFER_SIZE not in config:
|
||||
if not requires_buffer(config):
|
||||
return config # No buffer needed, so no need to set a buffer size
|
||||
# If PSRAM is not enabled, choose a small buffer size by default
|
||||
if not requires_buffer(config):
|
||||
# not our problem.
|
||||
return config
|
||||
color_depth = get_color_depth(config)
|
||||
frac = denominator(config)
|
||||
height, width, _offset_width, _offset_height = get_dimensions(config)
|
||||
|
||||
buffer_size = color_depth // 8 * width * height // frac
|
||||
# Target a buffer size of 20kB
|
||||
fraction = 20000.0 / buffer_size
|
||||
try:
|
||||
config[CONF_BUFFER_SIZE] = 1.0 / next(
|
||||
x for x in range(2, 17) if fraction >= 1 / x and height % x == 0
|
||||
)
|
||||
except StopIteration:
|
||||
# Either the screen is too big, or the height is not divisible by any of the fractions, so use 1.0
|
||||
# PSRAM will be needed.
|
||||
if CORE.is_esp32:
|
||||
raise cv.Invalid(
|
||||
"PSRAM is required for this display"
|
||||
) from StopIteration
|
||||
|
||||
return config
|
||||
|
||||
|
||||
FINAL_VALIDATE_SCHEMA = _final_validate
|
||||
|
||||
|
||||
def get_transform(config):
|
||||
"""
|
||||
Get the transformation configuration for the display.
|
||||
:param config:
|
||||
:return:
|
||||
"""
|
||||
model = MODELS[config[CONF_MODEL]]
|
||||
can_transform = is_rotation_transformable(config)
|
||||
transform = config.get(
|
||||
CONF_TRANSFORM,
|
||||
{
|
||||
@@ -350,16 +503,13 @@ def get_sequence(model, config):
|
||||
sequence = [x if isinstance(x, tuple) else (x,) for x in sequence]
|
||||
commands = [x[0] for x in sequence]
|
||||
# Set pixel format if not already in the custom sequence
|
||||
if PIXFMT not in commands:
|
||||
pixel_mode = config[CONF_PIXEL_MODE]
|
||||
if not isinstance(pixel_mode, int):
|
||||
pixel_mode = PIXEL_MODES[pixel_mode]
|
||||
sequence.append((PIXFMT, pixel_mode))
|
||||
pixel_mode = DISPLAY_PIXEL_MODES[config[CONF_PIXEL_MODE]]
|
||||
sequence.append((PIXFMT, pixel_mode[0]))
|
||||
# Does the chip use the flipping bits for mirroring rather than the reverse order bits?
|
||||
use_flip = config[CONF_USE_AXIS_FLIPS]
|
||||
if MADCTL not in commands:
|
||||
madctl = 0
|
||||
transform = get_transform(model, config)
|
||||
transform = get_transform(config)
|
||||
if transform.get(CONF_TRANSFORM):
|
||||
LOGGER.info("Using hardware transform to implement rotation")
|
||||
if transform.get(CONF_MIRROR_X):
|
||||
@@ -396,63 +546,62 @@ def get_sequence(model, config):
|
||||
)
|
||||
|
||||
|
||||
def get_instance(config):
|
||||
"""
|
||||
Get the type of MipiSpi instance to create based on the configuration,
|
||||
and the template arguments.
|
||||
:param config:
|
||||
:return: type, template arguments
|
||||
"""
|
||||
width, height, offset_width, offset_height = get_dimensions(config)
|
||||
|
||||
color_depth = int(config[CONF_COLOR_DEPTH].removesuffix("bit"))
|
||||
bufferpixels = COLOR_DEPTHS[color_depth]
|
||||
|
||||
display_pixel_mode = DISPLAY_PIXEL_MODES[config[CONF_PIXEL_MODE]][1]
|
||||
bus_type = config[CONF_BUS_MODE]
|
||||
if bus_type == TYPE_SINGLE and config.get(CONF_SPI_16, False):
|
||||
# If the bus mode is single and spi_16 is set, use single 16-bit mode
|
||||
bus_type = BusType.BUS_TYPE_SINGLE_16
|
||||
else:
|
||||
bus_type = BusTypes[bus_type]
|
||||
buffer_type = cg.uint8 if color_depth == 8 else cg.uint16
|
||||
frac = denominator(config)
|
||||
rotation = DISPLAY_ROTATIONS[
|
||||
0 if is_rotation_transformable(config) else config.get(CONF_ROTATION, 0)
|
||||
]
|
||||
templateargs = [
|
||||
buffer_type,
|
||||
bufferpixels,
|
||||
config[CONF_BYTE_ORDER] == "big_endian",
|
||||
display_pixel_mode,
|
||||
bus_type,
|
||||
width,
|
||||
height,
|
||||
offset_width,
|
||||
offset_height,
|
||||
]
|
||||
# If a buffer is required, use MipiSpiBuffer, otherwise use MipiSpi
|
||||
if requires_buffer(config):
|
||||
templateargs.append(rotation)
|
||||
templateargs.append(frac)
|
||||
return MipiSpiBuffer, templateargs
|
||||
return MipiSpi, templateargs
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
model = MODELS[config[CONF_MODEL]]
|
||||
transform = get_transform(model, config)
|
||||
if CONF_DIMENSIONS in config:
|
||||
# Explicit dimensions, just use as is
|
||||
dimensions = config[CONF_DIMENSIONS]
|
||||
if isinstance(dimensions, dict):
|
||||
width = dimensions[CONF_WIDTH]
|
||||
height = dimensions[CONF_HEIGHT]
|
||||
offset_width = dimensions[CONF_OFFSET_WIDTH]
|
||||
offset_height = dimensions[CONF_OFFSET_HEIGHT]
|
||||
else:
|
||||
(width, height) = dimensions
|
||||
offset_width = 0
|
||||
offset_height = 0
|
||||
else:
|
||||
# Default dimensions, use model defaults and transform if needed
|
||||
width = model.get_default(CONF_WIDTH)
|
||||
height = model.get_default(CONF_HEIGHT)
|
||||
offset_width = model.get_default(CONF_OFFSET_WIDTH, 0)
|
||||
offset_height = model.get_default(CONF_OFFSET_HEIGHT, 0)
|
||||
|
||||
# if mirroring axes and there are offsets, also mirror the offsets to cater for situations where
|
||||
# the offset is asymmetric
|
||||
if transform[CONF_MIRROR_X]:
|
||||
native_width = model.get_default(
|
||||
CONF_NATIVE_WIDTH, width + offset_width * 2
|
||||
)
|
||||
offset_width = native_width - width - offset_width
|
||||
if transform[CONF_MIRROR_Y]:
|
||||
native_height = model.get_default(
|
||||
CONF_NATIVE_HEIGHT, height + offset_height * 2
|
||||
)
|
||||
offset_height = native_height - height - offset_height
|
||||
# Swap default dimensions if swap_xy is set
|
||||
if transform[CONF_SWAP_XY] is True:
|
||||
width, height = height, width
|
||||
offset_height, offset_width = offset_width, offset_height
|
||||
|
||||
color_depth = config[CONF_COLOR_DEPTH]
|
||||
if color_depth.endswith("bit"):
|
||||
color_depth = color_depth[:-3]
|
||||
color_depth = COLOR_DEPTHS[int(color_depth)]
|
||||
|
||||
var = cg.new_Pvariable(
|
||||
config[CONF_ID], width, height, offset_width, offset_height, color_depth
|
||||
)
|
||||
var_id = config[CONF_ID]
|
||||
var_id.type, templateargs = get_instance(config)
|
||||
var = cg.new_Pvariable(var_id, TemplateArguments(*templateargs))
|
||||
cg.add(var.set_init_sequence(get_sequence(model, config)))
|
||||
if rotation_as_transform(model, config):
|
||||
if is_rotation_transformable(config):
|
||||
if CONF_TRANSFORM in config:
|
||||
LOGGER.warning("Use of 'transform' with 'rotation' is not recommended")
|
||||
else:
|
||||
config[CONF_ROTATION] = 0
|
||||
cg.add(var.set_model(config[CONF_MODEL]))
|
||||
cg.add(var.set_draw_from_origin(config[CONF_DRAW_FROM_ORIGIN]))
|
||||
cg.add(var.set_draw_rounding(config[CONF_DRAW_ROUNDING]))
|
||||
cg.add(var.set_spi_16(config[CONF_SPI_16]))
|
||||
if enable_pin := config.get(CONF_ENABLE_PIN):
|
||||
enable = [await cg.gpio_pin_expression(pin) for pin in enable_pin]
|
||||
cg.add(var.set_enable_pins(enable))
|
||||
@@ -472,4 +621,5 @@ async def to_code(config):
|
||||
cg.add(var.set_writer(lambda_))
|
||||
await display.register_display(var, config)
|
||||
await spi.register_spi_device(var, config)
|
||||
# Displays are write-only, set the SPI device to write-only as well
|
||||
cg.add(var.set_write_only(True))
|
||||
|
@@ -2,489 +2,5 @@
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace mipi_spi {
|
||||
|
||||
void MipiSpi::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
this->spi_setup();
|
||||
if (this->dc_pin_ != nullptr) {
|
||||
this->dc_pin_->setup();
|
||||
this->dc_pin_->digital_write(false);
|
||||
}
|
||||
for (auto *pin : this->enable_pins_) {
|
||||
pin->setup();
|
||||
pin->digital_write(true);
|
||||
}
|
||||
if (this->reset_pin_ != nullptr) {
|
||||
this->reset_pin_->setup();
|
||||
this->reset_pin_->digital_write(true);
|
||||
delay(5);
|
||||
this->reset_pin_->digital_write(false);
|
||||
delay(5);
|
||||
this->reset_pin_->digital_write(true);
|
||||
}
|
||||
this->bus_width_ = this->parent_->get_bus_width();
|
||||
|
||||
// need to know when the display is ready for SLPOUT command - will be 120ms after reset
|
||||
auto when = millis() + 120;
|
||||
delay(10);
|
||||
size_t index = 0;
|
||||
auto &vec = this->init_sequence_;
|
||||
while (index != vec.size()) {
|
||||
if (vec.size() - index < 2) {
|
||||
ESP_LOGE(TAG, "Malformed init sequence");
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
uint8_t cmd = vec[index++];
|
||||
uint8_t x = vec[index++];
|
||||
if (x == DELAY_FLAG) {
|
||||
ESP_LOGD(TAG, "Delay %dms", cmd);
|
||||
delay(cmd);
|
||||
} else {
|
||||
uint8_t num_args = x & 0x7F;
|
||||
if (vec.size() - index < num_args) {
|
||||
ESP_LOGE(TAG, "Malformed init sequence");
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
auto arg_byte = vec[index];
|
||||
switch (cmd) {
|
||||
case SLEEP_OUT: {
|
||||
// are we ready, boots?
|
||||
int duration = when - millis();
|
||||
if (duration > 0) {
|
||||
ESP_LOGD(TAG, "Sleep %dms", duration);
|
||||
delay(duration);
|
||||
}
|
||||
} break;
|
||||
|
||||
case INVERT_ON:
|
||||
this->invert_colors_ = true;
|
||||
break;
|
||||
case MADCTL_CMD:
|
||||
this->madctl_ = arg_byte;
|
||||
break;
|
||||
case PIXFMT:
|
||||
this->pixel_mode_ = arg_byte & 0x11 ? PIXEL_MODE_16 : PIXEL_MODE_18;
|
||||
break;
|
||||
case BRIGHTNESS:
|
||||
this->brightness_ = arg_byte;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
const auto *ptr = vec.data() + index;
|
||||
ESP_LOGD(TAG, "Command %02X, length %d, byte %02X", cmd, num_args, arg_byte);
|
||||
this->write_command_(cmd, ptr, num_args);
|
||||
index += num_args;
|
||||
if (cmd == SLEEP_OUT)
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
this->setup_complete_ = true;
|
||||
if (this->draw_from_origin_)
|
||||
check_buffer_();
|
||||
ESP_LOGCONFIG(TAG, "MIPI SPI setup complete");
|
||||
}
|
||||
|
||||
void MipiSpi::update() {
|
||||
if (!this->setup_complete_ || this->is_failed()) {
|
||||
return;
|
||||
}
|
||||
this->do_update_();
|
||||
if (this->buffer_ == nullptr || this->x_low_ > this->x_high_ || this->y_low_ > this->y_high_)
|
||||
return;
|
||||
ESP_LOGV(TAG, "x_low %d, y_low %d, x_high %d, y_high %d", this->x_low_, this->y_low_, this->x_high_, this->y_high_);
|
||||
// Some chips require that the drawing window be aligned on certain boundaries
|
||||
auto dr = this->draw_rounding_;
|
||||
this->x_low_ = this->x_low_ / dr * dr;
|
||||
this->y_low_ = this->y_low_ / dr * dr;
|
||||
this->x_high_ = (this->x_high_ + dr) / dr * dr - 1;
|
||||
this->y_high_ = (this->y_high_ + dr) / dr * dr - 1;
|
||||
if (this->draw_from_origin_) {
|
||||
this->x_low_ = 0;
|
||||
this->y_low_ = 0;
|
||||
this->x_high_ = this->width_ - 1;
|
||||
}
|
||||
int w = this->x_high_ - this->x_low_ + 1;
|
||||
int h = this->y_high_ - this->y_low_ + 1;
|
||||
this->write_to_display_(this->x_low_, this->y_low_, w, h, this->buffer_, this->x_low_, this->y_low_,
|
||||
this->width_ - w - this->x_low_);
|
||||
// invalidate watermarks
|
||||
this->x_low_ = this->width_;
|
||||
this->y_low_ = this->height_;
|
||||
this->x_high_ = 0;
|
||||
this->y_high_ = 0;
|
||||
}
|
||||
|
||||
void MipiSpi::fill(Color color) {
|
||||
if (!this->check_buffer_())
|
||||
return;
|
||||
this->x_low_ = 0;
|
||||
this->y_low_ = 0;
|
||||
this->x_high_ = this->get_width_internal() - 1;
|
||||
this->y_high_ = this->get_height_internal() - 1;
|
||||
switch (this->color_depth_) {
|
||||
case display::COLOR_BITNESS_332: {
|
||||
auto new_color = display::ColorUtil::color_to_332(color, display::ColorOrder::COLOR_ORDER_RGB);
|
||||
memset(this->buffer_, (uint8_t) new_color, this->buffer_bytes_);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
auto new_color = display::ColorUtil::color_to_565(color);
|
||||
if (((uint8_t) (new_color >> 8)) == ((uint8_t) new_color)) {
|
||||
// Upper and lower is equal can use quicker memset operation. Takes ~20ms.
|
||||
memset(this->buffer_, (uint8_t) new_color, this->buffer_bytes_);
|
||||
} else {
|
||||
auto *ptr_16 = reinterpret_cast<uint16_t *>(this->buffer_);
|
||||
auto len = this->buffer_bytes_ / 2;
|
||||
while (len--) {
|
||||
*ptr_16++ = new_color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MipiSpi::draw_absolute_pixel_internal(int x, int y, Color color) {
|
||||
if (x >= this->get_width_internal() || x < 0 || y >= this->get_height_internal() || y < 0) {
|
||||
return;
|
||||
}
|
||||
if (!this->check_buffer_())
|
||||
return;
|
||||
size_t pos = (y * this->width_) + x;
|
||||
switch (this->color_depth_) {
|
||||
case display::COLOR_BITNESS_332: {
|
||||
uint8_t new_color = display::ColorUtil::color_to_332(color);
|
||||
if (this->buffer_[pos] == new_color)
|
||||
return;
|
||||
this->buffer_[pos] = new_color;
|
||||
break;
|
||||
}
|
||||
|
||||
case display::COLOR_BITNESS_565: {
|
||||
auto *ptr_16 = reinterpret_cast<uint16_t *>(this->buffer_);
|
||||
uint8_t hi_byte = static_cast<uint8_t>(color.r & 0xF8) | (color.g >> 5);
|
||||
uint8_t lo_byte = static_cast<uint8_t>((color.g & 0x1C) << 3) | (color.b >> 3);
|
||||
uint16_t new_color = hi_byte | (lo_byte << 8); // big endian
|
||||
if (ptr_16[pos] == new_color)
|
||||
return;
|
||||
ptr_16[pos] = new_color;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return;
|
||||
}
|
||||
// low and high watermark may speed up drawing from buffer
|
||||
if (x < this->x_low_)
|
||||
this->x_low_ = x;
|
||||
if (y < this->y_low_)
|
||||
this->y_low_ = y;
|
||||
if (x > this->x_high_)
|
||||
this->x_high_ = x;
|
||||
if (y > this->y_high_)
|
||||
this->y_high_ = y;
|
||||
}
|
||||
|
||||
void MipiSpi::reset_params_() {
|
||||
if (!this->is_ready())
|
||||
return;
|
||||
this->write_command_(this->invert_colors_ ? INVERT_ON : INVERT_OFF);
|
||||
if (this->brightness_.has_value())
|
||||
this->write_command_(BRIGHTNESS, this->brightness_.value());
|
||||
}
|
||||
|
||||
void MipiSpi::write_init_sequence_() {
|
||||
size_t index = 0;
|
||||
auto &vec = this->init_sequence_;
|
||||
while (index != vec.size()) {
|
||||
if (vec.size() - index < 2) {
|
||||
ESP_LOGE(TAG, "Malformed init sequence");
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
uint8_t cmd = vec[index++];
|
||||
uint8_t x = vec[index++];
|
||||
if (x == DELAY_FLAG) {
|
||||
ESP_LOGV(TAG, "Delay %dms", cmd);
|
||||
delay(cmd);
|
||||
} else {
|
||||
uint8_t num_args = x & 0x7F;
|
||||
if (vec.size() - index < num_args) {
|
||||
ESP_LOGE(TAG, "Malformed init sequence");
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
const auto *ptr = vec.data() + index;
|
||||
this->write_command_(cmd, ptr, num_args);
|
||||
index += num_args;
|
||||
}
|
||||
}
|
||||
this->setup_complete_ = true;
|
||||
ESP_LOGCONFIG(TAG, "MIPI SPI setup complete");
|
||||
}
|
||||
|
||||
void MipiSpi::set_addr_window_(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
|
||||
ESP_LOGVV(TAG, "Set addr %d/%d, %d/%d", x1, y1, x2, y2);
|
||||
uint8_t buf[4];
|
||||
x1 += this->offset_width_;
|
||||
x2 += this->offset_width_;
|
||||
y1 += this->offset_height_;
|
||||
y2 += this->offset_height_;
|
||||
put16_be(buf, y1);
|
||||
put16_be(buf + 2, y2);
|
||||
this->write_command_(RASET, buf, sizeof buf);
|
||||
put16_be(buf, x1);
|
||||
put16_be(buf + 2, x2);
|
||||
this->write_command_(CASET, buf, sizeof buf);
|
||||
}
|
||||
|
||||
void MipiSpi::draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorOrder order,
|
||||
display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) {
|
||||
if (!this->setup_complete_ || this->is_failed())
|
||||
return;
|
||||
if (w <= 0 || h <= 0)
|
||||
return;
|
||||
if (bitness != this->color_depth_ || big_endian != (this->bit_order_ == spi::BIT_ORDER_MSB_FIRST)) {
|
||||
Display::draw_pixels_at(x_start, y_start, w, h, ptr, order, bitness, big_endian, x_offset, y_offset, x_pad);
|
||||
return;
|
||||
}
|
||||
if (this->draw_from_origin_) {
|
||||
auto stride = x_offset + w + x_pad;
|
||||
for (int y = 0; y != h; y++) {
|
||||
memcpy(this->buffer_ + ((y + y_start) * this->width_ + x_start) * 2,
|
||||
ptr + ((y + y_offset) * stride + x_offset) * 2, w * 2);
|
||||
}
|
||||
ptr = this->buffer_;
|
||||
w = this->width_;
|
||||
h += y_start;
|
||||
x_start = 0;
|
||||
y_start = 0;
|
||||
x_offset = 0;
|
||||
y_offset = 0;
|
||||
}
|
||||
this->write_to_display_(x_start, y_start, w, h, ptr, x_offset, y_offset, x_pad);
|
||||
}
|
||||
|
||||
void MipiSpi::write_18_from_16_bit_(const uint16_t *ptr, size_t w, size_t h, size_t stride) {
|
||||
stride -= w;
|
||||
uint8_t transfer_buffer[6 * 256];
|
||||
size_t idx = 0; // index into transfer_buffer
|
||||
while (h-- != 0) {
|
||||
for (auto x = w; x-- != 0;) {
|
||||
auto color_val = *ptr++;
|
||||
// deal with byte swapping
|
||||
transfer_buffer[idx++] = (color_val & 0xF8); // Blue
|
||||
transfer_buffer[idx++] = ((color_val & 0x7) << 5) | ((color_val & 0xE000) >> 11); // Green
|
||||
transfer_buffer[idx++] = (color_val >> 5) & 0xF8; // Red
|
||||
if (idx == sizeof(transfer_buffer)) {
|
||||
this->write_array(transfer_buffer, idx);
|
||||
idx = 0;
|
||||
}
|
||||
}
|
||||
ptr += stride;
|
||||
}
|
||||
if (idx != 0)
|
||||
this->write_array(transfer_buffer, idx);
|
||||
}
|
||||
|
||||
void MipiSpi::write_18_from_8_bit_(const uint8_t *ptr, size_t w, size_t h, size_t stride) {
|
||||
stride -= w;
|
||||
uint8_t transfer_buffer[6 * 256];
|
||||
size_t idx = 0; // index into transfer_buffer
|
||||
while (h-- != 0) {
|
||||
for (auto x = w; x-- != 0;) {
|
||||
auto color_val = *ptr++;
|
||||
transfer_buffer[idx++] = color_val & 0xE0; // Red
|
||||
transfer_buffer[idx++] = (color_val << 3) & 0xE0; // Green
|
||||
transfer_buffer[idx++] = color_val << 6; // Blue
|
||||
if (idx == sizeof(transfer_buffer)) {
|
||||
this->write_array(transfer_buffer, idx);
|
||||
idx = 0;
|
||||
}
|
||||
}
|
||||
ptr += stride;
|
||||
}
|
||||
if (idx != 0)
|
||||
this->write_array(transfer_buffer, idx);
|
||||
}
|
||||
|
||||
void MipiSpi::write_16_from_8_bit_(const uint8_t *ptr, size_t w, size_t h, size_t stride) {
|
||||
stride -= w;
|
||||
uint8_t transfer_buffer[6 * 256];
|
||||
size_t idx = 0; // index into transfer_buffer
|
||||
while (h-- != 0) {
|
||||
for (auto x = w; x-- != 0;) {
|
||||
auto color_val = *ptr++;
|
||||
transfer_buffer[idx++] = (color_val & 0xE0) | ((color_val & 0x1C) >> 2);
|
||||
transfer_buffer[idx++] = (color_val & 0x3) << 3;
|
||||
if (idx == sizeof(transfer_buffer)) {
|
||||
this->write_array(transfer_buffer, idx);
|
||||
idx = 0;
|
||||
}
|
||||
}
|
||||
ptr += stride;
|
||||
}
|
||||
if (idx != 0)
|
||||
this->write_array(transfer_buffer, idx);
|
||||
}
|
||||
|
||||
void MipiSpi::write_to_display_(int x_start, int y_start, int w, int h, const uint8_t *ptr, int x_offset, int y_offset,
|
||||
int x_pad) {
|
||||
this->set_addr_window_(x_start, y_start, x_start + w - 1, y_start + h - 1);
|
||||
auto stride = x_offset + w + x_pad;
|
||||
const auto *offset_ptr = ptr;
|
||||
if (this->color_depth_ == display::COLOR_BITNESS_332) {
|
||||
offset_ptr += y_offset * stride + x_offset;
|
||||
} else {
|
||||
stride *= 2;
|
||||
offset_ptr += y_offset * stride + x_offset * 2;
|
||||
}
|
||||
|
||||
switch (this->bus_width_) {
|
||||
case 4:
|
||||
this->enable();
|
||||
if (x_offset == 0 && x_pad == 0 && y_offset == 0) {
|
||||
// we could deal here with a non-zero y_offset, but if x_offset is zero, y_offset probably will be so don't
|
||||
// bother
|
||||
this->write_cmd_addr_data(8, 0x32, 24, WDATA << 8, ptr, w * h * 2, 4);
|
||||
} else {
|
||||
this->write_cmd_addr_data(8, 0x32, 24, WDATA << 8, nullptr, 0, 4);
|
||||
for (int y = 0; y != h; y++) {
|
||||
this->write_cmd_addr_data(0, 0, 0, 0, offset_ptr, w * 2, 4);
|
||||
offset_ptr += stride;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 8:
|
||||
this->write_command_(WDATA);
|
||||
this->enable();
|
||||
if (x_offset == 0 && x_pad == 0 && y_offset == 0) {
|
||||
this->write_cmd_addr_data(0, 0, 0, 0, ptr, w * h * 2, 8);
|
||||
} else {
|
||||
for (int y = 0; y != h; y++) {
|
||||
this->write_cmd_addr_data(0, 0, 0, 0, offset_ptr, w * 2, 8);
|
||||
offset_ptr += stride;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
this->write_command_(WDATA);
|
||||
this->enable();
|
||||
|
||||
if (this->color_depth_ == display::COLOR_BITNESS_565) {
|
||||
// Source buffer is 16-bit RGB565
|
||||
if (this->pixel_mode_ == PIXEL_MODE_18) {
|
||||
// Convert RGB565 to RGB666
|
||||
this->write_18_from_16_bit_(reinterpret_cast<const uint16_t *>(offset_ptr), w, h, stride / 2);
|
||||
} else {
|
||||
// Direct RGB565 output
|
||||
if (x_offset == 0 && x_pad == 0 && y_offset == 0) {
|
||||
this->write_array(ptr, w * h * 2);
|
||||
} else {
|
||||
for (int y = 0; y != h; y++) {
|
||||
this->write_array(offset_ptr, w * 2);
|
||||
offset_ptr += stride;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Source buffer is 8-bit RGB332
|
||||
if (this->pixel_mode_ == PIXEL_MODE_18) {
|
||||
// Convert RGB332 to RGB666
|
||||
this->write_18_from_8_bit_(offset_ptr, w, h, stride);
|
||||
} else {
|
||||
this->write_16_from_8_bit_(offset_ptr, w, h, stride);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->disable();
|
||||
}
|
||||
|
||||
void MipiSpi::write_command_(uint8_t cmd, const uint8_t *bytes, size_t len) {
|
||||
ESP_LOGV(TAG, "Command %02X, length %d, bytes %s", cmd, len, format_hex_pretty(bytes, len).c_str());
|
||||
if (this->bus_width_ == 4) {
|
||||
this->enable();
|
||||
this->write_cmd_addr_data(8, 0x02, 24, cmd << 8, bytes, len);
|
||||
this->disable();
|
||||
} else if (this->bus_width_ == 8) {
|
||||
this->dc_pin_->digital_write(false);
|
||||
this->enable();
|
||||
this->write_cmd_addr_data(0, 0, 0, 0, &cmd, 1, 8);
|
||||
this->disable();
|
||||
this->dc_pin_->digital_write(true);
|
||||
if (len != 0) {
|
||||
this->enable();
|
||||
this->write_cmd_addr_data(0, 0, 0, 0, bytes, len, 8);
|
||||
this->disable();
|
||||
}
|
||||
} else {
|
||||
this->dc_pin_->digital_write(false);
|
||||
this->enable();
|
||||
this->write_byte(cmd);
|
||||
this->disable();
|
||||
this->dc_pin_->digital_write(true);
|
||||
if (len != 0) {
|
||||
if (this->spi_16_) {
|
||||
for (size_t i = 0; i != len; i++) {
|
||||
this->enable();
|
||||
this->write_byte(0);
|
||||
this->write_byte(bytes[i]);
|
||||
this->disable();
|
||||
}
|
||||
} else {
|
||||
this->enable();
|
||||
this->write_array(bytes, len);
|
||||
this->disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MipiSpi::dump_config() {
|
||||
ESP_LOGCONFIG(TAG,
|
||||
"MIPI_SPI Display\n"
|
||||
" Model: %s\n"
|
||||
" Width: %u\n"
|
||||
" Height: %u",
|
||||
this->model_, this->width_, this->height_);
|
||||
if (this->offset_width_ != 0)
|
||||
ESP_LOGCONFIG(TAG, " Offset width: %u", this->offset_width_);
|
||||
if (this->offset_height_ != 0)
|
||||
ESP_LOGCONFIG(TAG, " Offset height: %u", this->offset_height_);
|
||||
ESP_LOGCONFIG(TAG,
|
||||
" Swap X/Y: %s\n"
|
||||
" Mirror X: %s\n"
|
||||
" Mirror Y: %s\n"
|
||||
" Color depth: %d bits\n"
|
||||
" Invert colors: %s\n"
|
||||
" Color order: %s\n"
|
||||
" Pixel mode: %s",
|
||||
YESNO(this->madctl_ & MADCTL_MV), YESNO(this->madctl_ & (MADCTL_MX | MADCTL_XFLIP)),
|
||||
YESNO(this->madctl_ & (MADCTL_MY | MADCTL_YFLIP)),
|
||||
this->color_depth_ == display::COLOR_BITNESS_565 ? 16 : 8, YESNO(this->invert_colors_),
|
||||
this->madctl_ & MADCTL_BGR ? "BGR" : "RGB", this->pixel_mode_ == PIXEL_MODE_18 ? "18bit" : "16bit");
|
||||
if (this->brightness_.has_value())
|
||||
ESP_LOGCONFIG(TAG, " Brightness: %u", this->brightness_.value());
|
||||
if (this->spi_16_)
|
||||
ESP_LOGCONFIG(TAG, " SPI 16bit: YES");
|
||||
ESP_LOGCONFIG(TAG, " Draw rounding: %u", this->draw_rounding_);
|
||||
if (this->draw_from_origin_)
|
||||
ESP_LOGCONFIG(TAG, " Draw from origin: YES");
|
||||
LOG_PIN(" CS Pin: ", this->cs_);
|
||||
LOG_PIN(" Reset Pin: ", this->reset_pin_);
|
||||
LOG_PIN(" DC Pin: ", this->dc_pin_);
|
||||
ESP_LOGCONFIG(TAG,
|
||||
" SPI Mode: %d\n"
|
||||
" SPI Data rate: %dMHz\n"
|
||||
" SPI Bus width: %d",
|
||||
this->mode_, static_cast<unsigned>(this->data_rate_ / 1000000), this->bus_width_);
|
||||
}
|
||||
|
||||
} // namespace mipi_spi
|
||||
namespace mipi_spi {} // namespace mipi_spi
|
||||
} // namespace esphome
|
||||
|
@@ -4,40 +4,39 @@
|
||||
|
||||
#include "esphome/components/spi/spi.h"
|
||||
#include "esphome/components/display/display.h"
|
||||
#include "esphome/components/display/display_buffer.h"
|
||||
#include "esphome/components/display/display_color_utils.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace mipi_spi {
|
||||
|
||||
constexpr static const char *const TAG = "display.mipi_spi";
|
||||
static const uint8_t SW_RESET_CMD = 0x01;
|
||||
static const uint8_t SLEEP_OUT = 0x11;
|
||||
static const uint8_t NORON = 0x13;
|
||||
static const uint8_t INVERT_OFF = 0x20;
|
||||
static const uint8_t INVERT_ON = 0x21;
|
||||
static const uint8_t ALL_ON = 0x23;
|
||||
static const uint8_t WRAM = 0x24;
|
||||
static const uint8_t MIPI = 0x26;
|
||||
static const uint8_t DISPLAY_ON = 0x29;
|
||||
static const uint8_t RASET = 0x2B;
|
||||
static const uint8_t CASET = 0x2A;
|
||||
static const uint8_t WDATA = 0x2C;
|
||||
static const uint8_t TEON = 0x35;
|
||||
static const uint8_t MADCTL_CMD = 0x36;
|
||||
static const uint8_t PIXFMT = 0x3A;
|
||||
static const uint8_t BRIGHTNESS = 0x51;
|
||||
static const uint8_t SWIRE1 = 0x5A;
|
||||
static const uint8_t SWIRE2 = 0x5B;
|
||||
static const uint8_t PAGESEL = 0xFE;
|
||||
static constexpr uint8_t SW_RESET_CMD = 0x01;
|
||||
static constexpr uint8_t SLEEP_OUT = 0x11;
|
||||
static constexpr uint8_t NORON = 0x13;
|
||||
static constexpr uint8_t INVERT_OFF = 0x20;
|
||||
static constexpr uint8_t INVERT_ON = 0x21;
|
||||
static constexpr uint8_t ALL_ON = 0x23;
|
||||
static constexpr uint8_t WRAM = 0x24;
|
||||
static constexpr uint8_t MIPI = 0x26;
|
||||
static constexpr uint8_t DISPLAY_ON = 0x29;
|
||||
static constexpr uint8_t RASET = 0x2B;
|
||||
static constexpr uint8_t CASET = 0x2A;
|
||||
static constexpr uint8_t WDATA = 0x2C;
|
||||
static constexpr uint8_t TEON = 0x35;
|
||||
static constexpr uint8_t MADCTL_CMD = 0x36;
|
||||
static constexpr uint8_t PIXFMT = 0x3A;
|
||||
static constexpr uint8_t BRIGHTNESS = 0x51;
|
||||
static constexpr uint8_t SWIRE1 = 0x5A;
|
||||
static constexpr uint8_t SWIRE2 = 0x5B;
|
||||
static constexpr uint8_t PAGESEL = 0xFE;
|
||||
|
||||
static const uint8_t MADCTL_MY = 0x80; // Bit 7 Bottom to top
|
||||
static const uint8_t MADCTL_MX = 0x40; // Bit 6 Right to left
|
||||
static const uint8_t MADCTL_MV = 0x20; // Bit 5 Swap axes
|
||||
static const uint8_t MADCTL_RGB = 0x00; // Bit 3 Red-Green-Blue pixel order
|
||||
static const uint8_t MADCTL_BGR = 0x08; // Bit 3 Blue-Green-Red pixel order
|
||||
static const uint8_t MADCTL_XFLIP = 0x02; // Mirror the display horizontally
|
||||
static const uint8_t MADCTL_YFLIP = 0x01; // Mirror the display vertically
|
||||
static constexpr uint8_t MADCTL_MY = 0x80; // Bit 7 Bottom to top
|
||||
static constexpr uint8_t MADCTL_MX = 0x40; // Bit 6 Right to left
|
||||
static constexpr uint8_t MADCTL_MV = 0x20; // Bit 5 Swap axes
|
||||
static constexpr uint8_t MADCTL_RGB = 0x00; // Bit 3 Red-Green-Blue pixel order
|
||||
static constexpr uint8_t MADCTL_BGR = 0x08; // Bit 3 Blue-Green-Red pixel order
|
||||
static constexpr uint8_t MADCTL_XFLIP = 0x02; // Mirror the display horizontally
|
||||
static constexpr uint8_t MADCTL_YFLIP = 0x01; // Mirror the display vertically
|
||||
|
||||
static const uint8_t DELAY_FLAG = 0xFF;
|
||||
// store a 16 bit value in a buffer, big endian.
|
||||
@@ -46,28 +45,44 @@ static inline void put16_be(uint8_t *buf, uint16_t value) {
|
||||
buf[1] = value;
|
||||
}
|
||||
|
||||
// Buffer mode, conveniently also the number of bytes in a pixel
|
||||
enum PixelMode {
|
||||
PIXEL_MODE_16,
|
||||
PIXEL_MODE_18,
|
||||
PIXEL_MODE_8 = 1,
|
||||
PIXEL_MODE_16 = 2,
|
||||
PIXEL_MODE_18 = 3,
|
||||
};
|
||||
|
||||
class MipiSpi : public display::DisplayBuffer,
|
||||
enum BusType {
|
||||
BUS_TYPE_SINGLE = 1,
|
||||
BUS_TYPE_QUAD = 4,
|
||||
BUS_TYPE_OCTAL = 8,
|
||||
BUS_TYPE_SINGLE_16 = 16, // Single bit bus, but 16 bits per transfer
|
||||
};
|
||||
|
||||
/**
|
||||
* Base class for MIPI SPI displays.
|
||||
* All the methods are defined here in the header file, as it is not possible to define templated methods in a cpp file.
|
||||
*
|
||||
* @tparam BUFFERTYPE The type of the buffer pixels, e.g. uint8_t or uint16_t
|
||||
* @tparam BUFFERPIXEL Color depth of the buffer
|
||||
* @tparam DISPLAYPIXEL Color depth of the display
|
||||
* @tparam BUS_TYPE The type of the interface bus (single, quad, octal)
|
||||
* @tparam WIDTH Width of the display in pixels
|
||||
* @tparam HEIGHT Height of the display in pixels
|
||||
* @tparam OFFSET_WIDTH The x-offset of the display in pixels
|
||||
* @tparam OFFSET_HEIGHT The y-offset of the display in pixels
|
||||
* buffer
|
||||
*/
|
||||
template<typename BUFFERTYPE, PixelMode BUFFERPIXEL, bool IS_BIG_ENDIAN, PixelMode DISPLAYPIXEL, BusType BUS_TYPE,
|
||||
int WIDTH, int HEIGHT, int OFFSET_WIDTH, int OFFSET_HEIGHT>
|
||||
class MipiSpi : public display::Display,
|
||||
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
|
||||
spi::DATA_RATE_1MHZ> {
|
||||
public:
|
||||
MipiSpi(size_t width, size_t height, int16_t offset_width, int16_t offset_height, display::ColorBitness color_depth)
|
||||
: width_(width),
|
||||
height_(height),
|
||||
offset_width_(offset_width),
|
||||
offset_height_(offset_height),
|
||||
color_depth_(color_depth) {}
|
||||
MipiSpi() {}
|
||||
void update() override { this->stop_poller(); }
|
||||
void draw_pixel_at(int x, int y, Color color) override {}
|
||||
void set_model(const char *model) { this->model_ = model; }
|
||||
void update() override;
|
||||
void setup() override;
|
||||
display::ColorOrder get_color_mode() {
|
||||
return this->madctl_ & MADCTL_BGR ? display::COLOR_ORDER_BGR : display::COLOR_ORDER_RGB;
|
||||
}
|
||||
|
||||
void set_reset_pin(GPIOPin *reset_pin) { this->reset_pin_ = reset_pin; }
|
||||
void set_enable_pins(std::vector<GPIOPin *> enable_pins) { this->enable_pins_ = std::move(enable_pins); }
|
||||
void set_dc_pin(GPIOPin *dc_pin) { this->dc_pin_ = dc_pin; }
|
||||
@@ -79,93 +94,524 @@ class MipiSpi : public display::DisplayBuffer,
|
||||
this->brightness_ = brightness;
|
||||
this->reset_params_();
|
||||
}
|
||||
|
||||
void set_draw_from_origin(bool draw_from_origin) { this->draw_from_origin_ = draw_from_origin; }
|
||||
display::DisplayType get_display_type() override { return display::DisplayType::DISPLAY_TYPE_COLOR; }
|
||||
void dump_config() override;
|
||||
|
||||
int get_width_internal() override { return this->width_; }
|
||||
int get_height_internal() override { return this->height_; }
|
||||
bool can_proceed() override { return this->setup_complete_; }
|
||||
int get_width_internal() override { return WIDTH; }
|
||||
int get_height_internal() override { return HEIGHT; }
|
||||
void set_init_sequence(const std::vector<uint8_t> &sequence) { this->init_sequence_ = sequence; }
|
||||
void set_draw_rounding(unsigned rounding) { this->draw_rounding_ = rounding; }
|
||||
void set_spi_16(bool spi_16) { this->spi_16_ = spi_16; }
|
||||
|
||||
// reset the display, and write the init sequence
|
||||
void setup() override {
|
||||
this->spi_setup();
|
||||
if (this->dc_pin_ != nullptr) {
|
||||
this->dc_pin_->setup();
|
||||
this->dc_pin_->digital_write(false);
|
||||
}
|
||||
for (auto *pin : this->enable_pins_) {
|
||||
pin->setup();
|
||||
pin->digital_write(true);
|
||||
}
|
||||
if (this->reset_pin_ != nullptr) {
|
||||
this->reset_pin_->setup();
|
||||
this->reset_pin_->digital_write(true);
|
||||
delay(5);
|
||||
this->reset_pin_->digital_write(false);
|
||||
delay(5);
|
||||
this->reset_pin_->digital_write(true);
|
||||
}
|
||||
|
||||
// need to know when the display is ready for SLPOUT command - will be 120ms after reset
|
||||
auto when = millis() + 120;
|
||||
delay(10);
|
||||
size_t index = 0;
|
||||
auto &vec = this->init_sequence_;
|
||||
while (index != vec.size()) {
|
||||
if (vec.size() - index < 2) {
|
||||
esph_log_e(TAG, "Malformed init sequence");
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
uint8_t cmd = vec[index++];
|
||||
uint8_t x = vec[index++];
|
||||
if (x == DELAY_FLAG) {
|
||||
esph_log_d(TAG, "Delay %dms", cmd);
|
||||
delay(cmd);
|
||||
} else {
|
||||
uint8_t num_args = x & 0x7F;
|
||||
if (vec.size() - index < num_args) {
|
||||
esph_log_e(TAG, "Malformed init sequence");
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
auto arg_byte = vec[index];
|
||||
switch (cmd) {
|
||||
case SLEEP_OUT: {
|
||||
// are we ready, boots?
|
||||
int duration = when - millis();
|
||||
if (duration > 0) {
|
||||
esph_log_d(TAG, "Sleep %dms", duration);
|
||||
delay(duration);
|
||||
}
|
||||
} break;
|
||||
|
||||
case INVERT_ON:
|
||||
this->invert_colors_ = true;
|
||||
break;
|
||||
case MADCTL_CMD:
|
||||
this->madctl_ = arg_byte;
|
||||
break;
|
||||
case BRIGHTNESS:
|
||||
this->brightness_ = arg_byte;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
const auto *ptr = vec.data() + index;
|
||||
esph_log_d(TAG, "Command %02X, length %d, byte %02X", cmd, num_args, arg_byte);
|
||||
this->write_command_(cmd, ptr, num_args);
|
||||
index += num_args;
|
||||
if (cmd == SLEEP_OUT)
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
// init sequence no longer needed
|
||||
this->init_sequence_.clear();
|
||||
}
|
||||
|
||||
// Drawing operations
|
||||
|
||||
void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorOrder order,
|
||||
display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override {
|
||||
if (this->is_failed())
|
||||
return;
|
||||
if (w <= 0 || h <= 0)
|
||||
return;
|
||||
if (get_pixel_mode(bitness) != BUFFERPIXEL || big_endian != IS_BIG_ENDIAN) {
|
||||
// note that the usual logging macros are banned in header files, so use their replacement
|
||||
esph_log_e(TAG, "Unsupported color depth or bit order");
|
||||
return;
|
||||
}
|
||||
this->write_to_display_(x_start, y_start, w, h, reinterpret_cast<const BUFFERTYPE *>(ptr), x_offset, y_offset,
|
||||
x_pad);
|
||||
}
|
||||
|
||||
void dump_config() override {
|
||||
esph_log_config(TAG,
|
||||
"MIPI_SPI Display\n"
|
||||
" Model: %s\n"
|
||||
" Width: %u\n"
|
||||
" Height: %u",
|
||||
this->model_, WIDTH, HEIGHT);
|
||||
if constexpr (OFFSET_WIDTH != 0)
|
||||
esph_log_config(TAG, " Offset width: %u", OFFSET_WIDTH);
|
||||
if constexpr (OFFSET_HEIGHT != 0)
|
||||
esph_log_config(TAG, " Offset height: %u", OFFSET_HEIGHT);
|
||||
esph_log_config(TAG,
|
||||
" Swap X/Y: %s\n"
|
||||
" Mirror X: %s\n"
|
||||
" Mirror Y: %s\n"
|
||||
" Invert colors: %s\n"
|
||||
" Color order: %s\n"
|
||||
" Display pixels: %d bits\n"
|
||||
" Endianness: %s\n",
|
||||
YESNO(this->madctl_ & MADCTL_MV), YESNO(this->madctl_ & (MADCTL_MX | MADCTL_XFLIP)),
|
||||
YESNO(this->madctl_ & (MADCTL_MY | MADCTL_YFLIP)), YESNO(this->invert_colors_),
|
||||
this->madctl_ & MADCTL_BGR ? "BGR" : "RGB", DISPLAYPIXEL * 8, IS_BIG_ENDIAN ? "Big" : "Little");
|
||||
if (this->brightness_.has_value())
|
||||
esph_log_config(TAG, " Brightness: %u", this->brightness_.value());
|
||||
if (this->cs_ != nullptr)
|
||||
esph_log_config(TAG, " CS Pin: %s", this->cs_->dump_summary().c_str());
|
||||
if (this->reset_pin_ != nullptr)
|
||||
esph_log_config(TAG, " Reset Pin: %s", this->reset_pin_->dump_summary().c_str());
|
||||
if (this->dc_pin_ != nullptr)
|
||||
esph_log_config(TAG, " DC Pin: %s", this->dc_pin_->dump_summary().c_str());
|
||||
esph_log_config(TAG,
|
||||
" SPI Mode: %d\n"
|
||||
" SPI Data rate: %dMHz\n"
|
||||
" SPI Bus width: %d",
|
||||
this->mode_, static_cast<unsigned>(this->data_rate_ / 1000000), BUS_TYPE);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool check_buffer_() {
|
||||
if (this->is_failed())
|
||||
return false;
|
||||
if (this->buffer_ != nullptr)
|
||||
return true;
|
||||
auto bytes_per_pixel = this->color_depth_ == display::COLOR_BITNESS_565 ? 2 : 1;
|
||||
this->init_internal_(this->width_ * this->height_ * bytes_per_pixel);
|
||||
if (this->buffer_ == nullptr) {
|
||||
this->mark_failed();
|
||||
return false;
|
||||
}
|
||||
this->buffer_bytes_ = this->width_ * this->height_ * bytes_per_pixel;
|
||||
return true;
|
||||
}
|
||||
void fill(Color color) override;
|
||||
void draw_absolute_pixel_internal(int x, int y, Color color) override;
|
||||
void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorOrder order,
|
||||
display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override;
|
||||
void write_18_from_16_bit_(const uint16_t *ptr, size_t w, size_t h, size_t stride);
|
||||
void write_18_from_8_bit_(const uint8_t *ptr, size_t w, size_t h, size_t stride);
|
||||
void write_16_from_8_bit_(const uint8_t *ptr, size_t w, size_t h, size_t stride);
|
||||
void write_to_display_(int x_start, int y_start, int w, int h, const uint8_t *ptr, int x_offset, int y_offset,
|
||||
int x_pad);
|
||||
/**
|
||||
* the RM67162 in quad SPI mode seems to work like this (not in the datasheet, this is deduced from the
|
||||
* sample code.)
|
||||
*
|
||||
* Immediately after enabling /CS send 4 bytes in single-dataline SPI mode:
|
||||
* 0: either 0x2 or 0x32. The first indicates that any subsequent data bytes after the initial 4 will be
|
||||
* sent in 1-dataline SPI. The second indicates quad mode.
|
||||
* 1: 0x00
|
||||
* 2: The command (register address) byte.
|
||||
* 3: 0x00
|
||||
*
|
||||
* This is followed by zero or more data bytes in either 1-wire or 4-wire mode, depending on the first byte.
|
||||
* At the conclusion of the write, de-assert /CS.
|
||||
*
|
||||
* @param cmd
|
||||
* @param bytes
|
||||
* @param len
|
||||
*/
|
||||
void write_command_(uint8_t cmd, const uint8_t *bytes, size_t len);
|
||||
|
||||
/* METHODS */
|
||||
// convenience functions to write commands with or without data
|
||||
void write_command_(uint8_t cmd, uint8_t data) { this->write_command_(cmd, &data, 1); }
|
||||
void write_command_(uint8_t cmd) { this->write_command_(cmd, &cmd, 0); }
|
||||
void reset_params_();
|
||||
void write_init_sequence_();
|
||||
void set_addr_window_(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
|
||||
|
||||
// Writes a command to the display, with the given bytes.
|
||||
void write_command_(uint8_t cmd, const uint8_t *bytes, size_t len) {
|
||||
esph_log_v(TAG, "Command %02X, length %d, bytes %s", cmd, len, format_hex_pretty(bytes, len).c_str());
|
||||
if constexpr (BUS_TYPE == BUS_TYPE_QUAD) {
|
||||
this->enable();
|
||||
this->write_cmd_addr_data(8, 0x02, 24, cmd << 8, bytes, len);
|
||||
this->disable();
|
||||
} else if constexpr (BUS_TYPE == BUS_TYPE_OCTAL) {
|
||||
this->dc_pin_->digital_write(false);
|
||||
this->enable();
|
||||
this->write_cmd_addr_data(0, 0, 0, 0, &cmd, 1, 8);
|
||||
this->disable();
|
||||
this->dc_pin_->digital_write(true);
|
||||
if (len != 0) {
|
||||
this->enable();
|
||||
this->write_cmd_addr_data(0, 0, 0, 0, bytes, len, 8);
|
||||
this->disable();
|
||||
}
|
||||
} else if constexpr (BUS_TYPE == BUS_TYPE_SINGLE) {
|
||||
this->dc_pin_->digital_write(false);
|
||||
this->enable();
|
||||
this->write_byte(cmd);
|
||||
this->disable();
|
||||
this->dc_pin_->digital_write(true);
|
||||
if (len != 0) {
|
||||
this->enable();
|
||||
this->write_array(bytes, len);
|
||||
this->disable();
|
||||
}
|
||||
} else if constexpr (BUS_TYPE == BUS_TYPE_SINGLE_16) {
|
||||
this->dc_pin_->digital_write(false);
|
||||
this->enable();
|
||||
this->write_byte(cmd);
|
||||
this->disable();
|
||||
this->dc_pin_->digital_write(true);
|
||||
for (size_t i = 0; i != len; i++) {
|
||||
this->enable();
|
||||
this->write_byte(0);
|
||||
this->write_byte(bytes[i]);
|
||||
this->disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// write changed parameters to the display
|
||||
void reset_params_() {
|
||||
if (!this->is_ready())
|
||||
return;
|
||||
this->write_command_(this->invert_colors_ ? INVERT_ON : INVERT_OFF);
|
||||
if (this->brightness_.has_value())
|
||||
this->write_command_(BRIGHTNESS, this->brightness_.value());
|
||||
}
|
||||
|
||||
// set the address window for the next data write
|
||||
void set_addr_window_(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
|
||||
esph_log_v(TAG, "Set addr %d/%d, %d/%d", x1, y1, x2, y2);
|
||||
uint8_t buf[4];
|
||||
x1 += OFFSET_WIDTH;
|
||||
x2 += OFFSET_WIDTH;
|
||||
y1 += OFFSET_HEIGHT;
|
||||
y2 += OFFSET_HEIGHT;
|
||||
put16_be(buf, y1);
|
||||
put16_be(buf + 2, y2);
|
||||
this->write_command_(RASET, buf, sizeof buf);
|
||||
put16_be(buf, x1);
|
||||
put16_be(buf + 2, x2);
|
||||
this->write_command_(CASET, buf, sizeof buf);
|
||||
if constexpr (BUS_TYPE != BUS_TYPE_QUAD) {
|
||||
this->write_command_(WDATA);
|
||||
}
|
||||
}
|
||||
|
||||
// map the display color bitness to the pixel mode
|
||||
static PixelMode get_pixel_mode(display::ColorBitness bitness) {
|
||||
switch (bitness) {
|
||||
case display::COLOR_BITNESS_888:
|
||||
return PIXEL_MODE_18; // 18 bits per pixel
|
||||
case display::COLOR_BITNESS_565:
|
||||
return PIXEL_MODE_16; // 16 bits per pixel
|
||||
default:
|
||||
return PIXEL_MODE_8; // Default to 8 bits per pixel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a buffer to the display.
|
||||
* @param w Width of each line in bytes
|
||||
* @param h Height of the buffer in rows
|
||||
* @param pad Padding in bytes after each line
|
||||
*/
|
||||
void write_display_data_(const uint8_t *ptr, size_t w, size_t h, size_t pad) {
|
||||
if (pad == 0) {
|
||||
if constexpr (BUS_TYPE == BUS_TYPE_SINGLE || BUS_TYPE == BUS_TYPE_SINGLE_16) {
|
||||
this->write_array(ptr, w * h);
|
||||
} else if constexpr (BUS_TYPE == BUS_TYPE_QUAD) {
|
||||
this->write_cmd_addr_data(8, 0x32, 24, WDATA << 8, ptr, w * h, 4);
|
||||
} else if constexpr (BUS_TYPE == BUS_TYPE_OCTAL) {
|
||||
this->write_cmd_addr_data(0, 0, 0, 0, ptr, w * h, 8);
|
||||
}
|
||||
} else {
|
||||
for (size_t y = 0; y != h; y++) {
|
||||
if constexpr (BUS_TYPE == BUS_TYPE_SINGLE || BUS_TYPE == BUS_TYPE_SINGLE_16) {
|
||||
this->write_array(ptr, w);
|
||||
} else if constexpr (BUS_TYPE == BUS_TYPE_QUAD) {
|
||||
this->write_cmd_addr_data(8, 0x32, 24, WDATA << 8, ptr, w, 4);
|
||||
} else if constexpr (BUS_TYPE == BUS_TYPE_OCTAL) {
|
||||
this->write_cmd_addr_data(0, 0, 0, 0, ptr, w, 8);
|
||||
}
|
||||
ptr += w + pad;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a buffer to the display.
|
||||
*
|
||||
* The ptr is a pointer to the pixel data
|
||||
* The other parameters are all in pixel units.
|
||||
*/
|
||||
void write_to_display_(int x_start, int y_start, int w, int h, const BUFFERTYPE *ptr, int x_offset, int y_offset,
|
||||
int x_pad) {
|
||||
this->set_addr_window_(x_start, y_start, x_start + w - 1, y_start + h - 1);
|
||||
this->enable();
|
||||
ptr += y_offset * (x_offset + w + x_pad) + x_offset;
|
||||
if constexpr (BUFFERPIXEL == DISPLAYPIXEL) {
|
||||
this->write_display_data_(reinterpret_cast<const uint8_t *>(ptr), w * sizeof(BUFFERTYPE), h,
|
||||
x_pad * sizeof(BUFFERTYPE));
|
||||
} else {
|
||||
// type conversion required, do it in chunks
|
||||
uint8_t dbuffer[DISPLAYPIXEL * 48];
|
||||
uint8_t *dptr = dbuffer;
|
||||
auto stride = x_offset + w + x_pad; // stride in pixels
|
||||
for (size_t y = 0; y != h; y++) {
|
||||
for (size_t x = 0; x != w; x++) {
|
||||
auto color_val = ptr[y * stride + x];
|
||||
if constexpr (DISPLAYPIXEL == PIXEL_MODE_18 && BUFFERPIXEL == PIXEL_MODE_16) {
|
||||
// 16 to 18 bit conversion
|
||||
if constexpr (IS_BIG_ENDIAN) {
|
||||
*dptr++ = color_val & 0xF8;
|
||||
*dptr++ = ((color_val & 0x7) << 5) | (color_val & 0xE000) >> 11;
|
||||
*dptr++ = (color_val >> 5) & 0xF8;
|
||||
} else {
|
||||
*dptr++ = (color_val >> 8) & 0xF8; // Blue
|
||||
*dptr++ = (color_val & 0x7E0) >> 3;
|
||||
*dptr++ = color_val << 3;
|
||||
}
|
||||
} else if constexpr (DISPLAYPIXEL == PIXEL_MODE_18 && BUFFERPIXEL == PIXEL_MODE_8) {
|
||||
// 8 bit to 18 bit conversion
|
||||
*dptr++ = color_val << 6; // Blue
|
||||
*dptr++ = (color_val & 0x1C) << 3; // Green
|
||||
*dptr++ = (color_val & 0xE0); // Red
|
||||
} else if constexpr (DISPLAYPIXEL == PIXEL_MODE_16 && BUFFERPIXEL == PIXEL_MODE_8) {
|
||||
if constexpr (IS_BIG_ENDIAN) {
|
||||
*dptr++ = (color_val & 0xE0) | ((color_val & 0x1C) >> 2);
|
||||
*dptr++ = (color_val & 3) << 3;
|
||||
} else {
|
||||
*dptr++ = (color_val & 3) << 3;
|
||||
*dptr++ = (color_val & 0xE0) | ((color_val & 0x1C) >> 2);
|
||||
}
|
||||
}
|
||||
// buffer full? Flush.
|
||||
if (dptr == dbuffer + sizeof(dbuffer)) {
|
||||
this->write_display_data_(dbuffer, sizeof(dbuffer), 1, 0);
|
||||
dptr = dbuffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
// flush any remaining data
|
||||
if (dptr != dbuffer) {
|
||||
this->write_display_data_(dbuffer, dptr - dbuffer, 1, 0);
|
||||
}
|
||||
}
|
||||
this->disable();
|
||||
}
|
||||
|
||||
/* PROPERTIES */
|
||||
|
||||
// GPIO pins
|
||||
GPIOPin *reset_pin_{nullptr};
|
||||
std::vector<GPIOPin *> enable_pins_{};
|
||||
GPIOPin *dc_pin_{nullptr};
|
||||
uint16_t x_low_{1};
|
||||
uint16_t y_low_{1};
|
||||
uint16_t x_high_{0};
|
||||
uint16_t y_high_{0};
|
||||
bool setup_complete_{};
|
||||
|
||||
// other properties set by configuration
|
||||
bool invert_colors_{};
|
||||
size_t width_;
|
||||
size_t height_;
|
||||
int16_t offset_width_;
|
||||
int16_t offset_height_;
|
||||
size_t buffer_bytes_{0};
|
||||
display::ColorBitness color_depth_;
|
||||
PixelMode pixel_mode_{PIXEL_MODE_16};
|
||||
uint8_t bus_width_{};
|
||||
bool spi_16_{};
|
||||
uint8_t madctl_{};
|
||||
bool draw_from_origin_{false};
|
||||
unsigned draw_rounding_{2};
|
||||
optional<uint8_t> brightness_{};
|
||||
const char *model_{"Unknown"};
|
||||
std::vector<uint8_t> init_sequence_{};
|
||||
uint8_t madctl_{};
|
||||
};
|
||||
|
||||
/**
|
||||
* Class for MIPI SPI displays with a buffer.
|
||||
*
|
||||
* @tparam BUFFERTYPE The type of the buffer pixels, e.g. uint8_t or uint16_t
|
||||
* @tparam BUFFERPIXEL Color depth of the buffer
|
||||
* @tparam DISPLAYPIXEL Color depth of the display
|
||||
* @tparam BUS_TYPE The type of the interface bus (single, quad, octal)
|
||||
* @tparam ROTATION The rotation of the display
|
||||
* @tparam WIDTH Width of the display in pixels
|
||||
* @tparam HEIGHT Height of the display in pixels
|
||||
* @tparam OFFSET_WIDTH The x-offset of the display in pixels
|
||||
* @tparam OFFSET_HEIGHT The y-offset of the display in pixels
|
||||
* @tparam FRACTION The fraction of the display size to use for the buffer (e.g. 4 means a 1/4 buffer).
|
||||
*/
|
||||
template<typename BUFFERTYPE, PixelMode BUFFERPIXEL, bool IS_BIG_ENDIAN, PixelMode DISPLAYPIXEL, BusType BUS_TYPE,
|
||||
int WIDTH, int HEIGHT, int OFFSET_WIDTH, int OFFSET_HEIGHT, display::DisplayRotation ROTATION, int FRACTION>
|
||||
class MipiSpiBuffer : public MipiSpi<BUFFERTYPE, BUFFERPIXEL, IS_BIG_ENDIAN, DISPLAYPIXEL, BUS_TYPE, WIDTH, HEIGHT,
|
||||
OFFSET_WIDTH, OFFSET_HEIGHT> {
|
||||
public:
|
||||
MipiSpiBuffer() { this->rotation_ = ROTATION; }
|
||||
|
||||
void dump_config() override {
|
||||
MipiSpi<BUFFERTYPE, BUFFERPIXEL, IS_BIG_ENDIAN, DISPLAYPIXEL, BUS_TYPE, WIDTH, HEIGHT, OFFSET_WIDTH,
|
||||
OFFSET_HEIGHT>::dump_config();
|
||||
esph_log_config(TAG,
|
||||
" Rotation: %d°\n"
|
||||
" Buffer pixels: %d bits\n"
|
||||
" Buffer fraction: 1/%d\n"
|
||||
" Buffer bytes: %zu\n"
|
||||
" Draw rounding: %u",
|
||||
this->rotation_, BUFFERPIXEL * 8, FRACTION, sizeof(BUFFERTYPE) * WIDTH * HEIGHT / FRACTION,
|
||||
this->draw_rounding_);
|
||||
}
|
||||
|
||||
void setup() override {
|
||||
MipiSpi<BUFFERTYPE, BUFFERPIXEL, IS_BIG_ENDIAN, DISPLAYPIXEL, BUS_TYPE, WIDTH, HEIGHT, OFFSET_WIDTH,
|
||||
OFFSET_HEIGHT>::setup();
|
||||
RAMAllocator<BUFFERTYPE> allocator{};
|
||||
this->buffer_ = allocator.allocate(WIDTH * HEIGHT / FRACTION);
|
||||
if (this->buffer_ == nullptr) {
|
||||
this->mark_failed("Buffer allocation failed");
|
||||
}
|
||||
}
|
||||
|
||||
void update() override {
|
||||
#if ESPHOME_LOG_LEVEL == ESPHOME_LOG_LEVEL_VERBOSE
|
||||
auto now = millis();
|
||||
#endif
|
||||
if (this->is_failed()) {
|
||||
return;
|
||||
}
|
||||
// for updates with a small buffer, we repeatedly call the writer_ function, clipping the height to a fraction of
|
||||
// the display height,
|
||||
for (this->start_line_ = 0; this->start_line_ < HEIGHT; this->start_line_ += HEIGHT / FRACTION) {
|
||||
#if ESPHOME_LOG_LEVEL == ESPHOME_LOG_LEVEL_VERBOSE
|
||||
auto lap = millis();
|
||||
#endif
|
||||
this->end_line_ = this->start_line_ + HEIGHT / FRACTION;
|
||||
if (this->auto_clear_enabled_) {
|
||||
this->clear();
|
||||
}
|
||||
if (this->page_ != nullptr) {
|
||||
this->page_->get_writer()(*this);
|
||||
} else if (this->writer_.has_value()) {
|
||||
(*this->writer_)(*this);
|
||||
} else {
|
||||
this->test_card();
|
||||
}
|
||||
#if ESPHOME_LOG_LEVEL == ESPHOME_LOG_LEVEL_VERBOSE
|
||||
esph_log_v(TAG, "Drawing from line %d took %dms", this->start_line_, millis() - lap);
|
||||
lap = millis();
|
||||
#endif
|
||||
if (this->x_low_ > this->x_high_ || this->y_low_ > this->y_high_)
|
||||
return;
|
||||
esph_log_v(TAG, "x_low %d, y_low %d, x_high %d, y_high %d", this->x_low_, this->y_low_, this->x_high_,
|
||||
this->y_high_);
|
||||
// Some chips require that the drawing window be aligned on certain boundaries
|
||||
auto dr = this->draw_rounding_;
|
||||
this->x_low_ = this->x_low_ / dr * dr;
|
||||
this->y_low_ = this->y_low_ / dr * dr;
|
||||
this->x_high_ = (this->x_high_ + dr) / dr * dr - 1;
|
||||
this->y_high_ = (this->y_high_ + dr) / dr * dr - 1;
|
||||
int w = this->x_high_ - this->x_low_ + 1;
|
||||
int h = this->y_high_ - this->y_low_ + 1;
|
||||
this->write_to_display_(this->x_low_, this->y_low_, w, h, this->buffer_, this->x_low_,
|
||||
this->y_low_ - this->start_line_, WIDTH - w);
|
||||
// invalidate watermarks
|
||||
this->x_low_ = WIDTH;
|
||||
this->y_low_ = HEIGHT;
|
||||
this->x_high_ = 0;
|
||||
this->y_high_ = 0;
|
||||
#if ESPHOME_LOG_LEVEL == ESPHOME_LOG_LEVEL_VERBOSE
|
||||
esph_log_v(TAG, "Write to display took %dms", millis() - lap);
|
||||
lap = millis();
|
||||
#endif
|
||||
}
|
||||
#if ESPHOME_LOG_LEVEL == ESPHOME_LOG_LEVEL_VERBOSE
|
||||
esph_log_v(TAG, "Total update took %dms", millis() - now);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Draw a pixel at the given coordinates.
|
||||
void draw_pixel_at(int x, int y, Color color) override {
|
||||
rotate_coordinates_(x, y);
|
||||
if (x < 0 || x >= WIDTH || y < this->start_line_ || y >= this->end_line_)
|
||||
return;
|
||||
this->buffer_[(y - this->start_line_) * WIDTH + x] = convert_color_(color);
|
||||
if (x < this->x_low_) {
|
||||
this->x_low_ = x;
|
||||
}
|
||||
if (x > this->x_high_) {
|
||||
this->x_high_ = x;
|
||||
}
|
||||
if (y < this->y_low_) {
|
||||
this->y_low_ = y;
|
||||
}
|
||||
if (y > this->y_high_) {
|
||||
this->y_high_ = y;
|
||||
}
|
||||
}
|
||||
|
||||
// Fills the display with a color.
|
||||
void fill(Color color) override {
|
||||
this->x_low_ = 0;
|
||||
this->y_low_ = this->start_line_;
|
||||
this->x_high_ = WIDTH - 1;
|
||||
this->y_high_ = this->end_line_ - 1;
|
||||
std::fill_n(this->buffer_, HEIGHT * WIDTH / FRACTION, convert_color_(color));
|
||||
}
|
||||
|
||||
int get_width() override {
|
||||
if constexpr (ROTATION == display::DISPLAY_ROTATION_90_DEGREES || ROTATION == display::DISPLAY_ROTATION_270_DEGREES)
|
||||
return HEIGHT;
|
||||
return WIDTH;
|
||||
}
|
||||
|
||||
int get_height() override {
|
||||
if constexpr (ROTATION == display::DISPLAY_ROTATION_90_DEGREES || ROTATION == display::DISPLAY_ROTATION_270_DEGREES)
|
||||
return WIDTH;
|
||||
return HEIGHT;
|
||||
}
|
||||
|
||||
protected:
|
||||
// Rotate the coordinates to match the display orientation.
|
||||
void rotate_coordinates_(int &x, int &y) const {
|
||||
if constexpr (ROTATION == display::DISPLAY_ROTATION_180_DEGREES) {
|
||||
x = WIDTH - x - 1;
|
||||
y = HEIGHT - y - 1;
|
||||
} else if constexpr (ROTATION == display::DISPLAY_ROTATION_90_DEGREES) {
|
||||
auto tmp = x;
|
||||
x = WIDTH - y - 1;
|
||||
y = tmp;
|
||||
} else if constexpr (ROTATION == display::DISPLAY_ROTATION_270_DEGREES) {
|
||||
auto tmp = y;
|
||||
y = HEIGHT - x - 1;
|
||||
x = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert a color to the buffer pixel format.
|
||||
BUFFERTYPE convert_color_(Color &color) const {
|
||||
if constexpr (BUFFERPIXEL == PIXEL_MODE_8) {
|
||||
return (color.red & 0xE0) | (color.g & 0xE0) >> 3 | color.b >> 6;
|
||||
} else if constexpr (BUFFERPIXEL == PIXEL_MODE_16) {
|
||||
if constexpr (IS_BIG_ENDIAN) {
|
||||
return (color.r & 0xF8) | color.g >> 5 | (color.g & 0x1C) << 11 | (color.b & 0xF8) << 5;
|
||||
} else {
|
||||
return (color.r & 0xF8) << 8 | (color.g & 0xFC) << 3 | color.b >> 3;
|
||||
}
|
||||
}
|
||||
return static_cast<BUFFERTYPE>(0);
|
||||
}
|
||||
|
||||
BUFFERTYPE *buffer_{};
|
||||
uint16_t x_low_{WIDTH};
|
||||
uint16_t y_low_{HEIGHT};
|
||||
uint16_t x_high_{0};
|
||||
uint16_t y_high_{0};
|
||||
uint16_t start_line_{0};
|
||||
uint16_t end_line_{1};
|
||||
};
|
||||
|
||||
} // namespace mipi_spi
|
||||
} // namespace esphome
|
||||
|
30
esphome/components/mipi_spi/models/adafruit.py
Normal file
30
esphome/components/mipi_spi/models/adafruit.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from .ili import ST7789V
|
||||
|
||||
ST7789V.extend(
|
||||
"ADAFRUIT-FUNHOUSE",
|
||||
height=240,
|
||||
width=240,
|
||||
offset_height=0,
|
||||
offset_width=0,
|
||||
cs_pin=40,
|
||||
dc_pin=39,
|
||||
reset_pin=41,
|
||||
invert_colors=True,
|
||||
mirror_x=True,
|
||||
mirror_y=True,
|
||||
data_rate="80MHz",
|
||||
)
|
||||
|
||||
ST7789V.extend(
|
||||
"ADAFRUIT-S2-TFT-FEATHER",
|
||||
height=240,
|
||||
width=135,
|
||||
offset_height=52,
|
||||
offset_width=40,
|
||||
cs_pin=7,
|
||||
dc_pin=39,
|
||||
reset_pin=40,
|
||||
invert_colors=True,
|
||||
)
|
||||
|
||||
models = {}
|
@@ -67,6 +67,14 @@ RM690B0 = DriverChip(
|
||||
),
|
||||
)
|
||||
|
||||
T4_S3_AMOLED = RM690B0.extend("T4-S3", width=450, offset_width=16, bus_mode=TYPE_QUAD)
|
||||
T4_S3_AMOLED = RM690B0.extend(
|
||||
"T4-S3",
|
||||
width=450,
|
||||
offset_width=16,
|
||||
cs_pin=11,
|
||||
reset_pin=13,
|
||||
enable_pin=9,
|
||||
bus_mode=TYPE_QUAD,
|
||||
)
|
||||
|
||||
models = {}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import esphome.config_validation as cv
|
||||
|
||||
from . import DriverChip
|
||||
from .ili import ILI9488_A
|
||||
|
||||
@@ -128,6 +130,7 @@ DriverChip(
|
||||
|
||||
ILI9488_A.extend(
|
||||
"PICO-RESTOUCH-LCD-3.5",
|
||||
swap_xy=cv.UNDEFINED,
|
||||
spi_16=True,
|
||||
pixel_mode="16bit",
|
||||
mirror_x=True,
|
||||
|
@@ -55,7 +55,8 @@ void MQTTAlarmControlPanelComponent::dump_config() {
|
||||
}
|
||||
|
||||
void MQTTAlarmControlPanelComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||
JsonArray supported_features = root.createNestedArray(MQTT_SUPPORTED_FEATURES);
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
JsonArray supported_features = root[MQTT_SUPPORTED_FEATURES].to<JsonArray>();
|
||||
const uint32_t acp_supported_features = this->alarm_control_panel_->get_supported_features();
|
||||
if (acp_supported_features & ACP_FEAT_ARM_AWAY) {
|
||||
supported_features.add("arm_away");
|
||||
|
@@ -30,6 +30,7 @@ MQTTBinarySensorComponent::MQTTBinarySensorComponent(binary_sensor::BinarySensor
|
||||
}
|
||||
|
||||
void MQTTBinarySensorComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
if (!this->binary_sensor_->get_device_class().empty())
|
||||
root[MQTT_DEVICE_CLASS] = this->binary_sensor_->get_device_class();
|
||||
if (this->binary_sensor_->is_status_binary_sensor())
|
||||
|
@@ -31,9 +31,12 @@ void MQTTButtonComponent::dump_config() {
|
||||
}
|
||||
|
||||
void MQTTButtonComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||
// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
config.state_topic = false;
|
||||
if (!this->button_->get_device_class().empty())
|
||||
if (!this->button_->get_device_class().empty()) {
|
||||
root[MQTT_DEVICE_CLASS] = this->button_->get_device_class();
|
||||
}
|
||||
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
|
||||
}
|
||||
|
||||
std::string MQTTButtonComponent::component_type() const { return "button"; }
|
||||
|
@@ -92,6 +92,7 @@ void MQTTClientComponent::send_device_info_() {
|
||||
std::string topic = "esphome/discover/";
|
||||
topic.append(App.get_name());
|
||||
|
||||
// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
this->publish_json(
|
||||
topic,
|
||||
[](JsonObject root) {
|
||||
@@ -147,6 +148,7 @@ void MQTTClientComponent::send_device_info_() {
|
||||
#endif
|
||||
},
|
||||
2, this->discovery_info_.retain);
|
||||
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
|
||||
}
|
||||
|
||||
void MQTTClientComponent::dump_config() {
|
||||
|
@@ -14,6 +14,7 @@ static const char *const TAG = "mqtt.climate";
|
||||
using namespace esphome::climate;
|
||||
|
||||
void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||
// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
auto traits = this->device_->get_traits();
|
||||
// current_temperature_topic
|
||||
if (traits.get_supports_current_temperature()) {
|
||||
@@ -28,7 +29,7 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo
|
||||
// mode_state_topic
|
||||
root[MQTT_MODE_STATE_TOPIC] = this->get_mode_state_topic();
|
||||
// modes
|
||||
JsonArray modes = root.createNestedArray(MQTT_MODES);
|
||||
JsonArray modes = root[MQTT_MODES].to<JsonArray>();
|
||||
// sort array for nice UI in HA
|
||||
if (traits.supports_mode(CLIMATE_MODE_AUTO))
|
||||
modes.add("auto");
|
||||
@@ -89,7 +90,7 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo
|
||||
// preset_mode_state_topic
|
||||
root[MQTT_PRESET_MODE_STATE_TOPIC] = this->get_preset_state_topic();
|
||||
// presets
|
||||
JsonArray presets = root.createNestedArray("preset_modes");
|
||||
JsonArray presets = root["preset_modes"].to<JsonArray>();
|
||||
if (traits.supports_preset(CLIMATE_PRESET_HOME))
|
||||
presets.add("home");
|
||||
if (traits.supports_preset(CLIMATE_PRESET_AWAY))
|
||||
@@ -119,7 +120,7 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo
|
||||
// fan_mode_state_topic
|
||||
root[MQTT_FAN_MODE_STATE_TOPIC] = this->get_fan_mode_state_topic();
|
||||
// fan_modes
|
||||
JsonArray fan_modes = root.createNestedArray("fan_modes");
|
||||
JsonArray fan_modes = root["fan_modes"].to<JsonArray>();
|
||||
if (traits.supports_fan_mode(CLIMATE_FAN_ON))
|
||||
fan_modes.add("on");
|
||||
if (traits.supports_fan_mode(CLIMATE_FAN_OFF))
|
||||
@@ -150,7 +151,7 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo
|
||||
// swing_mode_state_topic
|
||||
root[MQTT_SWING_MODE_STATE_TOPIC] = this->get_swing_mode_state_topic();
|
||||
// swing_modes
|
||||
JsonArray swing_modes = root.createNestedArray("swing_modes");
|
||||
JsonArray swing_modes = root["swing_modes"].to<JsonArray>();
|
||||
if (traits.supports_swing_mode(CLIMATE_SWING_OFF))
|
||||
swing_modes.add("off");
|
||||
if (traits.supports_swing_mode(CLIMATE_SWING_BOTH))
|
||||
@@ -163,6 +164,7 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo
|
||||
|
||||
config.state_topic = false;
|
||||
config.command_topic = false;
|
||||
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
|
||||
}
|
||||
void MQTTClimateComponent::setup() {
|
||||
auto traits = this->device_->get_traits();
|
||||
|
@@ -70,6 +70,7 @@ bool MQTTComponent::send_discovery_() {
|
||||
|
||||
ESP_LOGV(TAG, "'%s': Sending discovery", this->friendly_name().c_str());
|
||||
|
||||
// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
return global_mqtt_client->publish_json(
|
||||
this->get_discovery_topic_(discovery_info),
|
||||
[this](JsonObject root) {
|
||||
@@ -128,11 +129,7 @@ bool MQTTComponent::send_discovery_() {
|
||||
root[MQTT_PAYLOAD_NOT_AVAILABLE] = this->availability_->payload_not_available;
|
||||
}
|
||||
|
||||
std::string unique_id = this->unique_id();
|
||||
const MQTTDiscoveryInfo &discovery_info = global_mqtt_client->get_discovery_info();
|
||||
if (!unique_id.empty()) {
|
||||
root[MQTT_UNIQUE_ID] = unique_id;
|
||||
} else {
|
||||
if (discovery_info.unique_id_generator == MQTT_MAC_ADDRESS_UNIQUE_ID_GENERATOR) {
|
||||
char friendly_name_hash[9];
|
||||
sprintf(friendly_name_hash, "%08" PRIx32, fnv1_hash(this->friendly_name()));
|
||||
@@ -143,7 +140,6 @@ bool MQTTComponent::send_discovery_() {
|
||||
// gorgeous device registry view.
|
||||
root[MQTT_UNIQUE_ID] = "ESP" + this->component_type() + this->get_default_object_id_();
|
||||
}
|
||||
}
|
||||
|
||||
const std::string &node_name = App.get_name();
|
||||
if (discovery_info.object_id_generator == MQTT_DEVICE_NAME_OBJECT_ID_GENERATOR)
|
||||
@@ -155,7 +151,7 @@ bool MQTTComponent::send_discovery_() {
|
||||
}
|
||||
std::string node_area = App.get_area();
|
||||
|
||||
JsonObject device_info = root.createNestedObject(MQTT_DEVICE);
|
||||
JsonObject device_info = root[MQTT_DEVICE].to<JsonObject>();
|
||||
const auto mac = get_mac_address();
|
||||
device_info[MQTT_DEVICE_IDENTIFIERS] = mac;
|
||||
device_info[MQTT_DEVICE_NAME] = node_friendly_name;
|
||||
@@ -192,6 +188,7 @@ bool MQTTComponent::send_discovery_() {
|
||||
device_info[MQTT_DEVICE_CONNECTIONS][0][1] = mac;
|
||||
},
|
||||
this->qos_, discovery_info.retain);
|
||||
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
|
||||
}
|
||||
|
||||
uint8_t MQTTComponent::get_qos() const { return this->qos_; }
|
||||
@@ -284,7 +281,6 @@ void MQTTComponent::call_dump_config() {
|
||||
this->dump_config();
|
||||
}
|
||||
void MQTTComponent::schedule_resend_state() { this->resend_state_ = true; }
|
||||
std::string MQTTComponent::unique_id() { return ""; }
|
||||
bool MQTTComponent::is_connected_() const { return global_mqtt_client->is_connected(); }
|
||||
|
||||
// Pull these properties from EntityBase if not overridden
|
||||
|
@@ -164,13 +164,6 @@ class MQTTComponent : public Component {
|
||||
*/
|
||||
virtual const EntityBase *get_entity() const = 0;
|
||||
|
||||
/** A unique ID for this MQTT component, empty for no unique id. See unique ID requirements:
|
||||
* https://developers.home-assistant.io/docs/en/entity_registry_index.html#unique-id-requirements
|
||||
*
|
||||
* @return The unique id as a string.
|
||||
*/
|
||||
virtual std::string unique_id();
|
||||
|
||||
/// Get the friendly name of this MQTT component.
|
||||
virtual std::string friendly_name() const;
|
||||
|
||||
|
@@ -67,6 +67,7 @@ void MQTTCoverComponent::dump_config() {
|
||||
}
|
||||
}
|
||||
void MQTTCoverComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
if (!this->cover_->get_device_class().empty())
|
||||
root[MQTT_DEVICE_CLASS] = this->cover_->get_device_class();
|
||||
|
||||
|
@@ -20,13 +20,13 @@ MQTTDateComponent::MQTTDateComponent(DateEntity *date) : date_(date) {}
|
||||
void MQTTDateComponent::setup() {
|
||||
this->subscribe_json(this->get_command_topic_(), [this](const std::string &topic, JsonObject root) {
|
||||
auto call = this->date_->make_call();
|
||||
if (root.containsKey("year")) {
|
||||
if (root["year"].is<uint16_t>()) {
|
||||
call.set_year(root["year"]);
|
||||
}
|
||||
if (root.containsKey("month")) {
|
||||
if (root["month"].is<uint8_t>()) {
|
||||
call.set_month(root["month"]);
|
||||
}
|
||||
if (root.containsKey("day")) {
|
||||
if (root["day"].is<uint8_t>()) {
|
||||
call.set_day(root["day"]);
|
||||
}
|
||||
call.perform();
|
||||
@@ -55,6 +55,7 @@ bool MQTTDateComponent::send_initial_state() {
|
||||
}
|
||||
bool MQTTDateComponent::publish_state(uint16_t year, uint8_t month, uint8_t day) {
|
||||
return this->publish_json(this->get_state_topic_(), [year, month, day](JsonObject root) {
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
root["year"] = year;
|
||||
root["month"] = month;
|
||||
root["day"] = day;
|
||||
|
@@ -20,22 +20,22 @@ MQTTDateTimeComponent::MQTTDateTimeComponent(DateTimeEntity *datetime) : datetim
|
||||
void MQTTDateTimeComponent::setup() {
|
||||
this->subscribe_json(this->get_command_topic_(), [this](const std::string &topic, JsonObject root) {
|
||||
auto call = this->datetime_->make_call();
|
||||
if (root.containsKey("year")) {
|
||||
if (root["year"].is<uint16_t>()) {
|
||||
call.set_year(root["year"]);
|
||||
}
|
||||
if (root.containsKey("month")) {
|
||||
if (root["month"].is<uint8_t>()) {
|
||||
call.set_month(root["month"]);
|
||||
}
|
||||
if (root.containsKey("day")) {
|
||||
if (root["day"].is<uint8_t>()) {
|
||||
call.set_day(root["day"]);
|
||||
}
|
||||
if (root.containsKey("hour")) {
|
||||
if (root["hour"].is<uint8_t>()) {
|
||||
call.set_hour(root["hour"]);
|
||||
}
|
||||
if (root.containsKey("minute")) {
|
||||
if (root["minute"].is<uint8_t>()) {
|
||||
call.set_minute(root["minute"]);
|
||||
}
|
||||
if (root.containsKey("second")) {
|
||||
if (root["second"].is<uint8_t>()) {
|
||||
call.set_second(root["second"]);
|
||||
}
|
||||
call.perform();
|
||||
@@ -68,6 +68,7 @@ bool MQTTDateTimeComponent::send_initial_state() {
|
||||
bool MQTTDateTimeComponent::publish_state(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute,
|
||||
uint8_t second) {
|
||||
return this->publish_json(this->get_state_topic_(), [year, month, day, hour, minute, second](JsonObject root) {
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
root["year"] = year;
|
||||
root["month"] = month;
|
||||
root["day"] = day;
|
||||
|
@@ -16,7 +16,8 @@ using namespace esphome::event;
|
||||
MQTTEventComponent::MQTTEventComponent(event::Event *event) : event_(event) {}
|
||||
|
||||
void MQTTEventComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||
JsonArray event_types = root.createNestedArray(MQTT_EVENT_TYPES);
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
JsonArray event_types = root[MQTT_EVENT_TYPES].to<JsonArray>();
|
||||
for (const auto &event_type : this->event_->get_event_types())
|
||||
event_types.add(event_type);
|
||||
|
||||
@@ -40,8 +41,10 @@ void MQTTEventComponent::dump_config() {
|
||||
}
|
||||
|
||||
bool MQTTEventComponent::publish_event_(const std::string &event_type) {
|
||||
return this->publish_json(this->get_state_topic_(),
|
||||
[event_type](JsonObject root) { root[MQTT_EVENT_TYPE] = event_type; });
|
||||
return this->publish_json(this->get_state_topic_(), [event_type](JsonObject root) {
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
root[MQTT_EVENT_TYPE] = event_type;
|
||||
});
|
||||
}
|
||||
|
||||
std::string MQTTEventComponent::component_type() const { return "event"; }
|
||||
|
@@ -143,6 +143,7 @@ void MQTTFanComponent::dump_config() {
|
||||
bool MQTTFanComponent::send_initial_state() { return this->publish_state(); }
|
||||
|
||||
void MQTTFanComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
if (this->state_->get_traits().supports_direction()) {
|
||||
root[MQTT_DIRECTION_COMMAND_TOPIC] = this->get_direction_command_topic();
|
||||
root[MQTT_DIRECTION_STATE_TOPIC] = this->get_direction_state_topic();
|
||||
|
@@ -32,17 +32,21 @@ void MQTTJSONLightComponent::setup() {
|
||||
MQTTJSONLightComponent::MQTTJSONLightComponent(LightState *state) : state_(state) {}
|
||||
|
||||
bool MQTTJSONLightComponent::publish_state_() {
|
||||
return this->publish_json(this->get_state_topic_(),
|
||||
[this](JsonObject root) { LightJSONSchema::dump_json(*this->state_, root); });
|
||||
return this->publish_json(this->get_state_topic_(), [this](JsonObject root) {
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
LightJSONSchema::dump_json(*this->state_, root);
|
||||
});
|
||||
}
|
||||
LightState *MQTTJSONLightComponent::get_state() const { return this->state_; }
|
||||
|
||||
void MQTTJSONLightComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
root["schema"] = "json";
|
||||
auto traits = this->state_->get_traits();
|
||||
|
||||
root[MQTT_COLOR_MODE] = true;
|
||||
JsonArray color_modes = root.createNestedArray("supported_color_modes");
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
JsonArray color_modes = root["supported_color_modes"].to<JsonArray>();
|
||||
if (traits.supports_color_mode(ColorMode::ON_OFF))
|
||||
color_modes.add("onoff");
|
||||
if (traits.supports_color_mode(ColorMode::BRIGHTNESS))
|
||||
@@ -67,7 +71,7 @@ void MQTTJSONLightComponent::send_discovery(JsonObject root, mqtt::SendDiscovery
|
||||
|
||||
if (this->state_->supports_effects()) {
|
||||
root["effect"] = true;
|
||||
JsonArray effect_list = root.createNestedArray(MQTT_EFFECT_LIST);
|
||||
JsonArray effect_list = root[MQTT_EFFECT_LIST].to<JsonArray>();
|
||||
for (auto *effect : this->state_->get_effects())
|
||||
effect_list.add(effect->get_name());
|
||||
effect_list.add("None");
|
||||
|
@@ -38,8 +38,10 @@ void MQTTLockComponent::dump_config() {
|
||||
std::string MQTTLockComponent::component_type() const { return "lock"; }
|
||||
const EntityBase *MQTTLockComponent::get_entity() const { return this->lock_; }
|
||||
void MQTTLockComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||
if (this->lock_->traits.get_assumed_state())
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
if (this->lock_->traits.get_assumed_state()) {
|
||||
root[MQTT_OPTIMISTIC] = true;
|
||||
}
|
||||
if (this->lock_->traits.get_supports_open())
|
||||
root[MQTT_PAYLOAD_OPEN] = "OPEN";
|
||||
}
|
||||
|
@@ -40,6 +40,7 @@ const EntityBase *MQTTNumberComponent::get_entity() const { return this->number_
|
||||
void MQTTNumberComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||
const auto &traits = number_->traits;
|
||||
// https://www.home-assistant.io/integrations/number.mqtt/
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
root[MQTT_MIN] = traits.get_min_value();
|
||||
root[MQTT_MAX] = traits.get_max_value();
|
||||
root[MQTT_STEP] = traits.get_step();
|
||||
|
@@ -35,7 +35,8 @@ const EntityBase *MQTTSelectComponent::get_entity() const { return this->select_
|
||||
void MQTTSelectComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||
const auto &traits = select_->traits;
|
||||
// https://www.home-assistant.io/integrations/select.mqtt/
|
||||
JsonArray options = root.createNestedArray(MQTT_OPTIONS);
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
JsonArray options = root[MQTT_OPTIONS].to<JsonArray>();
|
||||
for (const auto &option : traits.get_options())
|
||||
options.add(option);
|
||||
|
||||
|
@@ -44,8 +44,10 @@ void MQTTSensorComponent::set_expire_after(uint32_t expire_after) { this->expire
|
||||
void MQTTSensorComponent::disable_expire_after() { this->expire_after_ = 0; }
|
||||
|
||||
void MQTTSensorComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||
if (!this->sensor_->get_device_class().empty())
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
if (!this->sensor_->get_device_class().empty()) {
|
||||
root[MQTT_DEVICE_CLASS] = this->sensor_->get_device_class();
|
||||
}
|
||||
|
||||
if (!this->sensor_->get_unit_of_measurement().empty())
|
||||
root[MQTT_UNIT_OF_MEASUREMENT] = this->sensor_->get_unit_of_measurement();
|
||||
@@ -74,7 +76,6 @@ bool MQTTSensorComponent::publish_state(float value) {
|
||||
int8_t accuracy = this->sensor_->get_accuracy_decimals();
|
||||
return this->publish(this->get_state_topic_(), value_accuracy_to_string(value, accuracy));
|
||||
}
|
||||
std::string MQTTSensorComponent::unique_id() { return this->sensor_->unique_id(); }
|
||||
|
||||
} // namespace mqtt
|
||||
} // namespace esphome
|
||||
|
@@ -46,7 +46,6 @@ class MQTTSensorComponent : public mqtt::MQTTComponent {
|
||||
/// Override for MQTTComponent, returns "sensor".
|
||||
std::string component_type() const override;
|
||||
const EntityBase *get_entity() const override;
|
||||
std::string unique_id() override;
|
||||
|
||||
sensor::Sensor *sensor_;
|
||||
optional<uint32_t> expire_after_; // Override the expire after advertised to Home Assistant
|
||||
|
@@ -45,8 +45,10 @@ void MQTTSwitchComponent::dump_config() {
|
||||
std::string MQTTSwitchComponent::component_type() const { return "switch"; }
|
||||
const EntityBase *MQTTSwitchComponent::get_entity() const { return this->switch_; }
|
||||
void MQTTSwitchComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||
if (this->switch_->assumed_state())
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
if (this->switch_->assumed_state()) {
|
||||
root[MQTT_OPTIMISTIC] = true;
|
||||
}
|
||||
}
|
||||
bool MQTTSwitchComponent::send_initial_state() { return this->publish_state(this->switch_->state); }
|
||||
|
||||
|
@@ -34,6 +34,7 @@ std::string MQTTTextComponent::component_type() const { return "text"; }
|
||||
const EntityBase *MQTTTextComponent::get_entity() const { return this->text_; }
|
||||
|
||||
void MQTTTextComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
switch (this->text_->traits.get_mode()) {
|
||||
case TEXT_MODE_TEXT:
|
||||
root[MQTT_MODE] = "text";
|
||||
|
@@ -15,8 +15,10 @@ using namespace esphome::text_sensor;
|
||||
|
||||
MQTTTextSensor::MQTTTextSensor(TextSensor *sensor) : sensor_(sensor) {}
|
||||
void MQTTTextSensor::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||
if (!this->sensor_->get_device_class().empty())
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
if (!this->sensor_->get_device_class().empty()) {
|
||||
root[MQTT_DEVICE_CLASS] = this->sensor_->get_device_class();
|
||||
}
|
||||
config.command_topic = false;
|
||||
}
|
||||
void MQTTTextSensor::setup() {
|
||||
@@ -38,7 +40,6 @@ bool MQTTTextSensor::send_initial_state() {
|
||||
}
|
||||
std::string MQTTTextSensor::component_type() const { return "sensor"; }
|
||||
const EntityBase *MQTTTextSensor::get_entity() const { return this->sensor_; }
|
||||
std::string MQTTTextSensor::unique_id() { return this->sensor_->unique_id(); }
|
||||
|
||||
} // namespace mqtt
|
||||
} // namespace esphome
|
||||
|
@@ -28,7 +28,6 @@ class MQTTTextSensor : public mqtt::MQTTComponent {
|
||||
protected:
|
||||
std::string component_type() const override;
|
||||
const EntityBase *get_entity() const override;
|
||||
std::string unique_id() override;
|
||||
|
||||
text_sensor::TextSensor *sensor_;
|
||||
};
|
||||
|
@@ -20,13 +20,13 @@ MQTTTimeComponent::MQTTTimeComponent(TimeEntity *time) : time_(time) {}
|
||||
void MQTTTimeComponent::setup() {
|
||||
this->subscribe_json(this->get_command_topic_(), [this](const std::string &topic, JsonObject root) {
|
||||
auto call = this->time_->make_call();
|
||||
if (root.containsKey("hour")) {
|
||||
if (root["hour"].is<uint8_t>()) {
|
||||
call.set_hour(root["hour"]);
|
||||
}
|
||||
if (root.containsKey("minute")) {
|
||||
if (root["minute"].is<uint8_t>()) {
|
||||
call.set_minute(root["minute"]);
|
||||
}
|
||||
if (root.containsKey("second")) {
|
||||
if (root["second"].is<uint8_t>()) {
|
||||
call.set_second(root["second"]);
|
||||
}
|
||||
call.perform();
|
||||
@@ -55,6 +55,7 @@ bool MQTTTimeComponent::send_initial_state() {
|
||||
}
|
||||
bool MQTTTimeComponent::publish_state(uint8_t hour, uint8_t minute, uint8_t second) {
|
||||
return this->publish_json(this->get_state_topic_(), [hour, minute, second](JsonObject root) {
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
root["hour"] = hour;
|
||||
root["minute"] = minute;
|
||||
root["second"] = second;
|
||||
|
@@ -41,6 +41,7 @@ bool MQTTUpdateComponent::publish_state() {
|
||||
}
|
||||
|
||||
void MQTTUpdateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
root["schema"] = "json";
|
||||
root[MQTT_PAYLOAD_INSTALL] = "INSTALL";
|
||||
}
|
||||
|
@@ -49,8 +49,10 @@ void MQTTValveComponent::dump_config() {
|
||||
}
|
||||
}
|
||||
void MQTTValveComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||
if (!this->valve_->get_device_class().empty())
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
|
||||
if (!this->valve_->get_device_class().empty()) {
|
||||
root[MQTT_DEVICE_CLASS] = this->valve_->get_device_class();
|
||||
}
|
||||
|
||||
auto traits = this->valve_->get_traits();
|
||||
if (traits.get_is_assumed_state()) {
|
||||
|
@@ -356,7 +356,7 @@ void MS8607Component::read_humidity_(float temperature_float) {
|
||||
|
||||
// map 16 bit humidity value into range [-6%, 118%]
|
||||
float const humidity_partial = double(humidity) / (1 << 16);
|
||||
float const humidity_percentage = lerp(humidity_partial, -6.0, 118.0);
|
||||
float const humidity_percentage = std::lerp(-6.0, 118.0, humidity_partial);
|
||||
float const compensated_humidity_percentage =
|
||||
humidity_percentage + (20 - temperature_float) * MS8607_H_TEMP_COEFFICIENT;
|
||||
ESP_LOGD(TAG, "Compensated for temperature, humidity=%.2f%%", compensated_humidity_percentage);
|
||||
|
218
esphome/components/nrf52/__init__.py
Normal file
218
esphome/components/nrf52/__init__.py
Normal file
@@ -0,0 +1,218 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import esphome.codegen as cg
|
||||
from esphome.components.zephyr import (
|
||||
copy_files as zephyr_copy_files,
|
||||
zephyr_add_pm_static,
|
||||
zephyr_set_core_data,
|
||||
zephyr_to_code,
|
||||
)
|
||||
from esphome.components.zephyr.const import (
|
||||
BOOTLOADER_MCUBOOT,
|
||||
KEY_BOOTLOADER,
|
||||
KEY_ZEPHYR,
|
||||
)
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
CONF_BOARD,
|
||||
CONF_FRAMEWORK,
|
||||
KEY_CORE,
|
||||
KEY_FRAMEWORK_VERSION,
|
||||
KEY_TARGET_FRAMEWORK,
|
||||
KEY_TARGET_PLATFORM,
|
||||
PLATFORM_NRF52,
|
||||
)
|
||||
from esphome.core import CORE, EsphomeError, coroutine_with_priority
|
||||
from esphome.storage_json import StorageJSON
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .boards import BOARDS_ZEPHYR, BOOTLOADER_CONFIG
|
||||
from .const import (
|
||||
BOOTLOADER_ADAFRUIT,
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD132,
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD140_V6,
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD140_V7,
|
||||
)
|
||||
|
||||
# force import gpio to register pin schema
|
||||
from .gpio import nrf52_pin_to_code # noqa
|
||||
|
||||
CODEOWNERS = ["@tomaszduda23"]
|
||||
AUTO_LOAD = ["zephyr"]
|
||||
IS_TARGET_PLATFORM = True
|
||||
|
||||
|
||||
def set_core_data(config: ConfigType) -> ConfigType:
|
||||
zephyr_set_core_data(config)
|
||||
CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = PLATFORM_NRF52
|
||||
CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK] = KEY_ZEPHYR
|
||||
CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION] = cv.Version(2, 6, 1)
|
||||
|
||||
if config[KEY_BOOTLOADER] in BOOTLOADER_CONFIG:
|
||||
zephyr_add_pm_static(BOOTLOADER_CONFIG[config[KEY_BOOTLOADER]])
|
||||
|
||||
return config
|
||||
|
||||
|
||||
BOOTLOADERS = [
|
||||
BOOTLOADER_ADAFRUIT,
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD132,
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD140_V6,
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD140_V7,
|
||||
BOOTLOADER_MCUBOOT,
|
||||
]
|
||||
|
||||
|
||||
def _detect_bootloader(config: ConfigType) -> ConfigType:
|
||||
"""Detect the bootloader for the given board."""
|
||||
config = config.copy()
|
||||
bootloaders: list[str] = []
|
||||
board = config[CONF_BOARD]
|
||||
|
||||
if board in BOARDS_ZEPHYR and KEY_BOOTLOADER in BOARDS_ZEPHYR[board]:
|
||||
# this board have bootloaders config available
|
||||
bootloaders = BOARDS_ZEPHYR[board][KEY_BOOTLOADER]
|
||||
|
||||
if KEY_BOOTLOADER not in config:
|
||||
if bootloaders:
|
||||
# there is no bootloader in config -> take first one
|
||||
config[KEY_BOOTLOADER] = bootloaders[0]
|
||||
else:
|
||||
# make mcuboot as default if there is no configuration for that board
|
||||
config[KEY_BOOTLOADER] = BOOTLOADER_MCUBOOT
|
||||
elif bootloaders and config[KEY_BOOTLOADER] not in bootloaders:
|
||||
raise cv.Invalid(
|
||||
f"{board} does not support {config[KEY_BOOTLOADER]}, select one of: {', '.join(bootloaders)}"
|
||||
)
|
||||
return config
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_BOARD): cv.string_strict,
|
||||
cv.Optional(KEY_BOOTLOADER): cv.one_of(*BOOTLOADERS, lower=True),
|
||||
}
|
||||
),
|
||||
_detect_bootloader,
|
||||
set_core_data,
|
||||
)
|
||||
|
||||
|
||||
@coroutine_with_priority(1000)
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
"""Convert the configuration to code."""
|
||||
cg.add_platformio_option("board", config[CONF_BOARD])
|
||||
cg.add_build_flag("-DUSE_NRF52")
|
||||
cg.add_define("ESPHOME_BOARD", config[CONF_BOARD])
|
||||
cg.add_define("ESPHOME_VARIANT", "NRF52")
|
||||
cg.add_platformio_option(CONF_FRAMEWORK, CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK])
|
||||
cg.add_platformio_option(
|
||||
"platform",
|
||||
"https://github.com/tomaszduda23/platform-nordicnrf52/archive/refs/tags/v10.3.0-1.zip",
|
||||
)
|
||||
cg.add_platformio_option(
|
||||
"platform_packages",
|
||||
[
|
||||
"platformio/framework-zephyr@https://github.com/tomaszduda23/framework-sdk-nrf/archive/refs/tags/v2.6.1-4.zip",
|
||||
"platformio/toolchain-gccarmnoneeabi@https://github.com/tomaszduda23/toolchain-sdk-ng/archive/refs/tags/v0.16.1-1.zip",
|
||||
],
|
||||
)
|
||||
|
||||
if config[KEY_BOOTLOADER] == BOOTLOADER_ADAFRUIT:
|
||||
# make sure that firmware.zip is created
|
||||
# for Adafruit_nRF52_Bootloader
|
||||
cg.add_platformio_option("board_upload.protocol", "nrfutil")
|
||||
cg.add_platformio_option("board_upload.use_1200bps_touch", "true")
|
||||
cg.add_platformio_option("board_upload.require_upload_port", "true")
|
||||
cg.add_platformio_option("board_upload.wait_for_upload_port", "true")
|
||||
|
||||
zephyr_to_code(config)
|
||||
|
||||
|
||||
def copy_files() -> None:
|
||||
"""Copy files to the build directory."""
|
||||
zephyr_copy_files()
|
||||
|
||||
|
||||
def get_download_types(storage_json: StorageJSON) -> list[dict[str, str]]:
|
||||
"""Get the download types for the firmware."""
|
||||
types = []
|
||||
UF2_PATH = "zephyr/zephyr.uf2"
|
||||
DFU_PATH = "firmware.zip"
|
||||
HEX_PATH = "zephyr/zephyr.hex"
|
||||
HEX_MERGED_PATH = "zephyr/merged.hex"
|
||||
APP_IMAGE_PATH = "zephyr/app_update.bin"
|
||||
build_dir = Path(storage_json.firmware_bin_path).parent
|
||||
if (build_dir / UF2_PATH).is_file():
|
||||
types = [
|
||||
{
|
||||
"title": "UF2 package (recommended)",
|
||||
"description": "For flashing via Adafruit nRF52 Bootloader as a flash drive.",
|
||||
"file": UF2_PATH,
|
||||
"download": f"{storage_json.name}.uf2",
|
||||
},
|
||||
{
|
||||
"title": "DFU package",
|
||||
"description": "For flashing via adafruit-nrfutil using USB CDC.",
|
||||
"file": DFU_PATH,
|
||||
"download": f"dfu-{storage_json.name}.zip",
|
||||
},
|
||||
]
|
||||
else:
|
||||
types = [
|
||||
{
|
||||
"title": "HEX package",
|
||||
"description": "For flashing via pyocd using SWD.",
|
||||
"file": (
|
||||
HEX_MERGED_PATH
|
||||
if (build_dir / HEX_MERGED_PATH).is_file()
|
||||
else HEX_PATH
|
||||
),
|
||||
"download": f"{storage_json.name}.hex",
|
||||
},
|
||||
]
|
||||
if (build_dir / APP_IMAGE_PATH).is_file():
|
||||
types += [
|
||||
{
|
||||
"title": "App update package",
|
||||
"description": "For flashing via mcumgr-web using BLE or smpclient using USB CDC.",
|
||||
"file": APP_IMAGE_PATH,
|
||||
"download": f"app-{storage_json.name}.img",
|
||||
},
|
||||
]
|
||||
|
||||
return types
|
||||
|
||||
|
||||
def _upload_using_platformio(
|
||||
config: ConfigType, port: str, upload_args: list[str]
|
||||
) -> int | str:
|
||||
from esphome import platformio_api
|
||||
|
||||
if port is not None:
|
||||
upload_args += ["--upload-port", port]
|
||||
return platformio_api.run_platformio_cli_run(config, CORE.verbose, *upload_args)
|
||||
|
||||
|
||||
def upload_program(config: ConfigType, args, host: str) -> bool:
|
||||
from esphome.__main__ import check_permissions, get_port_type
|
||||
|
||||
result = 0
|
||||
handled = False
|
||||
|
||||
if get_port_type(host) == "SERIAL":
|
||||
check_permissions(host)
|
||||
result = _upload_using_platformio(config, host, ["-t", "upload"])
|
||||
handled = True
|
||||
|
||||
if host == "PYOCD":
|
||||
result = _upload_using_platformio(config, host, ["-t", "flash_pyocd"])
|
||||
handled = True
|
||||
|
||||
if result != 0:
|
||||
raise EsphomeError(f"Upload failed with result: {result}")
|
||||
|
||||
return handled
|
34
esphome/components/nrf52/boards.py
Normal file
34
esphome/components/nrf52/boards.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from esphome.components.zephyr import Section
|
||||
from esphome.components.zephyr.const import KEY_BOOTLOADER
|
||||
|
||||
from .const import (
|
||||
BOOTLOADER_ADAFRUIT,
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD132,
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD140_V6,
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD140_V7,
|
||||
)
|
||||
|
||||
BOARDS_ZEPHYR = {
|
||||
"adafruit_itsybitsy_nrf52840": {
|
||||
KEY_BOOTLOADER: [
|
||||
BOOTLOADER_ADAFRUIT,
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD132,
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD140_V6,
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD140_V7,
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
# https://github.com/ffenix113/zigbee_home/blob/17bb7b9e9d375e756da9e38913f53303937fb66a/types/board/known_boards.go
|
||||
# https://learn.adafruit.com/introducing-the-adafruit-nrf52840-feather?view=all#hathach-memory-map
|
||||
BOOTLOADER_CONFIG = {
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD132: [
|
||||
Section("empty_app_offset", 0x0, 0x26000, "flash_primary"),
|
||||
],
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD140_V6: [
|
||||
Section("empty_app_offset", 0x0, 0x26000, "flash_primary"),
|
||||
],
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD140_V7: [
|
||||
Section("empty_app_offset", 0x0, 0x27000, "flash_primary"),
|
||||
],
|
||||
}
|
4
esphome/components/nrf52/const.py
Normal file
4
esphome/components/nrf52/const.py
Normal file
@@ -0,0 +1,4 @@
|
||||
BOOTLOADER_ADAFRUIT = "adafruit"
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD132 = "adafruit_nrf52_sd132"
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD140_V6 = "adafruit_nrf52_sd140_v6"
|
||||
BOOTLOADER_ADAFRUIT_NRF52_SD140_V7 = "adafruit_nrf52_sd140_v7"
|
53
esphome/components/nrf52/gpio.py
Normal file
53
esphome/components/nrf52/gpio.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from esphome import pins
|
||||
import esphome.codegen as cg
|
||||
from esphome.components.zephyr.const import zephyr_ns
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_ID, CONF_INVERTED, CONF_MODE, CONF_NUMBER, PLATFORM_NRF52
|
||||
|
||||
ZephyrGPIOPin = zephyr_ns.class_("ZephyrGPIOPin", cg.InternalGPIOPin)
|
||||
|
||||
|
||||
def _translate_pin(value):
|
||||
if isinstance(value, dict) or value is None:
|
||||
raise cv.Invalid(
|
||||
"This variable only supports pin numbers, not full pin schemas "
|
||||
"(with inverted and mode)."
|
||||
)
|
||||
if isinstance(value, int):
|
||||
return value
|
||||
try:
|
||||
return int(value)
|
||||
except ValueError:
|
||||
pass
|
||||
# e.g. P0.27
|
||||
if len(value) >= len("P0.0") and value[0] == "P" and value[2] == ".":
|
||||
return cv.int_(value[len("P")].strip()) * 32 + cv.int_(
|
||||
value[len("P0.") :].strip()
|
||||
)
|
||||
raise cv.Invalid(f"Invalid pin: {value}")
|
||||
|
||||
|
||||
def validate_gpio_pin(value):
|
||||
value = _translate_pin(value)
|
||||
if value < 0 or value > (32 + 16):
|
||||
raise cv.Invalid(f"NRF52: Invalid pin number: {value}")
|
||||
return value
|
||||
|
||||
|
||||
NRF52_PIN_SCHEMA = cv.All(
|
||||
pins.gpio_base_schema(
|
||||
ZephyrGPIOPin,
|
||||
validate_gpio_pin,
|
||||
modes=pins.GPIO_STANDARD_MODES,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@pins.PIN_SCHEMA_REGISTRY.register(PLATFORM_NRF52, NRF52_PIN_SCHEMA)
|
||||
async def nrf52_pin_to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
num = config[CONF_NUMBER]
|
||||
cg.add(var.set_pin(num))
|
||||
cg.add(var.set_inverted(config[CONF_INVERTED]))
|
||||
cg.add(var.set_flags(pins.gpio_flags_expr(config[CONF_MODE])))
|
||||
return var
|
@@ -11,8 +11,6 @@ const std::string &OneWireDevice::get_address_name() {
|
||||
return this->address_name_;
|
||||
}
|
||||
|
||||
std::string OneWireDevice::unique_id() { return "dallas-" + str_lower_case(format_hex(this->address_)); }
|
||||
|
||||
bool OneWireDevice::send_command_(uint8_t cmd) {
|
||||
if (!this->bus_->select(this->address_))
|
||||
return false;
|
||||
|
@@ -24,8 +24,6 @@ class OneWireDevice {
|
||||
/// Helper to create (and cache) the name for this sensor. For example "0xfe0000031f1eaf29".
|
||||
const std::string &get_address_name();
|
||||
|
||||
std::string unique_id();
|
||||
|
||||
protected:
|
||||
uint64_t address_{0};
|
||||
OneWireBus *bus_{nullptr}; ///< pointer to OneWireBus instance
|
||||
|
@@ -2,7 +2,7 @@ import logging
|
||||
|
||||
from esphome import automation
|
||||
import esphome.codegen as cg
|
||||
from esphome.components.const import CONF_REQUEST_HEADERS
|
||||
from esphome.components.const import CONF_BYTE_ORDER, CONF_REQUEST_HEADERS
|
||||
from esphome.components.http_request import CONF_HTTP_REQUEST_ID, HttpRequestComponent
|
||||
from esphome.components.image import (
|
||||
CONF_INVERT_ALPHA,
|
||||
@@ -11,6 +11,7 @@ from esphome.components.image import (
|
||||
Image_,
|
||||
get_image_type_enum,
|
||||
get_transparency_enum,
|
||||
validate_settings,
|
||||
)
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
@@ -161,6 +162,7 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
rp2040_arduino=cv.Version(0, 0, 0),
|
||||
host=cv.Version(0, 0, 0),
|
||||
),
|
||||
validate_settings,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -213,6 +215,7 @@ async def to_code(config):
|
||||
get_image_type_enum(config[CONF_TYPE]),
|
||||
transparent,
|
||||
config[CONF_BUFFER_SIZE],
|
||||
config.get(CONF_BYTE_ORDER) != "LITTLE_ENDIAN",
|
||||
)
|
||||
await cg.register_component(var, config)
|
||||
await cg.register_parented(var, config[CONF_HTTP_REQUEST_ID])
|
||||
|
@@ -35,14 +35,15 @@ inline bool is_color_on(const Color &color) {
|
||||
}
|
||||
|
||||
OnlineImage::OnlineImage(const std::string &url, int width, int height, ImageFormat format, ImageType type,
|
||||
image::Transparency transparency, uint32_t download_buffer_size)
|
||||
image::Transparency transparency, uint32_t download_buffer_size, bool is_big_endian)
|
||||
: Image(nullptr, 0, 0, type, transparency),
|
||||
buffer_(nullptr),
|
||||
download_buffer_(download_buffer_size),
|
||||
download_buffer_initial_size_(download_buffer_size),
|
||||
format_(format),
|
||||
fixed_width_(width),
|
||||
fixed_height_(height) {
|
||||
fixed_height_(height),
|
||||
is_big_endian_(is_big_endian) {
|
||||
this->set_url(url);
|
||||
}
|
||||
|
||||
@@ -296,7 +297,7 @@ void OnlineImage::draw_pixel_(int x, int y, Color color) {
|
||||
break;
|
||||
}
|
||||
case ImageType::IMAGE_TYPE_GRAYSCALE: {
|
||||
uint8_t gray = static_cast<uint8_t>(0.2125 * color.r + 0.7154 * color.g + 0.0721 * color.b);
|
||||
auto gray = static_cast<uint8_t>(0.2125 * color.r + 0.7154 * color.g + 0.0721 * color.b);
|
||||
if (this->transparency_ == image::TRANSPARENCY_CHROMA_KEY) {
|
||||
if (gray == 1) {
|
||||
gray = 0;
|
||||
@@ -314,8 +315,13 @@ void OnlineImage::draw_pixel_(int x, int y, Color color) {
|
||||
case ImageType::IMAGE_TYPE_RGB565: {
|
||||
this->map_chroma_key(color);
|
||||
uint16_t col565 = display::ColorUtil::color_to_565(color);
|
||||
if (this->is_big_endian_) {
|
||||
this->buffer_[pos + 0] = static_cast<uint8_t>((col565 >> 8) & 0xFF);
|
||||
this->buffer_[pos + 1] = static_cast<uint8_t>(col565 & 0xFF);
|
||||
} else {
|
||||
this->buffer_[pos + 0] = static_cast<uint8_t>(col565 & 0xFF);
|
||||
this->buffer_[pos + 1] = static_cast<uint8_t>((col565 >> 8) & 0xFF);
|
||||
}
|
||||
if (this->transparency_ == image::TRANSPARENCY_ALPHA_CHANNEL) {
|
||||
this->buffer_[pos + 2] = color.w;
|
||||
}
|
||||
|
@@ -50,7 +50,7 @@ class OnlineImage : public PollingComponent,
|
||||
* @param buffer_size Size of the buffer used to download the image.
|
||||
*/
|
||||
OnlineImage(const std::string &url, int width, int height, ImageFormat format, image::ImageType type,
|
||||
image::Transparency transparency, uint32_t buffer_size);
|
||||
image::Transparency transparency, uint32_t buffer_size, bool is_big_endian);
|
||||
|
||||
void draw(int x, int y, display::Display *display, Color color_on, Color color_off) override;
|
||||
|
||||
@@ -164,6 +164,11 @@ class OnlineImage : public PollingComponent,
|
||||
const int fixed_width_;
|
||||
/** height requested on configuration, or 0 if non specified. */
|
||||
const int fixed_height_;
|
||||
/**
|
||||
* Whether the image is stored in big-endian format.
|
||||
* This is used to determine how to store 16 bit colors in the buffer.
|
||||
*/
|
||||
bool is_big_endian_;
|
||||
/**
|
||||
* Actual width of the current image. If fixed_width_ is specified,
|
||||
* this will be equal to it; otherwise it will be set once the decoding
|
||||
|
@@ -10,7 +10,7 @@ void opentherm::OpenthermOutput::write_state(float state) {
|
||||
ESP_LOGD(TAG, "Received state: %.2f. Min value: %.2f, max value: %.2f", state, min_value_, max_value_);
|
||||
this->state = state < 0.003 && this->zero_means_zero_
|
||||
? 0.0
|
||||
: clamp(lerp(state, min_value_, max_value_), min_value_, max_value_);
|
||||
: clamp(std::lerp(min_value_, max_value_, state), min_value_, max_value_);
|
||||
this->has_state_ = true;
|
||||
ESP_LOGD(TAG, "Output %s set to %.2f", this->id_, this->state);
|
||||
}
|
||||
|
34
esphome/components/runtime_stats/__init__.py
Normal file
34
esphome/components/runtime_stats/__init__.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
Runtime statistics component for ESPHome.
|
||||
"""
|
||||
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_ID
|
||||
|
||||
CODEOWNERS = ["@bdraco"]
|
||||
|
||||
CONF_LOG_INTERVAL = "log_interval"
|
||||
|
||||
runtime_stats_ns = cg.esphome_ns.namespace("runtime_stats")
|
||||
RuntimeStatsCollector = runtime_stats_ns.class_("RuntimeStatsCollector")
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(RuntimeStatsCollector),
|
||||
cv.Optional(
|
||||
CONF_LOG_INTERVAL, default="60s"
|
||||
): cv.positive_time_period_milliseconds,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
"""Generate code for the runtime statistics component."""
|
||||
# Define USE_RUNTIME_STATS when this component is used
|
||||
cg.add_define("USE_RUNTIME_STATS")
|
||||
|
||||
# Create the runtime stats instance (constructor sets global_runtime_stats)
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
|
||||
cg.add(var.set_log_interval(config[CONF_LOG_INTERVAL]))
|
102
esphome/components/runtime_stats/runtime_stats.cpp
Normal file
102
esphome/components/runtime_stats/runtime_stats.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
#include "runtime_stats.h"
|
||||
|
||||
#ifdef USE_RUNTIME_STATS
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace esphome {
|
||||
|
||||
namespace runtime_stats {
|
||||
|
||||
RuntimeStatsCollector::RuntimeStatsCollector() : log_interval_(60000), next_log_time_(0) {
|
||||
global_runtime_stats = this;
|
||||
}
|
||||
|
||||
void RuntimeStatsCollector::record_component_time(Component *component, uint32_t duration_ms, uint32_t current_time) {
|
||||
if (component == nullptr)
|
||||
return;
|
||||
|
||||
// Check if we have cached the name for this component
|
||||
auto name_it = this->component_names_cache_.find(component);
|
||||
if (name_it == this->component_names_cache_.end()) {
|
||||
// First time seeing this component, cache its name
|
||||
const char *source = component->get_component_source();
|
||||
this->component_names_cache_[component] = source;
|
||||
this->component_stats_[source].record_time(duration_ms);
|
||||
} else {
|
||||
this->component_stats_[name_it->second].record_time(duration_ms);
|
||||
}
|
||||
|
||||
if (this->next_log_time_ == 0) {
|
||||
this->next_log_time_ = current_time + this->log_interval_;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void RuntimeStatsCollector::log_stats_() {
|
||||
ESP_LOGI(TAG, "Component Runtime Statistics");
|
||||
ESP_LOGI(TAG, "Period stats (last %" PRIu32 "ms):", this->log_interval_);
|
||||
|
||||
// First collect stats we want to display
|
||||
std::vector<ComponentStatPair> stats_to_display;
|
||||
|
||||
for (const auto &it : this->component_stats_) {
|
||||
const ComponentRuntimeStats &stats = it.second;
|
||||
if (stats.get_period_count() > 0) {
|
||||
ComponentStatPair pair = {it.first, &stats};
|
||||
stats_to_display.push_back(pair);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by period runtime (descending)
|
||||
std::sort(stats_to_display.begin(), stats_to_display.end(), std::greater<ComponentStatPair>());
|
||||
|
||||
// Log top components by period runtime
|
||||
for (const auto &it : stats_to_display) {
|
||||
const char *source = it.name;
|
||||
const ComponentRuntimeStats *stats = it.stats;
|
||||
|
||||
ESP_LOGI(TAG, " %s: count=%" PRIu32 ", avg=%.2fms, max=%" PRIu32 "ms, total=%" PRIu32 "ms", source,
|
||||
stats->get_period_count(), stats->get_period_avg_time_ms(), stats->get_period_max_time_ms(),
|
||||
stats->get_period_time_ms());
|
||||
}
|
||||
|
||||
// Log total stats since boot
|
||||
ESP_LOGI(TAG, "Total stats (since boot):");
|
||||
|
||||
// Re-sort by total runtime for all-time stats
|
||||
std::sort(stats_to_display.begin(), stats_to_display.end(),
|
||||
[](const ComponentStatPair &a, const ComponentStatPair &b) {
|
||||
return a.stats->get_total_time_ms() > b.stats->get_total_time_ms();
|
||||
});
|
||||
|
||||
for (const auto &it : stats_to_display) {
|
||||
const char *source = it.name;
|
||||
const ComponentRuntimeStats *stats = it.stats;
|
||||
|
||||
ESP_LOGI(TAG, " %s: count=%" PRIu32 ", avg=%.2fms, max=%" PRIu32 "ms, total=%" PRIu32 "ms", source,
|
||||
stats->get_total_count(), stats->get_total_avg_time_ms(), stats->get_total_max_time_ms(),
|
||||
stats->get_total_time_ms());
|
||||
}
|
||||
}
|
||||
|
||||
void RuntimeStatsCollector::process_pending_stats(uint32_t current_time) {
|
||||
if (this->next_log_time_ == 0)
|
||||
return;
|
||||
|
||||
if (current_time >= this->next_log_time_) {
|
||||
this->log_stats_();
|
||||
this->reset_stats_();
|
||||
this->next_log_time_ = current_time + this->log_interval_;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace runtime_stats
|
||||
|
||||
runtime_stats::RuntimeStatsCollector *global_runtime_stats =
|
||||
nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
|
||||
} // namespace esphome
|
||||
|
||||
#endif // USE_RUNTIME_STATS
|
132
esphome/components/runtime_stats/runtime_stats.h
Normal file
132
esphome/components/runtime_stats/runtime_stats.h
Normal file
@@ -0,0 +1,132 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
|
||||
#ifdef USE_RUNTIME_STATS
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
|
||||
class Component; // Forward declaration
|
||||
|
||||
namespace runtime_stats {
|
||||
|
||||
static const char *const TAG = "runtime_stats";
|
||||
|
||||
class ComponentRuntimeStats {
|
||||
public:
|
||||
ComponentRuntimeStats()
|
||||
: period_count_(0),
|
||||
period_time_ms_(0),
|
||||
period_max_time_ms_(0),
|
||||
total_count_(0),
|
||||
total_time_ms_(0),
|
||||
total_max_time_ms_(0) {}
|
||||
|
||||
void record_time(uint32_t duration_ms) {
|
||||
// Update period counters
|
||||
this->period_count_++;
|
||||
this->period_time_ms_ += duration_ms;
|
||||
if (duration_ms > this->period_max_time_ms_)
|
||||
this->period_max_time_ms_ = duration_ms;
|
||||
|
||||
// Update total counters
|
||||
this->total_count_++;
|
||||
this->total_time_ms_ += duration_ms;
|
||||
if (duration_ms > this->total_max_time_ms_)
|
||||
this->total_max_time_ms_ = duration_ms;
|
||||
}
|
||||
|
||||
void reset_period_stats() {
|
||||
this->period_count_ = 0;
|
||||
this->period_time_ms_ = 0;
|
||||
this->period_max_time_ms_ = 0;
|
||||
}
|
||||
|
||||
// Period stats (reset each logging interval)
|
||||
uint32_t get_period_count() const { return this->period_count_; }
|
||||
uint32_t get_period_time_ms() const { return this->period_time_ms_; }
|
||||
uint32_t get_period_max_time_ms() const { return this->period_max_time_ms_; }
|
||||
float get_period_avg_time_ms() const {
|
||||
return this->period_count_ > 0 ? this->period_time_ms_ / static_cast<float>(this->period_count_) : 0.0f;
|
||||
}
|
||||
|
||||
// Total stats (persistent until reboot)
|
||||
uint32_t get_total_count() const { return this->total_count_; }
|
||||
uint32_t get_total_time_ms() const { return this->total_time_ms_; }
|
||||
uint32_t get_total_max_time_ms() const { return this->total_max_time_ms_; }
|
||||
float get_total_avg_time_ms() const {
|
||||
return this->total_count_ > 0 ? this->total_time_ms_ / static_cast<float>(this->total_count_) : 0.0f;
|
||||
}
|
||||
|
||||
protected:
|
||||
// Period stats (reset each logging interval)
|
||||
uint32_t period_count_;
|
||||
uint32_t period_time_ms_;
|
||||
uint32_t period_max_time_ms_;
|
||||
|
||||
// Total stats (persistent until reboot)
|
||||
uint32_t total_count_;
|
||||
uint32_t total_time_ms_;
|
||||
uint32_t total_max_time_ms_;
|
||||
};
|
||||
|
||||
// For sorting components by run time
|
||||
struct ComponentStatPair {
|
||||
const char *name;
|
||||
const ComponentRuntimeStats *stats;
|
||||
|
||||
bool operator>(const ComponentStatPair &other) const {
|
||||
// Sort by period time as that's what we're displaying in the logs
|
||||
return stats->get_period_time_ms() > other.stats->get_period_time_ms();
|
||||
}
|
||||
};
|
||||
|
||||
class RuntimeStatsCollector {
|
||||
public:
|
||||
RuntimeStatsCollector();
|
||||
|
||||
void set_log_interval(uint32_t log_interval) { this->log_interval_ = log_interval; }
|
||||
uint32_t get_log_interval() const { return this->log_interval_; }
|
||||
|
||||
void record_component_time(Component *component, uint32_t duration_ms, uint32_t current_time);
|
||||
|
||||
// Process any pending stats printing (should be called after component loop)
|
||||
void process_pending_stats(uint32_t current_time);
|
||||
|
||||
protected:
|
||||
void log_stats_();
|
||||
|
||||
void reset_stats_() {
|
||||
for (auto &it : this->component_stats_) {
|
||||
it.second.reset_period_stats();
|
||||
}
|
||||
}
|
||||
|
||||
// Use const char* keys for efficiency
|
||||
// Custom comparator for const char* keys in map
|
||||
// Without this, std::map would compare pointer addresses instead of string contents,
|
||||
// causing identical component names at different addresses to be treated as different keys
|
||||
struct CStrCompare {
|
||||
bool operator()(const char *a, const char *b) const { return std::strcmp(a, b) < 0; }
|
||||
};
|
||||
std::map<const char *, ComponentRuntimeStats, CStrCompare> component_stats_;
|
||||
std::map<Component *, const char *> component_names_cache_;
|
||||
uint32_t log_interval_;
|
||||
uint32_t next_log_time_;
|
||||
};
|
||||
|
||||
} // namespace runtime_stats
|
||||
|
||||
extern runtime_stats::RuntimeStatsCollector
|
||||
*global_runtime_stats; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
|
||||
} // namespace esphome
|
||||
|
||||
#endif // USE_RUNTIME_STATS
|
@@ -50,6 +50,7 @@ optional<float> MedianFilter::new_value(float value) {
|
||||
if (!this->queue_.empty()) {
|
||||
// Copy queue without NaN values
|
||||
std::vector<float> median_queue;
|
||||
median_queue.reserve(this->queue_.size());
|
||||
for (auto v : this->queue_) {
|
||||
if (!std::isnan(v)) {
|
||||
median_queue.push_back(v);
|
||||
|
@@ -96,7 +96,6 @@ void Sensor::clear_filters() {
|
||||
}
|
||||
float Sensor::get_state() const { return this->state; }
|
||||
float Sensor::get_raw_state() const { return this->raw_state; }
|
||||
std::string Sensor::unique_id() { return ""; }
|
||||
|
||||
void Sensor::internal_send_state_to_frontend(float state) {
|
||||
this->set_has_state(true);
|
||||
|
@@ -28,9 +28,6 @@ namespace sensor {
|
||||
if (!(obj)->get_icon().empty()) { \
|
||||
ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, (obj)->get_icon().c_str()); \
|
||||
} \
|
||||
if (!(obj)->unique_id().empty()) { \
|
||||
ESP_LOGV(TAG, "%s Unique ID: '%s'", prefix, (obj)->unique_id().c_str()); \
|
||||
} \
|
||||
if ((obj)->get_force_update()) { \
|
||||
ESP_LOGV(TAG, "%s Force Update: YES", prefix); \
|
||||
} \
|
||||
@@ -141,12 +138,6 @@ class Sensor : public EntityBase, public EntityBase_DeviceClass, public EntityBa
|
||||
*/
|
||||
float raw_state;
|
||||
|
||||
/** Override this method to set the unique ID of this sensor.
|
||||
*
|
||||
* @deprecated Do not use for new sensors, a suitable unique ID is automatically generated (2023.4).
|
||||
*/
|
||||
virtual std::string unique_id();
|
||||
|
||||
void internal_send_state_to_frontend(float state);
|
||||
|
||||
protected:
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user