-
-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Kasa Cam support #537
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
"""Pan/Tilt/Zoom Module.""" | ||
from .module import Module, merge | ||
|
||
try: | ||
from pydantic.v1 import BaseModel | ||
except ImportError: | ||
from pydantic import BaseModel | ||
|
||
from typing import Literal, Optional | ||
|
||
from ..exceptions import SmartDeviceException | ||
|
||
|
||
class Position(BaseModel): | ||
"""Camera Position Schema.""" | ||
|
||
x: int | ||
y: int | ||
|
||
|
||
Direction = Literal["up", "down", "left", "right"] | ||
|
||
|
||
class PTZ(Module): | ||
"""Module implementing support for pan/tilt/zoom cameras.""" | ||
|
||
def query(self): | ||
"""Request PTZ info.""" | ||
q = self.query_for_command("get_position") | ||
merge(q, self.query_for_command("get_patrol_is_enable")) | ||
return q | ||
|
||
@property | ||
def position(self) -> Position: | ||
"""Return the camera's position coordinates.""" | ||
return Position.parse_obj(self.data["get_position"]) | ||
|
||
@property | ||
def is_patrol_enabled(self) -> bool: | ||
"""Whether or not the camera is patrolling.""" | ||
return self.data["get_patrol_is_enable"]["value"] == "on" | ||
|
||
async def set_enable_patrol(self, enabled: bool): | ||
"""Enable or disable camera patrolling.""" | ||
return await self.call( | ||
"set_patrol_is_enable", {"value": "on" if enabled else "off"} | ||
) | ||
|
||
async def go_to( | ||
self, | ||
position: Optional[Position] = None, | ||
x: Optional[int] = None, | ||
y: Optional[int] = None, | ||
): | ||
"""Move the camera to the given Position's x,y coordinates.""" | ||
if position is None and x is not None and y is not None: | ||
position = Position(x=x, y=y) | ||
if not position: | ||
raise SmartDeviceException( | ||
"Either a Position object or both x and y are required." | ||
) | ||
return await self.call("set_move", {"x": position.x, "y": position.y}) | ||
|
||
async def stop(self): | ||
"""Stop the camera where it is.""" | ||
return await self.call("set_stop") | ||
|
||
async def move(self, direction: Direction, speed: int): | ||
"""Move the camera in a relative direction.""" | ||
return await self.call("set_target", {"direction": direction, "speed": speed}) | ||
|
||
# async def add_preset(self): | ||
# # public String api_srv_url; | ||
# # public Integer index; | ||
# # public String name; | ||
# # public String path; | ||
# # public Integer wait_time; | ||
# pass | ||
|
||
# async def delete_preset(self, index: int): | ||
# pass | ||
|
||
# async def edit_preset(self, index: int, name: str, wait_time: int): | ||
# pass | ||
|
||
# async def get_all_preset(self): | ||
# # public Integer maximum; | ||
# # public List preset_attr; | ||
# pass | ||
|
||
# async def get_patrol_is_enable(self): | ||
# pass | ||
|
||
# async def get_position(self): | ||
# # public Integer x; | ||
# # public Integer y; | ||
# pass | ||
|
||
# async def get_ptz_rectify_state(self): | ||
# pass | ||
|
||
# async def get_ptz_tracking_is_enable(self): | ||
# pass | ||
|
||
# async def set_motor_rectify(self): | ||
# pass | ||
|
||
# async def set_move(self, x: int, y: int): | ||
# pass | ||
|
||
# async def set_patrol_is_enable(self): | ||
# pass | ||
|
||
# async def set_ptz_tracking_is_enable(self): | ||
# pass | ||
|
||
# async def set_run_to_preset(self, index: int): | ||
# pass | ||
|
||
# async def set_stop(self): | ||
# pass | ||
|
||
# async def set_target(self, direction: str, speed: int): | ||
# pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,12 +13,16 @@ def query(self): | |
q = self.query_for_command("get_time") | ||
|
||
merge(q, self.query_for_command("get_timezone")) | ||
merge(q, self.query_for_command("get_time_zone")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rytilahti the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it's better to create a separate class that inherits from the edit: Or maybe just a keyword argument to
and initializing it with |
||
return q | ||
|
||
@property | ||
def time(self) -> datetime: | ||
"""Return current device time.""" | ||
res = self.data["get_time"] | ||
if "epoch_sec" in res: | ||
return datetime.fromtimestamp(res["epoch_sec"]) | ||
|
||
return datetime( | ||
res["year"], | ||
res["month"], | ||
|
@@ -38,6 +42,8 @@ async def get_time(self): | |
"""Return current device time.""" | ||
try: | ||
res = await self.call("get_time") | ||
if "epoch_sec" in res: | ||
return datetime.fromtimestamp(res["epoch_sec"]) | ||
return datetime( | ||
res["year"], | ||
res["month"], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.