Skip to content

Commit

Permalink
inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Bong authored and Markus Bong committed Aug 14, 2020
1 parent cceb3f3 commit d7ee723
Show file tree
Hide file tree
Showing 7 changed files with 978 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ dmypy.json

# Pyre type checker
.pyre/

.idea
32 changes: 32 additions & 0 deletions devolo_plc_api/devolo_plc_api.py
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



9 changes: 9 additions & 0 deletions devolo_plc_api/protobuf_sender.py
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}")
Loading

0 comments on commit d7ee723

Please sign in to comment.