Skip to content

Commit e64eb09

Browse files
authored
Merge pull request #11 from Misiu/copilot/move-fallback-definitions-to-const
Move tag type fallback definitions from tag_types.py to const.py
2 parents eac5fbd + fa33a7c commit e64eb09

5 files changed

Lines changed: 153 additions & 153 deletions

File tree

.github/workflows/sync-tag-definitions.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
id: fetch
3232
run: python3 scripts/fetch_tag_types.py new_tag_types.json
3333

34-
- name: Generate updated tag_types.py
34+
- name: Generate updated const.py
3535
id: generate
3636
run: |
3737
python3 scripts/generate_tag_types.py new_tag_types.json
@@ -78,7 +78,7 @@ jobs:
7878
branch: 'automated/sync-tag-definitions'
7979
delete-branch: true
8080
add-paths: |
81-
custom_components/opendisplay/tag_types.py
81+
custom_components/opendisplay/const.py
8282
labels: |
8383
automated
8484
dependencies

custom_components/opendisplay/const.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,98 @@
44
SIGNAL_AP_UPDATE = f"{DOMAIN}_ap_update"
55
OEPL_CONFIG_URL = "https://config.openepaperlink.org/"
66
ATC_CONFIG_URL = "https://atc1441.github.io/ATC_BLE_OEPL_Image_Upload.html"
7+
8+
# Fallback tag type definitions
9+
# These definitions are automatically synced from OpenEPaperLink repository
10+
# See: https://github.com/OpenEPaperLink/OpenEPaperLink/tree/master/resources/tagtypes
11+
FALLBACK_TAG_DEFINITIONS = {
12+
0: {"version": 4, "name": "M2 1.54\"", "width": 152, "height": 152},
13+
1: {"version": 5, "name": "M2 2.9\"", "width": 296, "height": 128},
14+
2: {"version": 5, "name": "M2 4.2\"", "width": 400, "height": 300},
15+
3: {"version": 6, "name": "M2 2.2\"", "width": 212, "height": 104},
16+
4: {"version": 4, "name": "M2 2.6\"", "width": 296, "height": 152},
17+
5: {"version": 4, "name": "M2 7.4\"", "width": 640, "height": 384},
18+
6: {"version": 4, "name": "Opticon 2.2\"", "width": 250, "height": 128},
19+
7: {"version": 4, "name": "Opticon 2.9\"", "width": 296, "height": 128},
20+
8: {"version": 2, "name": "Opticon 4.2\"", "width": 400, "height": 300},
21+
9: {"version": 2, "name": "Opticon 7.5\"", "width": 640, "height": 384},
22+
17: {"version": 3, "name": "M2 2.9\" (UC8151)", "width": 296, "height": 128},
23+
18: {"version": 3, "name": "M2 4.2\" UC", "width": 400, "height": 300},
24+
33: {"version": 2, "name": "ST‐GM29XXF 2.9\"", "width": 296, "height": 128},
25+
34: {"version": 2, "name": "M2 2.7\"", "width": 264, "height": 176},
26+
38: {"version": 1, "name": "M2 7.5\" BW", "width": 640, "height": 384},
27+
39: {"version": 3, "name": "ST‐GM29MT1 2.9\"", "width": 296, "height": 128},
28+
40: {"version": 2, "name": "M3 1.6\" BWRY", "width": 168, "height": 168},
29+
41: {"version": 1, "name": "M3 2.4\" BWRY", "width": 296, "height": 168},
30+
42: {"version": 1, "name": "M3 3.0\" BWRY", "width": 400, "height": 168},
31+
43: {"version": 1, "name": "M3 2.9\" BWRY", "width": 384, "height": 168},
32+
44: {"version": 1, "name": "M3 4.3\" BWRY", "width": 522, "height": 152},
33+
45: {"version": 2, "name": "M3 12.2\"", "width": 960, "height": 768},
34+
46: {"version": 5, "name": "M3 9.7\"", "width": 960, "height": 672},
35+
47: {"version": 4, "name": "M3 4.3\"", "width": 522, "height": 152},
36+
48: {"version": 2, "name": "M3 1.6\"", "width": 200, "height": 200},
37+
49: {"version": 1, "name": "M3 2.2\"", "width": 296, "height": 160},
38+
50: {"version": 1, "name": "M3 2.6\"", "width": 360, "height": 184},
39+
51: {"version": 3, "name": "M3 2.9\"", "width": 384, "height": 168},
40+
52: {"version": 2, "name": "M3 4.2\"", "width": 400, "height": 300},
41+
53: {"version": 2, "name": "M3 6.0\"", "width": 600, "height": 448},
42+
54: {"version": 5, "name": "M3 7.5\"", "width": 800, "height": 480},
43+
55: {"version": 3, "name": "M3 11.6\"", "width": 960, "height": 640},
44+
60: {"version": 3, "name": "M3 4.2\" BWY", "width": 400, "height": 300},
45+
64: {"version": 1, "name": "M3 2.9\" BW", "width": 384, "height": 168},
46+
65: {"version": 1, "name": "M3 5.85\"", "width": 792, "height": 272},
47+
66: {"version": 1, "name": "M3 5.85\" BW", "width": 792, "height": 272},
48+
67: {"version": 2, "name": "M3 1.3\" Peghook", "width": 144, "height": 200},
49+
68: {"version": 2, "name": "M3 5.81\" BW", "width": 720, "height": 256},
50+
69: {"version": 3, "name": "M3 2.2 Lite\"", "width": 250, "height": 128},
51+
70: {"version": 1, "name": "M3 2.2\" BW", "width": 296, "height": 160},
52+
71: {"version": 4, "name": "M3 2.7\"", "width": 300, "height": 200},
53+
72: {"version": 1, "name": "M3 5.81\" BWR", "width": 720, "height": 256},
54+
73: {"version": 2, "name": "M3 5.81\" V2 BWR", "width": 720, "height": 256},
55+
74: {"version": 1, "name": "M3 1.6\" 200px BWRY", "width": 200, "height": 200},
56+
75: {"version": 1, "name": "M3 2.2\" BWRY", "width": 296, "height": 160},
57+
76: {"version": 1, "name": "M3 7.5\" BWRY", "width": 800, "height": 480},
58+
77: {"version": 3, "name": "M3 11.6\" BWRY", "width": 960, "height": 640},
59+
78: {"version": 2, "name": "M3 2.6\" BW", "width": 360, "height": 184},
60+
80: {"version": 2, "name": "HD150 5.83\" BWR", "width": 648, "height": 480},
61+
84: {"version": 4, "name": "HS BW 2.13\"", "width": 256, "height": 128},
62+
85: {"version": 5, "name": "HS BWR 2.13\"", "width": 256, "height": 128},
63+
86: {"version": 6, "name": "HS BWR 2.66\"", "width": 296, "height": 152},
64+
87: {"version": 3, "name": "TLSR BWR 1.54\"", "width": 200, "height": 200},
65+
88: {"version": 3, "name": "TLSR BW 2.13\"", "width": 256, "height": 128},
66+
89: {"version": 3, "name": "TLSR BWR 2.13\"", "width": 264, "height": 136},
67+
90: {"version": 1, "name": "HS BW 2.13\" LowRes", "width": 212, "height": 104},
68+
96: {"version": 6, "name": "HS BWY 3.5\"", "width": 384, "height": 184},
69+
97: {"version": 4, "name": "HS BWR 3.5\"", "width": 384, "height": 184},
70+
98: {"version": 4, "name": "HS BW 3.5\"", "width": 384, "height": 184},
71+
99: {"version": 6, "name": "TLSR BWR 4.2\"", "width": 400, "height": 300},
72+
102: {"version": 2, "name": "HS BWY 7,5\"", "width": 800, "height": 480},
73+
103: {"version": 3, "name": "HS 2.00\" BWY", "width": 152, "height": 200},
74+
104: {"version": 4, "name": "HS BWY 3.46\"", "width": 480, "height": 176},
75+
105: {"version": 4, "name": "TLSR BW 2.13\"", "width": 250, "height": 136},
76+
106: {"version": 1, "name": "HS BWR 5,83\"", "width": 648, "height": 480},
77+
107: {"version": 3, "name": "HS BWRY 7,5\"", "width": 800, "height": 480},
78+
108: {"version": 3, "name": "HS BWRY 2,00\"", "width": 152, "height": 200},
79+
109: {"version": 3, "name": "HS BWRY 3,5\"", "width": 384, "height": 184},
80+
110: {"version": 3, "name": "HS BWRY 2,9\"", "width": 296, "height": 128},
81+
111: {"version": 2, "name": "HS BWRY 2,60\"", "width": 296, "height": 152},
82+
128: {"version": 1, "name": "Chroma 7.4\"", "width": 640, "height": 384},
83+
129: {"version": 2, "name": "Chroma Aeon 74 7.4\"", "width": 800, "height": 480},
84+
130: {"version": 2, "name": "Chroma29 2.9\"", "width": 296, "height": 128},
85+
131: {"version": 2, "name": "Chroma42 4.2\"", "width": 400, "height": 300},
86+
176: {"version": 5, "name": "Gicisky BLE EPD BW 2.13\"", "width": 250, "height": 128},
87+
177: {"version": 5, "name": "Gicisky BLE EPD BWR 2.13\"", "width": 250, "height": 128},
88+
178: {"version": 2, "name": "Gicisky BLE EPD BW 2.9\"", "width": 296, "height": 128},
89+
179: {"version": 2, "name": "Gicisky BLE EPD BWR 2.9\"", "width": 296, "height": 128},
90+
181: {"version": 2, "name": "Gicisky BLE EPD BWR 4.2\"", "width": 400, "height": 300},
91+
186: {"version": 5, "name": "Gicisky BLE TFT 2.13\"", "width": 250, "height": 136},
92+
189: {"version": 2, "name": "BLE EPD BWR 2.9\" Silabs", "width": 384, "height": 168},
93+
190: {"version": 1, "name": "ATC MiThermometer BLE", "width": 6, "height": 8},
94+
192: {"version": 2, "name": "BWRY example", "width": 360, "height": 180},
95+
226: {"version": 1, "name": "LILYGO TPANEL 4\"", "width": 480, "height": 480},
96+
227: {"version": 1, "name": "GDEM1085Z51 10.85\"", "width": 1360, "height": 480},
97+
228: {"version": 1, "name": "BLE TFT 128x128", "width": 128, "height": 128},
98+
229: {"version": 1, "name": "TFT 240x320", "width": 320, "height": 172},
99+
240: {"version": 2, "name": "SLT‐EM007 Segmented", "width": 0, "height": 0},
100+
250: {"version": 1, "name": "ConfigMode", "width": 0, "height": 0},
101+
}

custom_components/opendisplay/tag_types.py

Lines changed: 2 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from homeassistant.core import HomeAssistant
1313
from homeassistant.exceptions import HomeAssistantError
1414
from homeassistant.helpers import storage
15-
from .const import DOMAIN
15+
from .const import DOMAIN, FALLBACK_TAG_DEFINITIONS
1616

1717
_LOGGER = logging.getLogger(__name__)
1818

@@ -475,99 +475,8 @@ def _load_fallback_types(self) -> None:
475475
The fallback types include all tag definitions from the OpenEPaperLink
476476
repository at: https://github.com/OpenEPaperLink/OpenEPaperLink/tree/master/resources/tagtypes
477477
"""
478-
fallback_definitions = {
479-
0: {"version": 4, "name": "M2 1.54\"", "width": 152, "height": 152},
480-
1: {"version": 5, "name": "M2 2.9\"", "width": 296, "height": 128},
481-
2: {"version": 5, "name": "M2 4.2\"", "width": 400, "height": 300},
482-
3: {"version": 6, "name": "M2 2.2\"", "width": 212, "height": 104},
483-
4: {"version": 4, "name": "M2 2.6\"", "width": 296, "height": 152},
484-
5: {"version": 4, "name": "M2 7.4\"", "width": 640, "height": 384},
485-
6: {"version": 4, "name": "Opticon 2.2\"", "width": 250, "height": 128},
486-
7: {"version": 4, "name": "Opticon 2.9\"", "width": 296, "height": 128},
487-
8: {"version": 2, "name": "Opticon 4.2\"", "width": 400, "height": 300},
488-
9: {"version": 2, "name": "Opticon 7.5\"", "width": 640, "height": 384},
489-
17: {"version": 3, "name": "M2 2.9\" (UC8151)", "width": 296, "height": 128},
490-
18: {"version": 3, "name": "M2 4.2\" UC", "width": 400, "height": 300},
491-
33: {"version": 2, "name": "ST‐GM29XXF 2.9\"", "width": 296, "height": 128},
492-
34: {"version": 2, "name": "M2 2.7\"", "width": 264, "height": 176},
493-
38: {"version": 1, "name": "M2 7.5\" BW", "width": 640, "height": 384},
494-
39: {"version": 3, "name": "ST‐GM29MT1 2.9\"", "width": 296, "height": 128},
495-
40: {"version": 2, "name": "M3 1.6\" BWRY", "width": 168, "height": 168},
496-
41: {"version": 1, "name": "M3 2.4\" BWRY", "width": 296, "height": 168},
497-
42: {"version": 1, "name": "M3 3.0\" BWRY", "width": 400, "height": 168},
498-
43: {"version": 1, "name": "M3 2.9\" BWRY", "width": 384, "height": 168},
499-
44: {"version": 1, "name": "M3 4.3\" BWRY", "width": 522, "height": 152},
500-
45: {"version": 2, "name": "M3 12.2\"", "width": 960, "height": 768},
501-
46: {"version": 5, "name": "M3 9.7\"", "width": 960, "height": 672},
502-
47: {"version": 4, "name": "M3 4.3\"", "width": 522, "height": 152},
503-
48: {"version": 2, "name": "M3 1.6\"", "width": 200, "height": 200},
504-
49: {"version": 1, "name": "M3 2.2\"", "width": 296, "height": 160},
505-
50: {"version": 1, "name": "M3 2.6\"", "width": 360, "height": 184},
506-
51: {"version": 3, "name": "M3 2.9\"", "width": 384, "height": 168},
507-
52: {"version": 2, "name": "M3 4.2\"", "width": 400, "height": 300},
508-
53: {"version": 2, "name": "M3 6.0\"", "width": 600, "height": 448},
509-
54: {"version": 5, "name": "M3 7.5\"", "width": 800, "height": 480},
510-
55: {"version": 3, "name": "M3 11.6\"", "width": 960, "height": 640},
511-
60: {"version": 3, "name": "M3 4.2\" BWY", "width": 400, "height": 300},
512-
64: {"version": 1, "name": "M3 2.9\" BW", "width": 384, "height": 168},
513-
65: {"version": 1, "name": "M3 5.85\"", "width": 792, "height": 272},
514-
66: {"version": 1, "name": "M3 5.85\" BW", "width": 792, "height": 272},
515-
67: {"version": 2, "name": "M3 1.3\" Peghook", "width": 144, "height": 200},
516-
68: {"version": 2, "name": "M3 5.81\" BW", "width": 720, "height": 256},
517-
69: {"version": 3, "name": "M3 2.2 Lite\"", "width": 250, "height": 128},
518-
70: {"version": 1, "name": "M3 2.2\" BW", "width": 296, "height": 160},
519-
71: {"version": 4, "name": "M3 2.7\"", "width": 300, "height": 200},
520-
72: {"version": 1, "name": "M3 5.81\" BWR", "width": 720, "height": 256},
521-
73: {"version": 2, "name": "M3 5.81\" V2 BWR", "width": 720, "height": 256},
522-
74: {"version": 1, "name": "M3 1.6\" 200px BWRY", "width": 200, "height": 200},
523-
75: {"version": 1, "name": "M3 2.2\" BWRY", "width": 296, "height": 160},
524-
76: {"version": 1, "name": "M3 7.5\" BWRY", "width": 800, "height": 480},
525-
77: {"version": 3, "name": "M3 11.6\" BWRY", "width": 960, "height": 640},
526-
78: {"version": 2, "name": "M3 2.6\" BW", "width": 360, "height": 184},
527-
80: {"version": 2, "name": "HD150 5.83\" BWR", "width": 648, "height": 480},
528-
84: {"version": 4, "name": "HS BW 2.13\"", "width": 256, "height": 128},
529-
85: {"version": 5, "name": "HS BWR 2.13\"", "width": 256, "height": 128},
530-
86: {"version": 6, "name": "HS BWR 2.66\"", "width": 296, "height": 152},
531-
87: {"version": 3, "name": "TLSR BWR 1.54\"", "width": 200, "height": 200},
532-
88: {"version": 3, "name": "TLSR BW 2.13\"", "width": 256, "height": 128},
533-
89: {"version": 3, "name": "TLSR BWR 2.13\"", "width": 264, "height": 136},
534-
90: {"version": 1, "name": "HS BW 2.13\" LowRes", "width": 212, "height": 104},
535-
96: {"version": 6, "name": "HS BWY 3.5\"", "width": 384, "height": 184},
536-
97: {"version": 4, "name": "HS BWR 3.5\"", "width": 384, "height": 184},
537-
98: {"version": 4, "name": "HS BW 3.5\"", "width": 384, "height": 184},
538-
99: {"version": 6, "name": "TLSR BWR 4.2\"", "width": 400, "height": 300},
539-
102: {"version": 2, "name": "HS BWY 7,5\"", "width": 800, "height": 480},
540-
103: {"version": 3, "name": "HS 2.00\" BWY", "width": 152, "height": 200},
541-
104: {"version": 4, "name": "HS BWY 3.46\"", "width": 480, "height": 176},
542-
105: {"version": 4, "name": "TLSR BW 2.13\"", "width": 250, "height": 136},
543-
106: {"version": 1, "name": "HS BWR 5,83\"", "width": 648, "height": 480},
544-
107: {"version": 3, "name": "HS BWRY 7,5\"", "width": 800, "height": 480},
545-
108: {"version": 3, "name": "HS BWRY 2,00\"", "width": 152, "height": 200},
546-
109: {"version": 3, "name": "HS BWRY 3,5\"", "width": 384, "height": 184},
547-
110: {"version": 3, "name": "HS BWRY 2,9\"", "width": 296, "height": 128},
548-
111: {"version": 2, "name": "HS BWRY 2,60\"", "width": 296, "height": 152},
549-
128: {"version": 1, "name": "Chroma 7.4\"", "width": 640, "height": 384},
550-
129: {"version": 2, "name": "Chroma Aeon 74 7.4\"", "width": 800, "height": 480},
551-
130: {"version": 2, "name": "Chroma29 2.9\"", "width": 296, "height": 128},
552-
131: {"version": 2, "name": "Chroma42 4.2\"", "width": 400, "height": 300},
553-
176: {"version": 5, "name": "Gicisky BLE EPD BW 2.13\"", "width": 250, "height": 128},
554-
177: {"version": 5, "name": "Gicisky BLE EPD BWR 2.13\"", "width": 250, "height": 128},
555-
178: {"version": 2, "name": "Gicisky BLE EPD BW 2.9\"", "width": 296, "height": 128},
556-
179: {"version": 2, "name": "Gicisky BLE EPD BWR 2.9\"", "width": 296, "height": 128},
557-
181: {"version": 2, "name": "Gicisky BLE EPD BWR 4.2\"", "width": 400, "height": 300},
558-
186: {"version": 5, "name": "Gicisky BLE TFT 2.13\"", "width": 250, "height": 136},
559-
189: {"version": 2, "name": "BLE EPD BWR 2.9\" Silabs", "width": 384, "height": 168},
560-
190: {"version": 1, "name": "ATC MiThermometer BLE", "width": 6, "height": 8},
561-
192: {"version": 2, "name": "BWRY example", "width": 360, "height": 180},
562-
226: {"version": 1, "name": "LILYGO TPANEL 4\"", "width": 480, "height": 480},
563-
227: {"version": 1, "name": "GDEM1085Z51 10.85\"", "width": 1360, "height": 480},
564-
228: {"version": 1, "name": "BLE TFT 128x128", "width": 128, "height": 128},
565-
229: {"version": 1, "name": "TFT 240x320", "width": 320, "height": 172},
566-
240: {"version": 2, "name": "SLT‐EM007 Segmented", "width": 0, "height": 0},
567-
250: {"version": 1, "name": "ConfigMode", "width": 0, "height": 0},
568-
}
569478
self._tag_types = {
570-
type_id: TagType(type_id, data) for type_id, data in fallback_definitions.items()
479+
type_id: TagType(type_id, data) for type_id, data in FALLBACK_TAG_DEFINITIONS.items()
571480
}
572481
self._last_update = datetime.now()
573482
_LOGGER.warning("Loaded fallback tag definitions")

scripts/generate_tag_types.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env python3
2-
"""Generate updated tag_types.py from fetched tag type definitions.
2+
"""Generate updated const.py from fetched tag type definitions.
33
44
Reads a JSON file of tag type definitions (produced by fetch_tag_types.py),
5-
compares them against the current fallback definitions in tag_types.py,
5+
compares them against the current fallback definitions in const.py,
66
and updates the file if there are changes.
77
88
Sets GitHub Actions outputs for downstream workflow steps.
@@ -14,9 +14,9 @@
1414
import sys
1515

1616

17-
TAG_TYPES_PATH = "custom_components/opendisplay/tag_types.py"
17+
CONST_PATH = "custom_components/opendisplay/const.py"
1818
FALLBACK_PATTERN = re.compile(
19-
r"( fallback_definitions = \{)\n(.*?)\n( \})", re.DOTALL
19+
r"(FALLBACK_TAG_DEFINITIONS = \{)\n(.*?)\n(\})", re.DOTALL
2020
)
2121
ENTRY_PATTERN = re.compile(r"\s+(\d+):")
2222

@@ -29,10 +29,10 @@ def load_new_tag_types(input_file):
2929

3030

3131
def parse_current_definitions(content):
32-
"""Extract current fallback definitions from tag_types.py content."""
32+
"""Extract current fallback definitions from const.py content."""
3333
match = FALLBACK_PATTERN.search(content)
3434
if not match:
35-
print("Error: Could not find fallback_definitions in tag_types.py")
35+
print("Error: Could not find FALLBACK_TAG_DEFINITIONS in const.py")
3636
sys.exit(1)
3737

3838
current_types = {}
@@ -67,20 +67,20 @@ def compute_changes(current_types, new_tag_types):
6767

6868

6969
def generate_fallback_content(new_tag_types):
70-
"""Generate the new fallback_definitions dict content."""
70+
"""Generate the new FALLBACK_TAG_DEFINITIONS dict content."""
7171
lines = []
7272
for type_id in sorted(new_tag_types.keys()):
7373
type_data = new_tag_types[type_id]
74-
line = f" {type_id}: {json.dumps(type_data, ensure_ascii=False)},"
74+
line = f" {type_id}: {json.dumps(type_data, ensure_ascii=False)},"
7575
lines.append(line)
7676
return "\n".join(lines)
7777

7878

7979
def update_tag_types_file(content, new_fallback):
80-
"""Replace fallback_definitions content in tag_types.py."""
80+
"""Replace FALLBACK_TAG_DEFINITIONS content in const.py."""
8181
match = FALLBACK_PATTERN.search(content)
8282
if not match:
83-
print("Error: Could not find fallback_definitions in tag_types.py")
83+
print("Error: Could not find FALLBACK_TAG_DEFINITIONS in const.py")
8484
sys.exit(1)
8585

8686
start = match.start(2)
@@ -119,12 +119,12 @@ def set_github_output(changed, summary):
119119

120120

121121
def main():
122-
"""Generate updated tag_types.py from fetched definitions."""
122+
"""Generate updated const.py from fetched definitions."""
123123
input_file = sys.argv[1] if len(sys.argv) > 1 else "new_tag_types.json"
124124

125125
new_tag_types = load_new_tag_types(input_file)
126126

127-
with open(TAG_TYPES_PATH, "r") as f:
127+
with open(CONST_PATH, "r") as f:
128128
content = f.read()
129129

130130
current_types = parse_current_definitions(content)
@@ -138,7 +138,7 @@ def main():
138138
new_fallback = generate_fallback_content(new_tag_types)
139139
new_content = update_tag_types_file(content, new_fallback)
140140

141-
with open(TAG_TYPES_PATH, "w") as f:
141+
with open(CONST_PATH, "w") as f:
142142
f.write(new_content)
143143

144144
summary = build_summary(added, removed, modified)

0 commit comments

Comments
 (0)