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