-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add and consolidate parameter handlers
- Loading branch information
Showing
16 changed files
with
267 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"""Brand parameters.""" | ||
|
||
from typing import cast | ||
|
||
from ...models.parameters.brand import BrandParam, BrandT | ||
from .param_handler import ParamHandler | ||
|
||
|
||
class BrandParameterHandler(ParamHandler[BrandParam]): | ||
"""Handler for brand parameters.""" | ||
|
||
parameter_group = "Brand" | ||
|
||
def get_params(self) -> dict[str, BrandParam]: | ||
"""Retrieve brand properties.""" | ||
params = {} | ||
if data := self.vapix.params.get_param(self.parameter_group): | ||
params["0"] = BrandParam.decode(cast(BrandT, data)) | ||
return params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Image parameters.""" | ||
|
||
from ...models.parameters.image import ImageParam | ||
from .param_handler import ParamHandler | ||
|
||
|
||
class ImageParameterHandler(ParamHandler[ImageParam]): | ||
"""Handler for image parameters.""" | ||
|
||
parameter_group = "Image" | ||
|
||
def get_params(self) -> dict[str, ImageParam]: | ||
"""Retrieve brand properties.""" | ||
params = {} | ||
if data := self.vapix.params.get_param(self.parameter_group): | ||
params["0"] = ImageParam.decode(data) | ||
return params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""I/O port parameters.""" | ||
|
||
from ...models.parameters.io_port import GetPortsResponse, Port | ||
from .param_handler import ParamHandler | ||
|
||
|
||
class IOPortParameterHandler(ParamHandler[Port]): | ||
"""Handler for I/O port parameters.""" | ||
|
||
parameter_group = "IOPort" | ||
|
||
def get_params(self) -> dict[str, Port]: | ||
"""Retrieve I/O port parameters.""" | ||
params = {} | ||
if data := self.vapix.params.get_param(self.parameter_group): | ||
params.update(GetPortsResponse.from_dict(data).data) | ||
return params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Parameter handler sub class of API handler. | ||
Generalises parameter specific handling like | ||
- Subscribing to new data | ||
- Defining parameter group | ||
""" | ||
|
||
from abc import abstractmethod | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from .param_cgi import Params | ||
|
||
from ...models.api import ApiItemT | ||
from ...models.api_discovery import ApiId | ||
from ..api_handler import ApiHandler | ||
|
||
|
||
class ParamHandler(ApiHandler[ApiItemT]): | ||
"""Base class for a map of API Items.""" | ||
|
||
parameter_group: str | ||
api_id = ApiId.PARAM_CGI | ||
|
||
def __init__(self, param_handler: "Params") -> None: | ||
"""Initialize API items.""" | ||
super().__init__(param_handler.vapix) | ||
param_handler.subscribe(self.update_params, self.parameter_group) | ||
|
||
@abstractmethod | ||
def get_params(self) -> dict[str, ApiItemT]: | ||
"""Retrieve parameters from param_cgi class.""" | ||
|
||
def update_params(self, obj_id: str) -> None: | ||
"""Update parameter data. | ||
Callback from parameter handler subscription. | ||
""" | ||
self._items = self.get_params() | ||
|
||
async def _api_request(self) -> dict[str, ApiItemT]: | ||
"""Get API data method defined by subclass.""" | ||
await self.vapix.params.update(self.parameter_group) | ||
return self.get_params() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Property parameters.""" | ||
|
||
from ...models.parameters.properties import PropertyParam | ||
from .param_handler import ParamHandler | ||
|
||
|
||
class PropertyParameterHandler(ParamHandler[PropertyParam]): | ||
"""Handler for property parameters.""" | ||
|
||
parameter_group = "Properties" | ||
|
||
def get_params(self) -> dict[str, PropertyParam]: | ||
"""Retrieve brand properties.""" | ||
params = {} | ||
if data := self.vapix.params.get_param(self.parameter_group): | ||
params["0"] = PropertyParam.decode(data) | ||
return params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""PTZ parameters.""" | ||
|
||
from ...models.parameters.ptz import GetPtzResponse, PtzItem | ||
from .param_handler import ParamHandler | ||
|
||
|
||
class PtzParameterHandler(ParamHandler[PtzItem]): | ||
"""Handler for PTZ parameters.""" | ||
|
||
parameter_group = "PTZ" | ||
|
||
def get_params(self) -> dict[str, PtzItem]: | ||
"""Retrieve brand properties.""" | ||
params = {} | ||
if data := self.vapix.params.get_param(self.parameter_group): | ||
params.update(GetPtzResponse.from_dict(data).data) | ||
return params |
Oops, something went wrong.