Skip to content

Commit

Permalink
Some more trial
Browse files Browse the repository at this point in the history
  • Loading branch information
Kane610 committed Sep 22, 2023
1 parent 0d994af commit e6c416c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
3 changes: 0 additions & 3 deletions axis/vapix/interfaces/api_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def api_version(self) -> str | None:
if (
discovery_item := self.vapix.api_discovery.get(self.api_id.value)
) is not None:
# if (discovery_item := self.vapix.api_discovery[self.api_id.value]) is not None:
return discovery_item.version
return self.default_api_version

Expand All @@ -115,8 +114,6 @@ async def _api_request(self) -> dict[str, ApiItemT]:

async def update(self) -> None:
"""Refresh data."""
# if self.api_request is None:
# return
self._items = await self._api_request()
self.initialized = True

Expand Down
17 changes: 15 additions & 2 deletions axis/vapix/models/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class ApiResponseSupportDecode(ABC):

@classmethod
@abstractmethod
def decode(cls, raw: str) -> Self:
"""Decode string to class object."""
def decode(cls, bytes_data: bytes) -> Self:
"""Decode data to class object."""


@dataclass
Expand Down Expand Up @@ -58,6 +58,19 @@ def data(self) -> dict[str, Any]:
"""Request data."""


@dataclass
class ApiRequest3(ABC):
"""Create API request body."""

method: str = field(init=False)
path: str = field(init=False)

@property
@abstractmethod
def data(self) -> dict[str, Any]:
"""Request data."""


@dataclass
class ApiRequest(ABC, Generic[ApiDataT]):
"""Create API request body."""
Expand Down
8 changes: 4 additions & 4 deletions axis/vapix/models/api_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ class GetAllApisResponse(ApiResponse[list[Api]]):
# error: ErrorDataT | None = None

@classmethod
def decode(cls, raw: str) -> Self:
def decode(cls, bytes_data: bytes) -> Self:
"""Prepare API description dictionary."""
data: ListApisResponseT = orjson.loads(raw)
data: ListApisResponseT = orjson.loads(bytes_data)
return cls(
api_version=data["apiVersion"],
context=data["context"],
Expand Down Expand Up @@ -249,9 +249,9 @@ class GetSupportedVersionsResponse(ApiResponse[list[str]]):
# error: ErrorDataT | None = None

@classmethod
def decode(cls, raw: str) -> Self:
def decode(cls, bytes_data: bytes) -> Self:
"""Prepare API description dictionary."""
data: GetSupportedVersionsResponseT = orjson.loads(raw)
data: GetSupportedVersionsResponseT = orjson.loads(bytes_data)
return cls(
api_version=data["apiVersion"],
context=data["context"],
Expand Down
32 changes: 27 additions & 5 deletions axis/vapix/models/basic_device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import orjson
from typing_extensions import NotRequired, Self, TypedDict

from .api import CONTEXT, ApiItem, ApiRequest2, ApiResponse
from .api import CONTEXT, ApiItem, ApiRequest2, ApiRequest3, ApiResponse

API_VERSION = "1.1"

Expand Down Expand Up @@ -136,9 +136,9 @@ class GetAllPropertiesResponse(ApiResponse[DeviceInformation]):
# error: ErrorDataT | None = None

@classmethod
def decode(cls, raw: str) -> Self:
def decode(cls, bytes_data: bytes) -> Self:
"""Prepare API description dictionary."""
data: GetAllPropertiesResponseT = orjson.loads(raw)
data: GetAllPropertiesResponseT = orjson.loads(bytes_data)
return cls(
api_version=data["apiVersion"],
context=data["context"],
Expand Down Expand Up @@ -170,6 +170,28 @@ def data(self) -> dict[str, Any]:
}


@dataclass
class GetAllPropertiesRequest2(ApiRequest3):
"""Request object for basic device info."""

method = "post"
path = "/axis-cgi/basicdeviceinfo.cgi"
content_type = "application/json"
error_codes = error_codes

api_version: str = API_VERSION
context: str = CONTEXT

@property
def data(self) -> dict[str, Any]:
"""Initialize request data."""
return {
"apiVersion": self.api_version,
"context": self.context,
"method": "getAllProperties",
}


@dataclass
class GetSupportedVersionsResponse(ApiResponse[list[str]]):
"""Response object for supported versions."""
Expand All @@ -181,9 +203,9 @@ class GetSupportedVersionsResponse(ApiResponse[list[str]]):
# error: ErrorDataT | None = None

@classmethod
def decode(cls, raw: str) -> Self:
def decode(cls, bytes_data: bytes) -> Self:
"""Prepare API description dictionary."""
data: GetSupportedVersionsResponseT = orjson.loads(raw)
data: GetSupportedVersionsResponseT = orjson.loads(bytes_data)
return cls(
api_version=data["apiVersion"],
context=data["context"],
Expand Down

0 comments on commit e6c416c

Please sign in to comment.