response.py 1.4 KB

from dataclasses import asdict, dataclass
from json import dumps


@dataclass
class Response:
    code: int
    msg: str
    success: bool

    @property
    def __dict__(self):
        return asdict(self)

    @property
    def json(self):
        return dumps(self.__dict__)


@dataclass
class DeviceDataHeader:
    cmd: str
    type: int
    factory: str

    @property
    def __dict__(self):
        return asdict(self)

    @property
    def json(self):
        return dumps(self.__dict__)


@dataclass
class GasConcentration:
    addr: int
    type: int
    value: float
    unit: str
    lowAlarmValue: float
    highAlarmValue: float
    range: float
    type: int
    name: str
    lastUpdateTime: str

    @property
    def __dict__(self):
        return asdict(self)

    @property
    def json(self):
        return dumps(self.__dict__)


@dataclass
class GasConcentrationDeviceRequest(DeviceDataHeader):
    data: GasConcentration

    @property
    def __dict__(self):
        return asdict(self)

    @property
    def json(self):
        return dumps(self.__dict__)


@dataclass
class VideoAnalysis:
    addr: int
    type: int
    channelId: int
    channelName: str
    eventName: str
    base64Image: str
    lastUpdateTime: str


@dataclass
class VideoAnalysisRequest(DeviceDataHeader):
    data: VideoAnalysis

    @property
    def __dict__(self):
        return asdict(self)

    @property
    def json(self):
        return dumps(self.__dict__)