-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from 2Fake/reuse_data
Reuse data and discover devices
- Loading branch information
Showing
20 changed files
with
429 additions
and
126 deletions.
There are no files selected for viewing
This file contains 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,12 @@ | ||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for all configuration options: | ||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "pip" | ||
directory: "/" # Location of package manifests | ||
schedule: | ||
interval: "daily" | ||
target-branch: "development" |
This file contains 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 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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.2.0" | ||
__version__ = "0.3.0" |
This file contains 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 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 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 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,51 @@ | ||
import asyncio | ||
import time | ||
from typing import Dict | ||
|
||
from zeroconf import ServiceBrowser, ServiceStateChange, Zeroconf | ||
|
||
from ..device import Device | ||
|
||
_devices: Dict[str, | ||
Device] = {} | ||
|
||
|
||
async def async_discover_network() -> Dict[str, Device]: | ||
""" | ||
Discover all devices that expose the devolo device API via mDNS asynchronous. | ||
:return: Devices accessible via serial number. | ||
""" | ||
browser = ServiceBrowser(Zeroconf(), "_dvl-deviceapi._tcp.local.", [_add]) | ||
await asyncio.sleep(3) | ||
browser.cancel() | ||
await asyncio.gather(*[device.async_connect() for device in _devices.values()]) | ||
return _devices | ||
|
||
|
||
def discover_network() -> Dict[str, Device]: | ||
""" | ||
Discover devices that expose the devolo device API via mDNS synchronous. | ||
:return: Devices accessible via serial number. | ||
""" | ||
browser = ServiceBrowser(Zeroconf(), "_dvl-deviceapi._tcp.local.", [_add]) | ||
time.sleep(3) | ||
browser.cancel() | ||
for device in _devices.values(): | ||
device.connect() | ||
return _devices | ||
|
||
|
||
def _add(zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange): | ||
"""" Create a device object to each matching device. """ | ||
if state_change is ServiceStateChange.Added: | ||
service_info = zeroconf.get_service_info(service_type, name) | ||
if service_info is None: | ||
return | ||
|
||
info = Device.info_from_service(service_info) | ||
if info is None: | ||
return | ||
|
||
_devices[info["properties"]["SN"]] = Device(ip=info["address"], deviceapi=info, zeroconf_instance=zeroconf) |
Oops, something went wrong.