Skip to content

Commit

Permalink
mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
RenierM26 committed Nov 18, 2021
1 parent 2c0e2c6 commit b912175
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
7 changes: 2 additions & 5 deletions pyezviz/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,9 @@ def move(self, direction: str, speed: int = 5) -> bool:

return True

def move_coordinates(self, x: float, y: float):
def move_coordinates(self, x_axis: float, y_axis: float) -> bool:
"""Move camera to specified coordinates."""

self._client.ptz_control_coordinates(self._serial, x, y)

return True
return self._client.ptz_control_coordinates(self._serial, x_axis, y_axis)

def alarm_notify(self, enable: int) -> bool:
"""Enable/Disable camera notification when movement is detected."""
Expand Down
28 changes: 16 additions & 12 deletions pyezviz/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def __init__(
) -> None:
"""Initialize the client object."""
self.account = account
self.password = hashlib.md5(
password.encode("utf-8")
).hexdigest() # Ezviz API sends md5 of password
self.password = (
hashlib.md5(password.encode("utf-8")).hexdigest() if password else None
) # Ezviz API sends md5 of password
self._session = requests.session()
# Set Android generic user agent.
self._session.headers.update({"User-Agent": "okhttp/3.12.1"})
Expand Down Expand Up @@ -519,23 +519,27 @@ def ptz_control(
return req.text

def ptz_control_coordinates(
self, serial: str, x: float, y: float
) -> Any:
self, serial: str, x_axis: float, y_axis: float
) -> bool:
"""PTZ Coordinate Move"""
if 0 < x > 1:
raise PyEzvizError(f"Invalid X coordinate: {x}: Should be between 0 and 1 inclusive")
if 0 < x_axis > 1:
raise PyEzvizError(
f"Invalid X coordinate: {x_axis}: Should be between 0 and 1 inclusive"
)

if 0 < y > 1:
raise PyEzvizError(f"Invalid Y coordinate: {y}: Should be between 0 and 1 inclusive")
if 0 < y_axis > 1:
raise PyEzvizError(
f"Invalid Y coordinate: {y_axis}: Should be between 0 and 1 inclusive"
)

try:
req = self._session.post(
"https://"
+ self._token["api_url"]
+ API_ENDPOINT_PANORAMIC_DEVICES_OPERATION,
data={
"x": f"{x:.6f}",
"y": f"{y:.6f}",
"x": f"{x_axis:.6f}",
"y": f"{y_axis:.6f}",
"deviceSerial": serial,
},
headers={"sessionId": self._token["session_id"], "clientType": "1"},
Expand All @@ -547,7 +551,7 @@ def ptz_control_coordinates(
except requests.HTTPError as err:
raise HTTPError from err

return req.text
return True

def login(self) -> dict[Any, Any]:
"""Get or refresh ezviz login token."""
Expand Down

0 comments on commit b912175

Please sign in to comment.