-
-
Notifications
You must be signed in to change notification settings - Fork 223
Add common childsetup interface #1470
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
027d9b4
Add childsetup module to smartcam hubs
sdb9696 8e2edf9
Apply suggestions from code review
sdb9696 88f64d2
Add common childsetup interface
sdb9696 c11da2e
Fix discovery readme example
sdb9696 03cd513
Merge branch 'master' into feat/smartcam_childsetup
sdb9696 54ff8fa
Merge branch 'feat/smartcam_childsetup' into feat/common_childsetup
sdb9696 5e21956
Merge remote-tracking branch 'upstream/master' into feat/common_child…
sdb9696 8b842ce
Apply suggestions from code review
sdb9696 7821cb4
Apply more suggestions from code review
sdb9696 c4c3940
Merge remote-tracking branch 'upstream/master' into feat/common_child…
sdb9696 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"""Module for childsetup interface. | ||
|
||
The childsetup module allows pairing and unpairing of supported child device types to | ||
hubs. | ||
|
||
>>> from kasa import Discover, Module, LightState | ||
>>> | ||
>>> dev = await Discover.discover_single( | ||
>>> "127.0.0.6", | ||
>>> username="user@example.com", | ||
>>> password="great_password" | ||
>>> ) | ||
>>> await dev.update() | ||
>>> print(dev.alias) | ||
Tapo Hub | ||
|
||
>>> childsetup = dev.modules[Module.ChildSetup] | ||
>>> childsetup.supported_categories | ||
['camera', 'subg.trv', 'subg.trigger', 'subg.plugswitch'] | ||
|
||
Put child devices in pairing mode. | ||
The hub will pair with all supported devices in pairing mode: | ||
|
||
>>> added = await childsetup.pair() | ||
>>> added | ||
[{'device_id': 'SCRUBBED_CHILD_DEVICE_ID_5', 'category': 'subg.trigger.button', \ | ||
'device_model': 'S200B', 'name': 'I01BU0tFRF9OQU1FIw===='}] | ||
|
||
>>> for child in dev.children: | ||
>>> print(f"{child.device_id} - {child.model}") | ||
SCRUBBED_CHILD_DEVICE_ID_1 - T310 | ||
SCRUBBED_CHILD_DEVICE_ID_2 - T315 | ||
SCRUBBED_CHILD_DEVICE_ID_3 - T110 | ||
SCRUBBED_CHILD_DEVICE_ID_4 - S200B | ||
SCRUBBED_CHILD_DEVICE_ID_5 - S200B | ||
|
||
Unpair with the child `device_id`: | ||
|
||
>>> await childsetup.unpair("SCRUBBED_CHILD_DEVICE_ID_4") | ||
>>> for child in dev.children: | ||
>>> print(f"{child.device_id} - {child.model}") | ||
SCRUBBED_CHILD_DEVICE_ID_1 - T310 | ||
SCRUBBED_CHILD_DEVICE_ID_2 - T315 | ||
SCRUBBED_CHILD_DEVICE_ID_3 - T110 | ||
SCRUBBED_CHILD_DEVICE_ID_5 - S200B | ||
|
||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
from ..module import Module | ||
|
||
|
||
class ChildSetup(Module, ABC): | ||
"""Interface for child setup on hubs.""" | ||
|
||
@property | ||
@abstractmethod | ||
def supported_categories(self) -> list[str]: | ||
"""Supported child device categories.""" | ||
|
||
@abstractmethod | ||
async def pair(self, *, timeout: int = 10) -> list[dict]: | ||
"""Scan for new devices and pair them.""" | ||
|
||
@abstractmethod | ||
async def unpair(self, device_id: str) -> dict: | ||
"""Remove device from the hub.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.