import pydantic instead of dataclassess

This commit is contained in:
2026-02-05 17:53:12 +01:00
parent 7bff68dc77
commit 376fe69b9f

View File

@@ -1,12 +1,11 @@
from projrequest import ProjectorConnection from projrequest import ProjectorConnection
from dataclasses import dataclass, field
from datetime import datetime from datetime import datetime
from pydantic import BaseModel
from typing import Dict, List, Any from typing import Dict, List, Any
from uuid import UUID from uuid import UUID
@dataclass class BaseCommand(BaseModel):
class BaseCommand():
projector: ProjectorConnection projector: ProjectorConnection
timestamp: datetime timestamp: datetime
type: str type: str
@@ -23,8 +22,7 @@ class BaseCommand():
self.type = resp['type'] self.type = resp['type']
self.content = resp['body'][resp['type']] self.content = resp['body'][resp['type']]
@dataclass class DCPInfo(BaseModel):
class DCPInfo():
ID: UUID ID: UUID
Title: str Title: str
Path: str Path: str
@@ -36,7 +34,6 @@ class DCPInfo():
IsPlayable: bool IsPlayable: bool
IsTransferred: bool IsTransferred: bool
@dataclass
class DCPInfoList(BaseCommand): class DCPInfoList(BaseCommand):
dcpInfoList: List[DCPInfo] dcpInfoList: List[DCPInfo]
path: List[str] = ['content', 'dcp', 'info', 'list'] path: List[str] = ['content', 'dcp', 'info', 'list']
@@ -46,12 +43,10 @@ class DCPInfoList(BaseCommand):
self.update(path=self.path, params=self.params) self.update(path=self.path, params=self.params)
self.dcpInfoList = [DCPInfo(**e) for e in self.content] self.dcpInfoList = [DCPInfo(**e) for e in self.content]
@dataclass class PowerStatus(BaseModel):
class PowerStatus():
Device: str Device: str
State: str State: str
@dataclass
class PowerStatusList(BaseCommand): class PowerStatusList(BaseCommand):
powerStatusList: List[PowerStatus] powerStatusList: List[PowerStatus]
path: List[str] = ['status', 'sms', 'powerstatus'] path: List[str] = ['status', 'sms', 'powerstatus']
@@ -60,8 +55,7 @@ class PowerStatusList(BaseCommand):
self.update(path=self.path) self.update(path=self.path)
self.powerStatusList = [PowerStatus(**e) for e in self.content] self.powerStatusList = [PowerStatus(**e) for e in self.content]
@dataclass class ShowStatusDetailClass(BaseModel):
class ShowStatusDetailClass():
Type: str Type: str
Id: UUID Id: UUID
RemainingTime: int RemainingTime: int
@@ -73,7 +67,6 @@ class ShowStatusDetailClass():
RewindTimeList: str RewindTimeList: str
MalfunctionTime: int MalfunctionTime: int
@dataclass
class ShowStatus(BaseCommand): class ShowStatus(BaseCommand):
PlayState: str PlayState: str
ShowStatusDetail: ShowStatusDetailClass ShowStatusDetail: ShowStatusDetailClass
@@ -88,8 +81,7 @@ class ShowStatus(BaseCommand):
self.PlayBackMode = self.content['PlayBackMode'] self.PlayBackMode = self.content['PlayBackMode']
self.AtmosPlayingStatus = self.content['AtmosPlayingStatus'] self.AtmosPlayingStatus = self.content['AtmosPlayingStatus']
@dataclass class ImportProgressClass(BaseModel):
class ImportProgressClass():
TotalBytesToTransfer: int TotalBytesToTransfer: int
BytesTransferred: int BytesTransferred: int
PercentCompleted: int PercentCompleted: int
@@ -99,8 +91,7 @@ class ImportProgressClass():
CompletionTime: str CompletionTime: str
DCPTitle: str DCPTitle: str
@dataclass class ValidationProgressClass(BaseModel):
class ValidationProgressClass():
TotalBytesToValidate: int TotalBytesToValidate: int
BytesValidated: int BytesValidated: int
PercentCompleted: int PercentCompleted: int
@@ -109,8 +100,7 @@ class ValidationProgressClass():
CompletionStatus: str CompletionStatus: str
CompletionTime: datetime CompletionTime: datetime
@dataclass class JobProgress(BaseModel):
class JobProgress():
Id: int Id: int
ValidateAfterImport: bool ValidateAfterImport: bool
AggregatePercentValidated: int AggregatePercentValidated: int
@@ -120,7 +110,13 @@ class JobProgress():
IngestedByFolder: bool IngestedByFolder: bool
ContentsTransferType: str ContentsTransferType: str
@dataclass
class DCPImportJobList(BaseCommand): class DCPImportJobList(BaseCommand):
IsPaused: bool IsPaused: bool
JobProgressList: List[JobProgress] JobProgressList: List[JobProgress]
path: List[str] = ['content', 'dcp', 'command']
params: Dict[str, str] = {'action': 'ListImportJobs'}
def get(self):
self.update(self.path)
self.IsPaused = self.content['IsPaused']
self.JobProgressList = [JobProgress(**e) for e in self.content['JobProgressList']]