Add English localization and MIT-licensed public release documentation
Tests / unit (de, 3.10) (push) Has been cancelled
Tests / unit (de, 3.14) (push) Has been cancelled
Tests / unit (en, 3.14) (push) Has been cancelled
Tests / unit (en, 3.10) (push) Has been cancelled

This commit is contained in:
Justin
2026-09-05 21:02:14 +02:00
parent 3579667c6e
commit dd0809e877
31 changed files with 1261 additions and 377 deletions
+7 -6
View File
@@ -1,4 +1,5 @@
"""BTD 700 control protocol. No updater transport or arbitrary commands."""
from .i18n import tr
from dataclasses import dataclass
from enum import IntEnum
import re
@@ -51,8 +52,8 @@ def validate_text(value: str, *, key: bool = False) -> bytes:
"""Match the original app's 416 ASCII character input bounds; empty resets."""
pattern = r'[A-Za-z0-9]{4,16}' if key else r'[A-Za-z0-9 ]{4,16}'
if value and (not re.fullmatch(pattern, value) or value != value.strip()):
what = 'Passwort: 416 Buchstaben oder Ziffern.' if key else (
'Name: 416 Buchstaben, Ziffern oder innere Leerzeichen.')
what = tr('Passwort: 416 Buchstaben oder Ziffern.') if key else (
tr('Name: 416 Buchstaben, Ziffern oder innere Leerzeichen.'))
raise ValueError(what)
return value.encode('ascii')
@@ -61,7 +62,7 @@ def encode(command: Command, payload: bytes = b'') -> bytes:
try:
command = Command(command)
except ValueError as exc:
raise ValueError('Unbekannter Steuerbefehl; kein Zugriff auf Update-Befehle.') from exc
raise ValueError(tr('Unbekannter Steuerbefehl; kein Zugriff auf Update-Befehle.')) from exc
if command in READ_COMMANDS or command == Command.FACTORY_RESET:
valid = not payload
elif command == Command.SET_MODE:
@@ -79,13 +80,13 @@ def encode(command: Command, payload: bytes = b'') -> bytes:
else:
valid = False
if not valid:
raise ValueError(f'Ungültige Parameter für {command.name}.')
raise ValueError(tr('Ungültige Parameter für {command}.').format(command=command.name))
return bytes((REPORT_ID, 0xFE, command, len(payload))) + payload + bytes(60 - len(payload))
def acknowledge(event: int) -> bytes:
if event not in EVENTS:
raise ProtocolError(f'Unbekannte Benachrichtigung: {event:#x}')
raise ProtocolError(tr('Unbekannte Benachrichtigung: {event:#x}').format(event=event))
return bytes((REPORT_ID, 0xFD, event, 0)) + bytes(60)
@@ -100,5 +101,5 @@ def decode(report: bytes) -> Message | None:
if not report or report[0] != REPORT_ID:
return None # Media keys share the same interface.
if len(report) < 4 or report[1] not in (0xFC, 0xFF) or report[3] > 60 or len(report) < 4 + report[3]:
raise ProtocolError('Ungültige Antwort des Dongles.')
raise ProtocolError(tr('Ungültige Antwort des Dongles.'))
return Message(report[1], report[2], report[4:4 + report[3]])