first version dataclasses
This commit is contained in:
126
projmon/commands.py
Normal file
126
projmon/commands.py
Normal file
@@ -0,0 +1,126 @@
|
||||
from projrequest import ProjectorConnection
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
|
||||
from typing import Dict, List, Any
|
||||
from uuid import UUID
|
||||
|
||||
@dataclass
|
||||
class BaseCommand():
|
||||
projector: ProjectorConnection
|
||||
timestamp: datetime
|
||||
type: str
|
||||
content: Any
|
||||
|
||||
def __init__(self, proj: ProjectorConnection) -> None:
|
||||
self.projector = proj
|
||||
pass
|
||||
|
||||
def update(self, path: List[str], params: Dict[str, Any] | None = None):
|
||||
resp = self.projector.get(path=path, params=params)
|
||||
if resp is not None:
|
||||
self.timestamp = datetime.fromtimestamp(float(resp['timestamp']))
|
||||
self.type = resp['type']
|
||||
self.content = resp['body'][resp['type']]
|
||||
|
||||
@dataclass
|
||||
class DCPInfo():
|
||||
ID: UUID
|
||||
Title: str
|
||||
Path: str
|
||||
Size: int
|
||||
ImportTime: datetime
|
||||
IsImported: bool
|
||||
VerifyStatus: bool
|
||||
ValidateStatus: bool
|
||||
IsPlayable: bool
|
||||
IsTransferred: bool
|
||||
|
||||
@dataclass
|
||||
class DCPInfoList(BaseCommand):
|
||||
dcpInfoList: List[DCPInfo]
|
||||
path: List[str] = ['content', 'dcp', 'info', 'list']
|
||||
params: Dict[str, str] = { 'formatDate': 'false' }
|
||||
|
||||
def get(self):
|
||||
self.update(path=self.path, params=self.params)
|
||||
self.dcpInfoList = [DCPInfo(**e) for e in self.content]
|
||||
|
||||
@dataclass
|
||||
class PowerStatus():
|
||||
Device: str
|
||||
State: str
|
||||
|
||||
@dataclass
|
||||
class PowerStatusList(BaseCommand):
|
||||
powerStatusList: List[PowerStatus]
|
||||
path: List[str] = ['status', 'sms', 'powerstatus']
|
||||
|
||||
def get(self):
|
||||
self.update(path=self.path)
|
||||
self.powerStatusList = [PowerStatus(**e) for e in self.content]
|
||||
|
||||
@dataclass
|
||||
class ShowStatusDetailClass():
|
||||
Type: str
|
||||
Id: UUID
|
||||
RemainingTime: int
|
||||
ElapsedTime: int
|
||||
TotalDuration: int
|
||||
CurrentEventId: UUID
|
||||
CurrentEventType: str
|
||||
IsStoppedByMalfunction: bool
|
||||
RewindTimeList: str
|
||||
MalfunctionTime: int
|
||||
|
||||
@dataclass
|
||||
class ShowStatus(BaseCommand):
|
||||
PlayState: str
|
||||
ShowStatusDetail: ShowStatusDetailClass
|
||||
PlayBackMode: str
|
||||
AtmosPlayingStatus: str
|
||||
path: List[str] = ['playback', 'showstatus']
|
||||
|
||||
def get(self):
|
||||
self.update(self.path)
|
||||
self.PlayState = self.content['PlayState']
|
||||
self.ShowStatusDetail = ShowStatusDetailClass(**self.content['StatusDetail'])
|
||||
self.PlayBackMode = self.content['PlayBackMode']
|
||||
self.AtmosPlayingStatus = self.content['AtmosPlayingStatus']
|
||||
|
||||
@dataclass
|
||||
class ImportProgressClass():
|
||||
TotalBytesToTransfer: int
|
||||
BytesTransferred: int
|
||||
PercentCompleted: int
|
||||
InProgress: int
|
||||
ImportPath: str
|
||||
CompletionStatus: str
|
||||
CompletionTime: str
|
||||
DCPTitle: str
|
||||
|
||||
@dataclass
|
||||
class ValidationProgressClass():
|
||||
TotalBytesToValidate: int
|
||||
BytesValidated: int
|
||||
PercentCompleted: int
|
||||
InProgress: bool
|
||||
Id: UUID
|
||||
CompletionStatus: str
|
||||
CompletionTime: datetime
|
||||
|
||||
@dataclass
|
||||
class JobProgress():
|
||||
Id: int
|
||||
ValidateAfterImport: bool
|
||||
AggregatePercentValidated: int
|
||||
State: str
|
||||
ImportProgress: ImportProgressClass
|
||||
ValidationProgressList: List[ValidationProgressClass]
|
||||
IngestedByFolder: bool
|
||||
ContentsTransferType: str
|
||||
|
||||
@dataclass
|
||||
class DCPImportJobList(BaseCommand):
|
||||
IsPaused: bool
|
||||
JobProgressList: List[JobProgress]
|
||||
@@ -41,14 +41,16 @@ def main() -> int:
|
||||
while handler.running:
|
||||
try:
|
||||
now:float = time.time()
|
||||
|
||||
resp = projector.get(path=['status', 'storage', 'info'], params={"area":"DCP"})
|
||||
if resp is not None:
|
||||
print(json.dumps(resp, indent=2))
|
||||
|
||||
|
||||
last: float = time.time()
|
||||
cycle_time: float = last - now
|
||||
LOGGER.debug(f"Cycle Time: {cycle_time:4.3f}")
|
||||
time.sleep(INTERVAL-cycle_time)
|
||||
time.sleep(INTERVAL-cycle_time)
|
||||
except Exception as e:
|
||||
print(f"Unexpected exception: [{e}]")
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user