Skip to content

Commit

Permalink
Fix image
Browse files Browse the repository at this point in the history
  • Loading branch information
Kane610 committed Oct 19, 2023
1 parent 64be816 commit 04a2256
Show file tree
Hide file tree
Showing 3 changed files with 327 additions and 189 deletions.
6 changes: 6 additions & 0 deletions axis/vapix/interfaces/param_cgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ..models.param_cgi import (
BrandParam,
BrandT,
ImageParam,
Param,
PropertyParam,
StreamProfileParam,
Expand Down Expand Up @@ -166,6 +167,11 @@ async def update_image(self) -> None:
"""Update image group of parameters."""
await self.update(IMAGE)

@property
def image_params(self) -> ImageParam:
"""Provide brand parameters."""
return ImageParam.decode(self[IMAGE].raw)

@property
def image_sources(self) -> dict:
"""Image source information."""
Expand Down
136 changes: 129 additions & 7 deletions axis/vapix/models/param_cgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,54 @@ class BrandT(TypedDict):
WebURL: str


class ImageParamT(TypedDict):
"""Represent an image object."""

Enabled: str
Name: str
Source: str
Appearance_ColorEnabled: str
Appearance_Compression: str
Appearance_MirrorEnabled: str
Appearance_Resolution: str
Appearance_Rotation: str
MPEG_Complexity: str
MPEG_ConfigHeaderInterval: str
MPEG_FrameSkipMode: str
MPEG_ICount: str
MPEG_PCount: str
MPEG_UserDataEnabled: str
MPEG_UserDataInterval: str
MPEG_ZChromaQPMode: str
MPEG_ZFpsMode: str
MPEG_ZGopMode: str
MPEG_ZMaxGopLength: str
MPEG_ZMinFps: str
MPEG_ZStrength: str
MPEG_H264_Profile: str
MPEG_H264_PSEnabled: str
Overlay_Enabled: str
Overlay_XPos: str
Overlay_YPos: str
Overlay_MaskWindows_Color: str
RateControl_MaxBitrate: str
RateControl_Mode: str
RateControl_Priority: str
RateControl_TargetBitrate: str
SizeControl_MaxFrameSize: str
Stream_Duration: str
Stream_FPS: str
Stream_NbrOfFrames: str
Text_BGColor: str
Text_ClockEnabled: str
Text_Color: str
Text_DateEnabled: str
Text_Position: str
Text_String: str
Text_TextEnabled: str
Text_TextSize: str


class PropertyT(TypedDict):
"""Represent a property object."""

Expand All @@ -51,7 +99,7 @@ def process_dynamic_group(
prefix: str,
attributes: tuple[str, ...],
group_range: range,
) -> dict[str, dict[str, str]]:
) -> dict[int, dict[str, bool | int | str]]:
"""Convert raw dynamic groups to a proper dictionary.
raw_group: self[group]
Expand All @@ -61,18 +109,29 @@ def process_dynamic_group(
"""
dynamic_group = {}
for index in group_range:
item = {}
item: dict[str, bool | int | str] = {}

for attribute in attributes:
parameter = f"{prefix}{index}.{attribute}" # Support.S0.AbsoluteZoom

if parameter not in raw_group:
continue

item[attribute] = raw_group[parameter]
parameter_value = raw_group[parameter]

if parameter_value in ("true", "false", "yes", "no"): # Boolean values
item[attribute] = parameter_value in ("true", "yes")

elif parameter_value.lstrip("-").isdigit(): # Positive/negative values
item[attribute] = int(parameter_value)

else:
item[attribute] = parameter_value

# item[attribute] = raw_group[parameter]

if item:
dynamic_group[str(index)] = item
dynamic_group[index] = item

return dynamic_group

Expand Down Expand Up @@ -133,6 +192,69 @@ def decode(cls, data: BrandT) -> Self:
)


@dataclass
class ImageParam(ApiItem):
"""Image parameters."""

data: dict[int, ImageParamT]

@classmethod
def decode(cls, data: dict[str, str]) -> Self:
"""Decode dictionary to class object."""
attributes = (
"Enabled",
"Name",
"Source",
"Appearance.ColorEnabled",
"Appearance.Compression",
"Appearance.MirrorEnabled",
"Appearance.Resolution",
"Appearance.Rotation",
"MPEG.Complexity",
"MPEG.ConfigHeaderInterval",
"MPEG.FrameSkipMode",
"MPEG.ICount",
"MPEG.PCount",
"MPEG.UserDataEnabled",
"MPEG.UserDataInterval",
"MPEG.ZChromaQPMode",
"MPEG.ZFpsMode",
"MPEG.ZGopMode",
"MPEG.ZMaxGopLength",
"MPEG.ZMinFps",
"MPEG.ZStrength",
"MPEG.H264.Profile",
"MPEG.H264.PSEnabled",
"Overlay.Enabled",
"Overlay.XPos",
"Overlay.YPos",
"Overlay.MaskWindows.Color",
"RateControl.MaxBitrate",
"RateControl.Mode",
"RateControl.Priority",
"RateControl.TargetBitrate",
"SizeControl.MaxFrameSize",
"Stream.Duration",
"Stream.FPS",
"Stream.NbrOfFrames",
"Text.BGColor",
"Text.ClockEnabled",
"Text.Color",
"Text.DateEnabled",
"Text.Position",
"Text.String",
"Text.TextEnabled",
"Text.TextSize",
)
return cls(
id="image",
data=cast(
dict[int, ImageParamT],
process_dynamic_group(data, "I", attributes, range(20)),
),
)


@dataclass
class PropertyParam(ApiItem):
"""Property parameters."""
Expand Down Expand Up @@ -238,9 +360,9 @@ def decode(cls, data: dict[str, str]) -> Self:

profiles = [
StreamProfile(
id=profile["Name"],
description=profile["Description"],
parameters=profile["Parameters"],
id=str(profile["Name"]),
description=str(profile["Description"]),
parameters=str(profile["Parameters"]),
)
for profile in raw_profiles.values()
]
Expand Down
Loading

0 comments on commit 04a2256

Please sign in to comment.