Skip to content

Commit

Permalink
Add additional dependencies to make Flake8 verify docstrings (#88)
Browse files Browse the repository at this point in the history
* Add additional dependencies to make Flake8 verify docstrings

* Fix pydocstyle for init, main, api and errors

* Fix pydocstyle for applications

* Fix pydocstyle in api discovery, basic device info and event instances

* Fix pydoctstyle in event stream, light control, MQTT and param cgi

* Fix pydocstyle in port cgi, port management, PTZ and pwdgrp cgi

* Fix pydocstyle in stream profiles, stream manager, user groups, vapix and view areas
  • Loading branch information
Kane610 authored May 20, 2021
1 parent 22ee807 commit 5c1d9a2
Show file tree
Hide file tree
Showing 29 changed files with 182 additions and 67 deletions.
2 changes: 2 additions & 0 deletions axis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
"""Library to communicate with a Axis device."""

from .device import AxisDevice # noqa: F401
from .errors import * # noqa: F401, F403
3 changes: 2 additions & 1 deletion axis/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@


def event_handler(action, event):
"""Receive and print events from RTSP stream."""
LOGGER.info(f"{action} {event}")


Expand Down Expand Up @@ -48,7 +49,7 @@ async def axis_device(host, port, username, password):


async def main(host, port, username, password, params, events):
"""Main function."""
"""CLI method for library."""
LOGGER.info("Connecting to Axis device")

device = await axis_device(host, port, username, password)
Expand Down
10 changes: 10 additions & 0 deletions axis/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class APIItems:
"""Base class for a map of API Items."""

def __init__(self, raw, request, path, item_cls) -> None:
"""Initialize API items."""
self._request = request
self._path = path
self._item_cls = item_cls
Expand All @@ -33,6 +34,7 @@ def __init__(self, raw, request, path, item_cls) -> None:
LOGGER.debug(pformat(raw))

async def update(self) -> None:
"""Refresh data."""
raw = await self._request("get", self._path)
self.process_raw(raw)

Expand All @@ -57,26 +59,33 @@ def process_raw(self, raw: Any) -> set:
return new_items

def items(self) -> dict:
"""Return items."""
return self._items.items()

def keys(self) -> str:
"""Return item keys."""
return self._items.keys()

def values(self):
"""Return item values."""
return self._items.values()

def get(self, obj_id: str, default: Optional[Any] = None):
"""Get item value based on key, return default if no match."""
if obj_id in self:
return self[obj_id]
return default

def __getitem__(self, obj_id: str):
"""Get item value based on key."""
return self._items[obj_id]

def __iter__(self):
"""Allow iterate over items."""
return iter(self._items)

def __contains__(self, obj_id: str):
"""Validate membership of item ID."""
return obj_id in self._items

def __len__(self) -> int:
Expand All @@ -95,6 +104,7 @@ class APIItem:
"""Base class for all end points using APIItems class."""

def __init__(self, id: str, raw: dict, request: object) -> None:
"""Initialize API item."""
self._id = id
self._raw = raw
self._request = request
Expand Down
2 changes: 2 additions & 0 deletions axis/api_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ class ApiDiscovery(APIItems):
"""API Discovery for Axis devices."""

def __init__(self, request: object) -> None:
"""Initialize API discovery manager."""
super().__init__({}, request, URL, Api)

async def update(self) -> None:
"""Refresh data."""
raw = await self.get_api_list()
self.process_raw(raw)

Expand Down
2 changes: 2 additions & 0 deletions axis/applications/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
"""Control stand alone applications of an Axis device."""

from .applications import * # noqa: F401, F403
11 changes: 6 additions & 5 deletions axis/applications/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ class ApplicationAPIItems(APIItems):
def __init__(
self, request: object, path: str, item_cls: object, api_version: str
) -> None:
"""Initialize API items."""
self._api_version = api_version
super().__init__({}, request, path, item_cls)

async def update(self) -> None:
"""No update method."""
"""Refresh data."""
raw = await self.get_configuration()
self.process_raw(raw)

Expand All @@ -32,7 +33,7 @@ def pre_process_raw(raw: dict) -> dict:
return profiles

async def get_configuration(self) -> dict:
"""Current configuration of application."""
"""Retrieve configuration of application."""
return await self._request(
"post",
self._path,
Expand All @@ -53,7 +54,7 @@ def camera(self) -> int:

@property
def filters(self) -> list:
"""An array of exclude filters."""
"""Array of exclude filters."""
return self.raw["filters"]

@property
Expand All @@ -68,10 +69,10 @@ def perspective(self) -> list:

@property
def triggers(self) -> list:
"""An array of triggers."""
"""Array of triggers."""
return self.raw["triggers"]

@property
def uid(self) -> int:
"""Unique ID of profile."""
"""Profile ID."""
return self.raw["uid"]
5 changes: 3 additions & 2 deletions axis/applications/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ class Applications(APIItems):
"""Applications on Axis devices."""

def __init__(self, request: object) -> None:
"""Initialize applications manager."""
super().__init__({}, request, URL, Application)

async def update(self) -> None:
"""No update method"""
"""Refresh data."""
raw = await self.list()
self.process_raw(raw)

Expand All @@ -52,7 +53,7 @@ def pre_process_raw(raw: dict) -> dict:
return applications

async def list(self) -> dict:
"""The applications/list.cgi is used to list information about installed applications."""
"""Retrieve information about installed applications."""
return await self._request("post", URL_LIST)


Expand Down
3 changes: 2 additions & 1 deletion axis/applications/fence_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@


class FenceGuard(ApplicationAPIItems):
"""Fence Guard application on Axis devices"""
"""Fence Guard application on Axis devices."""

APPLICATION_NAME = APPLICATION_NAME

def __init__(self, request: object) -> None:
"""Initialize fence guard manager."""
super().__init__(request, URL, ApplicationAPIItem, API_VERSION)
3 changes: 2 additions & 1 deletion axis/applications/loitering_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@


class LoiteringGuard(ApplicationAPIItems):
"""Loitering Guard application on Axis devices"""
"""Loitering Guard application on Axis devices."""

APPLICATION_NAME = APPLICATION_NAME

def __init__(self, request: object) -> None:
"""Initialize loitering guard manager."""
super().__init__(request, URL, ApplicationAPIItem, API_VERSION)
3 changes: 2 additions & 1 deletion axis/applications/motion_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@


class MotionGuard(ApplicationAPIItems):
"""Motion Guard application on Axis devices"""
"""Motion Guard application on Axis devices."""

APPLICATION_NAME = APPLICATION_NAME

def __init__(self, request: object) -> None:
"""Initialize motion guard manager."""
super().__init__(request, URL, ApplicationAPIItem, API_VERSION)
7 changes: 4 additions & 3 deletions axis/applications/object_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@


class ObjectAnalytics(ApplicationAPIItems):
"""Object Analytics application on Axis devices"""
"""Object Analytics application on Axis devices."""

APPLICATION_NAME = APPLICATION_NAME

def __init__(self, request: object) -> None:
"""Initialize object analyticz manager."""
super().__init__(request, URL, ObjectAnalyticsScenario, API_VERSION)

@staticmethod
Expand All @@ -38,7 +39,7 @@ def pre_process_raw(raw: dict) -> dict:
return scenarios

async def get_configuration(self) -> dict:
"""Current configuration of application."""
"""Retrieve configuration of application."""
return await self._request(
"post",
self._path,
Expand Down Expand Up @@ -78,5 +79,5 @@ def trigger_type(self) -> str:

@property
def uid(self) -> int:
"""Unique ID of scenario."""
"""Scenario ID."""
return self.raw["id"]
1 change: 1 addition & 0 deletions axis/applications/vmd4.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ class Vmd4(ApplicationAPIItems):
APPLICATION_NAME = APPLICATION_NAME

def __init__(self, request: object) -> None:
"""Initialize VMD4 manager."""
super().__init__(request, URL, ApplicationAPIItem, API_VERSION)
72 changes: 58 additions & 14 deletions axis/basic_device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ class BasicDeviceInfo(APIItems):
"""Basic device information for Axis devices."""

def __init__(self, request: object) -> None:
"""Initialize basic device information manager."""
super().__init__({}, request, URL, APIItem)

def __getitem__(self, obj_id: str) -> Optional[Any]:
"""self["string"] will return self._item["string"].raw."""
return self._items[obj_id].raw

async def update(self) -> None:
"""Refresh data."""
raw = await self.get_all_properties()
self.process_raw(raw)

Expand Down Expand Up @@ -59,70 +61,112 @@ async def get_supported_versions(self) -> dict:

@property
def architecture(self) -> str:
"""ApiVersion 1.1"""
"""SOC architecture.
ApiVersion 1.1.
"""
return self["Architecture"]

@property
def brand(self) -> str:
"""ApiVersion 1.1"""
"""Device branding.
ApiVersion 1.1.
"""
return self["Brand"]

@property
def builddate(self) -> str:
"""ApiVersion 1.1"""
"""Firmware build date.
ApiVersion 1.1.
"""
return self["BuildDate"]

@property
def hardwareid(self) -> str:
"""ApiVersion 1.1"""
"""Device hardware ID.
ApiVersion 1.1.
"""
return self["HardwareID"]

@property
def prodfullname(self) -> str:
"""ApiVersion 1.1"""
"""Device product full name.
ApiVersion 1.1.
"""
return self["ProdFullName"]

@property
def prodnbr(self) -> str:
"""ApiVersion 1.1"""
"""Device product number.
ApiVersion 1.1.
"""
return self["ProdNbr"]

@property
def prodshortname(self) -> str:
"""ApiVersion 1.1"""
"""Device product short name.
ApiVersion 1.1.
"""
return self["ProdShortName"]

@property
def prodtype(self) -> str:
"""ApiVersion 1.1"""
"""Device product type.
ApiVersion 1.1.
"""
return self["ProdType"]

@property
def prodvariant(self) -> str:
"""ApiVersion 1.1"""
"""Device product variant.
ApiVersion 1.1.
"""
return self["ProdVariant"]

@property
def serialnumber(self) -> str:
"""ApiVersion 1.1"""
"""Device serial number.
ApiVersion 1.1.
"""
return self["SerialNumber"]

@property
def soc(self) -> str:
"""ApiVersion 1.1"""
"""System on chip variant.
ApiVersion 1.1.
"""
return self["Soc"]

@property
def socserialnumber(self) -> str:
"""ApiVersion 1.1"""
"""SOC serial number.
ApiVersion 1.1.
"""
return self["SocSerialNumber"]

@property
def version(self) -> str:
"""ApiVersion 1.1"""
"""Firmware version.
ApiVersion 1.1.
"""
return self["Version"]

@property
def weburl(self) -> str:
"""ApiVersion 1.1"""
"""Device home page URL.
ApiVersion 1.1.
"""
return self["WebURL"]
1 change: 1 addition & 0 deletions axis/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class NoPermission(AxisException):


def raise_error(error):
"""Raise error."""
type = error
cls = ERRORS.get(type, AxisException)
raise cls("{}".format(type))
Loading

0 comments on commit 5c1d9a2

Please sign in to comment.