11"""A python implementation of the Vivotek IB8369A"""
22from textwrap import wrap
3+ from typing import Any
34
45import requests
56from requests .auth import HTTPBasicAuth
@@ -28,8 +29,17 @@ class VivotekCamera():
2829
2930 # pylint: disable=too-many-instance-attributes
3031 # pylint: disable=too-many-arguments
31- def __init__ (self , host , sec_lvl , port = None , usr = None , pwd = None , digest_auth = False , ssl = None ,
32- verify_ssl = True ):
32+ # pylint: disable=too-many-positional-arguments
33+ def __init__ (self ,
34+ host : str ,
35+ sec_lvl : str ,
36+ port : int | None = None ,
37+ usr : str = '' ,
38+ pwd : str = '' ,
39+ digest_auth : bool = False ,
40+ ssl : bool | None = None ,
41+ verify_ssl : bool = True
42+ ) -> None :
3343 """
3444 Initialize a camera.
3545 """
@@ -53,7 +63,9 @@ def __init__(self, host, sec_lvl, port=None, usr=None, pwd=None, digest_auth=Fal
5363 if sec_lvl not in SECURITY_LEVELS :
5464 raise VivotekCameraError (f"Invalid security level: { sec_lvl } " )
5565
56- if usr is None or sec_lvl == 'anonymous' :
66+ self ._requests_auth : HTTPBasicAuth | HTTPDigestAuth | None
67+
68+ if usr == '' or sec_lvl == 'anonymous' :
5769 self ._requests_auth = None
5870 self ._security_level = 'anonymous'
5971 else :
@@ -63,7 +75,7 @@ def __init__(self, host, sec_lvl, port=None, usr=None, pwd=None, digest_auth=Fal
6375 else :
6476 self ._requests_auth = HTTPBasicAuth (usr , pwd )
6577
66- self ._model_name = None
78+ self ._model_name : str | None = None
6779
6880 _protocol = 'https' if self ._ssl else 'http'
6981 self ._url_base = _protocol + "://" + self .host
@@ -75,12 +87,12 @@ def __init__(self, host, sec_lvl, port=None, usr=None, pwd=None, digest_auth=Fal
7587 self ._set_param_url = self ._cgi_url_base + API_PATHS ["set" ]
7688 self ._still_image_url = self ._url_base + CGI_BASE_PATH + "/viewer" + API_PATHS ["still" ]
7789
78- def event_enabled (self , event_key ) :
90+ def event_enabled (self , event_key : str ) -> bytes | Any | None :
7991 """Return true if event for the provided key is enabled."""
8092 response = self .get_param (event_key )
8193 return int (response .replace ("'" , "" )) == 1
8294
83- def snapshot (self , quality = 3 ) :
95+ def snapshot (self , quality : int = 3 ) -> bytes | Any :
8496 """Return the bytes of current still image."""
8597 try :
8698 response = requests .get (
@@ -95,31 +107,30 @@ def snapshot(self, quality=3):
95107 except requests .exceptions .RequestException as error :
96108 raise VivotekCameraError from error
97109
98- def get_mac (self ):
110+ def get_mac (self ) -> str :
99111 """Return the MAC address with colons"""
100112 return ":" .join (wrap (self .get_serial (), 2 ))
101113
102- def get_serial (self ):
114+ def get_serial (self ) -> str :
103115 """Return the serial number which is also the MAC address."""
104116 return self .get_param ('system_info_serialnumber' )
105117
106- def get_param (self , param ) :
118+ def get_param (self , param : str ) -> str :
107119 """Return the value of the provided key."""
108- request_args = {
109- "params" : param ,
110- "timeout" : 10 ,
111- "verify" : self .verify_ssl
112- }
113- if self ._requests_auth is not None :
114- request_args ['auth' ] = self ._requests_auth
115120 try :
116- response = requests .get (self ._get_param_url , ** request_args )
121+ response = requests .get (
122+ self ._get_param_url ,
123+ params = param ,
124+ timeout = 10 ,
125+ verify = self .verify_ssl ,
126+ auth = self ._requests_auth
127+ )
117128
118129 return self .__parse_response_value (response )
119130 except requests .exceptions .RequestException as error :
120131 raise VivotekCameraError from error
121132
122- def set_param (self , param , value ) :
133+ def set_param (self , param : str , value : str | int | bool ) -> str :
123134 """Set and return the value of the provided key."""
124135 if SECURITY_LEVELS [self ._security_level ] < 4 :
125136 raise VivotekCameraError (
@@ -139,7 +150,7 @@ def set_param(self, param, value):
139150 raise VivotekCameraError from error
140151
141152 @property
142- def model_name (self ):
153+ def model_name (self ) -> str :
143154 """Return the model name of the camera."""
144155 if self ._model_name is not None :
145156 return self ._model_name
@@ -148,7 +159,7 @@ def model_name(self):
148159 return self ._model_name
149160
150161 @staticmethod
151- def __parse_response_value (response ) :
162+ def __parse_response_value (response : requests . Response ) -> str :
152163 """
153164 Parse the response from an API call and return the value only.
154165 This assumes the response is in the key='value' format.
0 commit comments