sync
This commit is contained in:
38
tool/core/cmd/set_setting.py
Normal file
38
tool/core/cmd/set_setting.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import struct
|
||||
from core.utils import console, console_err
|
||||
from core.protocol import COMMANDS
|
||||
|
||||
class set_setting:
|
||||
def __init__(self, bus):
|
||||
self.bus = bus
|
||||
|
||||
def get(self, key: str, value: str):
|
||||
key_bytes = key.encode('utf-8')
|
||||
val_bytes = b''
|
||||
|
||||
# Typen-Konvertierung basierend auf dem Key
|
||||
try:
|
||||
if key == "audio/vol":
|
||||
val_bytes = struct.pack('<B', int(value))
|
||||
elif key == "play/norepeat":
|
||||
val_int = 1 if str(value).lower() in ['1', 'true', 'on', 'yes'] else 0
|
||||
val_bytes = struct.pack('<B', val_int)
|
||||
elif key == "settings/storage_interval":
|
||||
val_bytes = struct.pack('<H', int(value))
|
||||
else:
|
||||
console_err.print(f"[error]Unbekannter Key: {key}[/error]")
|
||||
return False
|
||||
except ValueError:
|
||||
console_err.print(f"[error]Ungültiger Wert für {key}: {value}[/error]")
|
||||
return False
|
||||
|
||||
# Payload: [Key Len] [Key] [Val Len] [Val Bytes]
|
||||
payload = struct.pack('B', len(key_bytes)) + key_bytes + struct.pack('B', len(val_bytes)) + val_bytes
|
||||
self.bus.send_request(COMMANDS['set_setting'], payload)
|
||||
|
||||
data = self.bus.receive_ack()
|
||||
return data is not None and data.get('type') == 'ack'
|
||||
|
||||
def print(self, result, key: str, value: str):
|
||||
if result:
|
||||
console.print(f"✓ Setting [info]{key}[/info] wurde auf [info]{value}[/info] gesetzt.")
|
||||
Reference in New Issue
Block a user