-
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.
- Loading branch information
Markus Bong
authored and
Markus Bong
committed
Aug 14, 2020
1 parent
cceb3f3
commit d7ee723
Showing
7 changed files
with
978 additions
and
0 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 |
---|---|---|
|
@@ -127,3 +127,5 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
.idea |
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,32 @@ | ||
import time | ||
|
||
from aiohttp import ClientSession | ||
from zeroconf import ServiceBrowser, ServiceStateChange, Zeroconf | ||
|
||
from .wifi_network.wifi_network import WifiNetwork | ||
|
||
|
||
def _on_service_state_change(zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange): | ||
""" Service handler for Zeroconf state changes. """ | ||
if state_change is ServiceStateChange.Added: | ||
zeroconf.get_service_info(service_type, name) | ||
|
||
|
||
class DevoloPlcApi(WifiNetwork): | ||
def __init__(self, ip: str, session: ClientSession, port: int): | ||
super().__init__(ip, session, port) | ||
|
||
|
||
def get_token(self): | ||
# Takes long time until the magic devices answer to zeroconf. | ||
zeroconf = Zeroconf() | ||
browser = ServiceBrowser(zeroconf, "_dvl._deviceapi._tcp.local.", handlers=[_on_service_state_change]) | ||
start_time = time.time() | ||
while not time.time() > start_time + 10: | ||
time.sleep(8) | ||
for mdns_name in zeroconf.cache.entries(): | ||
print(mdns_name) | ||
return | ||
|
||
|
||
|
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,9 @@ | ||
class ProtobufSender: | ||
def __init__(self, ip, session, port): | ||
self.ip = ip | ||
self.port = port | ||
self.session = session | ||
self.token = "1e6be8c2bb7ac289" | ||
|
||
async def get(self, sub_url, data=None): | ||
return await self.session.get(f"{self.ip}:{self.port}/{self.token}/deviceapi/v0/{sub_url}") |
Oops, something went wrong.