-
Notifications
You must be signed in to change notification settings - Fork 60
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
Add force white lamp state #31
Add force white lamp state #31
Conversation
return self.performRequest( | ||
{"method": "set", "image": {"common": {"inf_type": inf_type}}} | ||
) | ||
|
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.
Moved this further down the file to be near setLightFrequencyMode
.
@@ -355,6 +349,7 @@ def getRecordings(self, date): | |||
)["result"]["responses"][0]["result"]["playback"]["search_video_results"] | |||
|
|||
def getCommonImage(self): | |||
warn("Prefer to use a specific value getter", DeprecationWarning, stacklevel=2) | |||
return self.performRequest({"method": "get", "image": {"name": "common"}}) |
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.
This method forces the caller to know about the response structure, we should move towards specific getters for a clearer abstraction.
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.
First thank you for such a detailed PR and your contribution! I really like the code changes and the new feature.
I tested this on my C200 and found 2 changes we need to make;
def __getImageSwitch(self, switch: str) -> str:
data = self.performRequest({"method": "get", "image": {"name": ["switch"]}})
> return data["image"]["switch"][switch]
E KeyError: 'force_wtl_state'
pytapo/__init__.py:424: KeyError
We need to handle this properly - if the key is not in the function, we need to raise an Exception.
As for the unit tests I really like the idea, I have created #32 . |
Thanks @JurajNyiri , I have raised exceptions for when the switches or fields are not supported by the camera, and did the same for the playback (which is not supported by the C329WS). Feel free to modify the exception messages if another phrasing makes more sense to you! |
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.
💯 Thank you! Going to merge & deploy this as a new version to pypi.
Deployed to pypi as 2.2. |
Context
The Tapo C320WS supports a floodlight, referred to in the API as a "Whitelamp". This PR adds support for turning this on and off.
The PR also includes a refactor to simplify how "common' and "switch" values are set/get, and adds some abstractions so library consumers don't need to unpack response data.
Additions
getForceWhitelampState
andsetForceWhitelampState
for getting and setting floodlight status__getImageSwitch
/__setImageSwitch
and__getImageCommon
/__setImageCommon
functionalitygetLightFrequencyMode
andgetDayNightMode
to avoid depending on API implementation detailssetDayNightMode
to be consistent withsetLightFrequencyMode
Caveats
Some of the existing tests don't work with the C320WS, for example, due to the lack of a motor. Logging the failures here for future investigation, we might want to keep track of individual camera model capabilities, or simply bail on tests that return a
-40106
.Test sample
Untitled.mov