From e46f0f7e5da4dbb2d8fc095c9a11777d9423d113 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Fri, 21 Aug 2020 11:49:20 +0200 Subject: [PATCH 01/93] zeroconf is working now --- devolo_plc_api/device_api/device_api.py | 14 + ...olo_idl_proto_deviceapi_wifinetwork_pb2.py | 0 .../wifi_network/wifi_network.py | 11 +- devolo_plc_api/devolo_plc_api.py | 34 +- devolo_plc_api/helper/zeroconf.py | 58 +++ ...l_proto_plcnetapi_getnetworkoverview.proto | 63 +++ ..._proto_plcnetapi_getnetworkoverview_pb2.py | 358 ++++++++++++++++++ .../network_overview/network_overview.py | 17 + devolo_plc_api/plc_net_api/plc_net_api.py | 8 + devolo_plc_api/protobuf_sender.py | 7 +- example.py | 8 +- 11 files changed, 540 insertions(+), 38 deletions(-) create mode 100644 devolo_plc_api/device_api/device_api.py rename devolo_plc_api/{ => device_api}/wifi_network/devolo_idl_proto_deviceapi_wifinetwork_pb2.py (100%) rename devolo_plc_api/{ => device_api}/wifi_network/wifi_network.py (53%) create mode 100644 devolo_plc_api/helper/zeroconf.py create mode 100644 devolo_plc_api/plc_net_api/network_overview/devolo_idl_proto_plcnetapi_getnetworkoverview.proto create mode 100644 devolo_plc_api/plc_net_api/network_overview/devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.py create mode 100644 devolo_plc_api/plc_net_api/network_overview/network_overview.py create mode 100644 devolo_plc_api/plc_net_api/plc_net_api.py diff --git a/devolo_plc_api/device_api/device_api.py b/devolo_plc_api/device_api/device_api.py new file mode 100644 index 0000000..4a67690 --- /dev/null +++ b/devolo_plc_api/device_api/device_api.py @@ -0,0 +1,14 @@ +from .wifi_network.wifi_network import WifiNetwork +from ..helper.zeroconf import get_token + + +class DeviceApi: + def __init__(self, ip, session): + self.token, self.features = get_token(ip, "_dvl-deviceapi._tcp.local.") + feature_mapping = {"wifi1": WifiNetwork} + + for feature in self.features: + try: + setattr(self, feature, feature_mapping.get(feature)(ip, session, 14791, self.token)) + except TypeError: + continue \ No newline at end of file diff --git a/devolo_plc_api/wifi_network/devolo_idl_proto_deviceapi_wifinetwork_pb2.py b/devolo_plc_api/device_api/wifi_network/devolo_idl_proto_deviceapi_wifinetwork_pb2.py similarity index 100% rename from devolo_plc_api/wifi_network/devolo_idl_proto_deviceapi_wifinetwork_pb2.py rename to devolo_plc_api/device_api/wifi_network/devolo_idl_proto_deviceapi_wifinetwork_pb2.py diff --git a/devolo_plc_api/wifi_network/wifi_network.py b/devolo_plc_api/device_api/wifi_network/wifi_network.py similarity index 53% rename from devolo_plc_api/wifi_network/wifi_network.py rename to devolo_plc_api/device_api/wifi_network/wifi_network.py index 05c3c0c..3bb8919 100644 --- a/devolo_plc_api/wifi_network/wifi_network.py +++ b/devolo_plc_api/device_api/wifi_network/wifi_network.py @@ -1,13 +1,18 @@ from . import devolo_idl_proto_deviceapi_wifinetwork_pb2 -from ..protobuf_sender import ProtobufSender +from devolo_plc_api.protobuf_sender import ProtobufSender class WifiNetwork(ProtobufSender): - def __init__(self, ip: str, session, port): - super().__init__(ip, session, port) + def __init__(self, ip: str, session, port, token): + super().__init__(ip=ip, + session=session, + port=port, + api_type="deviceapi", + token=token) async def get_wifi_guest_access(self): wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() r = await self.get("WifiGuestAccessGet") + print(r) wifi_guest_proto.ParseFromString(await r.read()) return wifi_guest_proto diff --git a/devolo_plc_api/devolo_plc_api.py b/devolo_plc_api/devolo_plc_api.py index 086835a..8cc018d 100644 --- a/devolo_plc_api/devolo_plc_api.py +++ b/devolo_plc_api/devolo_plc_api.py @@ -1,32 +1,10 @@ -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 +from .device_api.device_api import DeviceApi +from .plc_net_api.plc_net_api import PlcNetApi +class DevoloPlcApi(): + def __init__(self, ip: str, session: ClientSession): + self.device_api = DeviceApi(ip, session) + self.plc_net_api = PlcNetApi(ip, session) diff --git a/devolo_plc_api/helper/zeroconf.py b/devolo_plc_api/helper/zeroconf.py new file mode 100644 index 0000000..e857d90 --- /dev/null +++ b/devolo_plc_api/helper/zeroconf.py @@ -0,0 +1,58 @@ +from zeroconf import ServiceBrowser, ServiceStateChange, Zeroconf +import time +import socket + + +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) + + +def get_token(ip, service_name): + # TODO: Optimize the for & if + zeroconf = Zeroconf() + browser = ServiceBrowser(zeroconf, service_name, [_on_service_state_change]) + start_time = time.time() + while not time.time() > start_time + 10: + for mdns_name in zeroconf.cache.entries(): + try: + if hasattr(mdns_name, "server"): + zc = zeroconf.cache.cache.get(mdns_name.key) + for item in zc: + if hasattr(item, "server"): + try: + zc2 = zeroconf.cache.cache[item.server.lower()] + for item2 in zc2: + try: + if socket.inet_ntoa(item2.address) == ip: + zc3 = zeroconf.cache.cache.get(item.key) + for item3 in zc3: + if hasattr(item3, "text"): + parsed_text = parse_zeroconf_text(item3.text) + if service_name == '_dvl-plcnetapi._tcp.local.': + return parsed_text['Path'] + else: + return parsed_text['Path'], parsed_text.get('Features').split(",") + except OSError: + continue + except KeyError: + continue + except (AttributeError, OSError, ValueError): + continue + browser.cancel() + zeroconf.close() + + +def parse_zeroconf_text(text): + entries = {} + total_length = len(text) + parsed_length = 0 + while parsed_length < total_length: + entry_length = int(text[parsed_length]) + entry = text[parsed_length + 1:parsed_length + entry_length + 1].decode('UTF-8') + parsed_length = parsed_length + entry_length + 1 + split_entry = entry.split('=') + entries[split_entry[0]] = split_entry[1] + entries["Path"] = entries["Path"].split("/")[0] + return entries diff --git a/devolo_plc_api/plc_net_api/network_overview/devolo_idl_proto_plcnetapi_getnetworkoverview.proto b/devolo_plc_api/plc_net_api/network_overview/devolo_idl_proto_plcnetapi_getnetworkoverview.proto new file mode 100644 index 0000000..064c6fc --- /dev/null +++ b/devolo_plc_api/plc_net_api/network_overview/devolo_idl_proto_plcnetapi_getnetworkoverview.proto @@ -0,0 +1,63 @@ +syntax = "proto3"; + +package plcnet.api; +option java_package = "plcnet"; +option java_outer_classname = "net"; + +message GetNetworkOverview +{ + message Device // describes a single powerline device + { + string product_name = 1; // product name for display purposes, like "devolo dLAN 1200+" + string product_id = 2; // internal product identifier, like "MT2639" + + string friendly_version = 3; // version string for display purposes, like "2.5.0.0-1" + string full_version = 4; // full version string + + string user_device_name = 5; // user provided device name, if any + string user_network_name = 6; // user provided network name, if any + + string mac_address = 7; // MAC address of the device, like "000B3BC3A4E6" + + enum Topology + { + UNKNOWN_TOPOLOGY = 0; + LOCAL = 1; // the device is LOCAL (i.e. reachable via eth/wifi) + REMOTE = 2; // the device is REMOTE (i.e. connected via powerline to the LOCAL device) + } + // in a real network, we will always see one LOCAL device + Topology topology = 8; // and zero or more REMOTEs + + enum Technology + { + UNKNOWN_TECHNOLOGY = 0; + HPAV_THUNDERBOLT = 3; // HomePlugAV device (based on Intellon/QCA Thunderbolt or later, i.e. 6x00/74x0 family) + HPAV_PANTHER = 4; // HomePlugAV device (based on Intellon/QCA Panther or later, i.e. 7420/75x0 family) + GHN_SPIRIT = 7; // G.hn device (based on Maxlinear Spirit firmware) + } + + Technology technology = 9; // in a real network, you will always see either HPAV or GHN devices, but never both + + repeated string bridged_devices = 10; // MAC addresses of devices attached to this device on the LAN side + + string ipv4_address = 11; // ipv4 address of the device; empty if none is available + + bool attached_to_router = 12; // indicates whether this adapter is attached to the router or not (only one should be set true) + } + + message DataRate // describes the data rate between two powerline devices in the same logical network + { + string mac_address_from = 1; // the powerline device from which we got information about the data rates + string mac_address_to = 2; // the powerline device to which we are transmitting/receiving + double tx_rate = 3; // transmit data rate in mbps + double rx_rate = 4; // receive data rate in mbps + } + + message LogicalNetwork + { + repeated Device devices = 1; // all devices in the logical network + repeated DataRate data_rates = 2; // all known data rates between devices in the logical network + } + + LogicalNetwork network = 1; +} diff --git a/devolo_plc_api/plc_net_api/network_overview/devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.py b/devolo_plc_api/plc_net_api/network_overview/devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.py new file mode 100644 index 0000000..dffcf5a --- /dev/null +++ b/devolo_plc_api/plc_net_api/network_overview/devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.py @@ -0,0 +1,358 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: devolo_idl_proto_plcnetapi_getnetworkoverview.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='devolo_idl_proto_plcnetapi_getnetworkoverview.proto', + package='plcnet.api', + syntax='proto3', + serialized_pb=_b('\n3devolo_idl_proto_plcnetapi_getnetworkoverview.proto\x12\nplcnet.api\"\xd5\x06\n\x12GetNetworkOverview\x12>\n\x07network\x18\x01 \x01(\x0b\x32-.plcnet.api.GetNetworkOverview.LogicalNetwork\x1a\x96\x04\n\x06\x44\x65vice\x12\x14\n\x0cproduct_name\x18\x01 \x01(\t\x12\x12\n\nproduct_id\x18\x02 \x01(\t\x12\x18\n\x10\x66riendly_version\x18\x03 \x01(\t\x12\x14\n\x0c\x66ull_version\x18\x04 \x01(\t\x12\x18\n\x10user_device_name\x18\x05 \x01(\t\x12\x19\n\x11user_network_name\x18\x06 \x01(\t\x12\x13\n\x0bmac_address\x18\x07 \x01(\t\x12@\n\x08topology\x18\x08 \x01(\x0e\x32..plcnet.api.GetNetworkOverview.Device.Topology\x12\x44\n\ntechnology\x18\t \x01(\x0e\x32\x30.plcnet.api.GetNetworkOverview.Device.Technology\x12\x17\n\x0f\x62ridged_devices\x18\n \x03(\t\x12\x14\n\x0cipv4_address\x18\x0b \x01(\t\x12\x1a\n\x12\x61ttached_to_router\x18\x0c \x01(\x08\"7\n\x08Topology\x12\x14\n\x10UNKNOWN_TOPOLOGY\x10\x00\x12\t\n\x05LOCAL\x10\x01\x12\n\n\x06REMOTE\x10\x02\"\\\n\nTechnology\x12\x16\n\x12UNKNOWN_TECHNOLOGY\x10\x00\x12\x14\n\x10HPAV_THUNDERBOLT\x10\x03\x12\x10\n\x0cHPAV_PANTHER\x10\x04\x12\x0e\n\nGHN_SPIRIT\x10\x07\x1a^\n\x08\x44\x61taRate\x12\x18\n\x10mac_address_from\x18\x01 \x01(\t\x12\x16\n\x0emac_address_to\x18\x02 \x01(\t\x12\x0f\n\x07tx_rate\x18\x03 \x01(\x01\x12\x0f\n\x07rx_rate\x18\x04 \x01(\x01\x1a\x85\x01\n\x0eLogicalNetwork\x12\x36\n\x07\x64\x65vices\x18\x01 \x03(\x0b\x32%.plcnet.api.GetNetworkOverview.Device\x12;\n\ndata_rates\x18\x02 \x03(\x0b\x32\'.plcnet.api.GetNetworkOverview.DataRateB\r\n\x06plcnetB\x03netb\x06proto3') +) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + + + +_GETNETWORKOVERVIEW_DEVICE_TOPOLOGY = _descriptor.EnumDescriptor( + name='Topology', + full_name='plcnet.api.GetNetworkOverview.Device.Topology', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='UNKNOWN_TOPOLOGY', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='LOCAL', index=1, number=1, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='REMOTE', index=2, number=2, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=540, + serialized_end=595, +) +_sym_db.RegisterEnumDescriptor(_GETNETWORKOVERVIEW_DEVICE_TOPOLOGY) + +_GETNETWORKOVERVIEW_DEVICE_TECHNOLOGY = _descriptor.EnumDescriptor( + name='Technology', + full_name='plcnet.api.GetNetworkOverview.Device.Technology', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='UNKNOWN_TECHNOLOGY', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='HPAV_THUNDERBOLT', index=1, number=3, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='HPAV_PANTHER', index=2, number=4, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='GHN_SPIRIT', index=3, number=7, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=597, + serialized_end=689, +) +_sym_db.RegisterEnumDescriptor(_GETNETWORKOVERVIEW_DEVICE_TECHNOLOGY) + + +_GETNETWORKOVERVIEW_DEVICE = _descriptor.Descriptor( + name='Device', + full_name='plcnet.api.GetNetworkOverview.Device', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='product_name', full_name='plcnet.api.GetNetworkOverview.Device.product_name', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='product_id', full_name='plcnet.api.GetNetworkOverview.Device.product_id', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='friendly_version', full_name='plcnet.api.GetNetworkOverview.Device.friendly_version', index=2, + number=3, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='full_version', full_name='plcnet.api.GetNetworkOverview.Device.full_version', index=3, + number=4, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='user_device_name', full_name='plcnet.api.GetNetworkOverview.Device.user_device_name', index=4, + number=5, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='user_network_name', full_name='plcnet.api.GetNetworkOverview.Device.user_network_name', index=5, + number=6, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='mac_address', full_name='plcnet.api.GetNetworkOverview.Device.mac_address', index=6, + number=7, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='topology', full_name='plcnet.api.GetNetworkOverview.Device.topology', index=7, + number=8, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='technology', full_name='plcnet.api.GetNetworkOverview.Device.technology', index=8, + number=9, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='bridged_devices', full_name='plcnet.api.GetNetworkOverview.Device.bridged_devices', index=9, + number=10, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='ipv4_address', full_name='plcnet.api.GetNetworkOverview.Device.ipv4_address', index=10, + number=11, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='attached_to_router', full_name='plcnet.api.GetNetworkOverview.Device.attached_to_router', index=11, + number=12, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + _GETNETWORKOVERVIEW_DEVICE_TOPOLOGY, + _GETNETWORKOVERVIEW_DEVICE_TECHNOLOGY, + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=155, + serialized_end=689, +) + +_GETNETWORKOVERVIEW_DATARATE = _descriptor.Descriptor( + name='DataRate', + full_name='plcnet.api.GetNetworkOverview.DataRate', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='mac_address_from', full_name='plcnet.api.GetNetworkOverview.DataRate.mac_address_from', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='mac_address_to', full_name='plcnet.api.GetNetworkOverview.DataRate.mac_address_to', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='tx_rate', full_name='plcnet.api.GetNetworkOverview.DataRate.tx_rate', index=2, + number=3, type=1, cpp_type=5, label=1, + has_default_value=False, default_value=float(0), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='rx_rate', full_name='plcnet.api.GetNetworkOverview.DataRate.rx_rate', index=3, + number=4, type=1, cpp_type=5, label=1, + has_default_value=False, default_value=float(0), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=691, + serialized_end=785, +) + +_GETNETWORKOVERVIEW_LOGICALNETWORK = _descriptor.Descriptor( + name='LogicalNetwork', + full_name='plcnet.api.GetNetworkOverview.LogicalNetwork', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='devices', full_name='plcnet.api.GetNetworkOverview.LogicalNetwork.devices', index=0, + number=1, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='data_rates', full_name='plcnet.api.GetNetworkOverview.LogicalNetwork.data_rates', index=1, + number=2, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=788, + serialized_end=921, +) + +_GETNETWORKOVERVIEW = _descriptor.Descriptor( + name='GetNetworkOverview', + full_name='plcnet.api.GetNetworkOverview', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='network', full_name='plcnet.api.GetNetworkOverview.network', index=0, + number=1, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[_GETNETWORKOVERVIEW_DEVICE, _GETNETWORKOVERVIEW_DATARATE, _GETNETWORKOVERVIEW_LOGICALNETWORK, ], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=68, + serialized_end=921, +) + +_GETNETWORKOVERVIEW_DEVICE.fields_by_name['topology'].enum_type = _GETNETWORKOVERVIEW_DEVICE_TOPOLOGY +_GETNETWORKOVERVIEW_DEVICE.fields_by_name['technology'].enum_type = _GETNETWORKOVERVIEW_DEVICE_TECHNOLOGY +_GETNETWORKOVERVIEW_DEVICE.containing_type = _GETNETWORKOVERVIEW +_GETNETWORKOVERVIEW_DEVICE_TOPOLOGY.containing_type = _GETNETWORKOVERVIEW_DEVICE +_GETNETWORKOVERVIEW_DEVICE_TECHNOLOGY.containing_type = _GETNETWORKOVERVIEW_DEVICE +_GETNETWORKOVERVIEW_DATARATE.containing_type = _GETNETWORKOVERVIEW +_GETNETWORKOVERVIEW_LOGICALNETWORK.fields_by_name['devices'].message_type = _GETNETWORKOVERVIEW_DEVICE +_GETNETWORKOVERVIEW_LOGICALNETWORK.fields_by_name['data_rates'].message_type = _GETNETWORKOVERVIEW_DATARATE +_GETNETWORKOVERVIEW_LOGICALNETWORK.containing_type = _GETNETWORKOVERVIEW +_GETNETWORKOVERVIEW.fields_by_name['network'].message_type = _GETNETWORKOVERVIEW_LOGICALNETWORK +DESCRIPTOR.message_types_by_name['GetNetworkOverview'] = _GETNETWORKOVERVIEW + +GetNetworkOverview = _reflection.GeneratedProtocolMessageType('GetNetworkOverview', (_message.Message,), dict( + + Device = _reflection.GeneratedProtocolMessageType('Device', (_message.Message,), dict( + DESCRIPTOR = _GETNETWORKOVERVIEW_DEVICE, + __module__ = 'devolo_idl_proto_plcnetapi_getnetworkoverview_pb2' + # @@protoc_insertion_point(class_scope:plcnet.api.GetNetworkOverview.Device) + )) + , + + DataRate = _reflection.GeneratedProtocolMessageType('DataRate', (_message.Message,), dict( + DESCRIPTOR = _GETNETWORKOVERVIEW_DATARATE, + __module__ = 'devolo_idl_proto_plcnetapi_getnetworkoverview_pb2' + # @@protoc_insertion_point(class_scope:plcnet.api.GetNetworkOverview.DataRate) + )) + , + + LogicalNetwork = _reflection.GeneratedProtocolMessageType('LogicalNetwork', (_message.Message,), dict( + DESCRIPTOR = _GETNETWORKOVERVIEW_LOGICALNETWORK, + __module__ = 'devolo_idl_proto_plcnetapi_getnetworkoverview_pb2' + # @@protoc_insertion_point(class_scope:plcnet.api.GetNetworkOverview.LogicalNetwork) + )) + , + DESCRIPTOR = _GETNETWORKOVERVIEW, + __module__ = 'devolo_idl_proto_plcnetapi_getnetworkoverview_pb2' + # @@protoc_insertion_point(class_scope:plcnet.api.GetNetworkOverview) + )) +_sym_db.RegisterMessage(GetNetworkOverview) +_sym_db.RegisterMessage(GetNetworkOverview.Device) +_sym_db.RegisterMessage(GetNetworkOverview.DataRate) +_sym_db.RegisterMessage(GetNetworkOverview.LogicalNetwork) + + +DESCRIPTOR.has_options = True +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\006plcnetB\003net')) +# @@protoc_insertion_point(module_scope) diff --git a/devolo_plc_api/plc_net_api/network_overview/network_overview.py b/devolo_plc_api/plc_net_api/network_overview/network_overview.py new file mode 100644 index 0000000..064ea57 --- /dev/null +++ b/devolo_plc_api/plc_net_api/network_overview/network_overview.py @@ -0,0 +1,17 @@ +from devolo_plc_api.plc_net_api.network_overview import devolo_idl_proto_plcnetapi_getnetworkoverview_pb2 +from devolo_plc_api.protobuf_sender import ProtobufSender + + +class NetworkOverview(ProtobufSender): + def __init__(self, ip: str, session, port, token): + super().__init__(ip=ip, + session=session, + port=port, + api_type="plcnetapi", + token=token) + + async def get_network_overview(self): + network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() + r = await self.get("GetNetworkOverview") + network_overview.ParseFromString(await r.read()) + return network_overview diff --git a/devolo_plc_api/plc_net_api/plc_net_api.py b/devolo_plc_api/plc_net_api/plc_net_api.py new file mode 100644 index 0000000..1996060 --- /dev/null +++ b/devolo_plc_api/plc_net_api/plc_net_api.py @@ -0,0 +1,8 @@ +from .network_overview.network_overview import NetworkOverview +from ..helper.zeroconf import get_token + + +class PlcNetApi(NetworkOverview): + def __init__(self, ip, session): + self.token = get_token(ip, "_dvl-plcnetapi._tcp.local.") + super().__init__(ip=ip, session=session, port=47219, token=self.token) diff --git a/devolo_plc_api/protobuf_sender.py b/devolo_plc_api/protobuf_sender.py index a9b654b..b8191a8 100644 --- a/devolo_plc_api/protobuf_sender.py +++ b/devolo_plc_api/protobuf_sender.py @@ -1,9 +1,10 @@ class ProtobufSender: - def __init__(self, ip, session, port): + def __init__(self, ip, session, port, api_type, token): self.ip = ip self.port = port self.session = session - self.token = "1e6be8c2bb7ac289" + self.token = token + self.api_type = api_type async def get(self, sub_url, data=None): - return await self.session.get(f"{self.ip}:{self.port}/{self.token}/deviceapi/v0/{sub_url}") \ No newline at end of file + return await self.session.get(f"http://{self.ip}:{self.port}/{self.token}/{self.api_type}/v0/{sub_url}") \ No newline at end of file diff --git a/example.py b/example.py index 6b9ee49..74bf5b5 100644 --- a/example.py +++ b/example.py @@ -4,14 +4,14 @@ from devolo_plc_api.devolo_plc_api import DevoloPlcApi -IP = "http://192.168.178.35" -PORT = 14791 +IP = "192.168.178.35" async def run(): async with ClientSession() as session: - dpa = DevoloPlcApi(IP, session, PORT) - print(await dpa.get_wifi_guest_access()) + dpa = DevoloPlcApi(IP, session) + print(await dpa.device_api.wifi1.get_wifi_guest_access()) + print(await dpa.plc_net_api.get_network_overview()) if __name__ == "__main__": From 4226f0448eb8121ca0832a522c615ce78073af10 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Sun, 23 Aug 2020 12:25:40 +0200 Subject: [PATCH 02/93] Add package structure --- devolo_plc_api/__init__.py | 1 + devolo_plc_api/clients/__init__.py | 0 devolo_plc_api/device_api/__init__.py | 0 devolo_plc_api/device_api/device_api.py | 14 - ...olo_idl_proto_deviceapi_wifinetwork_pb2.py | 900 ------------------ .../device_api/wifi_network/wifi_network.py | 18 - devolo_plc_api/devolo_plc_api.py | 10 - devolo_plc_api/exceptions/__init__.py | 0 devolo_plc_api/helper/zeroconf.py | 58 -- ...l_proto_plcnetapi_getnetworkoverview.proto | 63 -- ..._proto_plcnetapi_getnetworkoverview_pb2.py | 358 ------- .../network_overview/network_overview.py | 17 - devolo_plc_api/plc_net_api/plc_net_api.py | 8 - devolo_plc_api/plcnet_api/__init__.py | 0 devolo_plc_api/protobuf_sender.py | 10 - setup.py | 38 + 16 files changed, 39 insertions(+), 1456 deletions(-) create mode 100644 devolo_plc_api/__init__.py create mode 100644 devolo_plc_api/clients/__init__.py create mode 100644 devolo_plc_api/device_api/__init__.py delete mode 100644 devolo_plc_api/device_api/device_api.py delete mode 100644 devolo_plc_api/device_api/wifi_network/devolo_idl_proto_deviceapi_wifinetwork_pb2.py delete mode 100644 devolo_plc_api/device_api/wifi_network/wifi_network.py delete mode 100644 devolo_plc_api/devolo_plc_api.py create mode 100644 devolo_plc_api/exceptions/__init__.py delete mode 100644 devolo_plc_api/helper/zeroconf.py delete mode 100644 devolo_plc_api/plc_net_api/network_overview/devolo_idl_proto_plcnetapi_getnetworkoverview.proto delete mode 100644 devolo_plc_api/plc_net_api/network_overview/devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.py delete mode 100644 devolo_plc_api/plc_net_api/network_overview/network_overview.py delete mode 100644 devolo_plc_api/plc_net_api/plc_net_api.py create mode 100644 devolo_plc_api/plcnet_api/__init__.py delete mode 100644 devolo_plc_api/protobuf_sender.py create mode 100644 setup.py diff --git a/devolo_plc_api/__init__.py b/devolo_plc_api/__init__.py new file mode 100644 index 0000000..3dc1f76 --- /dev/null +++ b/devolo_plc_api/__init__.py @@ -0,0 +1 @@ +__version__ = "0.1.0" diff --git a/devolo_plc_api/clients/__init__.py b/devolo_plc_api/clients/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/devolo_plc_api/device_api/__init__.py b/devolo_plc_api/device_api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/devolo_plc_api/device_api/device_api.py b/devolo_plc_api/device_api/device_api.py deleted file mode 100644 index 4a67690..0000000 --- a/devolo_plc_api/device_api/device_api.py +++ /dev/null @@ -1,14 +0,0 @@ -from .wifi_network.wifi_network import WifiNetwork -from ..helper.zeroconf import get_token - - -class DeviceApi: - def __init__(self, ip, session): - self.token, self.features = get_token(ip, "_dvl-deviceapi._tcp.local.") - feature_mapping = {"wifi1": WifiNetwork} - - for feature in self.features: - try: - setattr(self, feature, feature_mapping.get(feature)(ip, session, 14791, self.token)) - except TypeError: - continue \ No newline at end of file diff --git a/devolo_plc_api/device_api/wifi_network/devolo_idl_proto_deviceapi_wifinetwork_pb2.py b/devolo_plc_api/device_api/wifi_network/devolo_idl_proto_deviceapi_wifinetwork_pb2.py deleted file mode 100644 index 62ad0ba..0000000 --- a/devolo_plc_api/device_api/wifi_network/devolo_idl_proto_deviceapi_wifinetwork_pb2.py +++ /dev/null @@ -1,900 +0,0 @@ -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: devolo_idl_proto_deviceapi_wifinetwork.proto - -import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) -from google.protobuf.internal import enum_type_wrapper -from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection -from google.protobuf import symbol_database as _symbol_database -from google.protobuf import descriptor_pb2 -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - - - -DESCRIPTOR = _descriptor.FileDescriptor( - name='devolo_idl_proto_deviceapi_wifinetwork.proto', - package='device.api', - syntax='proto3', - serialized_pb=_b('\n,devolo_idl_proto_deviceapi_wifinetwork.proto\x12\ndevice.api\".\n\x11WifiParametersSet\x12\x0c\n\x04ssid\x18\x01 \x01(\t\x12\x0b\n\x03key\x18\x02 \x01(\t\"C\n\x19WifiParametersSetResponse\x12&\n\x06result\x18\x01 \x01(\x0e\x32\x16.device.api.WifiResult\"6\n\x12WifiGuestAccessSet\x12\x0e\n\x06\x65nable\x18\x01 \x01(\x08\x12\x10\n\x08\x64uration\x18\x02 \x01(\r\"D\n\x1aWifiGuestAccessSetResponse\x12&\n\x06result\x18\x01 \x01(\x0e\x32\x16.device.api.WifiResult\"\\\n\x12WifiGuestAccessGet\x12\x0f\n\x07\x65nabled\x18\x01 \x01(\x08\x12\x1a\n\x12remaining_duration\x18\x02 \x01(\r\x12\x0c\n\x04ssid\x18\x03 \x01(\t\x12\x0b\n\x03key\x18\x04 \x01(\t\"\xe9\x01\n\x12WifiNeighborAPsGet\x12\x43\n\x0cneighbor_aps\x18\x01 \x03(\x0b\x32-.device.api.WifiNeighborAPsGet.NeighborAPInfo\x1a\x8d\x01\n\x0eNeighborAPInfo\x12\x13\n\x0bmac_address\x18\x01 \x01(\t\x12\x0c\n\x04ssid\x18\x02 \x01(\t\x12\"\n\x04\x62\x61nd\x18\x03 \x01(\x0e\x32\x14.device.api.WifiBand\x12\x0f\n\x07\x63hannel\x18\x04 \x01(\r\x12\x0e\n\x06signal\x18\x05 \x01(\x05\x12\x13\n\x0bsignal_bars\x18\x06 \x01(\x05\"\xf7\x01\n\x12WifiRepeatedAPsGet\x12\x43\n\x0crepeated_aps\x18\x01 \x03(\x0b\x32-.device.api.WifiRepeatedAPsGet.RepeatedAPInfo\x1a\x9b\x01\n\x0eRepeatedAPInfo\x12\x13\n\x0bmac_address\x18\x01 \x01(\t\x12\x0c\n\x04ssid\x18\x02 \x01(\t\x12\"\n\x04\x62\x61nd\x18\x03 \x01(\x0e\x32\x14.device.api.WifiBand\x12\x0f\n\x07\x63hannel\x18\x04 \x01(\r\x12\x0c\n\x04rate\x18\x05 \x01(\r\x12\x0e\n\x06signal\x18\x06 \x01(\x05\x12\x13\n\x0bsignal_bars\x18\x07 \x01(\x05\"\x90\x02\n\x18WifiConnectedStationsGet\x12U\n\x12\x63onnected_stations\x18\x01 \x03(\x0b\x32\x39.device.api.WifiConnectedStationsGet.ConnectedStationInfo\x1a\x9c\x01\n\x14\x43onnectedStationInfo\x12\x13\n\x0bmac_address\x18\x01 \x01(\t\x12)\n\x08vap_type\x18\x02 \x01(\x0e\x32\x17.device.api.WifiVAPType\x12\"\n\x04\x62\x61nd\x18\x03 \x01(\x0e\x32\x14.device.api.WifiBand\x12\x0f\n\x07rx_rate\x18\x04 \x01(\r\x12\x0f\n\x07tx_rate\x18\x05 \x01(\r\"u\n\x19WifiRepeaterParametersSet\x12\x0c\n\x04ssid\x18\x01 \x01(\t\x12\x0b\n\x03key\x18\x02 \x01(\t\x12\x11\n\tcrossband\x18\x03 \x01(\x08\x12*\n\x0cprimary_band\x18\x04 \x01(\x0e\x32\x14.device.api.WifiBand\"K\n!WifiRepeaterParametersSetResponse\x12&\n\x06result\x18\x01 \x01(\x0e\x32\x16.device.api.WifiResult\"9\n\x0fWifiWpsPbcStart\x12&\n\x06result\x18\x01 \x01(\x0e\x32\x16.device.api.WifiResult\"F\n\x1cWifiRepeaterWpsClonePbcStart\x12&\n\x06result\x18\x01 \x01(\x0e\x32\x16.device.api.WifiResult*z\n\nWifiResult\x12\x10\n\x0cWIFI_SUCCESS\x10\x00\x12\x15\n\x11WIFI_INVALID_SSID\x10\x01\x12\x14\n\x10WIFI_INVALID_KEY\x10\x02\x12\x14\n\x10WIFI_IS_DISABLED\x10\x03\x12\x17\n\x12WIFI_UNKNOWN_ERROR\x10\xff\x01*E\n\x08WifiBand\x12\x15\n\x11WIFI_BAND_UNKNOWN\x10\x00\x12\x10\n\x0cWIFI_BAND_2G\x10\x01\x12\x10\n\x0cWIFI_BAND_5G\x10\x02*f\n\x0bWifiVAPType\x12\x14\n\x10WIFI_VAP_UNKNOWN\x10\x00\x12\x14\n\x10WIFI_VAP_MAIN_AP\x10\x01\x12\x15\n\x11WIFI_VAP_GUEST_AP\x10\x02\x12\x14\n\x10WIFI_VAP_STATION\x10\x03\x42\x15\n\x06\x64\x65viceB\x0bwifinetworkb\x06proto3') -) -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -_WIFIRESULT = _descriptor.EnumDescriptor( - name='WifiResult', - full_name='device.api.WifiResult', - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name='WIFI_SUCCESS', index=0, number=0, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='WIFI_INVALID_SSID', index=1, number=1, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='WIFI_INVALID_KEY', index=2, number=2, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='WIFI_IS_DISABLED', index=3, number=3, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='WIFI_UNKNOWN_ERROR', index=4, number=255, - options=None, - type=None), - ], - containing_type=None, - options=None, - serialized_start=1485, - serialized_end=1607, -) -_sym_db.RegisterEnumDescriptor(_WIFIRESULT) - -WifiResult = enum_type_wrapper.EnumTypeWrapper(_WIFIRESULT) -_WIFIBAND = _descriptor.EnumDescriptor( - name='WifiBand', - full_name='device.api.WifiBand', - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name='WIFI_BAND_UNKNOWN', index=0, number=0, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='WIFI_BAND_2G', index=1, number=1, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='WIFI_BAND_5G', index=2, number=2, - options=None, - type=None), - ], - containing_type=None, - options=None, - serialized_start=1609, - serialized_end=1678, -) -_sym_db.RegisterEnumDescriptor(_WIFIBAND) - -WifiBand = enum_type_wrapper.EnumTypeWrapper(_WIFIBAND) -_WIFIVAPTYPE = _descriptor.EnumDescriptor( - name='WifiVAPType', - full_name='device.api.WifiVAPType', - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name='WIFI_VAP_UNKNOWN', index=0, number=0, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='WIFI_VAP_MAIN_AP', index=1, number=1, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='WIFI_VAP_GUEST_AP', index=2, number=2, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='WIFI_VAP_STATION', index=3, number=3, - options=None, - type=None), - ], - containing_type=None, - options=None, - serialized_start=1680, - serialized_end=1782, -) -_sym_db.RegisterEnumDescriptor(_WIFIVAPTYPE) - -WifiVAPType = enum_type_wrapper.EnumTypeWrapper(_WIFIVAPTYPE) -WIFI_SUCCESS = 0 -WIFI_INVALID_SSID = 1 -WIFI_INVALID_KEY = 2 -WIFI_IS_DISABLED = 3 -WIFI_UNKNOWN_ERROR = 255 -WIFI_BAND_UNKNOWN = 0 -WIFI_BAND_2G = 1 -WIFI_BAND_5G = 2 -WIFI_VAP_UNKNOWN = 0 -WIFI_VAP_MAIN_AP = 1 -WIFI_VAP_GUEST_AP = 2 -WIFI_VAP_STATION = 3 - - - -_WIFIPARAMETERSSET = _descriptor.Descriptor( - name='WifiParametersSet', - full_name='device.api.WifiParametersSet', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='ssid', full_name='device.api.WifiParametersSet.ssid', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='key', full_name='device.api.WifiParametersSet.key', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=60, - serialized_end=106, -) - - -_WIFIPARAMETERSSETRESPONSE = _descriptor.Descriptor( - name='WifiParametersSetResponse', - full_name='device.api.WifiParametersSetResponse', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='result', full_name='device.api.WifiParametersSetResponse.result', index=0, - number=1, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=108, - serialized_end=175, -) - - -_WIFIGUESTACCESSSET = _descriptor.Descriptor( - name='WifiGuestAccessSet', - full_name='device.api.WifiGuestAccessSet', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='enable', full_name='device.api.WifiGuestAccessSet.enable', index=0, - number=1, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='duration', full_name='device.api.WifiGuestAccessSet.duration', index=1, - number=2, type=13, cpp_type=3, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=177, - serialized_end=231, -) - - -_WIFIGUESTACCESSSETRESPONSE = _descriptor.Descriptor( - name='WifiGuestAccessSetResponse', - full_name='device.api.WifiGuestAccessSetResponse', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='result', full_name='device.api.WifiGuestAccessSetResponse.result', index=0, - number=1, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=233, - serialized_end=301, -) - - -_WIFIGUESTACCESSGET = _descriptor.Descriptor( - name='WifiGuestAccessGet', - full_name='device.api.WifiGuestAccessGet', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='enabled', full_name='device.api.WifiGuestAccessGet.enabled', index=0, - number=1, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='remaining_duration', full_name='device.api.WifiGuestAccessGet.remaining_duration', index=1, - number=2, type=13, cpp_type=3, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='ssid', full_name='device.api.WifiGuestAccessGet.ssid', index=2, - number=3, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='key', full_name='device.api.WifiGuestAccessGet.key', index=3, - number=4, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=303, - serialized_end=395, -) - - -_WIFINEIGHBORAPSGET_NEIGHBORAPINFO = _descriptor.Descriptor( - name='NeighborAPInfo', - full_name='device.api.WifiNeighborAPsGet.NeighborAPInfo', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='mac_address', full_name='device.api.WifiNeighborAPsGet.NeighborAPInfo.mac_address', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='ssid', full_name='device.api.WifiNeighborAPsGet.NeighborAPInfo.ssid', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='band', full_name='device.api.WifiNeighborAPsGet.NeighborAPInfo.band', index=2, - number=3, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='channel', full_name='device.api.WifiNeighborAPsGet.NeighborAPInfo.channel', index=3, - number=4, type=13, cpp_type=3, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='signal', full_name='device.api.WifiNeighborAPsGet.NeighborAPInfo.signal', index=4, - number=5, type=5, cpp_type=1, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='signal_bars', full_name='device.api.WifiNeighborAPsGet.NeighborAPInfo.signal_bars', index=5, - number=6, type=5, cpp_type=1, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=490, - serialized_end=631, -) - -_WIFINEIGHBORAPSGET = _descriptor.Descriptor( - name='WifiNeighborAPsGet', - full_name='device.api.WifiNeighborAPsGet', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='neighbor_aps', full_name='device.api.WifiNeighborAPsGet.neighbor_aps', index=0, - number=1, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[_WIFINEIGHBORAPSGET_NEIGHBORAPINFO, ], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=398, - serialized_end=631, -) - - -_WIFIREPEATEDAPSGET_REPEATEDAPINFO = _descriptor.Descriptor( - name='RepeatedAPInfo', - full_name='device.api.WifiRepeatedAPsGet.RepeatedAPInfo', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='mac_address', full_name='device.api.WifiRepeatedAPsGet.RepeatedAPInfo.mac_address', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='ssid', full_name='device.api.WifiRepeatedAPsGet.RepeatedAPInfo.ssid', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='band', full_name='device.api.WifiRepeatedAPsGet.RepeatedAPInfo.band', index=2, - number=3, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='channel', full_name='device.api.WifiRepeatedAPsGet.RepeatedAPInfo.channel', index=3, - number=4, type=13, cpp_type=3, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='rate', full_name='device.api.WifiRepeatedAPsGet.RepeatedAPInfo.rate', index=4, - number=5, type=13, cpp_type=3, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='signal', full_name='device.api.WifiRepeatedAPsGet.RepeatedAPInfo.signal', index=5, - number=6, type=5, cpp_type=1, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='signal_bars', full_name='device.api.WifiRepeatedAPsGet.RepeatedAPInfo.signal_bars', index=6, - number=7, type=5, cpp_type=1, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=726, - serialized_end=881, -) - -_WIFIREPEATEDAPSGET = _descriptor.Descriptor( - name='WifiRepeatedAPsGet', - full_name='device.api.WifiRepeatedAPsGet', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='repeated_aps', full_name='device.api.WifiRepeatedAPsGet.repeated_aps', index=0, - number=1, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[_WIFIREPEATEDAPSGET_REPEATEDAPINFO, ], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=634, - serialized_end=881, -) - - -_WIFICONNECTEDSTATIONSGET_CONNECTEDSTATIONINFO = _descriptor.Descriptor( - name='ConnectedStationInfo', - full_name='device.api.WifiConnectedStationsGet.ConnectedStationInfo', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='mac_address', full_name='device.api.WifiConnectedStationsGet.ConnectedStationInfo.mac_address', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='vap_type', full_name='device.api.WifiConnectedStationsGet.ConnectedStationInfo.vap_type', index=1, - number=2, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='band', full_name='device.api.WifiConnectedStationsGet.ConnectedStationInfo.band', index=2, - number=3, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='rx_rate', full_name='device.api.WifiConnectedStationsGet.ConnectedStationInfo.rx_rate', index=3, - number=4, type=13, cpp_type=3, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='tx_rate', full_name='device.api.WifiConnectedStationsGet.ConnectedStationInfo.tx_rate', index=4, - number=5, type=13, cpp_type=3, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1000, - serialized_end=1156, -) - -_WIFICONNECTEDSTATIONSGET = _descriptor.Descriptor( - name='WifiConnectedStationsGet', - full_name='device.api.WifiConnectedStationsGet', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='connected_stations', full_name='device.api.WifiConnectedStationsGet.connected_stations', index=0, - number=1, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[_WIFICONNECTEDSTATIONSGET_CONNECTEDSTATIONINFO, ], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=884, - serialized_end=1156, -) - - -_WIFIREPEATERPARAMETERSSET = _descriptor.Descriptor( - name='WifiRepeaterParametersSet', - full_name='device.api.WifiRepeaterParametersSet', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='ssid', full_name='device.api.WifiRepeaterParametersSet.ssid', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='key', full_name='device.api.WifiRepeaterParametersSet.key', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='crossband', full_name='device.api.WifiRepeaterParametersSet.crossband', index=2, - number=3, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='primary_band', full_name='device.api.WifiRepeaterParametersSet.primary_band', index=3, - number=4, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1158, - serialized_end=1275, -) - - -_WIFIREPEATERPARAMETERSSETRESPONSE = _descriptor.Descriptor( - name='WifiRepeaterParametersSetResponse', - full_name='device.api.WifiRepeaterParametersSetResponse', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='result', full_name='device.api.WifiRepeaterParametersSetResponse.result', index=0, - number=1, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1277, - serialized_end=1352, -) - - -_WIFIWPSPBCSTART = _descriptor.Descriptor( - name='WifiWpsPbcStart', - full_name='device.api.WifiWpsPbcStart', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='result', full_name='device.api.WifiWpsPbcStart.result', index=0, - number=1, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1354, - serialized_end=1411, -) - - -_WIFIREPEATERWPSCLONEPBCSTART = _descriptor.Descriptor( - name='WifiRepeaterWpsClonePbcStart', - full_name='device.api.WifiRepeaterWpsClonePbcStart', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='result', full_name='device.api.WifiRepeaterWpsClonePbcStart.result', index=0, - number=1, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1413, - serialized_end=1483, -) - -_WIFIPARAMETERSSETRESPONSE.fields_by_name['result'].enum_type = _WIFIRESULT -_WIFIGUESTACCESSSETRESPONSE.fields_by_name['result'].enum_type = _WIFIRESULT -_WIFINEIGHBORAPSGET_NEIGHBORAPINFO.fields_by_name['band'].enum_type = _WIFIBAND -_WIFINEIGHBORAPSGET_NEIGHBORAPINFO.containing_type = _WIFINEIGHBORAPSGET -_WIFINEIGHBORAPSGET.fields_by_name['neighbor_aps'].message_type = _WIFINEIGHBORAPSGET_NEIGHBORAPINFO -_WIFIREPEATEDAPSGET_REPEATEDAPINFO.fields_by_name['band'].enum_type = _WIFIBAND -_WIFIREPEATEDAPSGET_REPEATEDAPINFO.containing_type = _WIFIREPEATEDAPSGET -_WIFIREPEATEDAPSGET.fields_by_name['repeated_aps'].message_type = _WIFIREPEATEDAPSGET_REPEATEDAPINFO -_WIFICONNECTEDSTATIONSGET_CONNECTEDSTATIONINFO.fields_by_name['vap_type'].enum_type = _WIFIVAPTYPE -_WIFICONNECTEDSTATIONSGET_CONNECTEDSTATIONINFO.fields_by_name['band'].enum_type = _WIFIBAND -_WIFICONNECTEDSTATIONSGET_CONNECTEDSTATIONINFO.containing_type = _WIFICONNECTEDSTATIONSGET -_WIFICONNECTEDSTATIONSGET.fields_by_name['connected_stations'].message_type = _WIFICONNECTEDSTATIONSGET_CONNECTEDSTATIONINFO -_WIFIREPEATERPARAMETERSSET.fields_by_name['primary_band'].enum_type = _WIFIBAND -_WIFIREPEATERPARAMETERSSETRESPONSE.fields_by_name['result'].enum_type = _WIFIRESULT -_WIFIWPSPBCSTART.fields_by_name['result'].enum_type = _WIFIRESULT -_WIFIREPEATERWPSCLONEPBCSTART.fields_by_name['result'].enum_type = _WIFIRESULT -DESCRIPTOR.message_types_by_name['WifiParametersSet'] = _WIFIPARAMETERSSET -DESCRIPTOR.message_types_by_name['WifiParametersSetResponse'] = _WIFIPARAMETERSSETRESPONSE -DESCRIPTOR.message_types_by_name['WifiGuestAccessSet'] = _WIFIGUESTACCESSSET -DESCRIPTOR.message_types_by_name['WifiGuestAccessSetResponse'] = _WIFIGUESTACCESSSETRESPONSE -DESCRIPTOR.message_types_by_name['WifiGuestAccessGet'] = _WIFIGUESTACCESSGET -DESCRIPTOR.message_types_by_name['WifiNeighborAPsGet'] = _WIFINEIGHBORAPSGET -DESCRIPTOR.message_types_by_name['WifiRepeatedAPsGet'] = _WIFIREPEATEDAPSGET -DESCRIPTOR.message_types_by_name['WifiConnectedStationsGet'] = _WIFICONNECTEDSTATIONSGET -DESCRIPTOR.message_types_by_name['WifiRepeaterParametersSet'] = _WIFIREPEATERPARAMETERSSET -DESCRIPTOR.message_types_by_name['WifiRepeaterParametersSetResponse'] = _WIFIREPEATERPARAMETERSSETRESPONSE -DESCRIPTOR.message_types_by_name['WifiWpsPbcStart'] = _WIFIWPSPBCSTART -DESCRIPTOR.message_types_by_name['WifiRepeaterWpsClonePbcStart'] = _WIFIREPEATERWPSCLONEPBCSTART -DESCRIPTOR.enum_types_by_name['WifiResult'] = _WIFIRESULT -DESCRIPTOR.enum_types_by_name['WifiBand'] = _WIFIBAND -DESCRIPTOR.enum_types_by_name['WifiVAPType'] = _WIFIVAPTYPE - -WifiParametersSet = _reflection.GeneratedProtocolMessageType('WifiParametersSet', (_message.Message,), dict( - DESCRIPTOR = _WIFIPARAMETERSSET, - __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' - # @@protoc_insertion_point(class_scope:device.api.WifiParametersSet) - )) -_sym_db.RegisterMessage(WifiParametersSet) - -WifiParametersSetResponse = _reflection.GeneratedProtocolMessageType('WifiParametersSetResponse', (_message.Message,), dict( - DESCRIPTOR = _WIFIPARAMETERSSETRESPONSE, - __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' - # @@protoc_insertion_point(class_scope:device.api.WifiParametersSetResponse) - )) -_sym_db.RegisterMessage(WifiParametersSetResponse) - -WifiGuestAccessSet = _reflection.GeneratedProtocolMessageType('WifiGuestAccessSet', (_message.Message,), dict( - DESCRIPTOR = _WIFIGUESTACCESSSET, - __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' - # @@protoc_insertion_point(class_scope:device.api.WifiGuestAccessSet) - )) -_sym_db.RegisterMessage(WifiGuestAccessSet) - -WifiGuestAccessSetResponse = _reflection.GeneratedProtocolMessageType('WifiGuestAccessSetResponse', (_message.Message,), dict( - DESCRIPTOR = _WIFIGUESTACCESSSETRESPONSE, - __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' - # @@protoc_insertion_point(class_scope:device.api.WifiGuestAccessSetResponse) - )) -_sym_db.RegisterMessage(WifiGuestAccessSetResponse) - -WifiGuestAccessGet = _reflection.GeneratedProtocolMessageType('WifiGuestAccessGet', (_message.Message,), dict( - DESCRIPTOR = _WIFIGUESTACCESSGET, - __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' - # @@protoc_insertion_point(class_scope:device.api.WifiGuestAccessGet) - )) -_sym_db.RegisterMessage(WifiGuestAccessGet) - -WifiNeighborAPsGet = _reflection.GeneratedProtocolMessageType('WifiNeighborAPsGet', (_message.Message,), dict( - - NeighborAPInfo = _reflection.GeneratedProtocolMessageType('NeighborAPInfo', (_message.Message,), dict( - DESCRIPTOR = _WIFINEIGHBORAPSGET_NEIGHBORAPINFO, - __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' - # @@protoc_insertion_point(class_scope:device.api.WifiNeighborAPsGet.NeighborAPInfo) - )) - , - DESCRIPTOR = _WIFINEIGHBORAPSGET, - __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' - # @@protoc_insertion_point(class_scope:device.api.WifiNeighborAPsGet) - )) -_sym_db.RegisterMessage(WifiNeighborAPsGet) -_sym_db.RegisterMessage(WifiNeighborAPsGet.NeighborAPInfo) - -WifiRepeatedAPsGet = _reflection.GeneratedProtocolMessageType('WifiRepeatedAPsGet', (_message.Message,), dict( - - RepeatedAPInfo = _reflection.GeneratedProtocolMessageType('RepeatedAPInfo', (_message.Message,), dict( - DESCRIPTOR = _WIFIREPEATEDAPSGET_REPEATEDAPINFO, - __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' - # @@protoc_insertion_point(class_scope:device.api.WifiRepeatedAPsGet.RepeatedAPInfo) - )) - , - DESCRIPTOR = _WIFIREPEATEDAPSGET, - __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' - # @@protoc_insertion_point(class_scope:device.api.WifiRepeatedAPsGet) - )) -_sym_db.RegisterMessage(WifiRepeatedAPsGet) -_sym_db.RegisterMessage(WifiRepeatedAPsGet.RepeatedAPInfo) - -WifiConnectedStationsGet = _reflection.GeneratedProtocolMessageType('WifiConnectedStationsGet', (_message.Message,), dict( - - ConnectedStationInfo = _reflection.GeneratedProtocolMessageType('ConnectedStationInfo', (_message.Message,), dict( - DESCRIPTOR = _WIFICONNECTEDSTATIONSGET_CONNECTEDSTATIONINFO, - __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' - # @@protoc_insertion_point(class_scope:device.api.WifiConnectedStationsGet.ConnectedStationInfo) - )) - , - DESCRIPTOR = _WIFICONNECTEDSTATIONSGET, - __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' - # @@protoc_insertion_point(class_scope:device.api.WifiConnectedStationsGet) - )) -_sym_db.RegisterMessage(WifiConnectedStationsGet) -_sym_db.RegisterMessage(WifiConnectedStationsGet.ConnectedStationInfo) - -WifiRepeaterParametersSet = _reflection.GeneratedProtocolMessageType('WifiRepeaterParametersSet', (_message.Message,), dict( - DESCRIPTOR = _WIFIREPEATERPARAMETERSSET, - __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' - # @@protoc_insertion_point(class_scope:device.api.WifiRepeaterParametersSet) - )) -_sym_db.RegisterMessage(WifiRepeaterParametersSet) - -WifiRepeaterParametersSetResponse = _reflection.GeneratedProtocolMessageType('WifiRepeaterParametersSetResponse', (_message.Message,), dict( - DESCRIPTOR = _WIFIREPEATERPARAMETERSSETRESPONSE, - __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' - # @@protoc_insertion_point(class_scope:device.api.WifiRepeaterParametersSetResponse) - )) -_sym_db.RegisterMessage(WifiRepeaterParametersSetResponse) - -WifiWpsPbcStart = _reflection.GeneratedProtocolMessageType('WifiWpsPbcStart', (_message.Message,), dict( - DESCRIPTOR = _WIFIWPSPBCSTART, - __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' - # @@protoc_insertion_point(class_scope:device.api.WifiWpsPbcStart) - )) -_sym_db.RegisterMessage(WifiWpsPbcStart) - -WifiRepeaterWpsClonePbcStart = _reflection.GeneratedProtocolMessageType('WifiRepeaterWpsClonePbcStart', (_message.Message,), dict( - DESCRIPTOR = _WIFIREPEATERWPSCLONEPBCSTART, - __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' - # @@protoc_insertion_point(class_scope:device.api.WifiRepeaterWpsClonePbcStart) - )) -_sym_db.RegisterMessage(WifiRepeaterWpsClonePbcStart) - - -DESCRIPTOR.has_options = True -DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\006deviceB\013wifinetwork')) -# @@protoc_insertion_point(module_scope) diff --git a/devolo_plc_api/device_api/wifi_network/wifi_network.py b/devolo_plc_api/device_api/wifi_network/wifi_network.py deleted file mode 100644 index 3bb8919..0000000 --- a/devolo_plc_api/device_api/wifi_network/wifi_network.py +++ /dev/null @@ -1,18 +0,0 @@ -from . import devolo_idl_proto_deviceapi_wifinetwork_pb2 -from devolo_plc_api.protobuf_sender import ProtobufSender - - -class WifiNetwork(ProtobufSender): - def __init__(self, ip: str, session, port, token): - super().__init__(ip=ip, - session=session, - port=port, - api_type="deviceapi", - token=token) - - async def get_wifi_guest_access(self): - wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() - r = await self.get("WifiGuestAccessGet") - print(r) - wifi_guest_proto.ParseFromString(await r.read()) - return wifi_guest_proto diff --git a/devolo_plc_api/devolo_plc_api.py b/devolo_plc_api/devolo_plc_api.py deleted file mode 100644 index 8cc018d..0000000 --- a/devolo_plc_api/devolo_plc_api.py +++ /dev/null @@ -1,10 +0,0 @@ -from aiohttp import ClientSession - -from .device_api.device_api import DeviceApi -from .plc_net_api.plc_net_api import PlcNetApi - - -class DevoloPlcApi(): - def __init__(self, ip: str, session: ClientSession): - self.device_api = DeviceApi(ip, session) - self.plc_net_api = PlcNetApi(ip, session) diff --git a/devolo_plc_api/exceptions/__init__.py b/devolo_plc_api/exceptions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/devolo_plc_api/helper/zeroconf.py b/devolo_plc_api/helper/zeroconf.py deleted file mode 100644 index e857d90..0000000 --- a/devolo_plc_api/helper/zeroconf.py +++ /dev/null @@ -1,58 +0,0 @@ -from zeroconf import ServiceBrowser, ServiceStateChange, Zeroconf -import time -import socket - - -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) - - -def get_token(ip, service_name): - # TODO: Optimize the for & if - zeroconf = Zeroconf() - browser = ServiceBrowser(zeroconf, service_name, [_on_service_state_change]) - start_time = time.time() - while not time.time() > start_time + 10: - for mdns_name in zeroconf.cache.entries(): - try: - if hasattr(mdns_name, "server"): - zc = zeroconf.cache.cache.get(mdns_name.key) - for item in zc: - if hasattr(item, "server"): - try: - zc2 = zeroconf.cache.cache[item.server.lower()] - for item2 in zc2: - try: - if socket.inet_ntoa(item2.address) == ip: - zc3 = zeroconf.cache.cache.get(item.key) - for item3 in zc3: - if hasattr(item3, "text"): - parsed_text = parse_zeroconf_text(item3.text) - if service_name == '_dvl-plcnetapi._tcp.local.': - return parsed_text['Path'] - else: - return parsed_text['Path'], parsed_text.get('Features').split(",") - except OSError: - continue - except KeyError: - continue - except (AttributeError, OSError, ValueError): - continue - browser.cancel() - zeroconf.close() - - -def parse_zeroconf_text(text): - entries = {} - total_length = len(text) - parsed_length = 0 - while parsed_length < total_length: - entry_length = int(text[parsed_length]) - entry = text[parsed_length + 1:parsed_length + entry_length + 1].decode('UTF-8') - parsed_length = parsed_length + entry_length + 1 - split_entry = entry.split('=') - entries[split_entry[0]] = split_entry[1] - entries["Path"] = entries["Path"].split("/")[0] - return entries diff --git a/devolo_plc_api/plc_net_api/network_overview/devolo_idl_proto_plcnetapi_getnetworkoverview.proto b/devolo_plc_api/plc_net_api/network_overview/devolo_idl_proto_plcnetapi_getnetworkoverview.proto deleted file mode 100644 index 064c6fc..0000000 --- a/devolo_plc_api/plc_net_api/network_overview/devolo_idl_proto_plcnetapi_getnetworkoverview.proto +++ /dev/null @@ -1,63 +0,0 @@ -syntax = "proto3"; - -package plcnet.api; -option java_package = "plcnet"; -option java_outer_classname = "net"; - -message GetNetworkOverview -{ - message Device // describes a single powerline device - { - string product_name = 1; // product name for display purposes, like "devolo dLAN 1200+" - string product_id = 2; // internal product identifier, like "MT2639" - - string friendly_version = 3; // version string for display purposes, like "2.5.0.0-1" - string full_version = 4; // full version string - - string user_device_name = 5; // user provided device name, if any - string user_network_name = 6; // user provided network name, if any - - string mac_address = 7; // MAC address of the device, like "000B3BC3A4E6" - - enum Topology - { - UNKNOWN_TOPOLOGY = 0; - LOCAL = 1; // the device is LOCAL (i.e. reachable via eth/wifi) - REMOTE = 2; // the device is REMOTE (i.e. connected via powerline to the LOCAL device) - } - // in a real network, we will always see one LOCAL device - Topology topology = 8; // and zero or more REMOTEs - - enum Technology - { - UNKNOWN_TECHNOLOGY = 0; - HPAV_THUNDERBOLT = 3; // HomePlugAV device (based on Intellon/QCA Thunderbolt or later, i.e. 6x00/74x0 family) - HPAV_PANTHER = 4; // HomePlugAV device (based on Intellon/QCA Panther or later, i.e. 7420/75x0 family) - GHN_SPIRIT = 7; // G.hn device (based on Maxlinear Spirit firmware) - } - - Technology technology = 9; // in a real network, you will always see either HPAV or GHN devices, but never both - - repeated string bridged_devices = 10; // MAC addresses of devices attached to this device on the LAN side - - string ipv4_address = 11; // ipv4 address of the device; empty if none is available - - bool attached_to_router = 12; // indicates whether this adapter is attached to the router or not (only one should be set true) - } - - message DataRate // describes the data rate between two powerline devices in the same logical network - { - string mac_address_from = 1; // the powerline device from which we got information about the data rates - string mac_address_to = 2; // the powerline device to which we are transmitting/receiving - double tx_rate = 3; // transmit data rate in mbps - double rx_rate = 4; // receive data rate in mbps - } - - message LogicalNetwork - { - repeated Device devices = 1; // all devices in the logical network - repeated DataRate data_rates = 2; // all known data rates between devices in the logical network - } - - LogicalNetwork network = 1; -} diff --git a/devolo_plc_api/plc_net_api/network_overview/devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.py b/devolo_plc_api/plc_net_api/network_overview/devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.py deleted file mode 100644 index dffcf5a..0000000 --- a/devolo_plc_api/plc_net_api/network_overview/devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.py +++ /dev/null @@ -1,358 +0,0 @@ -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: devolo_idl_proto_plcnetapi_getnetworkoverview.proto - -import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) -from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection -from google.protobuf import symbol_database as _symbol_database -from google.protobuf import descriptor_pb2 -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - - - -DESCRIPTOR = _descriptor.FileDescriptor( - name='devolo_idl_proto_plcnetapi_getnetworkoverview.proto', - package='plcnet.api', - syntax='proto3', - serialized_pb=_b('\n3devolo_idl_proto_plcnetapi_getnetworkoverview.proto\x12\nplcnet.api\"\xd5\x06\n\x12GetNetworkOverview\x12>\n\x07network\x18\x01 \x01(\x0b\x32-.plcnet.api.GetNetworkOverview.LogicalNetwork\x1a\x96\x04\n\x06\x44\x65vice\x12\x14\n\x0cproduct_name\x18\x01 \x01(\t\x12\x12\n\nproduct_id\x18\x02 \x01(\t\x12\x18\n\x10\x66riendly_version\x18\x03 \x01(\t\x12\x14\n\x0c\x66ull_version\x18\x04 \x01(\t\x12\x18\n\x10user_device_name\x18\x05 \x01(\t\x12\x19\n\x11user_network_name\x18\x06 \x01(\t\x12\x13\n\x0bmac_address\x18\x07 \x01(\t\x12@\n\x08topology\x18\x08 \x01(\x0e\x32..plcnet.api.GetNetworkOverview.Device.Topology\x12\x44\n\ntechnology\x18\t \x01(\x0e\x32\x30.plcnet.api.GetNetworkOverview.Device.Technology\x12\x17\n\x0f\x62ridged_devices\x18\n \x03(\t\x12\x14\n\x0cipv4_address\x18\x0b \x01(\t\x12\x1a\n\x12\x61ttached_to_router\x18\x0c \x01(\x08\"7\n\x08Topology\x12\x14\n\x10UNKNOWN_TOPOLOGY\x10\x00\x12\t\n\x05LOCAL\x10\x01\x12\n\n\x06REMOTE\x10\x02\"\\\n\nTechnology\x12\x16\n\x12UNKNOWN_TECHNOLOGY\x10\x00\x12\x14\n\x10HPAV_THUNDERBOLT\x10\x03\x12\x10\n\x0cHPAV_PANTHER\x10\x04\x12\x0e\n\nGHN_SPIRIT\x10\x07\x1a^\n\x08\x44\x61taRate\x12\x18\n\x10mac_address_from\x18\x01 \x01(\t\x12\x16\n\x0emac_address_to\x18\x02 \x01(\t\x12\x0f\n\x07tx_rate\x18\x03 \x01(\x01\x12\x0f\n\x07rx_rate\x18\x04 \x01(\x01\x1a\x85\x01\n\x0eLogicalNetwork\x12\x36\n\x07\x64\x65vices\x18\x01 \x03(\x0b\x32%.plcnet.api.GetNetworkOverview.Device\x12;\n\ndata_rates\x18\x02 \x03(\x0b\x32\'.plcnet.api.GetNetworkOverview.DataRateB\r\n\x06plcnetB\x03netb\x06proto3') -) -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - - - -_GETNETWORKOVERVIEW_DEVICE_TOPOLOGY = _descriptor.EnumDescriptor( - name='Topology', - full_name='plcnet.api.GetNetworkOverview.Device.Topology', - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name='UNKNOWN_TOPOLOGY', index=0, number=0, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='LOCAL', index=1, number=1, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='REMOTE', index=2, number=2, - options=None, - type=None), - ], - containing_type=None, - options=None, - serialized_start=540, - serialized_end=595, -) -_sym_db.RegisterEnumDescriptor(_GETNETWORKOVERVIEW_DEVICE_TOPOLOGY) - -_GETNETWORKOVERVIEW_DEVICE_TECHNOLOGY = _descriptor.EnumDescriptor( - name='Technology', - full_name='plcnet.api.GetNetworkOverview.Device.Technology', - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name='UNKNOWN_TECHNOLOGY', index=0, number=0, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='HPAV_THUNDERBOLT', index=1, number=3, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='HPAV_PANTHER', index=2, number=4, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='GHN_SPIRIT', index=3, number=7, - options=None, - type=None), - ], - containing_type=None, - options=None, - serialized_start=597, - serialized_end=689, -) -_sym_db.RegisterEnumDescriptor(_GETNETWORKOVERVIEW_DEVICE_TECHNOLOGY) - - -_GETNETWORKOVERVIEW_DEVICE = _descriptor.Descriptor( - name='Device', - full_name='plcnet.api.GetNetworkOverview.Device', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='product_name', full_name='plcnet.api.GetNetworkOverview.Device.product_name', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='product_id', full_name='plcnet.api.GetNetworkOverview.Device.product_id', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='friendly_version', full_name='plcnet.api.GetNetworkOverview.Device.friendly_version', index=2, - number=3, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='full_version', full_name='plcnet.api.GetNetworkOverview.Device.full_version', index=3, - number=4, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='user_device_name', full_name='plcnet.api.GetNetworkOverview.Device.user_device_name', index=4, - number=5, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='user_network_name', full_name='plcnet.api.GetNetworkOverview.Device.user_network_name', index=5, - number=6, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='mac_address', full_name='plcnet.api.GetNetworkOverview.Device.mac_address', index=6, - number=7, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='topology', full_name='plcnet.api.GetNetworkOverview.Device.topology', index=7, - number=8, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='technology', full_name='plcnet.api.GetNetworkOverview.Device.technology', index=8, - number=9, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='bridged_devices', full_name='plcnet.api.GetNetworkOverview.Device.bridged_devices', index=9, - number=10, type=9, cpp_type=9, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='ipv4_address', full_name='plcnet.api.GetNetworkOverview.Device.ipv4_address', index=10, - number=11, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='attached_to_router', full_name='plcnet.api.GetNetworkOverview.Device.attached_to_router', index=11, - number=12, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - _GETNETWORKOVERVIEW_DEVICE_TOPOLOGY, - _GETNETWORKOVERVIEW_DEVICE_TECHNOLOGY, - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=155, - serialized_end=689, -) - -_GETNETWORKOVERVIEW_DATARATE = _descriptor.Descriptor( - name='DataRate', - full_name='plcnet.api.GetNetworkOverview.DataRate', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='mac_address_from', full_name='plcnet.api.GetNetworkOverview.DataRate.mac_address_from', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='mac_address_to', full_name='plcnet.api.GetNetworkOverview.DataRate.mac_address_to', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='tx_rate', full_name='plcnet.api.GetNetworkOverview.DataRate.tx_rate', index=2, - number=3, type=1, cpp_type=5, label=1, - has_default_value=False, default_value=float(0), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='rx_rate', full_name='plcnet.api.GetNetworkOverview.DataRate.rx_rate', index=3, - number=4, type=1, cpp_type=5, label=1, - has_default_value=False, default_value=float(0), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=691, - serialized_end=785, -) - -_GETNETWORKOVERVIEW_LOGICALNETWORK = _descriptor.Descriptor( - name='LogicalNetwork', - full_name='plcnet.api.GetNetworkOverview.LogicalNetwork', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='devices', full_name='plcnet.api.GetNetworkOverview.LogicalNetwork.devices', index=0, - number=1, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='data_rates', full_name='plcnet.api.GetNetworkOverview.LogicalNetwork.data_rates', index=1, - number=2, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=788, - serialized_end=921, -) - -_GETNETWORKOVERVIEW = _descriptor.Descriptor( - name='GetNetworkOverview', - full_name='plcnet.api.GetNetworkOverview', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='network', full_name='plcnet.api.GetNetworkOverview.network', index=0, - number=1, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[_GETNETWORKOVERVIEW_DEVICE, _GETNETWORKOVERVIEW_DATARATE, _GETNETWORKOVERVIEW_LOGICALNETWORK, ], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=68, - serialized_end=921, -) - -_GETNETWORKOVERVIEW_DEVICE.fields_by_name['topology'].enum_type = _GETNETWORKOVERVIEW_DEVICE_TOPOLOGY -_GETNETWORKOVERVIEW_DEVICE.fields_by_name['technology'].enum_type = _GETNETWORKOVERVIEW_DEVICE_TECHNOLOGY -_GETNETWORKOVERVIEW_DEVICE.containing_type = _GETNETWORKOVERVIEW -_GETNETWORKOVERVIEW_DEVICE_TOPOLOGY.containing_type = _GETNETWORKOVERVIEW_DEVICE -_GETNETWORKOVERVIEW_DEVICE_TECHNOLOGY.containing_type = _GETNETWORKOVERVIEW_DEVICE -_GETNETWORKOVERVIEW_DATARATE.containing_type = _GETNETWORKOVERVIEW -_GETNETWORKOVERVIEW_LOGICALNETWORK.fields_by_name['devices'].message_type = _GETNETWORKOVERVIEW_DEVICE -_GETNETWORKOVERVIEW_LOGICALNETWORK.fields_by_name['data_rates'].message_type = _GETNETWORKOVERVIEW_DATARATE -_GETNETWORKOVERVIEW_LOGICALNETWORK.containing_type = _GETNETWORKOVERVIEW -_GETNETWORKOVERVIEW.fields_by_name['network'].message_type = _GETNETWORKOVERVIEW_LOGICALNETWORK -DESCRIPTOR.message_types_by_name['GetNetworkOverview'] = _GETNETWORKOVERVIEW - -GetNetworkOverview = _reflection.GeneratedProtocolMessageType('GetNetworkOverview', (_message.Message,), dict( - - Device = _reflection.GeneratedProtocolMessageType('Device', (_message.Message,), dict( - DESCRIPTOR = _GETNETWORKOVERVIEW_DEVICE, - __module__ = 'devolo_idl_proto_plcnetapi_getnetworkoverview_pb2' - # @@protoc_insertion_point(class_scope:plcnet.api.GetNetworkOverview.Device) - )) - , - - DataRate = _reflection.GeneratedProtocolMessageType('DataRate', (_message.Message,), dict( - DESCRIPTOR = _GETNETWORKOVERVIEW_DATARATE, - __module__ = 'devolo_idl_proto_plcnetapi_getnetworkoverview_pb2' - # @@protoc_insertion_point(class_scope:plcnet.api.GetNetworkOverview.DataRate) - )) - , - - LogicalNetwork = _reflection.GeneratedProtocolMessageType('LogicalNetwork', (_message.Message,), dict( - DESCRIPTOR = _GETNETWORKOVERVIEW_LOGICALNETWORK, - __module__ = 'devolo_idl_proto_plcnetapi_getnetworkoverview_pb2' - # @@protoc_insertion_point(class_scope:plcnet.api.GetNetworkOverview.LogicalNetwork) - )) - , - DESCRIPTOR = _GETNETWORKOVERVIEW, - __module__ = 'devolo_idl_proto_plcnetapi_getnetworkoverview_pb2' - # @@protoc_insertion_point(class_scope:plcnet.api.GetNetworkOverview) - )) -_sym_db.RegisterMessage(GetNetworkOverview) -_sym_db.RegisterMessage(GetNetworkOverview.Device) -_sym_db.RegisterMessage(GetNetworkOverview.DataRate) -_sym_db.RegisterMessage(GetNetworkOverview.LogicalNetwork) - - -DESCRIPTOR.has_options = True -DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\006plcnetB\003net')) -# @@protoc_insertion_point(module_scope) diff --git a/devolo_plc_api/plc_net_api/network_overview/network_overview.py b/devolo_plc_api/plc_net_api/network_overview/network_overview.py deleted file mode 100644 index 064ea57..0000000 --- a/devolo_plc_api/plc_net_api/network_overview/network_overview.py +++ /dev/null @@ -1,17 +0,0 @@ -from devolo_plc_api.plc_net_api.network_overview import devolo_idl_proto_plcnetapi_getnetworkoverview_pb2 -from devolo_plc_api.protobuf_sender import ProtobufSender - - -class NetworkOverview(ProtobufSender): - def __init__(self, ip: str, session, port, token): - super().__init__(ip=ip, - session=session, - port=port, - api_type="plcnetapi", - token=token) - - async def get_network_overview(self): - network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() - r = await self.get("GetNetworkOverview") - network_overview.ParseFromString(await r.read()) - return network_overview diff --git a/devolo_plc_api/plc_net_api/plc_net_api.py b/devolo_plc_api/plc_net_api/plc_net_api.py deleted file mode 100644 index 1996060..0000000 --- a/devolo_plc_api/plc_net_api/plc_net_api.py +++ /dev/null @@ -1,8 +0,0 @@ -from .network_overview.network_overview import NetworkOverview -from ..helper.zeroconf import get_token - - -class PlcNetApi(NetworkOverview): - def __init__(self, ip, session): - self.token = get_token(ip, "_dvl-plcnetapi._tcp.local.") - super().__init__(ip=ip, session=session, port=47219, token=self.token) diff --git a/devolo_plc_api/plcnet_api/__init__.py b/devolo_plc_api/plcnet_api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/devolo_plc_api/protobuf_sender.py b/devolo_plc_api/protobuf_sender.py deleted file mode 100644 index b8191a8..0000000 --- a/devolo_plc_api/protobuf_sender.py +++ /dev/null @@ -1,10 +0,0 @@ -class ProtobufSender: - def __init__(self, ip, session, port, api_type, token): - self.ip = ip - self.port = port - self.session = session - self.token = token - self.api_type = api_type - - async def get(self, sub_url, data=None): - return await self.session.get(f"http://{self.ip}:{self.port}/{self.token}/{self.api_type}/v0/{sub_url}") \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..6191375 --- /dev/null +++ b/setup.py @@ -0,0 +1,38 @@ +import setuptools + +from devolo_home_control_api import __version__ + + +with open("README.md", "r") as fh: + long_description = fh.read() + +setuptools.setup( + name="devolo_plc_api", + version=__version__, + author="Markus Bong, Guido Schmitz", + author_email="m.bong@famabo.de, guido.schmitz@fedaix.de", + description="devolo PLC devices in Python", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/2Fake/devolo_plc_api", + packages=setuptools.find_packages(), + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Operating System :: OS Independent", + ], + install_requires=[ + "aiohttp", + "protobuf", + "zeroconf" + ], + setup_requires=[ + "pytest-runner" + ], + tests_require=[ + "pytest", + "pytest-cov", + "pytest-mock" + ], + python_requires='>=3.6', +) From 3386a6316a0fb5f2a08f12508e4d3d9f4137bccf Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Sun, 23 Aug 2020 12:27:16 +0200 Subject: [PATCH 03/93] Add IDEs --- .gitignore | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.gitignore b/.gitignore index 872c981..b05f8be 100644 --- a/.gitignore +++ b/.gitignore @@ -128,4 +128,12 @@ dmypy.json # Pyre type checker .pyre/ +### VisualStudioCode ### +.vscode/* + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +### PyCharm ### .idea From 4c3afe678ad81533e6164461c308ec0146b3fcfa Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Sun, 23 Aug 2020 12:27:34 +0200 Subject: [PATCH 04/93] Alternative inheritance --- devolo_plc_api/clients/protobuf.py | 4 + devolo_plc_api/device.py | 78 ++ devolo_plc_api/device_api/deviceapi.py | 32 + ...olo_idl_proto_deviceapi_wifinetwork_pb2.py | 900 ++++++++++++++++++ devolo_plc_api/exceptions/feature.py | 2 + ..._proto_plcnetapi_getnetworkoverview_pb2.py | 358 +++++++ devolo_plc_api/plcnet_api/plcnetapi.py | 18 + example.py | 11 +- 8 files changed, 1398 insertions(+), 5 deletions(-) create mode 100644 devolo_plc_api/clients/protobuf.py create mode 100644 devolo_plc_api/device.py create mode 100644 devolo_plc_api/device_api/deviceapi.py create mode 100644 devolo_plc_api/device_api/devolo_idl_proto_deviceapi_wifinetwork_pb2.py create mode 100644 devolo_plc_api/exceptions/feature.py create mode 100644 devolo_plc_api/plcnet_api/devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.py create mode 100644 devolo_plc_api/plcnet_api/plcnetapi.py diff --git a/devolo_plc_api/clients/protobuf.py b/devolo_plc_api/clients/protobuf.py new file mode 100644 index 0000000..a5d8b9c --- /dev/null +++ b/devolo_plc_api/clients/protobuf.py @@ -0,0 +1,4 @@ +class Protobuf: + + async def get(self, sub_url): + return await self._session.get(f"http://{self._ip}:{self._port}/{self._path}/{self._version}/{sub_url}") diff --git a/devolo_plc_api/device.py b/devolo_plc_api/device.py new file mode 100644 index 0000000..e1a160b --- /dev/null +++ b/devolo_plc_api/device.py @@ -0,0 +1,78 @@ +import re +import socket +import time +from datetime import date + +from aiohttp import ClientSession +from zeroconf import ServiceBrowser, ServiceStateChange, Zeroconf + +from .plcnet_api.plcnetapi import PlcNetApi +from .device_api.deviceapi import DeviceApi + + +class Device: + def __init__(self, ip: str, session: ClientSession): + self.firmware_date = date.fromtimestamp(0) + self.firmware_version = "" + self.ip = ip + self.mac = "" + self.mt_number = 0 + self.product = "" + self.technology = "" + self.serial_number = 0 + + self.device = None + self.plcnet = None + + self._session = session + + self._zeroconf = Zeroconf() + self._info = None + self._get_plcnet_info() + self._info = None + self._get_device_info() + self._zeroconf.close() + + delattr(self, "_info") + + + def _get_plcnet_info(self): + self._get_zeroconf_info(service_type="_dvl-plcnetapi._tcp.local.") + + info = dict(s.split('=') for s in [x for x in self._info if x]) + self.mac = info['PlcMacAddress'] + self.technology = info['PlcTechnology'] + + self.plcnet = PlcNetApi(ip=self.ip, + session=self._session, + path=info['Path'], + version=info['Version']) + + def _get_device_info(self): + self._get_zeroconf_info(service_type="_dvl-deviceapi._tcp.local.") + + info = dict(s.split('=') for s in [x for x in self._info if x]) + self.firmware_date = date.fromisoformat(info['FirmwareDate']) + self.firmware_version = info['FirmwareVersion'] + self.serial_number = info['SN'] + self.mt_number = info['MT'] + self.product = info['Product'] + + self.device = DeviceApi(ip=self.ip, + session=self._session, + path=info['Path'], + version=info['Version'], + features=info['Features']) + + def _get_zeroconf_info(self, service_type: str): + browser = ServiceBrowser(self._zeroconf, service_type, [self._state_change]) + start_time = time.time() + while not time.time() > start_time + 10 and self._info is None: + time.sleep(0.1) + browser.cancel() + + def _state_change(self, zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange): + if state_change is ServiceStateChange.Added and \ + socket.inet_ntoa(zeroconf.get_service_info(service_type, name).address) == self.ip: + service_info = zeroconf.get_service_info(service_type, name).text.decode("UTF-8") + self._info = re.split("[^ -~]+", service_info.replace("PS=", "")) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py new file mode 100644 index 0000000..4fb08ee --- /dev/null +++ b/devolo_plc_api/device_api/deviceapi.py @@ -0,0 +1,32 @@ +from ..clients.protobuf import Protobuf +from . import devolo_idl_proto_deviceapi_wifinetwork_pb2 +from ..exceptions.feature import FeatureNotSupported + + +class DeviceApi(Protobuf): + def __init__(self, ip, session, path, version, features): + self._ip = ip + self._port = 14791 + self._session = session + self._path = path + self._version = version + self._features = features.split(",") + + + def _feature(feature): + def feature_decorator(method): + def wrapper(self): + if feature in self._features: + return method(self) + else: + raise FeatureNotSupported + return wrapper + return feature_decorator + + + @_feature("wifi1") + async def get_wifi_guest_access(self): + wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() + r = await self.get("WifiGuestAccessGet") + wifi_guest_proto.ParseFromString(await r.read()) + return wifi_guest_proto diff --git a/devolo_plc_api/device_api/devolo_idl_proto_deviceapi_wifinetwork_pb2.py b/devolo_plc_api/device_api/devolo_idl_proto_deviceapi_wifinetwork_pb2.py new file mode 100644 index 0000000..62ad0ba --- /dev/null +++ b/devolo_plc_api/device_api/devolo_idl_proto_deviceapi_wifinetwork_pb2.py @@ -0,0 +1,900 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: devolo_idl_proto_deviceapi_wifinetwork.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf.internal import enum_type_wrapper +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='devolo_idl_proto_deviceapi_wifinetwork.proto', + package='device.api', + syntax='proto3', + serialized_pb=_b('\n,devolo_idl_proto_deviceapi_wifinetwork.proto\x12\ndevice.api\".\n\x11WifiParametersSet\x12\x0c\n\x04ssid\x18\x01 \x01(\t\x12\x0b\n\x03key\x18\x02 \x01(\t\"C\n\x19WifiParametersSetResponse\x12&\n\x06result\x18\x01 \x01(\x0e\x32\x16.device.api.WifiResult\"6\n\x12WifiGuestAccessSet\x12\x0e\n\x06\x65nable\x18\x01 \x01(\x08\x12\x10\n\x08\x64uration\x18\x02 \x01(\r\"D\n\x1aWifiGuestAccessSetResponse\x12&\n\x06result\x18\x01 \x01(\x0e\x32\x16.device.api.WifiResult\"\\\n\x12WifiGuestAccessGet\x12\x0f\n\x07\x65nabled\x18\x01 \x01(\x08\x12\x1a\n\x12remaining_duration\x18\x02 \x01(\r\x12\x0c\n\x04ssid\x18\x03 \x01(\t\x12\x0b\n\x03key\x18\x04 \x01(\t\"\xe9\x01\n\x12WifiNeighborAPsGet\x12\x43\n\x0cneighbor_aps\x18\x01 \x03(\x0b\x32-.device.api.WifiNeighborAPsGet.NeighborAPInfo\x1a\x8d\x01\n\x0eNeighborAPInfo\x12\x13\n\x0bmac_address\x18\x01 \x01(\t\x12\x0c\n\x04ssid\x18\x02 \x01(\t\x12\"\n\x04\x62\x61nd\x18\x03 \x01(\x0e\x32\x14.device.api.WifiBand\x12\x0f\n\x07\x63hannel\x18\x04 \x01(\r\x12\x0e\n\x06signal\x18\x05 \x01(\x05\x12\x13\n\x0bsignal_bars\x18\x06 \x01(\x05\"\xf7\x01\n\x12WifiRepeatedAPsGet\x12\x43\n\x0crepeated_aps\x18\x01 \x03(\x0b\x32-.device.api.WifiRepeatedAPsGet.RepeatedAPInfo\x1a\x9b\x01\n\x0eRepeatedAPInfo\x12\x13\n\x0bmac_address\x18\x01 \x01(\t\x12\x0c\n\x04ssid\x18\x02 \x01(\t\x12\"\n\x04\x62\x61nd\x18\x03 \x01(\x0e\x32\x14.device.api.WifiBand\x12\x0f\n\x07\x63hannel\x18\x04 \x01(\r\x12\x0c\n\x04rate\x18\x05 \x01(\r\x12\x0e\n\x06signal\x18\x06 \x01(\x05\x12\x13\n\x0bsignal_bars\x18\x07 \x01(\x05\"\x90\x02\n\x18WifiConnectedStationsGet\x12U\n\x12\x63onnected_stations\x18\x01 \x03(\x0b\x32\x39.device.api.WifiConnectedStationsGet.ConnectedStationInfo\x1a\x9c\x01\n\x14\x43onnectedStationInfo\x12\x13\n\x0bmac_address\x18\x01 \x01(\t\x12)\n\x08vap_type\x18\x02 \x01(\x0e\x32\x17.device.api.WifiVAPType\x12\"\n\x04\x62\x61nd\x18\x03 \x01(\x0e\x32\x14.device.api.WifiBand\x12\x0f\n\x07rx_rate\x18\x04 \x01(\r\x12\x0f\n\x07tx_rate\x18\x05 \x01(\r\"u\n\x19WifiRepeaterParametersSet\x12\x0c\n\x04ssid\x18\x01 \x01(\t\x12\x0b\n\x03key\x18\x02 \x01(\t\x12\x11\n\tcrossband\x18\x03 \x01(\x08\x12*\n\x0cprimary_band\x18\x04 \x01(\x0e\x32\x14.device.api.WifiBand\"K\n!WifiRepeaterParametersSetResponse\x12&\n\x06result\x18\x01 \x01(\x0e\x32\x16.device.api.WifiResult\"9\n\x0fWifiWpsPbcStart\x12&\n\x06result\x18\x01 \x01(\x0e\x32\x16.device.api.WifiResult\"F\n\x1cWifiRepeaterWpsClonePbcStart\x12&\n\x06result\x18\x01 \x01(\x0e\x32\x16.device.api.WifiResult*z\n\nWifiResult\x12\x10\n\x0cWIFI_SUCCESS\x10\x00\x12\x15\n\x11WIFI_INVALID_SSID\x10\x01\x12\x14\n\x10WIFI_INVALID_KEY\x10\x02\x12\x14\n\x10WIFI_IS_DISABLED\x10\x03\x12\x17\n\x12WIFI_UNKNOWN_ERROR\x10\xff\x01*E\n\x08WifiBand\x12\x15\n\x11WIFI_BAND_UNKNOWN\x10\x00\x12\x10\n\x0cWIFI_BAND_2G\x10\x01\x12\x10\n\x0cWIFI_BAND_5G\x10\x02*f\n\x0bWifiVAPType\x12\x14\n\x10WIFI_VAP_UNKNOWN\x10\x00\x12\x14\n\x10WIFI_VAP_MAIN_AP\x10\x01\x12\x15\n\x11WIFI_VAP_GUEST_AP\x10\x02\x12\x14\n\x10WIFI_VAP_STATION\x10\x03\x42\x15\n\x06\x64\x65viceB\x0bwifinetworkb\x06proto3') +) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +_WIFIRESULT = _descriptor.EnumDescriptor( + name='WifiResult', + full_name='device.api.WifiResult', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='WIFI_SUCCESS', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='WIFI_INVALID_SSID', index=1, number=1, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='WIFI_INVALID_KEY', index=2, number=2, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='WIFI_IS_DISABLED', index=3, number=3, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='WIFI_UNKNOWN_ERROR', index=4, number=255, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=1485, + serialized_end=1607, +) +_sym_db.RegisterEnumDescriptor(_WIFIRESULT) + +WifiResult = enum_type_wrapper.EnumTypeWrapper(_WIFIRESULT) +_WIFIBAND = _descriptor.EnumDescriptor( + name='WifiBand', + full_name='device.api.WifiBand', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='WIFI_BAND_UNKNOWN', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='WIFI_BAND_2G', index=1, number=1, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='WIFI_BAND_5G', index=2, number=2, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=1609, + serialized_end=1678, +) +_sym_db.RegisterEnumDescriptor(_WIFIBAND) + +WifiBand = enum_type_wrapper.EnumTypeWrapper(_WIFIBAND) +_WIFIVAPTYPE = _descriptor.EnumDescriptor( + name='WifiVAPType', + full_name='device.api.WifiVAPType', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='WIFI_VAP_UNKNOWN', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='WIFI_VAP_MAIN_AP', index=1, number=1, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='WIFI_VAP_GUEST_AP', index=2, number=2, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='WIFI_VAP_STATION', index=3, number=3, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=1680, + serialized_end=1782, +) +_sym_db.RegisterEnumDescriptor(_WIFIVAPTYPE) + +WifiVAPType = enum_type_wrapper.EnumTypeWrapper(_WIFIVAPTYPE) +WIFI_SUCCESS = 0 +WIFI_INVALID_SSID = 1 +WIFI_INVALID_KEY = 2 +WIFI_IS_DISABLED = 3 +WIFI_UNKNOWN_ERROR = 255 +WIFI_BAND_UNKNOWN = 0 +WIFI_BAND_2G = 1 +WIFI_BAND_5G = 2 +WIFI_VAP_UNKNOWN = 0 +WIFI_VAP_MAIN_AP = 1 +WIFI_VAP_GUEST_AP = 2 +WIFI_VAP_STATION = 3 + + + +_WIFIPARAMETERSSET = _descriptor.Descriptor( + name='WifiParametersSet', + full_name='device.api.WifiParametersSet', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='ssid', full_name='device.api.WifiParametersSet.ssid', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='key', full_name='device.api.WifiParametersSet.key', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=60, + serialized_end=106, +) + + +_WIFIPARAMETERSSETRESPONSE = _descriptor.Descriptor( + name='WifiParametersSetResponse', + full_name='device.api.WifiParametersSetResponse', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='result', full_name='device.api.WifiParametersSetResponse.result', index=0, + number=1, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=108, + serialized_end=175, +) + + +_WIFIGUESTACCESSSET = _descriptor.Descriptor( + name='WifiGuestAccessSet', + full_name='device.api.WifiGuestAccessSet', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='enable', full_name='device.api.WifiGuestAccessSet.enable', index=0, + number=1, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='duration', full_name='device.api.WifiGuestAccessSet.duration', index=1, + number=2, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=177, + serialized_end=231, +) + + +_WIFIGUESTACCESSSETRESPONSE = _descriptor.Descriptor( + name='WifiGuestAccessSetResponse', + full_name='device.api.WifiGuestAccessSetResponse', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='result', full_name='device.api.WifiGuestAccessSetResponse.result', index=0, + number=1, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=233, + serialized_end=301, +) + + +_WIFIGUESTACCESSGET = _descriptor.Descriptor( + name='WifiGuestAccessGet', + full_name='device.api.WifiGuestAccessGet', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='enabled', full_name='device.api.WifiGuestAccessGet.enabled', index=0, + number=1, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='remaining_duration', full_name='device.api.WifiGuestAccessGet.remaining_duration', index=1, + number=2, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='ssid', full_name='device.api.WifiGuestAccessGet.ssid', index=2, + number=3, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='key', full_name='device.api.WifiGuestAccessGet.key', index=3, + number=4, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=303, + serialized_end=395, +) + + +_WIFINEIGHBORAPSGET_NEIGHBORAPINFO = _descriptor.Descriptor( + name='NeighborAPInfo', + full_name='device.api.WifiNeighborAPsGet.NeighborAPInfo', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='mac_address', full_name='device.api.WifiNeighborAPsGet.NeighborAPInfo.mac_address', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='ssid', full_name='device.api.WifiNeighborAPsGet.NeighborAPInfo.ssid', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='band', full_name='device.api.WifiNeighborAPsGet.NeighborAPInfo.band', index=2, + number=3, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='channel', full_name='device.api.WifiNeighborAPsGet.NeighborAPInfo.channel', index=3, + number=4, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='signal', full_name='device.api.WifiNeighborAPsGet.NeighborAPInfo.signal', index=4, + number=5, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='signal_bars', full_name='device.api.WifiNeighborAPsGet.NeighborAPInfo.signal_bars', index=5, + number=6, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=490, + serialized_end=631, +) + +_WIFINEIGHBORAPSGET = _descriptor.Descriptor( + name='WifiNeighborAPsGet', + full_name='device.api.WifiNeighborAPsGet', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='neighbor_aps', full_name='device.api.WifiNeighborAPsGet.neighbor_aps', index=0, + number=1, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[_WIFINEIGHBORAPSGET_NEIGHBORAPINFO, ], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=398, + serialized_end=631, +) + + +_WIFIREPEATEDAPSGET_REPEATEDAPINFO = _descriptor.Descriptor( + name='RepeatedAPInfo', + full_name='device.api.WifiRepeatedAPsGet.RepeatedAPInfo', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='mac_address', full_name='device.api.WifiRepeatedAPsGet.RepeatedAPInfo.mac_address', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='ssid', full_name='device.api.WifiRepeatedAPsGet.RepeatedAPInfo.ssid', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='band', full_name='device.api.WifiRepeatedAPsGet.RepeatedAPInfo.band', index=2, + number=3, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='channel', full_name='device.api.WifiRepeatedAPsGet.RepeatedAPInfo.channel', index=3, + number=4, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='rate', full_name='device.api.WifiRepeatedAPsGet.RepeatedAPInfo.rate', index=4, + number=5, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='signal', full_name='device.api.WifiRepeatedAPsGet.RepeatedAPInfo.signal', index=5, + number=6, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='signal_bars', full_name='device.api.WifiRepeatedAPsGet.RepeatedAPInfo.signal_bars', index=6, + number=7, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=726, + serialized_end=881, +) + +_WIFIREPEATEDAPSGET = _descriptor.Descriptor( + name='WifiRepeatedAPsGet', + full_name='device.api.WifiRepeatedAPsGet', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='repeated_aps', full_name='device.api.WifiRepeatedAPsGet.repeated_aps', index=0, + number=1, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[_WIFIREPEATEDAPSGET_REPEATEDAPINFO, ], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=634, + serialized_end=881, +) + + +_WIFICONNECTEDSTATIONSGET_CONNECTEDSTATIONINFO = _descriptor.Descriptor( + name='ConnectedStationInfo', + full_name='device.api.WifiConnectedStationsGet.ConnectedStationInfo', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='mac_address', full_name='device.api.WifiConnectedStationsGet.ConnectedStationInfo.mac_address', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='vap_type', full_name='device.api.WifiConnectedStationsGet.ConnectedStationInfo.vap_type', index=1, + number=2, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='band', full_name='device.api.WifiConnectedStationsGet.ConnectedStationInfo.band', index=2, + number=3, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='rx_rate', full_name='device.api.WifiConnectedStationsGet.ConnectedStationInfo.rx_rate', index=3, + number=4, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='tx_rate', full_name='device.api.WifiConnectedStationsGet.ConnectedStationInfo.tx_rate', index=4, + number=5, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1000, + serialized_end=1156, +) + +_WIFICONNECTEDSTATIONSGET = _descriptor.Descriptor( + name='WifiConnectedStationsGet', + full_name='device.api.WifiConnectedStationsGet', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='connected_stations', full_name='device.api.WifiConnectedStationsGet.connected_stations', index=0, + number=1, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[_WIFICONNECTEDSTATIONSGET_CONNECTEDSTATIONINFO, ], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=884, + serialized_end=1156, +) + + +_WIFIREPEATERPARAMETERSSET = _descriptor.Descriptor( + name='WifiRepeaterParametersSet', + full_name='device.api.WifiRepeaterParametersSet', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='ssid', full_name='device.api.WifiRepeaterParametersSet.ssid', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='key', full_name='device.api.WifiRepeaterParametersSet.key', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='crossband', full_name='device.api.WifiRepeaterParametersSet.crossband', index=2, + number=3, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='primary_band', full_name='device.api.WifiRepeaterParametersSet.primary_band', index=3, + number=4, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1158, + serialized_end=1275, +) + + +_WIFIREPEATERPARAMETERSSETRESPONSE = _descriptor.Descriptor( + name='WifiRepeaterParametersSetResponse', + full_name='device.api.WifiRepeaterParametersSetResponse', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='result', full_name='device.api.WifiRepeaterParametersSetResponse.result', index=0, + number=1, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1277, + serialized_end=1352, +) + + +_WIFIWPSPBCSTART = _descriptor.Descriptor( + name='WifiWpsPbcStart', + full_name='device.api.WifiWpsPbcStart', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='result', full_name='device.api.WifiWpsPbcStart.result', index=0, + number=1, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1354, + serialized_end=1411, +) + + +_WIFIREPEATERWPSCLONEPBCSTART = _descriptor.Descriptor( + name='WifiRepeaterWpsClonePbcStart', + full_name='device.api.WifiRepeaterWpsClonePbcStart', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='result', full_name='device.api.WifiRepeaterWpsClonePbcStart.result', index=0, + number=1, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1413, + serialized_end=1483, +) + +_WIFIPARAMETERSSETRESPONSE.fields_by_name['result'].enum_type = _WIFIRESULT +_WIFIGUESTACCESSSETRESPONSE.fields_by_name['result'].enum_type = _WIFIRESULT +_WIFINEIGHBORAPSGET_NEIGHBORAPINFO.fields_by_name['band'].enum_type = _WIFIBAND +_WIFINEIGHBORAPSGET_NEIGHBORAPINFO.containing_type = _WIFINEIGHBORAPSGET +_WIFINEIGHBORAPSGET.fields_by_name['neighbor_aps'].message_type = _WIFINEIGHBORAPSGET_NEIGHBORAPINFO +_WIFIREPEATEDAPSGET_REPEATEDAPINFO.fields_by_name['band'].enum_type = _WIFIBAND +_WIFIREPEATEDAPSGET_REPEATEDAPINFO.containing_type = _WIFIREPEATEDAPSGET +_WIFIREPEATEDAPSGET.fields_by_name['repeated_aps'].message_type = _WIFIREPEATEDAPSGET_REPEATEDAPINFO +_WIFICONNECTEDSTATIONSGET_CONNECTEDSTATIONINFO.fields_by_name['vap_type'].enum_type = _WIFIVAPTYPE +_WIFICONNECTEDSTATIONSGET_CONNECTEDSTATIONINFO.fields_by_name['band'].enum_type = _WIFIBAND +_WIFICONNECTEDSTATIONSGET_CONNECTEDSTATIONINFO.containing_type = _WIFICONNECTEDSTATIONSGET +_WIFICONNECTEDSTATIONSGET.fields_by_name['connected_stations'].message_type = _WIFICONNECTEDSTATIONSGET_CONNECTEDSTATIONINFO +_WIFIREPEATERPARAMETERSSET.fields_by_name['primary_band'].enum_type = _WIFIBAND +_WIFIREPEATERPARAMETERSSETRESPONSE.fields_by_name['result'].enum_type = _WIFIRESULT +_WIFIWPSPBCSTART.fields_by_name['result'].enum_type = _WIFIRESULT +_WIFIREPEATERWPSCLONEPBCSTART.fields_by_name['result'].enum_type = _WIFIRESULT +DESCRIPTOR.message_types_by_name['WifiParametersSet'] = _WIFIPARAMETERSSET +DESCRIPTOR.message_types_by_name['WifiParametersSetResponse'] = _WIFIPARAMETERSSETRESPONSE +DESCRIPTOR.message_types_by_name['WifiGuestAccessSet'] = _WIFIGUESTACCESSSET +DESCRIPTOR.message_types_by_name['WifiGuestAccessSetResponse'] = _WIFIGUESTACCESSSETRESPONSE +DESCRIPTOR.message_types_by_name['WifiGuestAccessGet'] = _WIFIGUESTACCESSGET +DESCRIPTOR.message_types_by_name['WifiNeighborAPsGet'] = _WIFINEIGHBORAPSGET +DESCRIPTOR.message_types_by_name['WifiRepeatedAPsGet'] = _WIFIREPEATEDAPSGET +DESCRIPTOR.message_types_by_name['WifiConnectedStationsGet'] = _WIFICONNECTEDSTATIONSGET +DESCRIPTOR.message_types_by_name['WifiRepeaterParametersSet'] = _WIFIREPEATERPARAMETERSSET +DESCRIPTOR.message_types_by_name['WifiRepeaterParametersSetResponse'] = _WIFIREPEATERPARAMETERSSETRESPONSE +DESCRIPTOR.message_types_by_name['WifiWpsPbcStart'] = _WIFIWPSPBCSTART +DESCRIPTOR.message_types_by_name['WifiRepeaterWpsClonePbcStart'] = _WIFIREPEATERWPSCLONEPBCSTART +DESCRIPTOR.enum_types_by_name['WifiResult'] = _WIFIRESULT +DESCRIPTOR.enum_types_by_name['WifiBand'] = _WIFIBAND +DESCRIPTOR.enum_types_by_name['WifiVAPType'] = _WIFIVAPTYPE + +WifiParametersSet = _reflection.GeneratedProtocolMessageType('WifiParametersSet', (_message.Message,), dict( + DESCRIPTOR = _WIFIPARAMETERSSET, + __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' + # @@protoc_insertion_point(class_scope:device.api.WifiParametersSet) + )) +_sym_db.RegisterMessage(WifiParametersSet) + +WifiParametersSetResponse = _reflection.GeneratedProtocolMessageType('WifiParametersSetResponse', (_message.Message,), dict( + DESCRIPTOR = _WIFIPARAMETERSSETRESPONSE, + __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' + # @@protoc_insertion_point(class_scope:device.api.WifiParametersSetResponse) + )) +_sym_db.RegisterMessage(WifiParametersSetResponse) + +WifiGuestAccessSet = _reflection.GeneratedProtocolMessageType('WifiGuestAccessSet', (_message.Message,), dict( + DESCRIPTOR = _WIFIGUESTACCESSSET, + __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' + # @@protoc_insertion_point(class_scope:device.api.WifiGuestAccessSet) + )) +_sym_db.RegisterMessage(WifiGuestAccessSet) + +WifiGuestAccessSetResponse = _reflection.GeneratedProtocolMessageType('WifiGuestAccessSetResponse', (_message.Message,), dict( + DESCRIPTOR = _WIFIGUESTACCESSSETRESPONSE, + __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' + # @@protoc_insertion_point(class_scope:device.api.WifiGuestAccessSetResponse) + )) +_sym_db.RegisterMessage(WifiGuestAccessSetResponse) + +WifiGuestAccessGet = _reflection.GeneratedProtocolMessageType('WifiGuestAccessGet', (_message.Message,), dict( + DESCRIPTOR = _WIFIGUESTACCESSGET, + __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' + # @@protoc_insertion_point(class_scope:device.api.WifiGuestAccessGet) + )) +_sym_db.RegisterMessage(WifiGuestAccessGet) + +WifiNeighborAPsGet = _reflection.GeneratedProtocolMessageType('WifiNeighborAPsGet', (_message.Message,), dict( + + NeighborAPInfo = _reflection.GeneratedProtocolMessageType('NeighborAPInfo', (_message.Message,), dict( + DESCRIPTOR = _WIFINEIGHBORAPSGET_NEIGHBORAPINFO, + __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' + # @@protoc_insertion_point(class_scope:device.api.WifiNeighborAPsGet.NeighborAPInfo) + )) + , + DESCRIPTOR = _WIFINEIGHBORAPSGET, + __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' + # @@protoc_insertion_point(class_scope:device.api.WifiNeighborAPsGet) + )) +_sym_db.RegisterMessage(WifiNeighborAPsGet) +_sym_db.RegisterMessage(WifiNeighborAPsGet.NeighborAPInfo) + +WifiRepeatedAPsGet = _reflection.GeneratedProtocolMessageType('WifiRepeatedAPsGet', (_message.Message,), dict( + + RepeatedAPInfo = _reflection.GeneratedProtocolMessageType('RepeatedAPInfo', (_message.Message,), dict( + DESCRIPTOR = _WIFIREPEATEDAPSGET_REPEATEDAPINFO, + __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' + # @@protoc_insertion_point(class_scope:device.api.WifiRepeatedAPsGet.RepeatedAPInfo) + )) + , + DESCRIPTOR = _WIFIREPEATEDAPSGET, + __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' + # @@protoc_insertion_point(class_scope:device.api.WifiRepeatedAPsGet) + )) +_sym_db.RegisterMessage(WifiRepeatedAPsGet) +_sym_db.RegisterMessage(WifiRepeatedAPsGet.RepeatedAPInfo) + +WifiConnectedStationsGet = _reflection.GeneratedProtocolMessageType('WifiConnectedStationsGet', (_message.Message,), dict( + + ConnectedStationInfo = _reflection.GeneratedProtocolMessageType('ConnectedStationInfo', (_message.Message,), dict( + DESCRIPTOR = _WIFICONNECTEDSTATIONSGET_CONNECTEDSTATIONINFO, + __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' + # @@protoc_insertion_point(class_scope:device.api.WifiConnectedStationsGet.ConnectedStationInfo) + )) + , + DESCRIPTOR = _WIFICONNECTEDSTATIONSGET, + __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' + # @@protoc_insertion_point(class_scope:device.api.WifiConnectedStationsGet) + )) +_sym_db.RegisterMessage(WifiConnectedStationsGet) +_sym_db.RegisterMessage(WifiConnectedStationsGet.ConnectedStationInfo) + +WifiRepeaterParametersSet = _reflection.GeneratedProtocolMessageType('WifiRepeaterParametersSet', (_message.Message,), dict( + DESCRIPTOR = _WIFIREPEATERPARAMETERSSET, + __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' + # @@protoc_insertion_point(class_scope:device.api.WifiRepeaterParametersSet) + )) +_sym_db.RegisterMessage(WifiRepeaterParametersSet) + +WifiRepeaterParametersSetResponse = _reflection.GeneratedProtocolMessageType('WifiRepeaterParametersSetResponse', (_message.Message,), dict( + DESCRIPTOR = _WIFIREPEATERPARAMETERSSETRESPONSE, + __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' + # @@protoc_insertion_point(class_scope:device.api.WifiRepeaterParametersSetResponse) + )) +_sym_db.RegisterMessage(WifiRepeaterParametersSetResponse) + +WifiWpsPbcStart = _reflection.GeneratedProtocolMessageType('WifiWpsPbcStart', (_message.Message,), dict( + DESCRIPTOR = _WIFIWPSPBCSTART, + __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' + # @@protoc_insertion_point(class_scope:device.api.WifiWpsPbcStart) + )) +_sym_db.RegisterMessage(WifiWpsPbcStart) + +WifiRepeaterWpsClonePbcStart = _reflection.GeneratedProtocolMessageType('WifiRepeaterWpsClonePbcStart', (_message.Message,), dict( + DESCRIPTOR = _WIFIREPEATERWPSCLONEPBCSTART, + __module__ = 'devolo_idl_proto_deviceapi_wifinetwork_pb2' + # @@protoc_insertion_point(class_scope:device.api.WifiRepeaterWpsClonePbcStart) + )) +_sym_db.RegisterMessage(WifiRepeaterWpsClonePbcStart) + + +DESCRIPTOR.has_options = True +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\006deviceB\013wifinetwork')) +# @@protoc_insertion_point(module_scope) diff --git a/devolo_plc_api/exceptions/feature.py b/devolo_plc_api/exceptions/feature.py new file mode 100644 index 0000000..9f59404 --- /dev/null +++ b/devolo_plc_api/exceptions/feature.py @@ -0,0 +1,2 @@ +class FeatureNotSupported(Exception): + """ This feature is not supported by your device. """ diff --git a/devolo_plc_api/plcnet_api/devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.py b/devolo_plc_api/plcnet_api/devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.py new file mode 100644 index 0000000..dffcf5a --- /dev/null +++ b/devolo_plc_api/plcnet_api/devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.py @@ -0,0 +1,358 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: devolo_idl_proto_plcnetapi_getnetworkoverview.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='devolo_idl_proto_plcnetapi_getnetworkoverview.proto', + package='plcnet.api', + syntax='proto3', + serialized_pb=_b('\n3devolo_idl_proto_plcnetapi_getnetworkoverview.proto\x12\nplcnet.api\"\xd5\x06\n\x12GetNetworkOverview\x12>\n\x07network\x18\x01 \x01(\x0b\x32-.plcnet.api.GetNetworkOverview.LogicalNetwork\x1a\x96\x04\n\x06\x44\x65vice\x12\x14\n\x0cproduct_name\x18\x01 \x01(\t\x12\x12\n\nproduct_id\x18\x02 \x01(\t\x12\x18\n\x10\x66riendly_version\x18\x03 \x01(\t\x12\x14\n\x0c\x66ull_version\x18\x04 \x01(\t\x12\x18\n\x10user_device_name\x18\x05 \x01(\t\x12\x19\n\x11user_network_name\x18\x06 \x01(\t\x12\x13\n\x0bmac_address\x18\x07 \x01(\t\x12@\n\x08topology\x18\x08 \x01(\x0e\x32..plcnet.api.GetNetworkOverview.Device.Topology\x12\x44\n\ntechnology\x18\t \x01(\x0e\x32\x30.plcnet.api.GetNetworkOverview.Device.Technology\x12\x17\n\x0f\x62ridged_devices\x18\n \x03(\t\x12\x14\n\x0cipv4_address\x18\x0b \x01(\t\x12\x1a\n\x12\x61ttached_to_router\x18\x0c \x01(\x08\"7\n\x08Topology\x12\x14\n\x10UNKNOWN_TOPOLOGY\x10\x00\x12\t\n\x05LOCAL\x10\x01\x12\n\n\x06REMOTE\x10\x02\"\\\n\nTechnology\x12\x16\n\x12UNKNOWN_TECHNOLOGY\x10\x00\x12\x14\n\x10HPAV_THUNDERBOLT\x10\x03\x12\x10\n\x0cHPAV_PANTHER\x10\x04\x12\x0e\n\nGHN_SPIRIT\x10\x07\x1a^\n\x08\x44\x61taRate\x12\x18\n\x10mac_address_from\x18\x01 \x01(\t\x12\x16\n\x0emac_address_to\x18\x02 \x01(\t\x12\x0f\n\x07tx_rate\x18\x03 \x01(\x01\x12\x0f\n\x07rx_rate\x18\x04 \x01(\x01\x1a\x85\x01\n\x0eLogicalNetwork\x12\x36\n\x07\x64\x65vices\x18\x01 \x03(\x0b\x32%.plcnet.api.GetNetworkOverview.Device\x12;\n\ndata_rates\x18\x02 \x03(\x0b\x32\'.plcnet.api.GetNetworkOverview.DataRateB\r\n\x06plcnetB\x03netb\x06proto3') +) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + + + +_GETNETWORKOVERVIEW_DEVICE_TOPOLOGY = _descriptor.EnumDescriptor( + name='Topology', + full_name='plcnet.api.GetNetworkOverview.Device.Topology', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='UNKNOWN_TOPOLOGY', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='LOCAL', index=1, number=1, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='REMOTE', index=2, number=2, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=540, + serialized_end=595, +) +_sym_db.RegisterEnumDescriptor(_GETNETWORKOVERVIEW_DEVICE_TOPOLOGY) + +_GETNETWORKOVERVIEW_DEVICE_TECHNOLOGY = _descriptor.EnumDescriptor( + name='Technology', + full_name='plcnet.api.GetNetworkOverview.Device.Technology', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='UNKNOWN_TECHNOLOGY', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='HPAV_THUNDERBOLT', index=1, number=3, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='HPAV_PANTHER', index=2, number=4, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='GHN_SPIRIT', index=3, number=7, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=597, + serialized_end=689, +) +_sym_db.RegisterEnumDescriptor(_GETNETWORKOVERVIEW_DEVICE_TECHNOLOGY) + + +_GETNETWORKOVERVIEW_DEVICE = _descriptor.Descriptor( + name='Device', + full_name='plcnet.api.GetNetworkOverview.Device', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='product_name', full_name='plcnet.api.GetNetworkOverview.Device.product_name', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='product_id', full_name='plcnet.api.GetNetworkOverview.Device.product_id', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='friendly_version', full_name='plcnet.api.GetNetworkOverview.Device.friendly_version', index=2, + number=3, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='full_version', full_name='plcnet.api.GetNetworkOverview.Device.full_version', index=3, + number=4, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='user_device_name', full_name='plcnet.api.GetNetworkOverview.Device.user_device_name', index=4, + number=5, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='user_network_name', full_name='plcnet.api.GetNetworkOverview.Device.user_network_name', index=5, + number=6, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='mac_address', full_name='plcnet.api.GetNetworkOverview.Device.mac_address', index=6, + number=7, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='topology', full_name='plcnet.api.GetNetworkOverview.Device.topology', index=7, + number=8, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='technology', full_name='plcnet.api.GetNetworkOverview.Device.technology', index=8, + number=9, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='bridged_devices', full_name='plcnet.api.GetNetworkOverview.Device.bridged_devices', index=9, + number=10, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='ipv4_address', full_name='plcnet.api.GetNetworkOverview.Device.ipv4_address', index=10, + number=11, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='attached_to_router', full_name='plcnet.api.GetNetworkOverview.Device.attached_to_router', index=11, + number=12, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + _GETNETWORKOVERVIEW_DEVICE_TOPOLOGY, + _GETNETWORKOVERVIEW_DEVICE_TECHNOLOGY, + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=155, + serialized_end=689, +) + +_GETNETWORKOVERVIEW_DATARATE = _descriptor.Descriptor( + name='DataRate', + full_name='plcnet.api.GetNetworkOverview.DataRate', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='mac_address_from', full_name='plcnet.api.GetNetworkOverview.DataRate.mac_address_from', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='mac_address_to', full_name='plcnet.api.GetNetworkOverview.DataRate.mac_address_to', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='tx_rate', full_name='plcnet.api.GetNetworkOverview.DataRate.tx_rate', index=2, + number=3, type=1, cpp_type=5, label=1, + has_default_value=False, default_value=float(0), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='rx_rate', full_name='plcnet.api.GetNetworkOverview.DataRate.rx_rate', index=3, + number=4, type=1, cpp_type=5, label=1, + has_default_value=False, default_value=float(0), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=691, + serialized_end=785, +) + +_GETNETWORKOVERVIEW_LOGICALNETWORK = _descriptor.Descriptor( + name='LogicalNetwork', + full_name='plcnet.api.GetNetworkOverview.LogicalNetwork', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='devices', full_name='plcnet.api.GetNetworkOverview.LogicalNetwork.devices', index=0, + number=1, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='data_rates', full_name='plcnet.api.GetNetworkOverview.LogicalNetwork.data_rates', index=1, + number=2, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=788, + serialized_end=921, +) + +_GETNETWORKOVERVIEW = _descriptor.Descriptor( + name='GetNetworkOverview', + full_name='plcnet.api.GetNetworkOverview', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='network', full_name='plcnet.api.GetNetworkOverview.network', index=0, + number=1, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[_GETNETWORKOVERVIEW_DEVICE, _GETNETWORKOVERVIEW_DATARATE, _GETNETWORKOVERVIEW_LOGICALNETWORK, ], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=68, + serialized_end=921, +) + +_GETNETWORKOVERVIEW_DEVICE.fields_by_name['topology'].enum_type = _GETNETWORKOVERVIEW_DEVICE_TOPOLOGY +_GETNETWORKOVERVIEW_DEVICE.fields_by_name['technology'].enum_type = _GETNETWORKOVERVIEW_DEVICE_TECHNOLOGY +_GETNETWORKOVERVIEW_DEVICE.containing_type = _GETNETWORKOVERVIEW +_GETNETWORKOVERVIEW_DEVICE_TOPOLOGY.containing_type = _GETNETWORKOVERVIEW_DEVICE +_GETNETWORKOVERVIEW_DEVICE_TECHNOLOGY.containing_type = _GETNETWORKOVERVIEW_DEVICE +_GETNETWORKOVERVIEW_DATARATE.containing_type = _GETNETWORKOVERVIEW +_GETNETWORKOVERVIEW_LOGICALNETWORK.fields_by_name['devices'].message_type = _GETNETWORKOVERVIEW_DEVICE +_GETNETWORKOVERVIEW_LOGICALNETWORK.fields_by_name['data_rates'].message_type = _GETNETWORKOVERVIEW_DATARATE +_GETNETWORKOVERVIEW_LOGICALNETWORK.containing_type = _GETNETWORKOVERVIEW +_GETNETWORKOVERVIEW.fields_by_name['network'].message_type = _GETNETWORKOVERVIEW_LOGICALNETWORK +DESCRIPTOR.message_types_by_name['GetNetworkOverview'] = _GETNETWORKOVERVIEW + +GetNetworkOverview = _reflection.GeneratedProtocolMessageType('GetNetworkOverview', (_message.Message,), dict( + + Device = _reflection.GeneratedProtocolMessageType('Device', (_message.Message,), dict( + DESCRIPTOR = _GETNETWORKOVERVIEW_DEVICE, + __module__ = 'devolo_idl_proto_plcnetapi_getnetworkoverview_pb2' + # @@protoc_insertion_point(class_scope:plcnet.api.GetNetworkOverview.Device) + )) + , + + DataRate = _reflection.GeneratedProtocolMessageType('DataRate', (_message.Message,), dict( + DESCRIPTOR = _GETNETWORKOVERVIEW_DATARATE, + __module__ = 'devolo_idl_proto_plcnetapi_getnetworkoverview_pb2' + # @@protoc_insertion_point(class_scope:plcnet.api.GetNetworkOverview.DataRate) + )) + , + + LogicalNetwork = _reflection.GeneratedProtocolMessageType('LogicalNetwork', (_message.Message,), dict( + DESCRIPTOR = _GETNETWORKOVERVIEW_LOGICALNETWORK, + __module__ = 'devolo_idl_proto_plcnetapi_getnetworkoverview_pb2' + # @@protoc_insertion_point(class_scope:plcnet.api.GetNetworkOverview.LogicalNetwork) + )) + , + DESCRIPTOR = _GETNETWORKOVERVIEW, + __module__ = 'devolo_idl_proto_plcnetapi_getnetworkoverview_pb2' + # @@protoc_insertion_point(class_scope:plcnet.api.GetNetworkOverview) + )) +_sym_db.RegisterMessage(GetNetworkOverview) +_sym_db.RegisterMessage(GetNetworkOverview.Device) +_sym_db.RegisterMessage(GetNetworkOverview.DataRate) +_sym_db.RegisterMessage(GetNetworkOverview.LogicalNetwork) + + +DESCRIPTOR.has_options = True +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\006plcnetB\003net')) +# @@protoc_insertion_point(module_scope) diff --git a/devolo_plc_api/plcnet_api/plcnetapi.py b/devolo_plc_api/plcnet_api/plcnetapi.py new file mode 100644 index 0000000..048df80 --- /dev/null +++ b/devolo_plc_api/plcnet_api/plcnetapi.py @@ -0,0 +1,18 @@ +from ..clients.protobuf import Protobuf +from . import devolo_idl_proto_plcnetapi_getnetworkoverview_pb2 + + +class PlcNetApi(Protobuf): + def __init__(self, ip, session, path, version): + self._ip = ip + self._port = 47219 + self._session = session + self._path = path + self._version = version + + + async def get_network_overview(self): + network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() + responds = await self.get("GetNetworkOverview") + network_overview.ParseFromString(await responds.read()) + return network_overview diff --git a/example.py b/example.py index 74bf5b5..4adfba8 100644 --- a/example.py +++ b/example.py @@ -2,16 +2,17 @@ from aiohttp import ClientSession -from devolo_plc_api.devolo_plc_api import DevoloPlcApi +from devolo_plc_api.device import Device -IP = "192.168.178.35" + +IP = "192.168.3.13" async def run(): async with ClientSession() as session: - dpa = DevoloPlcApi(IP, session) - print(await dpa.device_api.wifi1.get_wifi_guest_access()) - print(await dpa.plc_net_api.get_network_overview()) + dpa = Device(IP, session) + print(await dpa.device.get_wifi_guest_access()) + print(await dpa.plcnet.get_network_overview()) if __name__ == "__main__": From e73ec6c9f2beb513c008d3de7c684f4c376ee4fa Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Sun, 23 Aug 2020 15:11:01 +0200 Subject: [PATCH 05/93] Add types and docstrings --- devolo_plc_api/clients/protobuf.py | 3 +++ devolo_plc_api/device_api/deviceapi.py | 28 ++++++++++++++++++++------ devolo_plc_api/plcnet_api/plcnetapi.py | 16 +++++++++++++-- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/devolo_plc_api/clients/protobuf.py b/devolo_plc_api/clients/protobuf.py index a5d8b9c..8ffb4af 100644 --- a/devolo_plc_api/clients/protobuf.py +++ b/devolo_plc_api/clients/protobuf.py @@ -1,4 +1,7 @@ class Protobuf: + """ + Google Protobuf client. + """ async def get(self, sub_url): return await self._session.get(f"http://{self._ip}:{self._port}/{self._path}/{self._version}/{sub_url}") diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index 4fb08ee..ed3a11b 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -1,10 +1,24 @@ +from typing import Callable + +from aiohttp import ClientSession + from ..clients.protobuf import Protobuf -from . import devolo_idl_proto_deviceapi_wifinetwork_pb2 from ..exceptions.feature import FeatureNotSupported +from . import devolo_idl_proto_deviceapi_wifinetwork_pb2 class DeviceApi(Protobuf): - def __init__(self, ip, session, path, version, features): + """ + Implementation of the devolo device API. + + :param ip: IP address of the device to communicate with + :param session: HTTP client session + :param path: Path to send queries to + :param version: Version of the API to use + :param features: Feature, the device has + """ + + def __init__(self, ip: str, session: ClientSession, path: str, version: str, features: str): self._ip = ip self._port = 14791 self._session = session @@ -13,19 +27,21 @@ def __init__(self, ip, session, path, version, features): self._features = features.split(",") - def _feature(feature): - def feature_decorator(method): + def _feature(feature: str): + """ Decorator to filter unsupported features before querying the device. """ + def feature_decorator(method: Callable): def wrapper(self): if feature in self._features: return method(self) else: - raise FeatureNotSupported + raise FeatureNotSupported(f"The device does not support {method}.") return wrapper return feature_decorator @_feature("wifi1") - async def get_wifi_guest_access(self): + async def get_wifi_guest_access(self) -> dict: + """ Get details about wifi guest access. """ wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() r = await self.get("WifiGuestAccessGet") wifi_guest_proto.ParseFromString(await r.read()) diff --git a/devolo_plc_api/plcnet_api/plcnetapi.py b/devolo_plc_api/plcnet_api/plcnetapi.py index 048df80..b5cef3f 100644 --- a/devolo_plc_api/plcnet_api/plcnetapi.py +++ b/devolo_plc_api/plcnet_api/plcnetapi.py @@ -1,9 +1,20 @@ +from aiohttp import ClientSession + from ..clients.protobuf import Protobuf from . import devolo_idl_proto_plcnetapi_getnetworkoverview_pb2 class PlcNetApi(Protobuf): - def __init__(self, ip, session, path, version): + """ + Implementation of the devolo plcnet API. + + :param ip: IP address of the device to communicate with + :param session: HTTP client session + :param path: Path to send queries to + :param version: Version of the API to use + """ + + def __init__(self, ip: str, session: ClientSession, path: str, version: str): self._ip = ip self._port = 47219 self._session = session @@ -11,7 +22,8 @@ def __init__(self, ip, session, path, version): self._version = version - async def get_network_overview(self): + async def get_network_overview(self) -> dict: + """ Get a PLC network overview. """ network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() responds = await self.get("GetNetworkOverview") network_overview.ParseFromString(await responds.read()) From aad51630635d5254b8f3975b17bc2cbb6ed54267 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Sun, 23 Aug 2020 15:11:20 +0200 Subject: [PATCH 06/93] Fix escape character handling --- devolo_plc_api/device.py | 71 +++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/devolo_plc_api/device.py b/devolo_plc_api/device.py index e1a160b..47a0364 100644 --- a/devolo_plc_api/device.py +++ b/devolo_plc_api/device.py @@ -1,16 +1,23 @@ -import re import socket +import struct import time from datetime import date from aiohttp import ClientSession from zeroconf import ServiceBrowser, ServiceStateChange, Zeroconf -from .plcnet_api.plcnetapi import PlcNetApi from .device_api.deviceapi import DeviceApi +from .plcnet_api.plcnetapi import PlcNetApi class Device: + """ + Representing object for your devolo PLC device. It stores all properties and functionallities discovered during setup. + + :param ip: IP address of the device to communicate with. + :param session: HTTP client session + """ + def __init__(self, ip: str, session: ClientSession): self.firmware_date = date.fromtimestamp(0) self.firmware_version = "" @@ -27,52 +34,62 @@ def __init__(self, ip: str, session: ClientSession): self._session = session self._zeroconf = Zeroconf() - self._info = None + self._info = {} self._get_plcnet_info() - self._info = None + self._info = {} self._get_device_info() self._zeroconf.close() delattr(self, "_info") - def _get_plcnet_info(self): - self._get_zeroconf_info(service_type="_dvl-plcnetapi._tcp.local.") + def _get_device_info(self): + """ Get information from the device API. """ + self._get_zeroconf_info(service_type="_dvl-deviceapi._tcp.local.") - info = dict(s.split('=') for s in [x for x in self._info if x]) - self.mac = info['PlcMacAddress'] - self.technology = info['PlcTechnology'] + self.firmware_date = date.fromisoformat(self._info['FirmwareDate']) + self.firmware_version = self._info['FirmwareVersion'] + self.serial_number = self._info['SN'] + self.mt_number = self._info['MT'] + self.product = self._info['Product'] - self.plcnet = PlcNetApi(ip=self.ip, + self.device = DeviceApi(ip=self.ip, session=self._session, - path=info['Path'], - version=info['Version']) + path=self._info['Path'], + version=self._info['Version'], + features=self._info['Features']) - def _get_device_info(self): - self._get_zeroconf_info(service_type="_dvl-deviceapi._tcp.local.") + def _get_plcnet_info(self): + """ Get information from the plcnet API. """ + self._get_zeroconf_info(service_type="_dvl-plcnetapi._tcp.local.") - info = dict(s.split('=') for s in [x for x in self._info if x]) - self.firmware_date = date.fromisoformat(info['FirmwareDate']) - self.firmware_version = info['FirmwareVersion'] - self.serial_number = info['SN'] - self.mt_number = info['MT'] - self.product = info['Product'] + self.mac = self._info['PlcMacAddress'] + self.technology = self._info['PlcTechnology'] - self.device = DeviceApi(ip=self.ip, + self.plcnet = PlcNetApi(ip=self.ip, session=self._session, - path=info['Path'], - version=info['Version'], - features=info['Features']) + path=self._info['Path'], + version=self._info['Version']) def _get_zeroconf_info(self, service_type: str): + """ Browse for the desired mDNS service types and query them. """ browser = ServiceBrowser(self._zeroconf, service_type, [self._state_change]) start_time = time.time() - while not time.time() > start_time + 10 and self._info is None: + while not time.time() > start_time + 10 and not self._info: time.sleep(0.1) browser.cancel() def _state_change(self, zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange): + """ Evaluate the query result. """ if state_change is ServiceStateChange.Added and \ socket.inet_ntoa(zeroconf.get_service_info(service_type, name).address) == self.ip: - service_info = zeroconf.get_service_info(service_type, name).text.decode("UTF-8") - self._info = re.split("[^ -~]+", service_info.replace("PS=", "")) + service_info = zeroconf.get_service_info(service_type, name).text + + # The answer is a byte string, that concatenates key-value pairs with their length as two byte hex value. + total_length = len(service_info) + offset = 0 + while offset < total_length: + parsed_length, = struct.unpack_from('!B', service_info, offset) + key_value = service_info[offset + 1:offset + 1 + parsed_length].decode("UTF-8").split("=") + self._info[key_value[0]] = key_value[1] + offset += parsed_length + 1 From 4b9d5ec3936f4a739e9c93bad66dc7bb477cdece Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Sun, 23 Aug 2020 15:15:30 +0200 Subject: [PATCH 07/93] Remove requirements.txt in favour of setup.py --- requirements.txt | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 624e430..0000000 --- a/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -requests -aiohttp -zeroconf -protobuf From f152c50c2e14b37b3f2a6f8ef599ca5c019bc127 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Sun, 23 Aug 2020 19:39:21 +0200 Subject: [PATCH 08/93] Add documentation --- .github/ISSUE_TEMPLATE/bug_report.md | 27 +++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 ++++++++ .github/pull_request_template.md | 15 ++++++ README.md | 57 ++++++++++++++++++++++- docs/CHANGELOG.md | 12 +++++ docs/CODE_OF_CONDUCT.md | 47 +++++++++++++++++++ docs/CONTRIBUTING.md | 35 ++++++++++++++ example.py | 7 ++- 8 files changed, 218 insertions(+), 2 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/pull_request_template.md create mode 100644 docs/CHANGELOG.md create mode 100644 docs/CODE_OF_CONDUCT.md create mode 100644 docs/CONTRIBUTING.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..9407a47 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,27 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**Used device** +Device and firmware version you used to trigger the bug. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..7a16000 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,15 @@ +## Proposed change + + + +## Checklist + + + +- [ ] Version number in \_\_init\_\_.py was properly set. +- [ ] Changelog is updated. diff --git a/README.md b/README.md index a65ccdd..1d00ed4 100644 --- a/README.md +++ b/README.md @@ -1 +1,56 @@ -# devolo_plc_api \ No newline at end of file +# devolo PLC API + +This project implements parts of the devolo PLC devices API in Python. Communication to the devices is formatted in protobuf and the IDLs were kindly provided by devolo. Nevertheless, we might miss updates to the IDLs. If you discover a breakage, please feel free to [report an issue](https://github.com/2Fake/devolo_plc_api/issues). + +## System requirements + +Defining the system requirements with exact versions typically is difficult. But there is a tested environment: + +* Linux +* Python 3.6.11 +* pip 20.0.2 +* aiohttp 3.6.2 +* protobuf 3.11.4 +* zeroconf 0.24.4 + +Other versions and even other operating systems might work. Feel free to tell us about your experience. If you want to run our unit tests, you also need: + +* pytest 5.4.3 +* pytest-mock 3.2.0 + +## Versioning + +In our versioning we follow [Semantic Versioning](https://semver.org/). + +## Installing for usage + +The Python Package Index takes care for you. Just use pip. + +```bash +pip install devolo-plc-api +``` + +## Installing for development + +First, you need to get the sources. + +```bash +git clone git@github.com:2Fake/devolo_plc_api.git +``` + +Then you need to take care of the requirements. + +```bash +cd devolo_plc_api +python setup.py install +``` + +If you want to run out tests, change to the tests directory and start pytest via setup.py. + +```bash +python setup.py test +``` + +## Usage + +All features we currently support are shown in our [example.py](https://github.com/2Fake/devolo_plc_api/blob/master/example.py) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md new file mode 100644 index 0000000..1bd3836 --- /dev/null +++ b/docs/CHANGELOG.md @@ -0,0 +1,12 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Added + +- Get PLC data rates +- Get details about wifi guest access diff --git a/docs/CODE_OF_CONDUCT.md b/docs/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..c97d8da --- /dev/null +++ b/docs/CODE_OF_CONDUCT.md @@ -0,0 +1,47 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at guido.schmitz@fedaix.de or m.bong@famabo.de. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see https://www.contributor-covenant.org/faq diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md new file mode 100644 index 0000000..272e2e2 --- /dev/null +++ b/docs/CONTRIBUTING.md @@ -0,0 +1,35 @@ +# Contributing + +Thank you very much for considering to contribute to our project. The devolo PLC devices deliver interesting data that we wanted to be usable in other projects. To achieve that goal, help is welcome. + +The following guidelines will help you to understand how you can help. They will also make transparent to you the time we need to manage and develop this open source project. In return, we will reciprocate that respect in addressing your issues, assessing changes, and helping you finalize your pull requests. + +## Table of contents + +1. [Reporting an issue](#reporting-an-issue) +1. [Requesting a feature](#requesting-a-feature) +1. [Code style guide](#code-style-guide) + +## Reporting an issue + +If you are having issues with our module, especially, if you found a bug, we want to know. Please [create an issue](https://github.com/2Fake/devolo_plc_api/issues). However, you should keep in mind that it might take some time for us to respond to your issue. We will try to get in contact with you within two weeks. Please also respond within two weeks, if we have further inquiries. + +## Requesting a feature + +While we develop this module, we have our own use cases in mind. Those use cases do not necessarily meet your use cases. Nevertheless we want to hear about them, so you can either [create an issue](https://github.com/2Fake/devolo_plc_api/issues) or create a merge request. By choosing the first option, you tell us to take care about your use case. That will take time as we will prioritize it with our own needs. By choosing the second option, you can speed up this process. Please read our code style guide. + +## Code style guide + +We basically follow [PEP8](https://www.python.org/dev/peps/pep-0008/), but deviate in some points for - as we think - good reasons. If you have good reasons to stick strictly to PEP8 or even have good reasons to deviate from our deviation, feel free to convince us. + +We limit out lines to 127 characters, as that is maximum length still allowing code reviews on GitHub without horizontal scrolling. + +As PEP8 allows to use extra blank lines sparingly to separate groups of related functions, we use an extra line between static methods and constructor, constructor and properties, properties and public methods, and public methods and internal methods. + +We use double string quotes, except when the string contains double string quotes itself or when used as key of a dictionary. + +If you find code where we violated our own rules, feel free to [tell us](https://github.com/2Fake/devolo_plc_api/issues). + +## Testing + +We cover our code with unit tests written in pytest, but we do not push them to hard. We want public methods covered, but we skip nested and trivial methods. Often we also skip constructors. If you want to contribute, please make sure to keep the unit tests green and to deliver new ones, if you extend the functionality. diff --git a/example.py b/example.py index 4adfba8..af04bfe 100644 --- a/example.py +++ b/example.py @@ -5,13 +5,18 @@ from devolo_plc_api.device import Device -IP = "192.168.3.13" +# IP of the device to query +IP = "192.168.0.10" async def run(): async with ClientSession() as session: dpa = Device(IP, session) + + # Get details about wifi guest access print(await dpa.device.get_wifi_guest_access()) + + # Get PLC data rates print(await dpa.plcnet.get_network_overview()) From 9d53476dcea7bbdb5588cd94cc983d875548080a Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Sun, 23 Aug 2020 22:22:52 +0200 Subject: [PATCH 09/93] Add test alias --- setup.cfg | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 setup.cfg diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..9af7e6f --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[aliases] +test=pytest \ No newline at end of file From 901ef3d8a524094c270d6abacb1eccb3da4f5d5a Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Sun, 23 Aug 2020 22:23:43 +0200 Subject: [PATCH 10/93] Add logging --- devolo_plc_api/clients/protobuf.py | 4 +++- devolo_plc_api/device.py | 4 ++++ devolo_plc_api/device_api/deviceapi.py | 3 +++ devolo_plc_api/plcnet_api/plcnetapi.py | 4 ++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/devolo_plc_api/clients/protobuf.py b/devolo_plc_api/clients/protobuf.py index 8ffb4af..469ccc2 100644 --- a/devolo_plc_api/clients/protobuf.py +++ b/devolo_plc_api/clients/protobuf.py @@ -4,4 +4,6 @@ class Protobuf: """ async def get(self, sub_url): - return await self._session.get(f"http://{self._ip}:{self._port}/{self._path}/{self._version}/{sub_url}") + url = f"http://{self._ip}:{self._port}/{self._path}/{self._version}/{sub_url}" + self._logger.debug(f"Calling {url}") + return await self._session.get(url) diff --git a/devolo_plc_api/device.py b/devolo_plc_api/device.py index 47a0364..ff94c37 100644 --- a/devolo_plc_api/device.py +++ b/devolo_plc_api/device.py @@ -1,3 +1,4 @@ +import logging import socket import struct import time @@ -31,6 +32,7 @@ def __init__(self, ip: str, session: ClientSession): self.device = None self.plcnet = None + self._logger = logging.getLogger(self.__class__.__name__) self._session = session self._zeroconf = Zeroconf() @@ -73,6 +75,7 @@ def _get_plcnet_info(self): def _get_zeroconf_info(self, service_type: str): """ Browse for the desired mDNS service types and query them. """ + self._logger.debug(f"Browsing for {service_type}") browser = ServiceBrowser(self._zeroconf, service_type, [self._state_change]) start_time = time.time() while not time.time() > start_time + 10 and not self._info: @@ -83,6 +86,7 @@ def _state_change(self, zeroconf: Zeroconf, service_type: str, name: str, state_ """ Evaluate the query result. """ if state_change is ServiceStateChange.Added and \ socket.inet_ntoa(zeroconf.get_service_info(service_type, name).address) == self.ip: + self._logger.debug(f"Adding service info of {service_type}") service_info = zeroconf.get_service_info(service_type, name).text # The answer is a byte string, that concatenates key-value pairs with their length as two byte hex value. diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index ed3a11b..9cd229f 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -1,3 +1,4 @@ +import logging from typing import Callable from aiohttp import ClientSession @@ -25,6 +26,7 @@ def __init__(self, ip: str, session: ClientSession, path: str, version: str, fea self._path = path self._version = version self._features = features.split(",") + self._logger = logging.getLogger(self.__class__.__name__) def _feature(feature: str): @@ -42,6 +44,7 @@ def wrapper(self): @_feature("wifi1") async def get_wifi_guest_access(self) -> dict: """ Get details about wifi guest access. """ + self._logger.debug("Getting wifi guest access") wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() r = await self.get("WifiGuestAccessGet") wifi_guest_proto.ParseFromString(await r.read()) diff --git a/devolo_plc_api/plcnet_api/plcnetapi.py b/devolo_plc_api/plcnet_api/plcnetapi.py index b5cef3f..6cec4e6 100644 --- a/devolo_plc_api/plcnet_api/plcnetapi.py +++ b/devolo_plc_api/plcnet_api/plcnetapi.py @@ -1,3 +1,5 @@ +import logging + from aiohttp import ClientSession from ..clients.protobuf import Protobuf @@ -20,10 +22,12 @@ def __init__(self, ip: str, session: ClientSession, path: str, version: str): self._session = session self._path = path self._version = version + self._logger = logging.getLogger(self.__class__.__name__) async def get_network_overview(self) -> dict: """ Get a PLC network overview. """ + self._logger.debug("Getting network overview") network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() responds = await self.get("GetNetworkOverview") network_overview.ParseFromString(await responds.read()) From 29448ac05e7c9c17ee8f8d2a9cc6ea0b0be88e78 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Sun, 23 Aug 2020 22:29:12 +0200 Subject: [PATCH 11/93] Correct version import --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6191375..d5dbc04 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ import setuptools -from devolo_home_control_api import __version__ +from devolo_plc_api import __version__ with open("README.md", "r") as fh: From 717f0d3bda890685ad21bf72517f63a5a8507d64 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Sun, 23 Aug 2020 23:11:16 +0200 Subject: [PATCH 12/93] Add test infrastructure --- tests/__init__.py | 0 tests/conftest.py | 3 +++ tests/fixtures/device_api.py | 8 ++++++++ tests/fixtures/plcnet_api.py | 8 ++++++++ tests/fixtures/zeroconf.py | 8 ++++++++ tests/mocks/mock_device_api.py | 3 +++ tests/mocks/mock_plcnet_api.py | 3 +++ tests/mocks/mock_zeroconf.py | 19 +++++++++++++++++++ tests/test_device.py | 13 +++++++++++++ 9 files changed, 65 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/conftest.py create mode 100644 tests/fixtures/device_api.py create mode 100644 tests/fixtures/plcnet_api.py create mode 100644 tests/fixtures/zeroconf.py create mode 100644 tests/mocks/mock_device_api.py create mode 100644 tests/mocks/mock_plcnet_api.py create mode 100644 tests/mocks/mock_zeroconf.py create mode 100644 tests/test_device.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..479e6cb --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,3 @@ +pytest_plugins = ['tests.fixtures.device_api', + 'tests.fixtures.plcnet_api', + 'tests.fixtures.zeroconf'] diff --git a/tests/fixtures/device_api.py b/tests/fixtures/device_api.py new file mode 100644 index 0000000..02573da --- /dev/null +++ b/tests/fixtures/device_api.py @@ -0,0 +1,8 @@ +import pytest + +from ..mocks.mock_device_api import DeviceApi + + +@pytest.fixture() +def mock_device_api(mocker): + mocker.patch("devolo_plc_api.device_api.deviceapi.DeviceApi", DeviceApi) diff --git a/tests/fixtures/plcnet_api.py b/tests/fixtures/plcnet_api.py new file mode 100644 index 0000000..3dd6256 --- /dev/null +++ b/tests/fixtures/plcnet_api.py @@ -0,0 +1,8 @@ +import pytest + +from ..mocks.mock_plcnet_api import PlcNetApi + + +@pytest.fixture() +def mock_plcnet_api(mocker): + mocker.patch("devolo_plc_api.plcnet_api.plcnetapi.PlcNetApi", PlcNetApi) diff --git a/tests/fixtures/zeroconf.py b/tests/fixtures/zeroconf.py new file mode 100644 index 0000000..f992945 --- /dev/null +++ b/tests/fixtures/zeroconf.py @@ -0,0 +1,8 @@ +import pytest + +from ..mocks.mock_zeroconf import _get_zeroconf_info + + +@pytest.fixture() +def mock_zeroconf(mocker): + mocker.patch("devolo_plc_api.device.Device._get_zeroconf_info", _get_zeroconf_info) diff --git a/tests/mocks/mock_device_api.py b/tests/mocks/mock_device_api.py new file mode 100644 index 0000000..8cee5ed --- /dev/null +++ b/tests/mocks/mock_device_api.py @@ -0,0 +1,3 @@ +class DeviceApi(): + def __init__(self, ip, session, path, version, features): + pass diff --git a/tests/mocks/mock_plcnet_api.py b/tests/mocks/mock_plcnet_api.py new file mode 100644 index 0000000..57ec66b --- /dev/null +++ b/tests/mocks/mock_plcnet_api.py @@ -0,0 +1,3 @@ +class PlcNetApi(): + def __init__(self, ip, session, path, version): + pass diff --git a/tests/mocks/mock_zeroconf.py b/tests/mocks/mock_zeroconf.py new file mode 100644 index 0000000..b4b1ea7 --- /dev/null +++ b/tests/mocks/mock_zeroconf.py @@ -0,0 +1,19 @@ +def _get_zeroconf_info(self, service_type): + if service_type == "_dvl-deviceapi._tcp.local.": + self._info = { + "FirmwareDate": "2020-06-29", + "FirmwareVersion": "5.5.1", + "SN": "1234567890123456", + "MT": "2730", + "Product": "dLAN pro 1200+ WiFi ac", + "Path": "/", + "Version": "v0", + "Features": "wifi1" + } + elif service_type == "_dvl-plcnetapi._tcp.local.": + self._info = { + "PlcMacAddress": "000000000000", + "PlcTechnology": "hpav", + "Path": "/", + "Version": "v0" + } diff --git a/tests/test_device.py b/tests/test_device.py new file mode 100644 index 0000000..8702764 --- /dev/null +++ b/tests/test_device.py @@ -0,0 +1,13 @@ +import pytest + +from devolo_plc_api.device import Device + + +class TestDevice: + @pytest.mark.usefixtures("mock_zeroconf") + @pytest.mark.usefixtures("mock_device_api") + @pytest.mark.usefixtures("mock_plcnet_api") + def test___get_device_info(self): + device = Device(ip="192.168.0.10", session="") + device._get_device_info() + assert device.serial_number == "1234567890123456" From deeb6210aeba9aee7bdd1caba654acb56b53133d Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Mon, 24 Aug 2020 14:18:03 +0200 Subject: [PATCH 13/93] make zeroconf run simultanously --- devolo_plc_api/device.py | 58 +++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/devolo_plc_api/device.py b/devolo_plc_api/device.py index ff94c37..9225d4f 100644 --- a/devolo_plc_api/device.py +++ b/devolo_plc_api/device.py @@ -1,3 +1,4 @@ +import asyncio import logging import socket import struct @@ -5,21 +6,23 @@ from datetime import date from aiohttp import ClientSession +from asyncinit import asyncinit from zeroconf import ServiceBrowser, ServiceStateChange, Zeroconf from .device_api.deviceapi import DeviceApi from .plcnet_api.plcnetapi import PlcNetApi +@asyncinit class Device: """ - Representing object for your devolo PLC device. It stores all properties and functionallities discovered during setup. + Representing object for your devolo PLC device. It stores all properties and functionalities discovered during setup. :param ip: IP address of the device to communicate with. :param session: HTTP client session """ - def __init__(self, ip: str, session: ClientSession): + async def __init__(self, ip: str, session: ClientSession): self.firmware_date = date.fromtimestamp(0) self.firmware_version = "" self.ip = ip @@ -32,68 +35,75 @@ def __init__(self, ip: str, session: ClientSession): self.device = None self.plcnet = None + self._zeroconf = Zeroconf() + + self._plc_info = {} + self._info = {} self._logger = logging.getLogger(self.__class__.__name__) self._session = session - self._zeroconf = Zeroconf() - self._info = {} - self._get_plcnet_info() - self._info = {} - self._get_device_info() + loop = asyncio.get_running_loop() + await loop.create_task(self.start()) + self._zeroconf.close() delattr(self, "_info") + async def start(self): + await asyncio.gather(self._get_device_info(), self._get_plcnet_info()) - def _get_device_info(self): + async def _get_device_info(self): """ Get information from the device API. """ - self._get_zeroconf_info(service_type="_dvl-deviceapi._tcp.local.") + await self._get_zeroconf_info(service_type="_dvl-deviceapi._tcp.local.") - self.firmware_date = date.fromisoformat(self._info['FirmwareDate']) + self.firmware_date = date.fromisoformat(self._info.get("FirmwareDate", "1970-01-01")) self.firmware_version = self._info['FirmwareVersion'] self.serial_number = self._info['SN'] self.mt_number = self._info['MT'] - self.product = self._info['Product'] + self.product = self._info.get("Product", "") self.device = DeviceApi(ip=self.ip, session=self._session, path=self._info['Path'], version=self._info['Version'], - features=self._info['Features']) + features=self._info.get('Features')) - def _get_plcnet_info(self): + async def _get_plcnet_info(self): """ Get information from the plcnet API. """ - self._get_zeroconf_info(service_type="_dvl-plcnetapi._tcp.local.") + await self._get_zeroconf_info(service_type="_dvl-plcnetapi._tcp.local.") - self.mac = self._info['PlcMacAddress'] - self.technology = self._info['PlcTechnology'] + self.mac = self._plc_info['PlcMacAddress'] + self.technology = self._plc_info['PlcTechnology'] self.plcnet = PlcNetApi(ip=self.ip, session=self._session, - path=self._info['Path'], - version=self._info['Version']) + path=self._plc_info['Path'], + version=self._plc_info['Version']) - def _get_zeroconf_info(self, service_type: str): + async def _get_zeroconf_info(self, service_type: str): """ Browse for the desired mDNS service types and query them. """ self._logger.debug(f"Browsing for {service_type}") browser = ServiceBrowser(self._zeroconf, service_type, [self._state_change]) start_time = time.time() - while not time.time() > start_time + 10 and not self._info: - time.sleep(0.1) + while not time.time() > start_time + 10 and not (self._plc_info or self._info): + await asyncio.sleep(1) browser.cancel() def _state_change(self, zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange): """ Evaluate the query result. """ if state_change is ServiceStateChange.Added and \ - socket.inet_ntoa(zeroconf.get_service_info(service_type, name).address) == self.ip: + self.ip in [socket.inet_ntoa(address) for address in zeroconf.get_service_info(service_type, name).addresses]: + self._logger.debug(f"Adding service info of {service_type}") service_info = zeroconf.get_service_info(service_type, name).text - # The answer is a byte string, that concatenates key-value pairs with their length as two byte hex value. total_length = len(service_info) offset = 0 while offset < total_length: parsed_length, = struct.unpack_from('!B', service_info, offset) key_value = service_info[offset + 1:offset + 1 + parsed_length].decode("UTF-8").split("=") - self._info[key_value[0]] = key_value[1] + if service_type == '_dvl-deviceapi._tcp.local.': + self._info[key_value[0]] = key_value[1] + else: + self._plc_info[key_value[0]] = key_value[1] offset += parsed_length + 1 From cb7abf5bb39650b9348d3cbc98372994d0b02086 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Mon, 24 Aug 2020 14:18:39 +0200 Subject: [PATCH 14/93] features are an empty list, if the device reports no features --- devolo_plc_api/device_api/deviceapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index 9cd229f..a4cced8 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -25,7 +25,7 @@ def __init__(self, ip: str, session: ClientSession, path: str, version: str, fea self._session = session self._path = path self._version = version - self._features = features.split(",") + self._features = features.split(",") if features else [] self._logger = logging.getLogger(self.__class__.__name__) From 7860493898099f0d8e4ef89e644ea4a63f9d40f3 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Mon, 24 Aug 2020 14:19:46 +0200 Subject: [PATCH 15/93] pin zeroconf, as they change the their attibutes --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d5dbc04..4c6542f 100644 --- a/setup.py +++ b/setup.py @@ -23,8 +23,9 @@ ], install_requires=[ "aiohttp", + "asyncinit", "protobuf", - "zeroconf" + "zeroconf>=0.27.0" ], setup_requires=[ "pytest-runner" From 1e6de323b106239dbea72467ed5699f1f237d2c5 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Mon, 24 Aug 2020 17:03:41 +0200 Subject: [PATCH 16/93] Try to get rid of async init --- devolo_plc_api/device.py | 75 ++++++++++++++++++++++------------------ example.py | 3 +- 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/devolo_plc_api/device.py b/devolo_plc_api/device.py index 9225d4f..f8360f3 100644 --- a/devolo_plc_api/device.py +++ b/devolo_plc_api/device.py @@ -6,14 +6,13 @@ from datetime import date from aiohttp import ClientSession -from asyncinit import asyncinit from zeroconf import ServiceBrowser, ServiceStateChange, Zeroconf from .device_api.deviceapi import DeviceApi +from .exceptions.device import DeviceNotFound from .plcnet_api.plcnetapi import PlcNetApi -@asyncinit class Device: """ Representing object for your devolo PLC device. It stores all properties and functionalities discovered during setup. @@ -22,7 +21,7 @@ class Device: :param session: HTTP client session """ - async def __init__(self, ip: str, session: ClientSession): + def __init__(self, ip: str): self.firmware_date = date.fromtimestamp(0) self.firmware_version = "" self.ip = ip @@ -35,60 +34,72 @@ async def __init__(self, ip: str, session: ClientSession): self.device = None self.plcnet = None - self._zeroconf = Zeroconf() - - self._plc_info = {} - self._info = {} self._logger = logging.getLogger(self.__class__.__name__) - self._session = session + + async def __aenter__(self): + self._info = {"_dvl-plcnetapi._tcp.local.": {}, "_dvl-deviceapi._tcp.local.": {}} + self._session = ClientSession() + self._zeroconf = Zeroconf() + loop = asyncio.get_running_loop() - await loop.create_task(self.start()) + await loop.create_task(self._gather_apis()) + + delattr(self, "_info") + async def __aexit__(self): self._zeroconf.close() + self._session.close() - delattr(self, "_info") - async def start(self): + async def _gather_apis(self): await asyncio.gather(self._get_device_info(), self._get_plcnet_info()) async def _get_device_info(self): """ Get information from the device API. """ - await self._get_zeroconf_info(service_type="_dvl-deviceapi._tcp.local.") - - self.firmware_date = date.fromisoformat(self._info.get("FirmwareDate", "1970-01-01")) - self.firmware_version = self._info['FirmwareVersion'] - self.serial_number = self._info['SN'] - self.mt_number = self._info['MT'] - self.product = self._info.get("Product", "") + service_type = "_dvl-deviceapi._tcp.local." + try: + await asyncio.wait_for(self._get_zeroconf_info(service_type=service_type), timeout=10) + except asyncio.TimeoutError: + raise DeviceNotFound(f"The device {self.ip} did not answer.") from None + + self.firmware_date = date.fromisoformat(self._info[service_type].get("FirmwareDate", "1970-01-01")) + self.firmware_version = self._info[service_type].get("FirmwareVersion", "") + self.serial_number = self._info[service_type].get("SN", 0) + self.mt_number = self._info[service_type].get("MT", 0) + self.product = self._info[service_type].get("Product", "") self.device = DeviceApi(ip=self.ip, session=self._session, - path=self._info['Path'], - version=self._info['Version'], - features=self._info.get('Features')) + path=self._info[service_type]['Path'], + version=self._info[service_type]['Version'], + features=self._info[service_type].get("Features", "")) async def _get_plcnet_info(self): """ Get information from the plcnet API. """ - await self._get_zeroconf_info(service_type="_dvl-plcnetapi._tcp.local.") + service_type = "_dvl-plcnetapi._tcp.local." + try: + await asyncio.wait_for(self._get_zeroconf_info(service_type=service_type), timeout=10) + except asyncio.TimeoutError: + raise DeviceNotFound(f"The device {self.ip} did not answer.") from None - self.mac = self._plc_info['PlcMacAddress'] - self.technology = self._plc_info['PlcTechnology'] + self.mac = self._plc_info[service_type].get("PlcMacAddress", "") + self.technology = self._plc_info[service_type].get("PlcTechnology", "") self.plcnet = PlcNetApi(ip=self.ip, session=self._session, - path=self._plc_info['Path'], - version=self._plc_info['Version']) + path=self._plc_info[service_type]['Path'], + version=self._plc_info[service_type]['Version']) async def _get_zeroconf_info(self, service_type: str): """ Browse for the desired mDNS service types and query them. """ self._logger.debug(f"Browsing for {service_type}") browser = ServiceBrowser(self._zeroconf, service_type, [self._state_change]) - start_time = time.time() - while not time.time() > start_time + 10 and not (self._plc_info or self._info): - await asyncio.sleep(1) + while not self._info: + await asyncio.sleep(0.1) browser.cancel() + def _state_change(self, zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange): """ Evaluate the query result. """ if state_change is ServiceStateChange.Added and \ @@ -96,14 +107,12 @@ def _state_change(self, zeroconf: Zeroconf, service_type: str, name: str, state_ self._logger.debug(f"Adding service info of {service_type}") service_info = zeroconf.get_service_info(service_type, name).text + # The answer is a byte string, that concatenates key-value pairs with their length as two byte hex value. total_length = len(service_info) offset = 0 while offset < total_length: parsed_length, = struct.unpack_from('!B', service_info, offset) key_value = service_info[offset + 1:offset + 1 + parsed_length].decode("UTF-8").split("=") - if service_type == '_dvl-deviceapi._tcp.local.': - self._info[key_value[0]] = key_value[1] - else: - self._plc_info[key_value[0]] = key_value[1] + self._info[service_type][key_value[0]] = key_value[1] offset += parsed_length + 1 diff --git a/example.py b/example.py index af04bfe..e569f98 100644 --- a/example.py +++ b/example.py @@ -10,8 +10,7 @@ async def run(): - async with ClientSession() as session: - dpa = Device(IP, session) + async with Device(IP) as dpa: # Get details about wifi guest access print(await dpa.device.get_wifi_guest_access()) From adc185cf8a56f97a584a49108b64405595b17601 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Mon, 24 Aug 2020 17:04:09 +0200 Subject: [PATCH 17/93] Add DeviceNotFound exception --- devolo_plc_api/exceptions/device.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 devolo_plc_api/exceptions/device.py diff --git a/devolo_plc_api/exceptions/device.py b/devolo_plc_api/exceptions/device.py new file mode 100644 index 0000000..841737b --- /dev/null +++ b/devolo_plc_api/exceptions/device.py @@ -0,0 +1,2 @@ +class DeviceNotFound(Exception): + """ The device was not found. """ \ No newline at end of file From 347a684872ab1000270884415f4a20e3a2b23d6f Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Mon, 24 Aug 2020 19:35:32 +0200 Subject: [PATCH 18/93] Fix _get_zeroconf_info --- devolo_plc_api/device.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/devolo_plc_api/device.py b/devolo_plc_api/device.py index f8360f3..9e50340 100644 --- a/devolo_plc_api/device.py +++ b/devolo_plc_api/device.py @@ -2,7 +2,6 @@ import logging import socket import struct -import time from datetime import date from aiohttp import ClientSession @@ -41,15 +40,15 @@ async def __aenter__(self): self._info = {"_dvl-plcnetapi._tcp.local.": {}, "_dvl-deviceapi._tcp.local.": {}} self._session = ClientSession() self._zeroconf = Zeroconf() - + loop = asyncio.get_running_loop() await loop.create_task(self._gather_apis()) delattr(self, "_info") - async def __aexit__(self): + async def __aexit__(self, exc_type, exc, tb): self._zeroconf.close() - self._session.close() + await self._session.close() async def _gather_apis(self): @@ -83,19 +82,19 @@ async def _get_plcnet_info(self): except asyncio.TimeoutError: raise DeviceNotFound(f"The device {self.ip} did not answer.") from None - self.mac = self._plc_info[service_type].get("PlcMacAddress", "") - self.technology = self._plc_info[service_type].get("PlcTechnology", "") + self.mac = self._info[service_type].get("PlcMacAddress", "") + self.technology = self._info[service_type].get("PlcTechnology", "") self.plcnet = PlcNetApi(ip=self.ip, session=self._session, - path=self._plc_info[service_type]['Path'], - version=self._plc_info[service_type]['Version']) + path=self._info[service_type]['Path'], + version=self._info[service_type]['Version']) async def _get_zeroconf_info(self, service_type: str): """ Browse for the desired mDNS service types and query them. """ self._logger.debug(f"Browsing for {service_type}") browser = ServiceBrowser(self._zeroconf, service_type, [self._state_change]) - while not self._info: + while not self._info[service_type]: await asyncio.sleep(0.1) browser.cancel() @@ -103,8 +102,7 @@ async def _get_zeroconf_info(self, service_type: str): def _state_change(self, zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange): """ Evaluate the query result. """ if state_change is ServiceStateChange.Added and \ - self.ip in [socket.inet_ntoa(address) for address in zeroconf.get_service_info(service_type, name).addresses]: - + self.ip in [socket.inet_ntoa(address) for address in zeroconf.get_service_info(service_type, name).addresses]: self._logger.debug(f"Adding service info of {service_type}") service_info = zeroconf.get_service_info(service_type, name).text From d376c7f6eb26168951ad99f66c787d24a167148c Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Mon, 24 Aug 2020 19:35:47 +0200 Subject: [PATCH 19/93] Cosmetic change --- devolo_plc_api/exceptions/device.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devolo_plc_api/exceptions/device.py b/devolo_plc_api/exceptions/device.py index 841737b..d21618e 100644 --- a/devolo_plc_api/exceptions/device.py +++ b/devolo_plc_api/exceptions/device.py @@ -1,2 +1,2 @@ class DeviceNotFound(Exception): - """ The device was not found. """ \ No newline at end of file + """ The device was not found. """ From 6d8d3c0f7641a7f5b8f57e8100a1971400a1941a Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Tue, 25 Aug 2020 07:19:18 +0200 Subject: [PATCH 20/93] return self in aenter --- devolo_plc_api/device.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/devolo_plc_api/device.py b/devolo_plc_api/device.py index 9e50340..2c3b956 100644 --- a/devolo_plc_api/device.py +++ b/devolo_plc_api/device.py @@ -46,6 +46,8 @@ async def __aenter__(self): delattr(self, "_info") + return self + async def __aexit__(self, exc_type, exc, tb): self._zeroconf.close() await self._session.close() From 7ceaad596a616cf9512348b861456307a93348e5 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Tue, 25 Aug 2020 07:21:20 +0200 Subject: [PATCH 21/93] add testfile to gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index b05f8be..14b4afa 100644 --- a/.gitignore +++ b/.gitignore @@ -137,3 +137,7 @@ dmypy.json ### PyCharm ### .idea + + +### Testfile ### +test.py \ No newline at end of file From 6da6d009aec31b4c69b85f73e2c57c4956f79c07 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Tue, 25 Aug 2020 07:42:14 +0200 Subject: [PATCH 22/93] add workflow --- .github/workflows/pythonpackage.yml | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/pythonpackage.yml diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml new file mode 100644 index 0000000..232a5c3 --- /dev/null +++ b/.github/workflows/pythonpackage.yml @@ -0,0 +1,30 @@ +name: Python package + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.6, 3.7, 3.8] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + - name: Lint with flake8 + run: | + pip install flake8 + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --ignore=E303,W503 --statistics + + From 8483dee192c1d93ee271f18f0b26377c1b4c7f23 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Tue, 25 Aug 2020 13:22:14 +0200 Subject: [PATCH 23/93] add syncronous methods --- devolo_plc_api/clients/protobuf.py | 13 +++++++++++-- devolo_plc_api/device.py | 15 +++++++++++++-- devolo_plc_api/plcnet_api/plcnetapi.py | 11 +++++++++-- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/devolo_plc_api/clients/protobuf.py b/devolo_plc_api/clients/protobuf.py index 469ccc2..8a01bfa 100644 --- a/devolo_plc_api/clients/protobuf.py +++ b/devolo_plc_api/clients/protobuf.py @@ -3,7 +3,16 @@ class Protobuf: Google Protobuf client. """ - async def get(self, sub_url): - url = f"http://{self._ip}:{self._port}/{self._path}/{self._version}/{sub_url}" + @property + def url(self): + return f"http://{self._ip}:{self._port}/{self._path}/{self._version}/" + + async def async_get(self, sub_url): + url = f"{self.url}{sub_url}" self._logger.debug(f"Calling {url}") return await self._session.get(url) + + def get(self, sub_url): + url = f"{self.url}{sub_url}" + self._logger.debug(f"Calling {url}") + return self._session.get(url) \ No newline at end of file diff --git a/devolo_plc_api/device.py b/devolo_plc_api/device.py index 2c3b956..eaf5d19 100644 --- a/devolo_plc_api/device.py +++ b/devolo_plc_api/device.py @@ -4,6 +4,7 @@ import struct from datetime import date +import requests from aiohttp import ClientSession from zeroconf import ServiceBrowser, ServiceStateChange, Zeroconf @@ -36,6 +37,18 @@ def __init__(self, ip: str): self._logger = logging.getLogger(self.__class__.__name__) + def __enter__(self): + self._info = {"_dvl-plcnetapi._tcp.local.": {}, "_dvl-deviceapi._tcp.local.": {}} + self._session = requests.Session() + self._zeroconf = Zeroconf() + + asyncio.run(self._gather_apis()) + + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + self._session.close() + async def __aenter__(self): self._info = {"_dvl-plcnetapi._tcp.local.": {}, "_dvl-deviceapi._tcp.local.": {}} self._session = ClientSession() @@ -44,8 +57,6 @@ async def __aenter__(self): loop = asyncio.get_running_loop() await loop.create_task(self._gather_apis()) - delattr(self, "_info") - return self async def __aexit__(self, exc_type, exc, tb): diff --git a/devolo_plc_api/plcnet_api/plcnetapi.py b/devolo_plc_api/plcnet_api/plcnetapi.py index 6cec4e6..30435f5 100644 --- a/devolo_plc_api/plcnet_api/plcnetapi.py +++ b/devolo_plc_api/plcnet_api/plcnetapi.py @@ -25,10 +25,17 @@ def __init__(self, ip: str, session: ClientSession, path: str, version: str): self._logger = logging.getLogger(self.__class__.__name__) - async def get_network_overview(self) -> dict: + async def async_get_network_overview(self) -> dict: """ Get a PLC network overview. """ self._logger.debug("Getting network overview") network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() - responds = await self.get("GetNetworkOverview") + responds = await self.async_get("GetNetworkOverview") network_overview.ParseFromString(await responds.read()) return network_overview + + def get_network_overview(self): + self._logger.debug("Getting network overview") + network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() + response = self.get("GetNetworkOverview") + network_overview.ParseFromString(response.content) + return network_overview From 2c01829278cc040535f3f2356d0e8f0dc8f68616 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Tue, 25 Aug 2020 13:22:50 +0200 Subject: [PATCH 24/93] remove unused import --- example.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/example.py b/example.py index e569f98..d923b8e 100644 --- a/example.py +++ b/example.py @@ -1,7 +1,5 @@ import asyncio -from aiohttp import ClientSession - from devolo_plc_api.device import Device From 3a382559208a586314e7b4581c3fd3b91b7f64dd Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Tue, 25 Aug 2020 13:23:08 +0200 Subject: [PATCH 25/93] add first async test --- tests/conftest.py | 16 ++++++++++++++++ tests/fixtures/zeroconf.py | 9 ++++++--- tests/test_data.json | 13 +++++++++++++ tests/test_device.py | 23 +++++++++++++++-------- 4 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 tests/test_data.json diff --git a/tests/conftest.py b/tests/conftest.py index 479e6cb..e14ee52 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,19 @@ +import json +import pathlib +import pytest + pytest_plugins = ['tests.fixtures.device_api', 'tests.fixtures.plcnet_api', 'tests.fixtures.zeroconf'] + +file = pathlib.Path(__file__).parent / "test_data.json" +with file.open("r") as fh: + test_data = json.load(fh) + + +@pytest.fixture(autouse=True, scope="class") +def test_data_fixture(request): + """ Load test data. """ + request.cls.device_info = test_data['device_info'] + + diff --git a/tests/fixtures/zeroconf.py b/tests/fixtures/zeroconf.py index f992945..356d949 100644 --- a/tests/fixtures/zeroconf.py +++ b/tests/fixtures/zeroconf.py @@ -1,8 +1,11 @@ import pytest -from ..mocks.mock_zeroconf import _get_zeroconf_info +from devolo_plc_api.device import Device @pytest.fixture() -def mock_zeroconf(mocker): - mocker.patch("devolo_plc_api.device.Device._get_zeroconf_info", _get_zeroconf_info) +def mock_device(request): + device = Device(ip="192.168.0.10") + device._info = request.cls.device_info + device._session = None + return device diff --git a/tests/test_data.json b/tests/test_data.json new file mode 100644 index 0000000..4de471f --- /dev/null +++ b/tests/test_data.json @@ -0,0 +1,13 @@ +{ + "device_info": { + "_dvl-deviceapi._tcp.local.": { + "FirmwareDate": "2020-06-29", + "FirmwareVersion": "5.5.1", + "SN": "1234567890123456", + "MT": "2730", + "Product": "dLAN pro 1200+ WiFi ac", + "Path": "/", + "Version": "v0", + "Features": "wifi1" + }} +} \ No newline at end of file diff --git a/tests/test_device.py b/tests/test_device.py index 8702764..356aa56 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -1,13 +1,20 @@ +from unittest.mock import patch +from datetime import date import pytest - -from devolo_plc_api.device import Device +from asynctest import CoroutineMock +from devolo_plc_api.device_api.deviceapi import DeviceApi class TestDevice: - @pytest.mark.usefixtures("mock_zeroconf") @pytest.mark.usefixtures("mock_device_api") - @pytest.mark.usefixtures("mock_plcnet_api") - def test___get_device_info(self): - device = Device(ip="192.168.0.10", session="") - device._get_device_info() - assert device.serial_number == "1234567890123456" + @pytest.mark.asyncio + async def test___get_device_info(self, mock_device): + with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=CoroutineMock()): + await mock_device._get_device_info() + assert mock_device.firmware_date == date.fromisoformat(self.device_info["_dvl-deviceapi._tcp.local."]["FirmwareDate"]) + assert mock_device.firmware_version == self.device_info["_dvl-deviceapi._tcp.local."]["FirmwareVersion"] + assert mock_device.serial_number == self.device_info["_dvl-deviceapi._tcp.local."]["SN"] + assert mock_device.mt_number == self.device_info["_dvl-deviceapi._tcp.local."]["MT"] + assert mock_device.product == self.device_info["_dvl-deviceapi._tcp.local."]["Product"] + assert type(mock_device.device) == DeviceApi + From 694337a0df459aaf58d556ee9522fd210b3afd74 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Tue, 25 Aug 2020 13:23:21 +0200 Subject: [PATCH 26/93] enable tests in workflo --- .github/workflows/pythonpackage.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 232a5c3..1cebb7c 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -26,5 +26,8 @@ jobs: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --ignore=E303,W503 --statistics + - name: Test with pytest + run: | + python setup.py test --addopts --cov=devolo_plc_api From 6138442627b378a2fced0c2ed17599e140797772 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Tue, 25 Aug 2020 13:25:22 +0200 Subject: [PATCH 27/93] correct requirements --- setup.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 4c6542f..9eb96ad 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,8 @@ "aiohttp", "asyncinit", "protobuf", - "zeroconf>=0.27.0" + "requests", + "zeroconf>=0.27.0", ], setup_requires=[ "pytest-runner" @@ -33,7 +34,7 @@ tests_require=[ "pytest", "pytest-cov", - "pytest-mock" + "pytest-mock", ], python_requires='>=3.6', ) From b2a3165b5de245e34f65537450a92fc0bcc3610c Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Tue, 25 Aug 2020 13:27:42 +0200 Subject: [PATCH 28/93] correct test requirements --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9eb96ad..3f17dce 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,6 @@ ], install_requires=[ "aiohttp", - "asyncinit", "protobuf", "requests", "zeroconf>=0.27.0", @@ -32,9 +31,11 @@ "pytest-runner" ], tests_require=[ + "asynctest", "pytest", "pytest-cov", "pytest-mock", + "unittest", ], python_requires='>=3.6', ) From e39086a9f1dc9954d61c1971e999c26404d06bf9 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Tue, 25 Aug 2020 13:28:54 +0200 Subject: [PATCH 29/93] correct test requirements --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index 3f17dce..24e81b1 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,6 @@ "pytest", "pytest-cov", "pytest-mock", - "unittest", ], python_requires='>=3.6', ) From 69e356849fada67694c7b8d6d105f98e4abac844 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Tue, 25 Aug 2020 13:31:16 +0200 Subject: [PATCH 30/93] correct test requirements --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 24e81b1..9f7cbd8 100644 --- a/setup.py +++ b/setup.py @@ -33,6 +33,7 @@ tests_require=[ "asynctest", "pytest", + "pytest-asyncio", "pytest-cov", "pytest-mock", ], From 0131b09bab38635408f453dacb3a9dc25922709a Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Tue, 25 Aug 2020 13:34:16 +0200 Subject: [PATCH 31/93] code is incompatible with python3.6 because of fromisoformat --- .github/workflows/pythonpackage.yml | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 1cebb7c..6a66981 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.6, 3.7, 3.8] + python-version: [3.7, 3.8] steps: - uses: actions/checkout@v2 diff --git a/setup.py b/setup.py index 9f7cbd8..908faa5 100644 --- a/setup.py +++ b/setup.py @@ -37,5 +37,5 @@ "pytest-cov", "pytest-mock", ], - python_requires='>=3.6', + python_requires='>=3.7', ) From 3785e253be77cab53fb50dc8f0309f7b88f49e5c Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Tue, 25 Aug 2020 14:57:52 +0200 Subject: [PATCH 32/93] Cosmetic changes --- devolo_plc_api/clients/protobuf.py | 6 +++++- devolo_plc_api/device.py | 30 ++++++++++++-------------- devolo_plc_api/device_api/deviceapi.py | 15 ++++++++++--- devolo_plc_api/plcnet_api/plcnetapi.py | 7 +++--- tests/conftest.py | 8 ++++--- tests/mocks/mock_zeroconf.py | 19 ---------------- tests/test_data.json | 23 ++++++++++---------- tests/test_device.py | 17 ++++++++------- 8 files changed, 61 insertions(+), 64 deletions(-) delete mode 100644 tests/mocks/mock_zeroconf.py diff --git a/devolo_plc_api/clients/protobuf.py b/devolo_plc_api/clients/protobuf.py index 8a01bfa..db0ab28 100644 --- a/devolo_plc_api/clients/protobuf.py +++ b/devolo_plc_api/clients/protobuf.py @@ -5,14 +5,18 @@ class Protobuf: @property def url(self): + """ The URL to query. """ return f"http://{self._ip}:{self._port}/{self._path}/{self._version}/" + async def async_get(self, sub_url): + """ Query URL asynchronously. """ url = f"{self.url}{sub_url}" self._logger.debug(f"Calling {url}") return await self._session.get(url) def get(self, sub_url): + """ Query URL synchronously. """ url = f"{self.url}{sub_url}" self._logger.debug(f"Calling {url}") - return self._session.get(url) \ No newline at end of file + return self._session.get(url) diff --git a/devolo_plc_api/device.py b/devolo_plc_api/device.py index eaf5d19..ee44966 100644 --- a/devolo_plc_api/device.py +++ b/devolo_plc_api/device.py @@ -34,35 +34,34 @@ def __init__(self, ip: str): self.device = None self.plcnet = None + self._info = {"_dvl-plcnetapi._tcp.local.": {}, "_dvl-deviceapi._tcp.local.": {}} self._logger = logging.getLogger(self.__class__.__name__) - - def __enter__(self): - self._info = {"_dvl-plcnetapi._tcp.local.": {}, "_dvl-deviceapi._tcp.local.": {}} - self._session = requests.Session() + async def __aenter__(self): + self._session = ClientSession() self._zeroconf = Zeroconf() - asyncio.run(self._gather_apis()) + loop = asyncio.get_running_loop() + await loop.create_task(self._gather_apis()) return self - def __exit__(self, exc_type, exc_val, exc_tb): - self._session.close() - - async def __aenter__(self): - self._info = {"_dvl-plcnetapi._tcp.local.": {}, "_dvl-deviceapi._tcp.local.": {}} - self._session = ClientSession() + def __enter__(self): + self._session = requests.Session() self._zeroconf = Zeroconf() - loop = asyncio.get_running_loop() - await loop.create_task(self._gather_apis()) + asyncio.run(self._gather_apis()) return self - async def __aexit__(self, exc_type, exc, tb): + async def __aexit__(self, exc_type, exc_val, exc_tb): self._zeroconf.close() await self._session.close() + def __exit__(self, exc_type, exc_val, exc_tb): + self._zeroconf.close() + self._session.close() + async def _gather_apis(self): await asyncio.gather(self._get_device_info(), self._get_plcnet_info()) @@ -111,7 +110,6 @@ async def _get_zeroconf_info(self, service_type: str): await asyncio.sleep(0.1) browser.cancel() - def _state_change(self, zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange): """ Evaluate the query result. """ if state_change is ServiceStateChange.Added and \ @@ -123,7 +121,7 @@ def _state_change(self, zeroconf: Zeroconf, service_type: str, name: str, state_ total_length = len(service_info) offset = 0 while offset < total_length: - parsed_length, = struct.unpack_from('!B', service_info, offset) + parsed_length, = struct.unpack_from("!B", service_info, offset) key_value = service_info[offset + 1:offset + 1 + parsed_length].decode("UTF-8").split("=") self._info[service_type][key_value[0]] = key_value[1] offset += parsed_length + 1 diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index a4cced8..48a22b0 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -42,10 +42,19 @@ def wrapper(self): @_feature("wifi1") - async def get_wifi_guest_access(self) -> dict: + async def async_get_wifi_guest_access(self) -> dict: """ Get details about wifi guest access. """ self._logger.debug("Getting wifi guest access") wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() - r = await self.get("WifiGuestAccessGet") - wifi_guest_proto.ParseFromString(await r.read()) + response = await self.async_get("WifiGuestAccessGet") + wifi_guest_proto.ParseFromString(await response.read()) + return wifi_guest_proto + + @_feature("wifi1") + def get_wifi_guest_access(self) -> dict: + """ Get details about wifi guest access. """ + self._logger.debug("Getting wifi guest access") + wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() + response = self.get("WifiGuestAccessGet") + wifi_guest_proto.ParseFromString(response.content) return wifi_guest_proto diff --git a/devolo_plc_api/plcnet_api/plcnetapi.py b/devolo_plc_api/plcnet_api/plcnetapi.py index 30435f5..01ec180 100644 --- a/devolo_plc_api/plcnet_api/plcnetapi.py +++ b/devolo_plc_api/plcnet_api/plcnetapi.py @@ -26,14 +26,15 @@ def __init__(self, ip: str, session: ClientSession, path: str, version: str): async def async_get_network_overview(self) -> dict: - """ Get a PLC network overview. """ + """ Get a PLC network overview asynchronously. """ self._logger.debug("Getting network overview") network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() - responds = await self.async_get("GetNetworkOverview") - network_overview.ParseFromString(await responds.read()) + response = await self.async_get("GetNetworkOverview") + network_overview.ParseFromString(await response.read()) return network_overview def get_network_overview(self): + """ Get a PLC network overview synchronously. """ self._logger.debug("Getting network overview") network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() response = self.get("GetNetworkOverview") diff --git a/tests/conftest.py b/tests/conftest.py index e14ee52..606105c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,10 +1,14 @@ import json import pathlib + import pytest + pytest_plugins = ['tests.fixtures.device_api', 'tests.fixtures.plcnet_api', - 'tests.fixtures.zeroconf'] + 'tests.fixtures.zeroconf', + ] + file = pathlib.Path(__file__).parent / "test_data.json" with file.open("r") as fh: @@ -15,5 +19,3 @@ def test_data_fixture(request): """ Load test data. """ request.cls.device_info = test_data['device_info'] - - diff --git a/tests/mocks/mock_zeroconf.py b/tests/mocks/mock_zeroconf.py deleted file mode 100644 index b4b1ea7..0000000 --- a/tests/mocks/mock_zeroconf.py +++ /dev/null @@ -1,19 +0,0 @@ -def _get_zeroconf_info(self, service_type): - if service_type == "_dvl-deviceapi._tcp.local.": - self._info = { - "FirmwareDate": "2020-06-29", - "FirmwareVersion": "5.5.1", - "SN": "1234567890123456", - "MT": "2730", - "Product": "dLAN pro 1200+ WiFi ac", - "Path": "/", - "Version": "v0", - "Features": "wifi1" - } - elif service_type == "_dvl-plcnetapi._tcp.local.": - self._info = { - "PlcMacAddress": "000000000000", - "PlcTechnology": "hpav", - "Path": "/", - "Version": "v0" - } diff --git a/tests/test_data.json b/tests/test_data.json index 4de471f..ea52a72 100644 --- a/tests/test_data.json +++ b/tests/test_data.json @@ -1,13 +1,14 @@ { - "device_info": { - "_dvl-deviceapi._tcp.local.": { - "FirmwareDate": "2020-06-29", - "FirmwareVersion": "5.5.1", - "SN": "1234567890123456", - "MT": "2730", - "Product": "dLAN pro 1200+ WiFi ac", - "Path": "/", - "Version": "v0", - "Features": "wifi1" - }} + "device_info": { + "_dvl-deviceapi._tcp.local.": { + "FirmwareDate": "2020-06-29", + "FirmwareVersion": "5.5.1", + "SN": "1234567890123456", + "MT": "2730", + "Product": "dLAN pro 1200+ WiFi ac", + "Path": "/", + "Version": "v0", + "Features": "wifi1" + } + } } \ No newline at end of file diff --git a/tests/test_device.py b/tests/test_device.py index 356aa56..a084261 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -1,20 +1,21 @@ -from unittest.mock import patch from datetime import date +from unittest.mock import patch + import pytest + from asynctest import CoroutineMock from devolo_plc_api.device_api.deviceapi import DeviceApi class TestDevice: - @pytest.mark.usefixtures("mock_device_api") @pytest.mark.asyncio + @pytest.mark.usefixtures("mock_device_api") async def test___get_device_info(self, mock_device): with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=CoroutineMock()): await mock_device._get_device_info() - assert mock_device.firmware_date == date.fromisoformat(self.device_info["_dvl-deviceapi._tcp.local."]["FirmwareDate"]) - assert mock_device.firmware_version == self.device_info["_dvl-deviceapi._tcp.local."]["FirmwareVersion"] - assert mock_device.serial_number == self.device_info["_dvl-deviceapi._tcp.local."]["SN"] - assert mock_device.mt_number == self.device_info["_dvl-deviceapi._tcp.local."]["MT"] - assert mock_device.product == self.device_info["_dvl-deviceapi._tcp.local."]["Product"] + assert mock_device.firmware_date == date.fromisoformat(self.device_info['_dvl-deviceapi._tcp.local.']['FirmwareDate']) + assert mock_device.firmware_version == self.device_info['_dvl-deviceapi._tcp.local.']['FirmwareVersion'] + assert mock_device.serial_number == self.device_info['_dvl-deviceapi._tcp.local.']['SN'] + assert mock_device.mt_number == self.device_info['_dvl-deviceapi._tcp.local.']['MT'] + assert mock_device.product == self.device_info['_dvl-deviceapi._tcp.local.']['Product'] assert type(mock_device.device) == DeviceApi - From 43211f4e6c8f278a9fe175cda2864f2c9d8b5813 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Tue, 25 Aug 2020 16:47:35 +0200 Subject: [PATCH 33/93] Add license --- LICENSE | 674 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 674 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. From 19ad34fb20999489cafd45f0a5326530c52f8cf9 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Tue, 25 Aug 2020 20:16:28 +0200 Subject: [PATCH 34/93] Update package versions --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1d00ed4..10d6e90 100644 --- a/README.md +++ b/README.md @@ -7,16 +7,19 @@ This project implements parts of the devolo PLC devices API in Python. Communica Defining the system requirements with exact versions typically is difficult. But there is a tested environment: * Linux -* Python 3.6.11 +* Python 3.7.8 * pip 20.0.2 * aiohttp 3.6.2 +* requests 2.24.0 * protobuf 3.11.4 -* zeroconf 0.24.4 +* zeroconf 0.27.0 Other versions and even other operating systems might work. Feel free to tell us about your experience. If you want to run our unit tests, you also need: * pytest 5.4.3 +* pytest-asyncio 0.14.0 * pytest-mock 3.2.0 +* asynctest 0.13.0 ## Versioning From 30495ec8388205632454bb6d3f3c55c5fde603f5 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Tue, 25 Aug 2020 20:17:54 +0200 Subject: [PATCH 35/93] Resolve #1 --- devolo_plc_api/device.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/devolo_plc_api/device.py b/devolo_plc_api/device.py index ee44966..8314b1d 100644 --- a/devolo_plc_api/device.py +++ b/devolo_plc_api/device.py @@ -18,10 +18,10 @@ class Device: Representing object for your devolo PLC device. It stores all properties and functionalities discovered during setup. :param ip: IP address of the device to communicate with. - :param session: HTTP client session + :param zeroconf_instance: Zeroconf instance to be potentially reused. """ - def __init__(self, ip: str): + def __init__(self, ip: str, zeroconf_instance: Zeroconf = None): self.firmware_date = date.fromtimestamp(0) self.firmware_version = "" self.ip = ip @@ -36,30 +36,29 @@ def __init__(self, ip: str): self._info = {"_dvl-plcnetapi._tcp.local.": {}, "_dvl-deviceapi._tcp.local.": {}} self._logger = logging.getLogger(self.__class__.__name__) + self._zeroconf_instance = zeroconf_instance - async def __aenter__(self): + async def __aenter__(self): self._session = ClientSession() - self._zeroconf = Zeroconf() - + self._zeroconf = self._zeroconf_instance or Zeroconf() loop = asyncio.get_running_loop() await loop.create_task(self._gather_apis()) - return self def __enter__(self): self._session = requests.Session() - self._zeroconf = Zeroconf() - + self._zeroconf = self._zeroconf_instance or Zeroconf() asyncio.run(self._gather_apis()) - return self async def __aexit__(self, exc_type, exc_val, exc_tb): - self._zeroconf.close() + if not self._zeroconf_instance: + self._zeroconf.close() await self._session.close() def __exit__(self, exc_type, exc_val, exc_tb): - self._zeroconf.close() + if not self._zeroconf_instance: + self._zeroconf.close() self._session.close() From edf3a7e81c15069b7d7668814b5247032402b1b8 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Tue, 25 Aug 2020 20:24:02 +0200 Subject: [PATCH 36/93] Exclude IDLs from linting --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 6a66981..c73dedd 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -25,7 +25,7 @@ jobs: # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --ignore=E303,W503 --statistics + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --ignore=E303,W503 --statistics --exclude=.*,devolo_plc_api/*/devolo_idl_*.py - name: Test with pytest run: | python setup.py test --addopts --cov=devolo_plc_api From 2a089b1cd72cc610003e17340cacdadeebfd2223 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Tue, 25 Aug 2020 20:32:16 +0200 Subject: [PATCH 37/93] Help mypy with type detecting --- devolo_plc_api/device.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/devolo_plc_api/device.py b/devolo_plc_api/device.py index 8314b1d..9336a94 100644 --- a/devolo_plc_api/device.py +++ b/devolo_plc_api/device.py @@ -34,7 +34,7 @@ def __init__(self, ip: str, zeroconf_instance: Zeroconf = None): self.device = None self.plcnet = None - self._info = {"_dvl-plcnetapi._tcp.local.": {}, "_dvl-deviceapi._tcp.local.": {}} + self._info: dict = {"_dvl-plcnetapi._tcp.local.": {}, "_dvl-deviceapi._tcp.local.": {}} self._logger = logging.getLogger(self.__class__.__name__) self._zeroconf_instance = zeroconf_instance @@ -111,16 +111,16 @@ async def _get_zeroconf_info(self, service_type: str): def _state_change(self, zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange): """ Evaluate the query result. """ - if state_change is ServiceStateChange.Added and \ - self.ip in [socket.inet_ntoa(address) for address in zeroconf.get_service_info(service_type, name).addresses]: + service_info = zeroconf.get_service_info(service_type, name) + if service_info and state_change is ServiceStateChange.Added and \ + self.ip in [socket.inet_ntoa(address) for address in service_info.addresses]: self._logger.debug(f"Adding service info of {service_type}") - service_info = zeroconf.get_service_info(service_type, name).text # The answer is a byte string, that concatenates key-value pairs with their length as two byte hex value. - total_length = len(service_info) + total_length = len(service_info.text) offset = 0 while offset < total_length: - parsed_length, = struct.unpack_from("!B", service_info, offset) - key_value = service_info[offset + 1:offset + 1 + parsed_length].decode("UTF-8").split("=") + parsed_length, = struct.unpack_from("!B", service_info.text, offset) + key_value = service_info.text[offset + 1:offset + 1 + parsed_length].decode("UTF-8").split("=") self._info[service_type][key_value[0]] = key_value[1] offset += parsed_length + 1 From 07f85381919a1746fd8a832f11380f222f7f4bd3 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Tue, 25 Aug 2020 20:41:40 +0200 Subject: [PATCH 38/93] Tell mypy to ignore a decorator --- devolo_plc_api/device_api/deviceapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index 48a22b0..e2979ab 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -29,7 +29,7 @@ def __init__(self, ip: str, session: ClientSession, path: str, version: str, fea self._logger = logging.getLogger(self.__class__.__name__) - def _feature(feature: str): + def _feature(feature: str): # type: ignore """ Decorator to filter unsupported features before querying the device. """ def feature_decorator(method: Callable): def wrapper(self): From 228ef806e994a81bde93b5f346a52c44f83aa240 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Tue, 25 Aug 2020 20:44:16 +0200 Subject: [PATCH 39/93] Fix linting issues --- tests/conftest.py | 2 +- tests/test_device.py | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 606105c..4600926 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,7 +7,7 @@ pytest_plugins = ['tests.fixtures.device_api', 'tests.fixtures.plcnet_api', 'tests.fixtures.zeroconf', - ] + ] file = pathlib.Path(__file__).parent / "test_data.json" diff --git a/tests/test_device.py b/tests/test_device.py index a084261..5cd0f45 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -12,10 +12,12 @@ class TestDevice: @pytest.mark.usefixtures("mock_device_api") async def test___get_device_info(self, mock_device): with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=CoroutineMock()): + device_info = self.device_info['_dvl-deviceapi._tcp.local.'] await mock_device._get_device_info() - assert mock_device.firmware_date == date.fromisoformat(self.device_info['_dvl-deviceapi._tcp.local.']['FirmwareDate']) - assert mock_device.firmware_version == self.device_info['_dvl-deviceapi._tcp.local.']['FirmwareVersion'] - assert mock_device.serial_number == self.device_info['_dvl-deviceapi._tcp.local.']['SN'] - assert mock_device.mt_number == self.device_info['_dvl-deviceapi._tcp.local.']['MT'] - assert mock_device.product == self.device_info['_dvl-deviceapi._tcp.local.']['Product'] + + assert mock_device.firmware_date == date.fromisoformat(device_info['FirmwareDate']) + assert mock_device.firmware_version == device_info['FirmwareVersion'] + assert mock_device.serial_number == device_info['SN'] + assert mock_device.mt_number == device_info['MT'] + assert mock_device.product == device_info['Product'] assert type(mock_device.device) == DeviceApi From a8d11bed3927b1f1770f9d6e7d00d843d5356bdd Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Tue, 25 Aug 2020 22:23:14 +0200 Subject: [PATCH 40/93] Cosmetic changes --- devolo_plc_api/clients/protobuf.py | 2 +- devolo_plc_api/device_api/deviceapi.py | 4 ++-- devolo_plc_api/plcnet_api/plcnetapi.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/devolo_plc_api/clients/protobuf.py b/devolo_plc_api/clients/protobuf.py index db0ab28..d225589 100644 --- a/devolo_plc_api/clients/protobuf.py +++ b/devolo_plc_api/clients/protobuf.py @@ -5,7 +5,7 @@ class Protobuf: @property def url(self): - """ The URL to query. """ + """ The base URL to query. """ return f"http://{self._ip}:{self._port}/{self._path}/{self._version}/" diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index e2979ab..326f13e 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -43,7 +43,7 @@ def wrapper(self): @_feature("wifi1") async def async_get_wifi_guest_access(self) -> dict: - """ Get details about wifi guest access. """ + """ Get details about wifi guest access asynchronously. """ self._logger.debug("Getting wifi guest access") wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() response = await self.async_get("WifiGuestAccessGet") @@ -52,7 +52,7 @@ async def async_get_wifi_guest_access(self) -> dict: @_feature("wifi1") def get_wifi_guest_access(self) -> dict: - """ Get details about wifi guest access. """ + """ Get details about wifi guest access synchronously. """ self._logger.debug("Getting wifi guest access") wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() response = self.get("WifiGuestAccessGet") diff --git a/devolo_plc_api/plcnet_api/plcnetapi.py b/devolo_plc_api/plcnet_api/plcnetapi.py index 01ec180..eb14317 100644 --- a/devolo_plc_api/plcnet_api/plcnetapi.py +++ b/devolo_plc_api/plcnet_api/plcnetapi.py @@ -33,7 +33,7 @@ async def async_get_network_overview(self) -> dict: network_overview.ParseFromString(await response.read()) return network_overview - def get_network_overview(self): + def get_network_overview(self) -> dict: """ Get a PLC network overview synchronously. """ self._logger.debug("Getting network overview") network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() From 4d3afbc8620e85d7f973b4209d3549cbd3e9889e Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Tue, 25 Aug 2020 22:23:49 +0200 Subject: [PATCH 41/93] Add testcase for _get_plcnet_info --- tests/test_data.json | 6 ++++++ tests/test_device.py | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/test_data.json b/tests/test_data.json index ea52a72..e534710 100644 --- a/tests/test_data.json +++ b/tests/test_data.json @@ -9,6 +9,12 @@ "Path": "/", "Version": "v0", "Features": "wifi1" + }, + "_dvl-plcnetapi._tcp.local.": { + "Path": "/", + "PlcMacAddress": "AABBCCDDEEFF", + "PlcTechnology": "hpav", + "Version": "v0" } } } \ No newline at end of file diff --git a/tests/test_device.py b/tests/test_device.py index 5cd0f45..898ef56 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -2,9 +2,10 @@ from unittest.mock import patch import pytest - from asynctest import CoroutineMock + from devolo_plc_api.device_api.deviceapi import DeviceApi +from devolo_plc_api.plcnet_api.plcnetapi import PlcNetApi class TestDevice: @@ -21,3 +22,14 @@ async def test___get_device_info(self, mock_device): assert mock_device.mt_number == device_info['MT'] assert mock_device.product == device_info['Product'] assert type(mock_device.device) == DeviceApi + + @pytest.mark.asyncio + @pytest.mark.usefixtures("mock_plcnet_api") + async def test___get_plcnet_info(self, mock_device): + with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=CoroutineMock()): + device_info = self.device_info['_dvl-plcnetapi._tcp.local.'] + await mock_device._get_plcnet_info() + + assert mock_device.mac == device_info['PlcMacAddress'] + assert mock_device.technology == device_info['PlcTechnology'] + assert type(mock_device.plcnet) == PlcNetApi From 00d018c239f47e62dfeaf5787b88e050c63b7355 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Wed, 26 Aug 2020 07:51:14 +0200 Subject: [PATCH 42/93] . --- devolo_plc_api/clients/protobuf.py | 7 +++++++ devolo_plc_api/device_api/deviceapi.py | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/devolo_plc_api/clients/protobuf.py b/devolo_plc_api/clients/protobuf.py index db0ab28..53117f1 100644 --- a/devolo_plc_api/clients/protobuf.py +++ b/devolo_plc_api/clients/protobuf.py @@ -15,6 +15,13 @@ async def async_get(self, sub_url): self._logger.debug(f"Calling {url}") return await self._session.get(url) + async def async_post(self, sub_url): + from requests.auth import HTTPDigestAuth + url = f"{self.url}{sub_url}" + self._logger.debug(f"Calling {url}") + headers = {"realm":"devolo-api"} + return await self._session.post(url, auth=aiohttp.BasicAuth("devolo", "oloved03"), headers=headers) + def get(self, sub_url): """ Query URL synchronously. """ url = f"{self.url}{sub_url}" diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index 48a22b0..9c6bb9b 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -58,3 +58,11 @@ def get_wifi_guest_access(self) -> dict: response = self.get("WifiGuestAccessGet") wifi_guest_proto.ParseFromString(response.content) return wifi_guest_proto + + @_feature("wifi1") + async def set_wifi_guest_access(self): + wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSet() + print() + r = await self.async_post("WifiGuestAccessSet") + wifi_guest_proto.ParseFromString(await r.read()) + return wifi_guest_proto From 984cd616cdf2b547d091c673a153fd5a5d288570 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Wed, 26 Aug 2020 07:52:05 +0200 Subject: [PATCH 43/93] . --- devolo_plc_api/clients/protobuf.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/devolo_plc_api/clients/protobuf.py b/devolo_plc_api/clients/protobuf.py index 53117f1..096dea5 100644 --- a/devolo_plc_api/clients/protobuf.py +++ b/devolo_plc_api/clients/protobuf.py @@ -16,11 +16,9 @@ async def async_get(self, sub_url): return await self._session.get(url) async def async_post(self, sub_url): - from requests.auth import HTTPDigestAuth url = f"{self.url}{sub_url}" self._logger.debug(f"Calling {url}") - headers = {"realm":"devolo-api"} - return await self._session.post(url, auth=aiohttp.BasicAuth("devolo", "oloved03"), headers=headers) + return await self._session.post(url) def get(self, sub_url): """ Query URL synchronously. """ From 41d13eade0a2ab9e463add854b79f77effda2b2a Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Wed, 26 Aug 2020 08:19:08 +0200 Subject: [PATCH 44/93] preperation for password protected device --- devolo_plc_api/clients/protobuf.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/devolo_plc_api/clients/protobuf.py b/devolo_plc_api/clients/protobuf.py index a561e26..4518992 100644 --- a/devolo_plc_api/clients/protobuf.py +++ b/devolo_plc_api/clients/protobuf.py @@ -1,3 +1,5 @@ +from httpx import DigestAuth + class Protobuf: """ Google Protobuf client. @@ -15,10 +17,10 @@ async def async_get(self, sub_url): self._logger.debug(f"Calling {url}") return await self._session.get(url) - async def async_post(self, sub_url): + async def async_post(self, sub_url, data): url = f"{self.url}{sub_url}" self._logger.debug(f"Calling {url}") - return await self._session.post(url) + return await self._session.post(url, auth=DigestAuth("USER", "PASSWORD"), data=data) def get(self, sub_url): """ Query URL synchronously. """ From 24c69a42e9bfd483c5583df8e27da7208859f8f6 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Wed, 26 Aug 2020 08:19:38 +0200 Subject: [PATCH 45/93] switch to httpx --- devolo_plc_api/device.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/devolo_plc_api/device.py b/devolo_plc_api/device.py index 9336a94..2154973 100644 --- a/devolo_plc_api/device.py +++ b/devolo_plc_api/device.py @@ -4,8 +4,7 @@ import struct from datetime import date -import requests -from aiohttp import ClientSession +import httpx from zeroconf import ServiceBrowser, ServiceStateChange, Zeroconf from .device_api.deviceapi import DeviceApi @@ -39,23 +38,23 @@ def __init__(self, ip: str, zeroconf_instance: Zeroconf = None): self._zeroconf_instance = zeroconf_instance async def __aenter__(self): - self._session = ClientSession() + self._session = httpx.AsyncClient() self._zeroconf = self._zeroconf_instance or Zeroconf() loop = asyncio.get_running_loop() await loop.create_task(self._gather_apis()) return self + async def __aexit__(self, exc_type, exc_val, exc_tb): + if not self._zeroconf_instance: + self._zeroconf.close() + await self._session.aclose() + def __enter__(self): - self._session = requests.Session() + self._session = httpx.Client() self._zeroconf = self._zeroconf_instance or Zeroconf() asyncio.run(self._gather_apis()) return self - async def __aexit__(self, exc_type, exc_val, exc_tb): - if not self._zeroconf_instance: - self._zeroconf.close() - await self._session.close() - def __exit__(self, exc_type, exc_val, exc_tb): if not self._zeroconf_instance: self._zeroconf.close() From 8d105101709896a7769c435fcbad1e01e2d02b16 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Wed, 26 Aug 2020 08:21:37 +0200 Subject: [PATCH 46/93] add kwargs to _feature to use arguments in decorated functions --- devolo_plc_api/device_api/deviceapi.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index 5edf967..c275679 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -29,12 +29,12 @@ def __init__(self, ip: str, session: ClientSession, path: str, version: str, fea self._logger = logging.getLogger(self.__class__.__name__) - def _feature(feature: str): # type: ignore + def _feature(feature: str, **kwargs): # type: ignore """ Decorator to filter unsupported features before querying the device. """ def feature_decorator(method: Callable): - def wrapper(self): + def wrapper(self, **kwargs): if feature in self._features: - return method(self) + return method(self, **kwargs) else: raise FeatureNotSupported(f"The device does not support {method}.") return wrapper @@ -47,7 +47,7 @@ async def async_get_wifi_guest_access(self) -> dict: self._logger.debug("Getting wifi guest access") wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() response = await self.async_get("WifiGuestAccessGet") - wifi_guest_proto.ParseFromString(await response.read()) + wifi_guest_proto.ParseFromString(await response.aread()) return wifi_guest_proto @_feature("wifi1") @@ -60,9 +60,9 @@ def get_wifi_guest_access(self) -> dict: return wifi_guest_proto @_feature("wifi1") - async def set_wifi_guest_access(self): + async def async_set_wifi_guest_access(self, enable): wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSet() - print() - r = await self.async_post("WifiGuestAccessSet") - wifi_guest_proto.ParseFromString(await r.read()) + wifi_guest_proto.enable = enable + r = await self.async_post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) + wifi_guest_proto.ParseFromString(await r.aread()) return wifi_guest_proto From c9f9180ff38240a9caa6038bd5ec6194b19d94d2 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Wed, 26 Aug 2020 08:54:15 +0200 Subject: [PATCH 47/93] add credentials to calls --- devolo_plc_api/clients/protobuf.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/devolo_plc_api/clients/protobuf.py b/devolo_plc_api/clients/protobuf.py index 4518992..18ede1b 100644 --- a/devolo_plc_api/clients/protobuf.py +++ b/devolo_plc_api/clients/protobuf.py @@ -1,5 +1,6 @@ from httpx import DigestAuth + class Protobuf: """ Google Protobuf client. @@ -15,15 +16,20 @@ async def async_get(self, sub_url): """ Query URL asynchronously. """ url = f"{self.url}{sub_url}" self._logger.debug(f"Calling {url}") - return await self._session.get(url) + return await self._session.get(url, auth=DigestAuth(self._user, self._password)) async def async_post(self, sub_url, data): url = f"{self.url}{sub_url}" self._logger.debug(f"Calling {url}") - return await self._session.post(url, auth=DigestAuth("USER", "PASSWORD"), data=data) + return await self._session.post(url, auth=DigestAuth(self._user, self._password), data=data) def get(self, sub_url): """ Query URL synchronously. """ url = f"{self.url}{sub_url}" self._logger.debug(f"Calling {url}") - return self._session.get(url) + return self._session.get(url, auth=DigestAuth(self._user, self._password)) + + def post(self, sub_url, data): + url = f"{self.url}{sub_url}" + self._logger.debug(f"Calling {url}") + return self._session.post(url, auth=DigestAuth(self._user, self._password), data=data) From fc91481bfef115120c126407b370d74f63d7f3be Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Wed, 26 Aug 2020 08:55:01 +0200 Subject: [PATCH 48/93] add credentials --- devolo_plc_api/device.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/devolo_plc_api/device.py b/devolo_plc_api/device.py index 2154973..eb8f9c7 100644 --- a/devolo_plc_api/device.py +++ b/devolo_plc_api/device.py @@ -20,7 +20,7 @@ class Device: :param zeroconf_instance: Zeroconf instance to be potentially reused. """ - def __init__(self, ip: str, zeroconf_instance: Zeroconf = None): + def __init__(self, ip: str, password: str = None, zeroconf_instance: Zeroconf = None): self.firmware_date = date.fromtimestamp(0) self.firmware_version = "" self.ip = ip @@ -32,6 +32,7 @@ def __init__(self, ip: str, zeroconf_instance: Zeroconf = None): self.device = None self.plcnet = None + self.password = password self._info: dict = {"_dvl-plcnetapi._tcp.local.": {}, "_dvl-deviceapi._tcp.local.": {}} self._logger = logging.getLogger(self.__class__.__name__) @@ -82,7 +83,8 @@ async def _get_device_info(self): session=self._session, path=self._info[service_type]['Path'], version=self._info[service_type]['Version'], - features=self._info[service_type].get("Features", "")) + features=self._info[service_type].get("Features", ""), + password=self.password) async def _get_plcnet_info(self): """ Get information from the plcnet API. """ From b1d37d1419885f1edd664eb42ac97ab511378a37 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Wed, 26 Aug 2020 08:55:36 +0200 Subject: [PATCH 49/93] add credentials --- devolo_plc_api/device_api/deviceapi.py | 14 ++++++++++++-- devolo_plc_api/plcnet_api/plcnetapi.py | 10 +++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index c275679..cd52032 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -1,7 +1,7 @@ import logging from typing import Callable -from aiohttp import ClientSession +from httpx import Client from ..clients.protobuf import Protobuf from ..exceptions.feature import FeatureNotSupported @@ -19,7 +19,7 @@ class DeviceApi(Protobuf): :param features: Feature, the device has """ - def __init__(self, ip: str, session: ClientSession, path: str, version: str, features: str): + def __init__(self, ip: str, session: Client, path: str, version: str, features: str, password: str): self._ip = ip self._port = 14791 self._session = session @@ -27,6 +27,8 @@ def __init__(self, ip: str, session: ClientSession, path: str, version: str, fea self._version = version self._features = features.split(",") if features else [] self._logger = logging.getLogger(self.__class__.__name__) + self._user = "devolo" + self._password = password def _feature(feature: str, **kwargs): # type: ignore @@ -66,3 +68,11 @@ async def async_set_wifi_guest_access(self, enable): r = await self.async_post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) wifi_guest_proto.ParseFromString(await r.aread()) return wifi_guest_proto + + @_feature("wifi1") + async def set_wifi_guest_access(self, enable): + wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSet() + wifi_guest_proto.enable = enable + r = await self.async_post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) + wifi_guest_proto.ParseFromString(await r.aread()) + return wifi_guest_proto diff --git a/devolo_plc_api/plcnet_api/plcnetapi.py b/devolo_plc_api/plcnet_api/plcnetapi.py index eb14317..5ad5fac 100644 --- a/devolo_plc_api/plcnet_api/plcnetapi.py +++ b/devolo_plc_api/plcnet_api/plcnetapi.py @@ -1,6 +1,6 @@ import logging -from aiohttp import ClientSession +from httpx import Client from ..clients.protobuf import Protobuf from . import devolo_idl_proto_plcnetapi_getnetworkoverview_pb2 @@ -16,13 +16,17 @@ class PlcNetApi(Protobuf): :param version: Version of the API to use """ - def __init__(self, ip: str, session: ClientSession, path: str, version: str): + def __init__(self, ip: str, session: Client, path: str, version: str): self._ip = ip self._port = 47219 self._session = session self._path = path self._version = version self._logger = logging.getLogger(self.__class__.__name__) + # PLC APi is not password protected. + self._user = None + self._password = None + async def async_get_network_overview(self) -> dict: @@ -30,7 +34,7 @@ async def async_get_network_overview(self) -> dict: self._logger.debug("Getting network overview") network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() response = await self.async_get("GetNetworkOverview") - network_overview.ParseFromString(await response.read()) + network_overview.ParseFromString(await response.aread()) return network_overview def get_network_overview(self) -> dict: From 14e28a30005f4d8fa1160d1f3c71ff970b8ae85f Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Wed, 26 Aug 2020 10:31:19 +0200 Subject: [PATCH 50/93] add *args to deviceapi --- devolo_plc_api/device_api/deviceapi.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index cd52032..767c82b 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -31,12 +31,12 @@ def __init__(self, ip: str, session: Client, path: str, version: str, features: self._password = password - def _feature(feature: str, **kwargs): # type: ignore + def _feature(feature: str, *args, **kwargs): # type: ignore """ Decorator to filter unsupported features before querying the device. """ def feature_decorator(method: Callable): - def wrapper(self, **kwargs): + def wrapper(self, *args, **kwargs): if feature in self._features: - return method(self, **kwargs) + return method(self, *args, **kwargs) else: raise FeatureNotSupported(f"The device does not support {method}.") return wrapper From 99fe817f882368fcb442b5444244f977330c4679 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Wed, 26 Aug 2020 10:36:08 +0200 Subject: [PATCH 51/93] correct requirement --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 908faa5..7d5becc 100644 --- a/setup.py +++ b/setup.py @@ -22,9 +22,8 @@ "Operating System :: OS Independent", ], install_requires=[ - "aiohttp", + "httpx", "protobuf", - "requests", "zeroconf>=0.27.0", ], setup_requires=[ From 1b30e51cfd275c2b94f7a2db90c83e13a5d5e590 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Wed, 26 Aug 2020 10:43:24 +0200 Subject: [PATCH 52/93] Update packages --- README.md | 3 +-- setup.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 10d6e90..dfb1279 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,7 @@ Defining the system requirements with exact versions typically is difficult. But * Linux * Python 3.7.8 * pip 20.0.2 -* aiohttp 3.6.2 -* requests 2.24.0 +* httpx 0.14.2 * protobuf 3.11.4 * zeroconf 0.27.0 diff --git a/setup.py b/setup.py index 908faa5..697e68b 100644 --- a/setup.py +++ b/setup.py @@ -22,9 +22,8 @@ "Operating System :: OS Independent", ], install_requires=[ - "aiohttp", + "httpx>=0.14,<0.15", "protobuf", - "requests", "zeroconf>=0.27.0", ], setup_requires=[ From 7534b1fb4ae06bc43f77579de378a742db5326c5 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Wed, 26 Aug 2020 10:43:59 +0200 Subject: [PATCH 53/93] Cosmetic changes --- devolo_plc_api/clients/protobuf.py | 20 +++++++++++--------- devolo_plc_api/device.py | 11 +++++++---- devolo_plc_api/device_api/deviceapi.py | 18 ++++++++++-------- devolo_plc_api/plcnet_api/plcnetapi.py | 6 ++---- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/devolo_plc_api/clients/protobuf.py b/devolo_plc_api/clients/protobuf.py index 18ede1b..3d57fc5 100644 --- a/devolo_plc_api/clients/protobuf.py +++ b/devolo_plc_api/clients/protobuf.py @@ -3,7 +3,7 @@ class Protobuf: """ - Google Protobuf client. + Google Protobuf client. This client is not usable stand alone but needs to be derived. """ @property @@ -15,21 +15,23 @@ def url(self): async def async_get(self, sub_url): """ Query URL asynchronously. """ url = f"{self.url}{sub_url}" - self._logger.debug(f"Calling {url}") + self._logger.debug(f"Getting from {url}") return await self._session.get(url, auth=DigestAuth(self._user, self._password)) - async def async_post(self, sub_url, data): - url = f"{self.url}{sub_url}" - self._logger.debug(f"Calling {url}") - return await self._session.post(url, auth=DigestAuth(self._user, self._password), data=data) - def get(self, sub_url): """ Query URL synchronously. """ url = f"{self.url}{sub_url}" - self._logger.debug(f"Calling {url}") + self._logger.debug(f"Getting from {url}") return self._session.get(url, auth=DigestAuth(self._user, self._password)) + async def async_post(self, sub_url, data): + """ Post data asynchronously. """ + url = f"{self.url}{sub_url}" + self._logger.debug(f"Posting to {url}") + return await self._session.post(url, auth=DigestAuth(self._user, self._password), data=data) + def post(self, sub_url, data): + """ Post data synchronously. """ url = f"{self.url}{sub_url}" - self._logger.debug(f"Calling {url}") + self._logger.debug(f"Posting to {url}") return self._session.post(url, auth=DigestAuth(self._user, self._password), data=data) diff --git a/devolo_plc_api/device.py b/devolo_plc_api/device.py index eb8f9c7..e8af809 100644 --- a/devolo_plc_api/device.py +++ b/devolo_plc_api/device.py @@ -3,6 +3,7 @@ import socket import struct from datetime import date +from typing import Optional import httpx from zeroconf import ServiceBrowser, ServiceStateChange, Zeroconf @@ -17,22 +18,23 @@ class Device: Representing object for your devolo PLC device. It stores all properties and functionalities discovered during setup. :param ip: IP address of the device to communicate with. + :param password: Password of the Web-UI, if it is protected :param zeroconf_instance: Zeroconf instance to be potentially reused. """ - def __init__(self, ip: str, password: str = None, zeroconf_instance: Zeroconf = None): + def __init__(self, ip: str, password: Optional[str] = None, zeroconf_instance: Optional[Zeroconf] = None): self.firmware_date = date.fromtimestamp(0) self.firmware_version = "" self.ip = ip self.mac = "" self.mt_number = 0 + self.password = password self.product = "" self.technology = "" self.serial_number = 0 self.device = None self.plcnet = None - self.password = password self._info: dict = {"_dvl-plcnetapi._tcp.local.": {}, "_dvl-deviceapi._tcp.local.": {}} self._logger = logging.getLogger(self.__class__.__name__) @@ -63,10 +65,11 @@ def __exit__(self, exc_type, exc_val, exc_tb): async def _gather_apis(self): + """ Get information from all APIs. """ await asyncio.gather(self._get_device_info(), self._get_plcnet_info()) async def _get_device_info(self): - """ Get information from the device API. """ + """ Get information from the devolo Device API. """ service_type = "_dvl-deviceapi._tcp.local." try: await asyncio.wait_for(self._get_zeroconf_info(service_type=service_type), timeout=10) @@ -87,7 +90,7 @@ async def _get_device_info(self): password=self.password) async def _get_plcnet_info(self): - """ Get information from the plcnet API. """ + """ Get information from the devolo PlcNet API. """ service_type = "_dvl-plcnetapi._tcp.local." try: await asyncio.wait_for(self._get_zeroconf_info(service_type=service_type), timeout=10) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index cd52032..efa48e9 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -26,9 +26,9 @@ def __init__(self, ip: str, session: Client, path: str, version: str, features: self._path = path self._version = version self._features = features.split(",") if features else [] - self._logger = logging.getLogger(self.__class__.__name__) self._user = "devolo" self._password = password + self._logger = logging.getLogger(self.__class__.__name__) def _feature(feature: str, **kwargs): # type: ignore @@ -58,21 +58,23 @@ def get_wifi_guest_access(self) -> dict: self._logger.debug("Getting wifi guest access") wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() response = self.get("WifiGuestAccessGet") - wifi_guest_proto.ParseFromString(response.content) + wifi_guest_proto.ParseFromString(response.read()) return wifi_guest_proto @_feature("wifi1") - async def async_set_wifi_guest_access(self, enable): + async def async_set_wifi_guest_access(self, enable) -> dict: + """ Enable wifi guest access asynchronously. """ wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSet() wifi_guest_proto.enable = enable - r = await self.async_post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) - wifi_guest_proto.ParseFromString(await r.aread()) + response = await self.async_post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) + wifi_guest_proto.ParseFromString(await response.aread()) return wifi_guest_proto @_feature("wifi1") - async def set_wifi_guest_access(self, enable): + def set_wifi_guest_access(self, enable) -> dict: + """ Enable wifi guest access synchronously. """ wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSet() wifi_guest_proto.enable = enable - r = await self.async_post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) - wifi_guest_proto.ParseFromString(await r.aread()) + response = self.async_post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) + wifi_guest_proto.ParseFromString(response.read()) return wifi_guest_proto diff --git a/devolo_plc_api/plcnet_api/plcnetapi.py b/devolo_plc_api/plcnet_api/plcnetapi.py index 5ad5fac..fcee9ac 100644 --- a/devolo_plc_api/plcnet_api/plcnetapi.py +++ b/devolo_plc_api/plcnet_api/plcnetapi.py @@ -22,11 +22,9 @@ def __init__(self, ip: str, session: Client, path: str, version: str): self._session = session self._path = path self._version = version + self._user = None # PLC APi is not password protected. + self._password = None # PLC APi is not password protected. self._logger = logging.getLogger(self.__class__.__name__) - # PLC APi is not password protected. - self._user = None - self._password = None - async def async_get_network_overview(self) -> dict: From 17c9a911497c31b81ac811e63768eef3559978ed Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Wed, 26 Aug 2020 10:53:51 +0200 Subject: [PATCH 54/93] correct post in sync method --- devolo_plc_api/device_api/deviceapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index 029fe49..0c4d66d 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -75,6 +75,6 @@ def set_wifi_guest_access(self, enable) -> dict: """ Enable wifi guest access synchronously. """ wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSet() wifi_guest_proto.enable = enable - response = self.async_post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) + response = self.post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) wifi_guest_proto.ParseFromString(response.read()) return wifi_guest_proto From dbc8c3a9c2aed8a57900d9a1d8097fcedf99875e Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Wed, 26 Aug 2020 12:22:10 +0200 Subject: [PATCH 55/93] Rename Device fixtures --- tests/conftest.py | 4 ++-- tests/fixtures/{zeroconf.py => device.py} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename tests/fixtures/{zeroconf.py => device.py} (100%) diff --git a/tests/conftest.py b/tests/conftest.py index 4600926..66e5fde 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,9 +4,9 @@ import pytest -pytest_plugins = ['tests.fixtures.device_api', +pytest_plugins = ['tests.fixtures.device', + 'tests.fixtures.device_api', 'tests.fixtures.plcnet_api', - 'tests.fixtures.zeroconf', ] diff --git a/tests/fixtures/zeroconf.py b/tests/fixtures/device.py similarity index 100% rename from tests/fixtures/zeroconf.py rename to tests/fixtures/device.py From 8f9a4efbbfaf6257ef77c61bd9476dd1f4874731 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Wed, 26 Aug 2020 12:22:30 +0200 Subject: [PATCH 56/93] WIP: add testcase for _gather_apis --- tests/test_device.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_device.py b/tests/test_device.py index 898ef56..3e5278e 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -9,6 +9,16 @@ class TestDevice: + + @pytest.mark.asyncio + async def test__gather_apis(self, mocker, mock_device): + spy_device_info = mocker.spy(mock_device, "_get_device_info") + spy_plcnet_info = mocker.spy(mock_device, "_get_plcnet_info") + with patch("devolo_plc_api.device.Device._get_device_info", new=CoroutineMock()), \ + patch("devolo_plc_api.device.Device._get_plcnet_info", new=CoroutineMock()): + assert spy_device_info.call_count == 1 + assert spy_plcnet_info.call_count == 1 + @pytest.mark.asyncio @pytest.mark.usefixtures("mock_device_api") async def test___get_device_info(self, mock_device): From e655f9ec8003966bc23d2ff16ea1aa0aa4cbe3e4 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Wed, 26 Aug 2020 13:02:44 +0200 Subject: [PATCH 57/93] fix test__gather_apis --- tests/test_device.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_device.py b/tests/test_device.py index 3e5278e..e0f11dd 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -1,9 +1,7 @@ from datetime import date from unittest.mock import patch - import pytest from asynctest import CoroutineMock - from devolo_plc_api.device_api.deviceapi import DeviceApi from devolo_plc_api.plcnet_api.plcnetapi import PlcNetApi @@ -12,10 +10,11 @@ class TestDevice: @pytest.mark.asyncio async def test__gather_apis(self, mocker, mock_device): - spy_device_info = mocker.spy(mock_device, "_get_device_info") - spy_plcnet_info = mocker.spy(mock_device, "_get_plcnet_info") with patch("devolo_plc_api.device.Device._get_device_info", new=CoroutineMock()), \ patch("devolo_plc_api.device.Device._get_plcnet_info", new=CoroutineMock()): + spy_device_info = mocker.spy(mock_device, "_get_device_info") + spy_plcnet_info = mocker.spy(mock_device, "_get_plcnet_info") + await mock_device._gather_apis() assert spy_device_info.call_count == 1 assert spy_plcnet_info.call_count == 1 From 60b79bde027f77cc81f654689937bfeb7e400814 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Wed, 26 Aug 2020 13:39:09 +0200 Subject: [PATCH 58/93] add some wifi calls --- devolo_plc_api/device_api/deviceapi.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index 0c4d66d..1657b81 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -42,6 +42,27 @@ def wrapper(self, *args, **kwargs): return wrapper return feature_decorator + @_feature("wifi1") + async def async_get_wifi_connected_station(self): + wifi_connected_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiConnectedStationsGet() + response = await self.async_get("WifiConnectedStationsGet") + wifi_connected_proto.ParseFromString(await response.aread()) + return wifi_connected_proto + + @_feature("wifi1") + async def async_get_wifi_neighbor_access_points(self): + # ReadTimeout + wifi_neighbor_aps = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiNeighborAPsGet() + response = await self.async_get("WifiNeighborAPsGet") + wifi_neighbor_aps.ParseFromString(await response.aread()) + return wifi_neighbor_aps + + @_feature("wifi1") + async def async_get_wifi_repeated_access_points(self): + wifi_connected_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiRepeatedAPsGet() + response = await self.async_get("WifiRepeatedAPsGet") + wifi_connected_proto.ParseFromString(await response.aread()) + return wifi_connected_proto @_feature("wifi1") async def async_get_wifi_guest_access(self) -> dict: From 82e5e33ffa49ede0672c1a2bcd486f56632567b7 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Wed, 26 Aug 2020 14:36:15 +0200 Subject: [PATCH 59/93] add todos workflow --- .github/workflows/convert_todos_to_issues.yml | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/convert_todos_to_issues.yml diff --git a/.github/workflows/convert_todos_to_issues.yml b/.github/workflows/convert_todos_to_issues.yml new file mode 100644 index 0000000..f3296db --- /dev/null +++ b/.github/workflows/convert_todos_to_issues.yml @@ -0,0 +1,20 @@ +name: "TODOs to issues" +on: + push: + branches: + - development +jobs: + build: + runs-on: "ubuntu-latest" + steps: + - uses: "actions/checkout@master" + - name: "TODO to Issue" + uses: "alstr/todo-to-issue-action@master" + with: + REPO: ${{ github.repository }} + BEFORE: ${{ github.event.before }} + SHA: ${{ github.sha }} + TOKEN: ${{ secrets.GITHUB_TOKEN }} + LABEL: "# TODO:" + COMMENT_MARKER: "#" + id: "todo" \ No newline at end of file From df491c3ff2b47eb619428a567774865b4b23c2a4 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Wed, 26 Aug 2020 14:36:38 +0200 Subject: [PATCH 60/93] add several endpoints --- ..._idl_proto_plcnetapi_identifydevice_pb2.py | 186 ++++++++++++++++++ ...l_proto_plcnetapi_setuserdevicename_pb2.py | 158 +++++++++++++++ devolo_plc_api/plcnet_api/plcnetapi.py | 36 +++- 3 files changed, 379 insertions(+), 1 deletion(-) create mode 100644 devolo_plc_api/plcnet_api/devolo_idl_proto_plcnetapi_identifydevice_pb2.py create mode 100644 devolo_plc_api/plcnet_api/devolo_idl_proto_plcnetapi_setuserdevicename_pb2.py diff --git a/devolo_plc_api/plcnet_api/devolo_idl_proto_plcnetapi_identifydevice_pb2.py b/devolo_plc_api/plcnet_api/devolo_idl_proto_plcnetapi_identifydevice_pb2.py new file mode 100644 index 0000000..5baecdd --- /dev/null +++ b/devolo_plc_api/plcnet_api/devolo_idl_proto_plcnetapi_identifydevice_pb2.py @@ -0,0 +1,186 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: devolo_idl_proto_plcnetapi_identifydevice.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='devolo_idl_proto_plcnetapi_identifydevice.proto', + package='plcnet.api', + syntax='proto3', + serialized_pb=_b('\n/devolo_idl_proto_plcnetapi_identifydevice.proto\x12\nplcnet.api\"*\n\x13IdentifyDeviceStart\x12\x13\n\x0bmac_address\x18\x01 \x01(\t\")\n\x12IdentifyDeviceStop\x12\x13\n\x0bmac_address\x18\x01 \x01(\t\"\xc2\x01\n\x16IdentifyDeviceResponse\x12\x39\n\x06result\x18\x01 \x01(\x0e\x32).plcnet.api.IdentifyDeviceResponse.Result\"m\n\x06Result\x12\x0b\n\x07SUCCESS\x10\x00\x12\x13\n\x0fMACADDR_INVALID\x10\x01\x12\x13\n\x0fMACADDR_UNKNOWN\x10\x02\x12\x18\n\x13\x43OMMUNICATION_ERROR\x10\xfe\x01\x12\x12\n\rUNKNOWN_ERROR\x10\xff\x01\x42\x12\n\x06plcnetB\x08identityb\x06proto3') +) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + + + +_IDENTIFYDEVICERESPONSE_RESULT = _descriptor.EnumDescriptor( + name='Result', + full_name='plcnet.api.IdentifyDeviceResponse.Result', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='SUCCESS', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='MACADDR_INVALID', index=1, number=1, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='MACADDR_UNKNOWN', index=2, number=2, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='COMMUNICATION_ERROR', index=3, number=254, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='UNKNOWN_ERROR', index=4, number=255, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=236, + serialized_end=345, +) +_sym_db.RegisterEnumDescriptor(_IDENTIFYDEVICERESPONSE_RESULT) + + +_IDENTIFYDEVICESTART = _descriptor.Descriptor( + name='IdentifyDeviceStart', + full_name='plcnet.api.IdentifyDeviceStart', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='mac_address', full_name='plcnet.api.IdentifyDeviceStart.mac_address', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=63, + serialized_end=105, +) + + +_IDENTIFYDEVICESTOP = _descriptor.Descriptor( + name='IdentifyDeviceStop', + full_name='plcnet.api.IdentifyDeviceStop', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='mac_address', full_name='plcnet.api.IdentifyDeviceStop.mac_address', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=107, + serialized_end=148, +) + + +_IDENTIFYDEVICERESPONSE = _descriptor.Descriptor( + name='IdentifyDeviceResponse', + full_name='plcnet.api.IdentifyDeviceResponse', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='result', full_name='plcnet.api.IdentifyDeviceResponse.result', index=0, + number=1, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + _IDENTIFYDEVICERESPONSE_RESULT, + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=151, + serialized_end=345, +) + +_IDENTIFYDEVICERESPONSE.fields_by_name['result'].enum_type = _IDENTIFYDEVICERESPONSE_RESULT +_IDENTIFYDEVICERESPONSE_RESULT.containing_type = _IDENTIFYDEVICERESPONSE +DESCRIPTOR.message_types_by_name['IdentifyDeviceStart'] = _IDENTIFYDEVICESTART +DESCRIPTOR.message_types_by_name['IdentifyDeviceStop'] = _IDENTIFYDEVICESTOP +DESCRIPTOR.message_types_by_name['IdentifyDeviceResponse'] = _IDENTIFYDEVICERESPONSE + +IdentifyDeviceStart = _reflection.GeneratedProtocolMessageType('IdentifyDeviceStart', (_message.Message,), dict( + DESCRIPTOR = _IDENTIFYDEVICESTART, + __module__ = 'devolo_idl_proto_plcnetapi_identifydevice_pb2' + # @@protoc_insertion_point(class_scope:plcnet.api.IdentifyDeviceStart) + )) +_sym_db.RegisterMessage(IdentifyDeviceStart) + +IdentifyDeviceStop = _reflection.GeneratedProtocolMessageType('IdentifyDeviceStop', (_message.Message,), dict( + DESCRIPTOR = _IDENTIFYDEVICESTOP, + __module__ = 'devolo_idl_proto_plcnetapi_identifydevice_pb2' + # @@protoc_insertion_point(class_scope:plcnet.api.IdentifyDeviceStop) + )) +_sym_db.RegisterMessage(IdentifyDeviceStop) + +IdentifyDeviceResponse = _reflection.GeneratedProtocolMessageType('IdentifyDeviceResponse', (_message.Message,), dict( + DESCRIPTOR = _IDENTIFYDEVICERESPONSE, + __module__ = 'devolo_idl_proto_plcnetapi_identifydevice_pb2' + # @@protoc_insertion_point(class_scope:plcnet.api.IdentifyDeviceResponse) + )) +_sym_db.RegisterMessage(IdentifyDeviceResponse) + + +DESCRIPTOR.has_options = True +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\006plcnetB\010identity')) +# @@protoc_insertion_point(module_scope) diff --git a/devolo_plc_api/plcnet_api/devolo_idl_proto_plcnetapi_setuserdevicename_pb2.py b/devolo_plc_api/plcnet_api/devolo_idl_proto_plcnetapi_setuserdevicename_pb2.py new file mode 100644 index 0000000..52e9527 --- /dev/null +++ b/devolo_plc_api/plcnet_api/devolo_idl_proto_plcnetapi_setuserdevicename_pb2.py @@ -0,0 +1,158 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: devolo_idl_proto_plcnetapi_setuserdevicename.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='devolo_idl_proto_plcnetapi_setuserdevicename.proto', + package='plcnet.api', + syntax='proto3', + serialized_pb=_b('\n2devolo_idl_proto_plcnetapi_setuserdevicename.proto\x12\nplcnet.api\"B\n\x11SetUserDeviceName\x12\x13\n\x0bmac_address\x18\x01 \x01(\t\x12\x18\n\x10user_device_name\x18\x02 \x01(\t\"\xe2\x01\n\x19SetUserDeviceNameResponse\x12<\n\x06result\x18\x01 \x01(\x0e\x32,.plcnet.api.SetUserDeviceNameResponse.Result\"\x86\x01\n\x06Result\x12\x0b\n\x07SUCCESS\x10\x00\x12\x13\n\x0fMACADDR_INVALID\x10\x01\x12\x13\n\x0fMACADDR_UNKNOWN\x10\x02\x12\x17\n\x13\x44\x45VICE_NAME_INVALID\x10\x03\x12\x18\n\x13\x43OMMUNICATION_ERROR\x10\xfe\x01\x12\x12\n\rUNKNOWN_ERROR\x10\xff\x01\x42\x0e\n\x06plcnetB\x04nameb\x06proto3') +) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + + + +_SETUSERDEVICENAMERESPONSE_RESULT = _descriptor.EnumDescriptor( + name='Result', + full_name='plcnet.api.SetUserDeviceNameResponse.Result', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='SUCCESS', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='MACADDR_INVALID', index=1, number=1, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='MACADDR_UNKNOWN', index=2, number=2, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='DEVICE_NAME_INVALID', index=3, number=3, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='COMMUNICATION_ERROR', index=4, number=254, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='UNKNOWN_ERROR', index=5, number=255, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=227, + serialized_end=361, +) +_sym_db.RegisterEnumDescriptor(_SETUSERDEVICENAMERESPONSE_RESULT) + + +_SETUSERDEVICENAME = _descriptor.Descriptor( + name='SetUserDeviceName', + full_name='plcnet.api.SetUserDeviceName', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='mac_address', full_name='plcnet.api.SetUserDeviceName.mac_address', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='user_device_name', full_name='plcnet.api.SetUserDeviceName.user_device_name', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=66, + serialized_end=132, +) + + +_SETUSERDEVICENAMERESPONSE = _descriptor.Descriptor( + name='SetUserDeviceNameResponse', + full_name='plcnet.api.SetUserDeviceNameResponse', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='result', full_name='plcnet.api.SetUserDeviceNameResponse.result', index=0, + number=1, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + _SETUSERDEVICENAMERESPONSE_RESULT, + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=135, + serialized_end=361, +) + +_SETUSERDEVICENAMERESPONSE.fields_by_name['result'].enum_type = _SETUSERDEVICENAMERESPONSE_RESULT +_SETUSERDEVICENAMERESPONSE_RESULT.containing_type = _SETUSERDEVICENAMERESPONSE +DESCRIPTOR.message_types_by_name['SetUserDeviceName'] = _SETUSERDEVICENAME +DESCRIPTOR.message_types_by_name['SetUserDeviceNameResponse'] = _SETUSERDEVICENAMERESPONSE + +SetUserDeviceName = _reflection.GeneratedProtocolMessageType('SetUserDeviceName', (_message.Message,), dict( + DESCRIPTOR = _SETUSERDEVICENAME, + __module__ = 'devolo_idl_proto_plcnetapi_setuserdevicename_pb2' + # @@protoc_insertion_point(class_scope:plcnet.api.SetUserDeviceName) + )) +_sym_db.RegisterMessage(SetUserDeviceName) + +SetUserDeviceNameResponse = _reflection.GeneratedProtocolMessageType('SetUserDeviceNameResponse', (_message.Message,), dict( + DESCRIPTOR = _SETUSERDEVICENAMERESPONSE, + __module__ = 'devolo_idl_proto_plcnetapi_setuserdevicename_pb2' + # @@protoc_insertion_point(class_scope:plcnet.api.SetUserDeviceNameResponse) + )) +_sym_db.RegisterMessage(SetUserDeviceNameResponse) + + +DESCRIPTOR.has_options = True +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\006plcnetB\004name')) +# @@protoc_insertion_point(module_scope) diff --git a/devolo_plc_api/plcnet_api/plcnetapi.py b/devolo_plc_api/plcnet_api/plcnetapi.py index fcee9ac..ff4914c 100644 --- a/devolo_plc_api/plcnet_api/plcnetapi.py +++ b/devolo_plc_api/plcnet_api/plcnetapi.py @@ -1,9 +1,12 @@ import logging +from google.protobuf.json_format import MessageToDict from httpx import Client from ..clients.protobuf import Protobuf from . import devolo_idl_proto_plcnetapi_getnetworkoverview_pb2 +from . import devolo_idl_proto_plcnetapi_identifydevice_pb2 +from . import devolo_idl_proto_plcnetapi_setuserdevicename_pb2 class PlcNetApi(Protobuf): @@ -16,12 +19,13 @@ class PlcNetApi(Protobuf): :param version: Version of the API to use """ - def __init__(self, ip: str, session: Client, path: str, version: str): + def __init__(self, ip: str, session: Client, path: str, version: str, mac: str): self._ip = ip self._port = 47219 self._session = session self._path = path self._version = version + self._mac = mac self._user = None # PLC APi is not password protected. self._password = None # PLC APi is not password protected. self._logger = logging.getLogger(self.__class__.__name__) @@ -42,3 +46,33 @@ def get_network_overview(self) -> dict: response = self.get("GetNetworkOverview") network_overview.ParseFromString(response.content) return network_overview + + async def identify_device_start(self): + identify_device = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceStart() + identify_device.mac_address = self._mac + response = await self.async_post("IdentifyDeviceStart", data=identify_device.SerializeToString()) + r = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceResponse() + # TODO: ParseFromString --> AttributeError + # r.ParseFromstring(await response.aread()) + return MessageToDict(message=r, including_default_value_fields=True, preserving_proto_field_name=True) + + async def identify_device_stop(self): + identify_device = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceStop() + identify_device.mac_address = self._mac + response = await self.async_post("IdentifyDeviceStop", data=identify_device.SerializeToString()) + # TODO: ParseFromString isn't working. + identify_device.ParseFromString(await response.aread()) + r = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceResponse() + # TODO: ParseFromString --> AttributeError + # r.ParseFromstring(await response.aread()) + return MessageToDict(message=r, including_default_value_fields=True, preserving_proto_field_name=True) + + async def set_user_device_name(self, name): + # TODO: ReadTimeout ?? + set_user_name = devolo_idl_proto_plcnetapi_setuserdevicename_pb2.SetUserDeviceName() + set_user_name.mac_address = self._mac + set_user_name.user_device_name = name + response = await self.async_post("SetUserDeviceName", data=set_user_name.SerializeToString()) + r = devolo_idl_proto_plcnetapi_setuserdevicename_pb2.SetUserDeviceNameResponse() + r.ParseFromString(await response.aread()) + return MessageToDict(message=r, including_default_value_fields=True, preserving_proto_field_name=True) From 25ddd6800a821428b38ca89553ce4078f03869d4 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Wed, 26 Aug 2020 14:40:54 +0200 Subject: [PATCH 61/93] add several endpoints --- devolo_plc_api/device.py | 3 +- devolo_plc_api/device_api/deviceapi.py | 25 +- ...olo_idl_proto_deviceapi_ledsettings_pb2.py | 224 ++++++++++++++++++ tests/mocks/mock_plcnet_api.py | 2 +- 4 files changed, 249 insertions(+), 5 deletions(-) create mode 100644 devolo_plc_api/device_api/devolo_idl_proto_deviceapi_ledsettings_pb2.py diff --git a/devolo_plc_api/device.py b/devolo_plc_api/device.py index e8af809..7993ff5 100644 --- a/devolo_plc_api/device.py +++ b/devolo_plc_api/device.py @@ -103,7 +103,8 @@ async def _get_plcnet_info(self): self.plcnet = PlcNetApi(ip=self.ip, session=self._session, path=self._info[service_type]['Path'], - version=self._info[service_type]['Version']) + version=self._info[service_type]['Version'], + mac=self.mac) async def _get_zeroconf_info(self, service_type: str): """ Browse for the desired mDNS service types and query them. """ diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index 1657b81..a4510f9 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -2,10 +2,12 @@ from typing import Callable from httpx import Client +from google.protobuf.json_format import MessageToDict from ..clients.protobuf import Protobuf from ..exceptions.feature import FeatureNotSupported from . import devolo_idl_proto_deviceapi_wifinetwork_pb2 +from . import devolo_idl_proto_deviceapi_ledsettings_pb2 class DeviceApi(Protobuf): @@ -42,6 +44,22 @@ def wrapper(self, *args, **kwargs): return wrapper return feature_decorator + @_feature("led") + async def async_get_led_setting(self): + led_setting = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsGet() + response = await self.async_get("LedSettingsGet") + led_setting.ParseFromString(await response.aread()) + return MessageToDict(message=led_setting, including_default_value_fields=True, preserving_proto_field_name=True) + + @_feature("led") + async def async_set_led_setting(self, enable: bool): + led_setting = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsSet() + led_setting.state = int(not enable) + response = await self.async_post("LedSettingsSet", data=led_setting.SerializeToString()) + r = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsSetResponse() + r.ParseFromString(await response.aread()) + return MessageToDict(message=r, including_default_value_fields=True, preserving_proto_field_name=True) + @_feature("wifi1") async def async_get_wifi_connected_station(self): wifi_connected_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiConnectedStationsGet() @@ -71,7 +89,7 @@ async def async_get_wifi_guest_access(self) -> dict: wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() response = await self.async_get("WifiGuestAccessGet") wifi_guest_proto.ParseFromString(await response.aread()) - return wifi_guest_proto + return MessageToDict(wifi_guest_proto) @_feature("wifi1") def get_wifi_guest_access(self) -> dict: @@ -88,8 +106,9 @@ async def async_set_wifi_guest_access(self, enable) -> dict: wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSet() wifi_guest_proto.enable = enable response = await self.async_post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) - wifi_guest_proto.ParseFromString(await response.aread()) - return wifi_guest_proto + r = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSetResponse() + r.ParseFromString(await response.aread()) + return MessageToDict(message=r, including_default_value_fields=True, preserving_proto_field_name=True) @_feature("wifi1") def set_wifi_guest_access(self, enable) -> dict: diff --git a/devolo_plc_api/device_api/devolo_idl_proto_deviceapi_ledsettings_pb2.py b/devolo_plc_api/device_api/devolo_idl_proto_deviceapi_ledsettings_pb2.py new file mode 100644 index 0000000..814784d --- /dev/null +++ b/devolo_plc_api/device_api/devolo_idl_proto_deviceapi_ledsettings_pb2.py @@ -0,0 +1,224 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: devolo_idl_proto_deviceapi_ledsettings.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='devolo_idl_proto_deviceapi_ledsettings.proto', + package='device.api', + syntax='proto3', + serialized_pb=_b('\n,devolo_idl_proto_deviceapi_ledsettings.proto\x12\ndevice.api\"i\n\x0eLedSettingsGet\x12\x32\n\x05state\x18\x01 \x01(\x0e\x32#.device.api.LedSettingsGet.Ledstate\"#\n\x08Ledstate\x12\n\n\x06LED_ON\x10\x00\x12\x0b\n\x07LED_OFF\x10\x01\"i\n\x0eLedSettingsSet\x12\x32\n\x05state\x18\x01 \x01(\x0e\x32#.device.api.LedSettingsSet.Ledstate\"#\n\x08Ledstate\x12\n\n\x06LED_ON\x10\x00\x12\x0b\n\x07LED_OFF\x10\x01\"~\n\x16LedSettingsSetResponse\x12\x39\n\x06result\x18\x01 \x01(\x0e\x32).device.api.LedSettingsSetResponse.Result\")\n\x06Result\x12\x0b\n\x07SUCCESS\x10\x00\x12\x12\n\rUNKNOWN_ERROR\x10\xff\x01\x42\x0e\n\x06\x64\x65viceB\x04ledsb\x06proto3') +) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + + + +_LEDSETTINGSGET_LEDSTATE = _descriptor.EnumDescriptor( + name='Ledstate', + full_name='device.api.LedSettingsGet.Ledstate', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='LED_ON', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='LED_OFF', index=1, number=1, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=130, + serialized_end=165, +) +_sym_db.RegisterEnumDescriptor(_LEDSETTINGSGET_LEDSTATE) + +_LEDSETTINGSSET_LEDSTATE = _descriptor.EnumDescriptor( + name='Ledstate', + full_name='device.api.LedSettingsSet.Ledstate', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='LED_ON', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='LED_OFF', index=1, number=1, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=130, + serialized_end=165, +) +_sym_db.RegisterEnumDescriptor(_LEDSETTINGSSET_LEDSTATE) + +_LEDSETTINGSSETRESPONSE_RESULT = _descriptor.EnumDescriptor( + name='Result', + full_name='device.api.LedSettingsSetResponse.Result', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='SUCCESS', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='UNKNOWN_ERROR', index=1, number=255, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=359, + serialized_end=400, +) +_sym_db.RegisterEnumDescriptor(_LEDSETTINGSSETRESPONSE_RESULT) + + +_LEDSETTINGSGET = _descriptor.Descriptor( + name='LedSettingsGet', + full_name='device.api.LedSettingsGet', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='state', full_name='device.api.LedSettingsGet.state', index=0, + number=1, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + _LEDSETTINGSGET_LEDSTATE, + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=60, + serialized_end=165, +) + + +_LEDSETTINGSSET = _descriptor.Descriptor( + name='LedSettingsSet', + full_name='device.api.LedSettingsSet', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='state', full_name='device.api.LedSettingsSet.state', index=0, + number=1, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + _LEDSETTINGSSET_LEDSTATE, + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=167, + serialized_end=272, +) + + +_LEDSETTINGSSETRESPONSE = _descriptor.Descriptor( + name='LedSettingsSetResponse', + full_name='device.api.LedSettingsSetResponse', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='result', full_name='device.api.LedSettingsSetResponse.result', index=0, + number=1, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + _LEDSETTINGSSETRESPONSE_RESULT, + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=274, + serialized_end=400, +) + +_LEDSETTINGSGET.fields_by_name['state'].enum_type = _LEDSETTINGSGET_LEDSTATE +_LEDSETTINGSGET_LEDSTATE.containing_type = _LEDSETTINGSGET +_LEDSETTINGSSET.fields_by_name['state'].enum_type = _LEDSETTINGSSET_LEDSTATE +_LEDSETTINGSSET_LEDSTATE.containing_type = _LEDSETTINGSSET +_LEDSETTINGSSETRESPONSE.fields_by_name['result'].enum_type = _LEDSETTINGSSETRESPONSE_RESULT +_LEDSETTINGSSETRESPONSE_RESULT.containing_type = _LEDSETTINGSSETRESPONSE +DESCRIPTOR.message_types_by_name['LedSettingsGet'] = _LEDSETTINGSGET +DESCRIPTOR.message_types_by_name['LedSettingsSet'] = _LEDSETTINGSSET +DESCRIPTOR.message_types_by_name['LedSettingsSetResponse'] = _LEDSETTINGSSETRESPONSE + +LedSettingsGet = _reflection.GeneratedProtocolMessageType('LedSettingsGet', (_message.Message,), dict( + DESCRIPTOR = _LEDSETTINGSGET, + __module__ = 'devolo_idl_proto_deviceapi_ledsettings_pb2' + # @@protoc_insertion_point(class_scope:device.api.LedSettingsGet) + )) +_sym_db.RegisterMessage(LedSettingsGet) + +LedSettingsSet = _reflection.GeneratedProtocolMessageType('LedSettingsSet', (_message.Message,), dict( + DESCRIPTOR = _LEDSETTINGSSET, + __module__ = 'devolo_idl_proto_deviceapi_ledsettings_pb2' + # @@protoc_insertion_point(class_scope:device.api.LedSettingsSet) + )) +_sym_db.RegisterMessage(LedSettingsSet) + +LedSettingsSetResponse = _reflection.GeneratedProtocolMessageType('LedSettingsSetResponse', (_message.Message,), dict( + DESCRIPTOR = _LEDSETTINGSSETRESPONSE, + __module__ = 'devolo_idl_proto_deviceapi_ledsettings_pb2' + # @@protoc_insertion_point(class_scope:device.api.LedSettingsSetResponse) + )) +_sym_db.RegisterMessage(LedSettingsSetResponse) + + +DESCRIPTOR.has_options = True +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\006deviceB\004leds')) +# @@protoc_insertion_point(module_scope) diff --git a/tests/mocks/mock_plcnet_api.py b/tests/mocks/mock_plcnet_api.py index 57ec66b..2d8c3b2 100644 --- a/tests/mocks/mock_plcnet_api.py +++ b/tests/mocks/mock_plcnet_api.py @@ -1,3 +1,3 @@ class PlcNetApi(): - def __init__(self, ip, session, path, version): + def __init__(self, ip, session, path, version, mac): pass From efecb42356776a38a80fced3441e9542bd9f22cd Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Wed, 26 Aug 2020 16:55:37 +0200 Subject: [PATCH 62/93] Reduce timeout --- devolo_plc_api/device.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/devolo_plc_api/device.py b/devolo_plc_api/device.py index 7993ff5..a94b7ad 100644 --- a/devolo_plc_api/device.py +++ b/devolo_plc_api/device.py @@ -72,7 +72,7 @@ async def _get_device_info(self): """ Get information from the devolo Device API. """ service_type = "_dvl-deviceapi._tcp.local." try: - await asyncio.wait_for(self._get_zeroconf_info(service_type=service_type), timeout=10) + await asyncio.wait_for(self._get_zeroconf_info(service_type=service_type), timeout=3) except asyncio.TimeoutError: raise DeviceNotFound(f"The device {self.ip} did not answer.") from None @@ -93,11 +93,11 @@ async def _get_plcnet_info(self): """ Get information from the devolo PlcNet API. """ service_type = "_dvl-plcnetapi._tcp.local." try: - await asyncio.wait_for(self._get_zeroconf_info(service_type=service_type), timeout=10) + await asyncio.wait_for(self._get_zeroconf_info(service_type=service_type), timeout=3) except asyncio.TimeoutError: raise DeviceNotFound(f"The device {self.ip} did not answer.") from None - self.mac = self._info[service_type].get("PlcMacAddress", "") + self.mac = self._info[service_type]['PlcMacAddress'] self.technology = self._info[service_type].get("PlcTechnology", "") self.plcnet = PlcNetApi(ip=self.ip, From 6cd565a780a2676f6e20469ea1b25f16657c886c Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Wed, 26 Aug 2020 16:56:13 +0200 Subject: [PATCH 63/93] Cosmetic changes --- devolo_plc_api/device_api/deviceapi.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index a4510f9..8e73981 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -46,6 +46,7 @@ def wrapper(self, *args, **kwargs): @_feature("led") async def async_get_led_setting(self): + """ Get LED setting asynchronously. """ led_setting = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsGet() response = await self.async_get("LedSettingsGet") led_setting.ParseFromString(await response.aread()) @@ -69,7 +70,7 @@ async def async_get_wifi_connected_station(self): @_feature("wifi1") async def async_get_wifi_neighbor_access_points(self): - # ReadTimeout + # TODO: Why does WifiNeighborAPsGet send a ReadTimeout wifi_neighbor_aps = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiNeighborAPsGet() response = await self.async_get("WifiNeighborAPsGet") wifi_neighbor_aps.ParseFromString(await response.aread()) From e3d280e454aa7271218cdf40deee8860c8e1079d Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Wed, 26 Aug 2020 16:56:42 +0200 Subject: [PATCH 64/93] Add test for _get_zeroconf_info --- tests/fixtures/device.py | 7 +++++++ tests/mocks/mock_service_browser.py | 6 ++++++ tests/test_device.py | 19 +++++++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 tests/mocks/mock_service_browser.py diff --git a/tests/fixtures/device.py b/tests/fixtures/device.py index 356d949..8de5d16 100644 --- a/tests/fixtures/device.py +++ b/tests/fixtures/device.py @@ -1,6 +1,7 @@ import pytest from devolo_plc_api.device import Device +from ..mocks.mock_service_browser import ServiceBrowser @pytest.fixture() @@ -8,4 +9,10 @@ def mock_device(request): device = Device(ip="192.168.0.10") device._info = request.cls.device_info device._session = None + device._zeroconf = None return device + + +@pytest.fixture() +def mock_service_browser(mocker): + mocker.patch("zeroconf.ServiceBrowser", ServiceBrowser) diff --git a/tests/mocks/mock_service_browser.py b/tests/mocks/mock_service_browser.py new file mode 100644 index 0000000..1e5aa70 --- /dev/null +++ b/tests/mocks/mock_service_browser.py @@ -0,0 +1,6 @@ +class ServiceBrowser: + def __init__(self, zeroconf, service_type, handler): + pass + + def cancel(self): + pass diff --git a/tests/test_device.py b/tests/test_device.py index e0f11dd..c940845 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -1,10 +1,14 @@ from datetime import date from unittest.mock import patch + import pytest from asynctest import CoroutineMock + from devolo_plc_api.device_api.deviceapi import DeviceApi from devolo_plc_api.plcnet_api.plcnetapi import PlcNetApi +from .mocks.mock_service_browser import ServiceBrowser + class TestDevice: @@ -15,12 +19,13 @@ async def test__gather_apis(self, mocker, mock_device): spy_device_info = mocker.spy(mock_device, "_get_device_info") spy_plcnet_info = mocker.spy(mock_device, "_get_plcnet_info") await mock_device._gather_apis() + assert spy_device_info.call_count == 1 assert spy_plcnet_info.call_count == 1 @pytest.mark.asyncio @pytest.mark.usefixtures("mock_device_api") - async def test___get_device_info(self, mock_device): + async def test__get_device_info(self, mock_device): with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=CoroutineMock()): device_info = self.device_info['_dvl-deviceapi._tcp.local.'] await mock_device._get_device_info() @@ -34,7 +39,7 @@ async def test___get_device_info(self, mock_device): @pytest.mark.asyncio @pytest.mark.usefixtures("mock_plcnet_api") - async def test___get_plcnet_info(self, mock_device): + async def test__get_plcnet_info(self, mock_device): with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=CoroutineMock()): device_info = self.device_info['_dvl-plcnetapi._tcp.local.'] await mock_device._get_plcnet_info() @@ -42,3 +47,13 @@ async def test___get_plcnet_info(self, mock_device): assert mock_device.mac == device_info['PlcMacAddress'] assert mock_device.technology == device_info['PlcTechnology'] assert type(mock_device.plcnet) == PlcNetApi + + @pytest.mark.asyncio + @pytest.mark.usefixtures("mock_service_browser") + async def test__get_zeroconf_info(self, mocker, mock_device): + # TODO: test__get_zeroconf_info failes, because the mock is not applied correctly. + browser = ServiceBrowser(None, None, None) + spy_cancel = mocker.spy(browser, "cancel") + await mock_device._get_zeroconf_info("_dvl-plcnetapi._tcp.local.") + + assert spy_cancel.call_count == 1 From 3b03476d4e050096ec84e0912cc7d26c957910be Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Wed, 26 Aug 2020 21:31:57 +0200 Subject: [PATCH 65/93] React on wrong password --- devolo_plc_api/clients/protobuf.py | 41 ++++++++++++++++++++++------- devolo_plc_api/exceptions/device.py | 4 +++ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/devolo_plc_api/clients/protobuf.py b/devolo_plc_api/clients/protobuf.py index 3d57fc5..12777b2 100644 --- a/devolo_plc_api/clients/protobuf.py +++ b/devolo_plc_api/clients/protobuf.py @@ -1,10 +1,17 @@ -from httpx import DigestAuth +from logging import Logger + +from google.protobuf.json_format import MessageToDict +from httpx import DigestAuth, Response + +from ..exceptions.device import DevicePasswordProtected class Protobuf: """ Google Protobuf client. This client is not usable stand alone but needs to be derived. """ + _logger: Logger + @property def url(self): @@ -12,26 +19,42 @@ def url(self): return f"http://{self._ip}:{self._port}/{self._path}/{self._version}/" - async def async_get(self, sub_url): + async def _async_get(self, sub_url: str) -> Response: """ Query URL asynchronously. """ url = f"{self.url}{sub_url}" self._logger.debug(f"Getting from {url}") - return await self._session.get(url, auth=DigestAuth(self._user, self._password)) + try: + return await self._session.get(url, auth=DigestAuth(self._user, self._password)) # type: ignore + except TypeError: + raise DevicePasswordProtected("The used password is wrong.") from None - def get(self, sub_url): + def _get(self, sub_url: str) -> Response: """ Query URL synchronously. """ url = f"{self.url}{sub_url}" self._logger.debug(f"Getting from {url}") - return self._session.get(url, auth=DigestAuth(self._user, self._password)) + try: + return self._session.get(url, auth=DigestAuth(self._user, self._password)) # type: ignore + except TypeError: + raise DevicePasswordProtected("The used password is wrong.") from None + + def _message_to_dict(self, message) -> dict: + """ Convert message to dict with certain settings. """ + return MessageToDict(message=message, including_default_value_fields=True, preserving_proto_field_name=True) - async def async_post(self, sub_url, data): + async def _async_post(self, sub_url: str, data: str) -> Response: """ Post data asynchronously. """ url = f"{self.url}{sub_url}" self._logger.debug(f"Posting to {url}") - return await self._session.post(url, auth=DigestAuth(self._user, self._password), data=data) + try: + return await self._session.post(url, auth=DigestAuth(self._user, self._password), data=data) # type: ignore + except TypeError: + raise DevicePasswordProtected("The used password is wrong.") from None - def post(self, sub_url, data): + def _post(self, sub_url: str, data: str) -> Response: """ Post data synchronously. """ url = f"{self.url}{sub_url}" self._logger.debug(f"Posting to {url}") - return self._session.post(url, auth=DigestAuth(self._user, self._password), data=data) + try: + return self._session.post(url, auth=DigestAuth(self._user, self._password), data=data) # type: ignore + except TypeError: + raise DevicePasswordProtected("The used password is wrong.") from None diff --git a/devolo_plc_api/exceptions/device.py b/devolo_plc_api/exceptions/device.py index d21618e..846e902 100644 --- a/devolo_plc_api/exceptions/device.py +++ b/devolo_plc_api/exceptions/device.py @@ -1,2 +1,6 @@ class DeviceNotFound(Exception): """ The device was not found. """ + + +class DevicePasswordProtected(Exception): + """ The device is passwort protected. """ From 6b0de4d08f393127c5f647fad06157a4a2da135c Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Wed, 26 Aug 2020 21:33:05 +0200 Subject: [PATCH 66/93] Add some missing sync methods --- devolo_plc_api/device_api/deviceapi.py | 81 +++++++++++++++++--------- 1 file changed, 55 insertions(+), 26 deletions(-) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index 8e73981..9e1ea1e 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -2,7 +2,6 @@ from typing import Callable from httpx import Client -from google.protobuf.json_format import MessageToDict from ..clients.protobuf import Protobuf from ..exceptions.feature import FeatureNotSupported @@ -44,42 +43,71 @@ def wrapper(self, *args, **kwargs): return wrapper return feature_decorator + @_feature("led") async def async_get_led_setting(self): """ Get LED setting asynchronously. """ led_setting = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsGet() - response = await self.async_get("LedSettingsGet") + response = await self._async_get("LedSettingsGet") led_setting.ParseFromString(await response.aread()) - return MessageToDict(message=led_setting, including_default_value_fields=True, preserving_proto_field_name=True) + return self._message_to_dict(message=led_setting) + + @_feature("led") + def get_led_setting(self): + """ Get LED setting synchronously. """ + led_setting = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsGet() + response = self._get("LedSettingsGet") + led_setting.ParseFromString(response.read()) + return self._message_to_dict(message=led_setting) @_feature("led") - async def async_set_led_setting(self, enable: bool): + async def async_set_led_setting(self, enable: bool) -> bool: + """ Set LED setting asynchronously. """ led_setting = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsSet() led_setting.state = int(not enable) - response = await self.async_post("LedSettingsSet", data=led_setting.SerializeToString()) - r = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsSetResponse() - r.ParseFromString(await response.aread()) - return MessageToDict(message=r, including_default_value_fields=True, preserving_proto_field_name=True) + query = await self._async_post("LedSettingsSet", data=led_setting.SerializeToString()) + response = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsSetResponse() + response.ParseFromString(await query.aread()) + return True if response.result == 0 else False + + @_feature("led") + def set_led_setting(self, enable: bool) -> bool: + """ Set LED setting synchronously. """ + led_setting = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsSet() + led_setting.state = int(not enable) + query = self._post("LedSettingsSet", data=led_setting.SerializeToString()) + response = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsSetResponse() + response.ParseFromString(query.read()) + return True if response.result == 0 else False @_feature("wifi1") - async def async_get_wifi_connected_station(self): + async def async_get_wifi_connected_station(self) -> dict: + """ Get wifi stations connected to the device asynchronously. """ wifi_connected_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiConnectedStationsGet() - response = await self.async_get("WifiConnectedStationsGet") + response = await self._async_get("WifiConnectedStationsGet") wifi_connected_proto.ParseFromString(await response.aread()) - return wifi_connected_proto + return self._message_to_dict(wifi_connected_proto) + + @_feature("wifi1") + def get_wifi_connected_station(self) -> dict: + """ Get wifi stations connected to the device synchronously. """ + wifi_connected_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiConnectedStationsGet() + response = self._get("WifiConnectedStationsGet") + wifi_connected_proto.ParseFromString(response.read()) + return self._message_to_dict(wifi_connected_proto) @_feature("wifi1") async def async_get_wifi_neighbor_access_points(self): # TODO: Why does WifiNeighborAPsGet send a ReadTimeout wifi_neighbor_aps = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiNeighborAPsGet() - response = await self.async_get("WifiNeighborAPsGet") + response = await self._async_get("WifiNeighborAPsGet") wifi_neighbor_aps.ParseFromString(await response.aread()) return wifi_neighbor_aps @_feature("wifi1") async def async_get_wifi_repeated_access_points(self): wifi_connected_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiRepeatedAPsGet() - response = await self.async_get("WifiRepeatedAPsGet") + response = await self._async_get("WifiRepeatedAPsGet") wifi_connected_proto.ParseFromString(await response.aread()) return wifi_connected_proto @@ -88,34 +116,35 @@ async def async_get_wifi_guest_access(self) -> dict: """ Get details about wifi guest access asynchronously. """ self._logger.debug("Getting wifi guest access") wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() - response = await self.async_get("WifiGuestAccessGet") + response = await self._async_get("WifiGuestAccessGet") wifi_guest_proto.ParseFromString(await response.aread()) - return MessageToDict(wifi_guest_proto) + return self._message_to_dict(wifi_guest_proto) @_feature("wifi1") def get_wifi_guest_access(self) -> dict: """ Get details about wifi guest access synchronously. """ self._logger.debug("Getting wifi guest access") wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() - response = self.get("WifiGuestAccessGet") + response = self._get("WifiGuestAccessGet") wifi_guest_proto.ParseFromString(response.read()) - return wifi_guest_proto + return self._message_to_dict(wifi_guest_proto) @_feature("wifi1") - async def async_set_wifi_guest_access(self, enable) -> dict: + async def async_set_wifi_guest_access(self, enable: bool) -> bool: """ Enable wifi guest access asynchronously. """ wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSet() wifi_guest_proto.enable = enable - response = await self.async_post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) - r = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSetResponse() - r.ParseFromString(await response.aread()) - return MessageToDict(message=r, including_default_value_fields=True, preserving_proto_field_name=True) + query = await self._async_post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) + response = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSetResponse() + response.ParseFromString(await query.aread()) + return True if response.result == 0 else False @_feature("wifi1") - def set_wifi_guest_access(self, enable) -> dict: + def set_wifi_guest_access(self, enable: bool) -> bool: """ Enable wifi guest access synchronously. """ wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSet() wifi_guest_proto.enable = enable - response = self.post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) - wifi_guest_proto.ParseFromString(response.read()) - return wifi_guest_proto + query = self._post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) + response = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSetResponse() + response.ParseFromString(query.read()) + return True if response.result == 0 else False From c441a2dabb953a07413623d70619ad12148be18c Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Wed, 26 Aug 2020 21:33:25 +0200 Subject: [PATCH 67/93] Rename get and post --- devolo_plc_api/plcnet_api/plcnetapi.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/devolo_plc_api/plcnet_api/plcnetapi.py b/devolo_plc_api/plcnet_api/plcnetapi.py index ff4914c..1b7cb12 100644 --- a/devolo_plc_api/plcnet_api/plcnetapi.py +++ b/devolo_plc_api/plcnet_api/plcnetapi.py @@ -35,22 +35,22 @@ async def async_get_network_overview(self) -> dict: """ Get a PLC network overview asynchronously. """ self._logger.debug("Getting network overview") network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() - response = await self.async_get("GetNetworkOverview") + response = await self._async_get("GetNetworkOverview") network_overview.ParseFromString(await response.aread()) - return network_overview + return self._message_to_dict(network_overview) def get_network_overview(self) -> dict: """ Get a PLC network overview synchronously. """ self._logger.debug("Getting network overview") network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() - response = self.get("GetNetworkOverview") + response = self._get("GetNetworkOverview") network_overview.ParseFromString(response.content) - return network_overview + return self._message_to_dict(network_overview) async def identify_device_start(self): identify_device = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceStart() identify_device.mac_address = self._mac - response = await self.async_post("IdentifyDeviceStart", data=identify_device.SerializeToString()) + response = await self._async_post("IdentifyDeviceStart", data=identify_device.SerializeToString()) r = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceResponse() # TODO: ParseFromString --> AttributeError # r.ParseFromstring(await response.aread()) @@ -59,7 +59,7 @@ async def identify_device_start(self): async def identify_device_stop(self): identify_device = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceStop() identify_device.mac_address = self._mac - response = await self.async_post("IdentifyDeviceStop", data=identify_device.SerializeToString()) + response = await self._async_post("IdentifyDeviceStop", data=identify_device.SerializeToString()) # TODO: ParseFromString isn't working. identify_device.ParseFromString(await response.aread()) r = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceResponse() @@ -72,7 +72,7 @@ async def set_user_device_name(self, name): set_user_name = devolo_idl_proto_plcnetapi_setuserdevicename_pb2.SetUserDeviceName() set_user_name.mac_address = self._mac set_user_name.user_device_name = name - response = await self.async_post("SetUserDeviceName", data=set_user_name.SerializeToString()) + response = await self._async_post("SetUserDeviceName", data=set_user_name.SerializeToString()) r = devolo_idl_proto_plcnetapi_setuserdevicename_pb2.SetUserDeviceNameResponse() r.ParseFromString(await response.aread()) return MessageToDict(message=r, including_default_value_fields=True, preserving_proto_field_name=True) From 113b383efa5244f4c9583a3e7735e63e89910e2e Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Thu, 27 Aug 2020 09:12:23 +0200 Subject: [PATCH 68/93] fix test__get_zeroconf_info --- tests/fixtures/device.py | 3 ++- tests/test_device.py | 7 ++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/fixtures/device.py b/tests/fixtures/device.py index 8de5d16..ae44d7d 100644 --- a/tests/fixtures/device.py +++ b/tests/fixtures/device.py @@ -15,4 +15,5 @@ def mock_device(request): @pytest.fixture() def mock_service_browser(mocker): - mocker.patch("zeroconf.ServiceBrowser", ServiceBrowser) + mocker.patch("zeroconf.ServiceBrowser.__init__", ServiceBrowser.__init__) + mocker.patch("zeroconf.ServiceBrowser.cancel", ServiceBrowser.cancel) diff --git a/tests/test_device.py b/tests/test_device.py index c940845..9eb4737 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -2,13 +2,12 @@ from unittest.mock import patch import pytest +import zeroconf from asynctest import CoroutineMock from devolo_plc_api.device_api.deviceapi import DeviceApi from devolo_plc_api.plcnet_api.plcnetapi import PlcNetApi -from .mocks.mock_service_browser import ServiceBrowser - class TestDevice: @@ -51,9 +50,7 @@ async def test__get_plcnet_info(self, mock_device): @pytest.mark.asyncio @pytest.mark.usefixtures("mock_service_browser") async def test__get_zeroconf_info(self, mocker, mock_device): - # TODO: test__get_zeroconf_info failes, because the mock is not applied correctly. - browser = ServiceBrowser(None, None, None) - spy_cancel = mocker.spy(browser, "cancel") + spy_cancel = mocker.spy(zeroconf.ServiceBrowser, "cancel") await mock_device._get_zeroconf_info("_dvl-plcnetapi._tcp.local.") assert spy_cancel.call_count == 1 From 617be18c61507f39b839641300e49d86ea30e179 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Thu, 27 Aug 2020 09:22:05 +0200 Subject: [PATCH 69/93] add default timeout --- devolo_plc_api/clients/protobuf.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/devolo_plc_api/clients/protobuf.py b/devolo_plc_api/clients/protobuf.py index 12777b2..3959fd7 100644 --- a/devolo_plc_api/clients/protobuf.py +++ b/devolo_plc_api/clients/protobuf.py @@ -5,6 +5,8 @@ from ..exceptions.device import DevicePasswordProtected +TIMEOUT = 3.0 + class Protobuf: """ @@ -19,21 +21,21 @@ def url(self): return f"http://{self._ip}:{self._port}/{self._path}/{self._version}/" - async def _async_get(self, sub_url: str) -> Response: + async def _async_get(self, sub_url: str, timeout: float = TIMEOUT) -> Response: """ Query URL asynchronously. """ url = f"{self.url}{sub_url}" self._logger.debug(f"Getting from {url}") try: - return await self._session.get(url, auth=DigestAuth(self._user, self._password)) # type: ignore + return await self._session.get(url, auth=DigestAuth(self._user, self._password), timeout=timeout) # type: ignore except TypeError: raise DevicePasswordProtected("The used password is wrong.") from None - def _get(self, sub_url: str) -> Response: + def _get(self, sub_url: str, timeout: float = TIMEOUT) -> Response: """ Query URL synchronously. """ url = f"{self.url}{sub_url}" self._logger.debug(f"Getting from {url}") try: - return self._session.get(url, auth=DigestAuth(self._user, self._password)) # type: ignore + return self._session.get(url, auth=DigestAuth(self._user, self._password, timeout=timeout)) # type: ignore except TypeError: raise DevicePasswordProtected("The used password is wrong.") from None @@ -41,20 +43,20 @@ def _message_to_dict(self, message) -> dict: """ Convert message to dict with certain settings. """ return MessageToDict(message=message, including_default_value_fields=True, preserving_proto_field_name=True) - async def _async_post(self, sub_url: str, data: str) -> Response: + async def _async_post(self, sub_url: str, data: str, timeout: float = TIMEOUT) -> Response: """ Post data asynchronously. """ url = f"{self.url}{sub_url}" self._logger.debug(f"Posting to {url}") try: - return await self._session.post(url, auth=DigestAuth(self._user, self._password), data=data) # type: ignore + return await self._session.post(url, auth=DigestAuth(self._user, self._password), data=data, timeout=timeout) # type: ignore except TypeError: raise DevicePasswordProtected("The used password is wrong.") from None - def _post(self, sub_url: str, data: str) -> Response: + def _post(self, sub_url: str, data: str, timeout: float = TIMEOUT) -> Response: """ Post data synchronously. """ url = f"{self.url}{sub_url}" self._logger.debug(f"Posting to {url}") try: - return self._session.post(url, auth=DigestAuth(self._user, self._password), data=data) # type: ignore + return self._session.post(url, auth=DigestAuth(self._user, self._password), data=data, timeout=timeout) # type: ignore except TypeError: raise DevicePasswordProtected("The used password is wrong.") from None From 3b0d7d33af7a3ce4801734c7f7644d053ce2e166 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Thu, 27 Aug 2020 09:22:35 +0200 Subject: [PATCH 70/93] add longer timeout to long running calls --- devolo_plc_api/device_api/deviceapi.py | 3 +-- devolo_plc_api/plcnet_api/plcnetapi.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index 9e1ea1e..2dfaedf 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -98,9 +98,8 @@ def get_wifi_connected_station(self) -> dict: @_feature("wifi1") async def async_get_wifi_neighbor_access_points(self): - # TODO: Why does WifiNeighborAPsGet send a ReadTimeout wifi_neighbor_aps = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiNeighborAPsGet() - response = await self._async_get("WifiNeighborAPsGet") + response = await self._async_get("WifiNeighborAPsGet", timeout=15.0) wifi_neighbor_aps.ParseFromString(await response.aread()) return wifi_neighbor_aps diff --git a/devolo_plc_api/plcnet_api/plcnetapi.py b/devolo_plc_api/plcnet_api/plcnetapi.py index 1b7cb12..b22f60e 100644 --- a/devolo_plc_api/plcnet_api/plcnetapi.py +++ b/devolo_plc_api/plcnet_api/plcnetapi.py @@ -68,11 +68,10 @@ async def identify_device_stop(self): return MessageToDict(message=r, including_default_value_fields=True, preserving_proto_field_name=True) async def set_user_device_name(self, name): - # TODO: ReadTimeout ?? set_user_name = devolo_idl_proto_plcnetapi_setuserdevicename_pb2.SetUserDeviceName() set_user_name.mac_address = self._mac set_user_name.user_device_name = name - response = await self._async_post("SetUserDeviceName", data=set_user_name.SerializeToString()) + response = await self._async_post("SetUserDeviceName", data=set_user_name.SerializeToString(), timeout=10.0) r = devolo_idl_proto_plcnetapi_setuserdevicename_pb2.SetUserDeviceNameResponse() r.ParseFromString(await response.aread()) return MessageToDict(message=r, including_default_value_fields=True, preserving_proto_field_name=True) From 25496ed745525109bc4b45fcd13f967b67e55e37 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Thu, 27 Aug 2020 09:28:15 +0200 Subject: [PATCH 71/93] Fix mocking of DeviceApi and PlcNetApi --- tests/fixtures/device_api.py | 2 +- tests/fixtures/plcnet_api.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/device_api.py b/tests/fixtures/device_api.py index 02573da..4d07774 100644 --- a/tests/fixtures/device_api.py +++ b/tests/fixtures/device_api.py @@ -5,4 +5,4 @@ @pytest.fixture() def mock_device_api(mocker): - mocker.patch("devolo_plc_api.device_api.deviceapi.DeviceApi", DeviceApi) + mocker.patch("devolo_plc_api.device_api.deviceapi.DeviceApi.__init__", DeviceApi.__init__) diff --git a/tests/fixtures/plcnet_api.py b/tests/fixtures/plcnet_api.py index 3dd6256..1afe203 100644 --- a/tests/fixtures/plcnet_api.py +++ b/tests/fixtures/plcnet_api.py @@ -5,4 +5,4 @@ @pytest.fixture() def mock_plcnet_api(mocker): - mocker.patch("devolo_plc_api.plcnet_api.plcnetapi.PlcNetApi", PlcNetApi) + mocker.patch("devolo_plc_api.plcnet_api.plcnetapi.PlcNetApi.__init__", PlcNetApi.__init__) From 5c6c8c027d7f19a3c365d70c78243008abc55938 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Thu, 27 Aug 2020 09:28:56 +0200 Subject: [PATCH 72/93] Ease mocked classes --- tests/mocks/mock_device_api.py | 2 +- tests/mocks/mock_plcnet_api.py | 2 +- tests/mocks/mock_service_browser.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/mocks/mock_device_api.py b/tests/mocks/mock_device_api.py index 8cee5ed..b10328b 100644 --- a/tests/mocks/mock_device_api.py +++ b/tests/mocks/mock_device_api.py @@ -1,3 +1,3 @@ class DeviceApi(): - def __init__(self, ip, session, path, version, features): + def __init__(self, *args, **kwargs): pass diff --git a/tests/mocks/mock_plcnet_api.py b/tests/mocks/mock_plcnet_api.py index 2d8c3b2..df7eeaa 100644 --- a/tests/mocks/mock_plcnet_api.py +++ b/tests/mocks/mock_plcnet_api.py @@ -1,3 +1,3 @@ class PlcNetApi(): - def __init__(self, ip, session, path, version, mac): + def __init__(self, *args, **kwargs): pass diff --git a/tests/mocks/mock_service_browser.py b/tests/mocks/mock_service_browser.py index 1e5aa70..47b5954 100644 --- a/tests/mocks/mock_service_browser.py +++ b/tests/mocks/mock_service_browser.py @@ -1,5 +1,5 @@ class ServiceBrowser: - def __init__(self, zeroconf, service_type, handler): + def __init__(self, *args, **kwargs): pass def cancel(self): From ec42f02476dec4df8ed610ee2b84ba15b79a15fc Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Thu, 27 Aug 2020 11:02:34 +0200 Subject: [PATCH 73/93] Add testcases for _state_change_removed --- tests/conftest.py | 1 + tests/fixtures/device.py | 9 ++++++++- tests/mocks/mock_zeroconf.py | 17 +++++++++++++++++ tests/test_data.json | 3 ++- tests/test_device.py | 21 +++++++++++++++++++++ 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 tests/mocks/mock_zeroconf.py diff --git a/tests/conftest.py b/tests/conftest.py index 66e5fde..6bb62d2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -19,3 +19,4 @@ def test_data_fixture(request): """ Load test data. """ request.cls.device_info = test_data['device_info'] + request.cls.ip = test_data['ip'] diff --git a/tests/fixtures/device.py b/tests/fixtures/device.py index ae44d7d..0ee5074 100644 --- a/tests/fixtures/device.py +++ b/tests/fixtures/device.py @@ -1,12 +1,14 @@ import pytest from devolo_plc_api.device import Device + from ..mocks.mock_service_browser import ServiceBrowser +from ..mocks.mock_zeroconf import Zeroconf @pytest.fixture() def mock_device(request): - device = Device(ip="192.168.0.10") + device = Device(ip=request.cls.ip) device._info = request.cls.device_info device._session = None device._zeroconf = None @@ -17,3 +19,8 @@ def mock_device(request): def mock_service_browser(mocker): mocker.patch("zeroconf.ServiceBrowser.__init__", ServiceBrowser.__init__) mocker.patch("zeroconf.ServiceBrowser.cancel", ServiceBrowser.cancel) + + +@pytest.fixture() +def mock_zeroconf(mocker): + mocker.patch("zeroconf.Zeroconf.get_service_info", Zeroconf.get_service_info) diff --git a/tests/mocks/mock_zeroconf.py b/tests/mocks/mock_zeroconf.py new file mode 100644 index 0000000..3f15387 --- /dev/null +++ b/tests/mocks/mock_zeroconf.py @@ -0,0 +1,17 @@ +import json +import pathlib +import socket + +from zeroconf import ServiceInfo + +file = pathlib.Path(__file__).parent / ".." / "test_data.json" +with file.open("r") as fh: + test_data = json.load(fh) + + +class Zeroconf: + def get_service_info(self, service_type, name): + service_info = ServiceInfo(service_type, name) + service_info.addresses = [socket.inet_aton(test_data['ip'])] + service_info.text = b"\x09new=value" + return service_info diff --git a/tests/test_data.json b/tests/test_data.json index e534710..e4054b5 100644 --- a/tests/test_data.json +++ b/tests/test_data.json @@ -16,5 +16,6 @@ "PlcTechnology": "hpav", "Version": "v0" } - } + }, + "ip": "192.168.0.10" } \ No newline at end of file diff --git a/tests/test_device.py b/tests/test_device.py index 9eb4737..83cf270 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -1,3 +1,4 @@ +import asyncio from datetime import date from unittest.mock import patch @@ -51,6 +52,26 @@ async def test__get_plcnet_info(self, mock_device): @pytest.mark.usefixtures("mock_service_browser") async def test__get_zeroconf_info(self, mocker, mock_device): spy_cancel = mocker.spy(zeroconf.ServiceBrowser, "cancel") + spy_sleep = mocker.spy(asyncio, "sleep") await mock_device._get_zeroconf_info("_dvl-plcnetapi._tcp.local.") assert spy_cancel.call_count == 1 + assert spy_sleep.call_count == 0 + + @pytest.mark.asyncio + @pytest.mark.usefixtures("mock_zeroconf") + def test__state_change_added(self, mock_device): + zc = zeroconf.Zeroconf() + service_type = "_dvl-plcnetapi._tcp.local." + mock_device._state_change(zc, service_type, service_type, zeroconf.ServiceStateChange.Added) + + assert mock_device._info[service_type]['new'] == "value" + + @pytest.mark.asyncio + @pytest.mark.usefixtures("mock_zeroconf") + def test__state_change_removed(self, mock_device): + zc = zeroconf.Zeroconf() + service_type = "_dvl-plcnetapi._tcp.local." + mock_device._state_change(zc, service_type, service_type, zeroconf.ServiceStateChange.Removed) + + assert "new" not in mock_device._info[service_type] From 5ed8a52eef12aff4748aa816693ccad148fbf66b Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Thu, 27 Aug 2020 12:19:12 +0200 Subject: [PATCH 74/93] fix test procedure --- tests/fixtures/device.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/device.py b/tests/fixtures/device.py index 0ee5074..3e556d9 100644 --- a/tests/fixtures/device.py +++ b/tests/fixtures/device.py @@ -1,7 +1,8 @@ +from copy import deepcopy + import pytest from devolo_plc_api.device import Device - from ..mocks.mock_service_browser import ServiceBrowser from ..mocks.mock_zeroconf import Zeroconf @@ -9,7 +10,7 @@ @pytest.fixture() def mock_device(request): device = Device(ip=request.cls.ip) - device._info = request.cls.device_info + device._info = deepcopy(request.cls.device_info) device._session = None device._zeroconf = None return device From 8c95b1b1f547bdc2ae2b20429894213319b4e976 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Thu, 27 Aug 2020 12:28:30 +0200 Subject: [PATCH 75/93] use typecase --- devolo_plc_api/device_api/deviceapi.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index 2dfaedf..11c4047 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -32,7 +32,7 @@ def __init__(self, ip: str, session: Client, path: str, version: str, features: self._logger = logging.getLogger(self.__class__.__name__) - def _feature(feature: str, *args, **kwargs): # type: ignore + def _feature(feature: str, *args, **kwargs): """ Decorator to filter unsupported features before querying the device. """ def feature_decorator(method: Callable): def wrapper(self, *args, **kwargs): @@ -68,7 +68,7 @@ async def async_set_led_setting(self, enable: bool) -> bool: query = await self._async_post("LedSettingsSet", data=led_setting.SerializeToString()) response = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsSetResponse() response.ParseFromString(await query.aread()) - return True if response.result == 0 else False + return bool(not response.result) @_feature("led") def set_led_setting(self, enable: bool) -> bool: @@ -78,7 +78,7 @@ def set_led_setting(self, enable: bool) -> bool: query = self._post("LedSettingsSet", data=led_setting.SerializeToString()) response = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsSetResponse() response.ParseFromString(query.read()) - return True if response.result == 0 else False + return bool(not response.result) @_feature("wifi1") async def async_get_wifi_connected_station(self) -> dict: @@ -136,7 +136,7 @@ async def async_set_wifi_guest_access(self, enable: bool) -> bool: query = await self._async_post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) response = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSetResponse() response.ParseFromString(await query.aread()) - return True if response.result == 0 else False + return bool(not response.result) @_feature("wifi1") def set_wifi_guest_access(self, enable: bool) -> bool: @@ -146,4 +146,4 @@ def set_wifi_guest_access(self, enable: bool) -> bool: query = self._post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) response = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSetResponse() response.ParseFromString(query.read()) - return True if response.result == 0 else False + return bool(not response.result) From e3cf670c54a2f867d84d073124275ef0dedf437f Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Thu, 27 Aug 2020 12:55:30 +0200 Subject: [PATCH 76/93] switch to FromString --- devolo_plc_api/device_api/deviceapi.py | 24 ++++++++++++------------ devolo_plc_api/plcnet_api/plcnetapi.py | 15 ++++++--------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index 11c4047..8b3a143 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -49,7 +49,7 @@ async def async_get_led_setting(self): """ Get LED setting asynchronously. """ led_setting = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsGet() response = await self._async_get("LedSettingsGet") - led_setting.ParseFromString(await response.aread()) + led_setting.FromString(await response.aread()) return self._message_to_dict(message=led_setting) @_feature("led") @@ -57,7 +57,7 @@ def get_led_setting(self): """ Get LED setting synchronously. """ led_setting = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsGet() response = self._get("LedSettingsGet") - led_setting.ParseFromString(response.read()) + led_setting.FromString(response.read()) return self._message_to_dict(message=led_setting) @_feature("led") @@ -67,7 +67,7 @@ async def async_set_led_setting(self, enable: bool) -> bool: led_setting.state = int(not enable) query = await self._async_post("LedSettingsSet", data=led_setting.SerializeToString()) response = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsSetResponse() - response.ParseFromString(await query.aread()) + response.FromString(await query.aread()) return bool(not response.result) @_feature("led") @@ -77,7 +77,7 @@ def set_led_setting(self, enable: bool) -> bool: led_setting.state = int(not enable) query = self._post("LedSettingsSet", data=led_setting.SerializeToString()) response = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsSetResponse() - response.ParseFromString(query.read()) + response.FromString(query.read()) return bool(not response.result) @_feature("wifi1") @@ -85,7 +85,7 @@ async def async_get_wifi_connected_station(self) -> dict: """ Get wifi stations connected to the device asynchronously. """ wifi_connected_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiConnectedStationsGet() response = await self._async_get("WifiConnectedStationsGet") - wifi_connected_proto.ParseFromString(await response.aread()) + wifi_connected_proto.FromString(await response.aread()) return self._message_to_dict(wifi_connected_proto) @_feature("wifi1") @@ -93,21 +93,21 @@ def get_wifi_connected_station(self) -> dict: """ Get wifi stations connected to the device synchronously. """ wifi_connected_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiConnectedStationsGet() response = self._get("WifiConnectedStationsGet") - wifi_connected_proto.ParseFromString(response.read()) + wifi_connected_proto.FromString(response.read()) return self._message_to_dict(wifi_connected_proto) @_feature("wifi1") async def async_get_wifi_neighbor_access_points(self): wifi_neighbor_aps = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiNeighborAPsGet() response = await self._async_get("WifiNeighborAPsGet", timeout=15.0) - wifi_neighbor_aps.ParseFromString(await response.aread()) + wifi_neighbor_aps.FromString(await response.aread()) return wifi_neighbor_aps @_feature("wifi1") async def async_get_wifi_repeated_access_points(self): wifi_connected_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiRepeatedAPsGet() response = await self._async_get("WifiRepeatedAPsGet") - wifi_connected_proto.ParseFromString(await response.aread()) + wifi_connected_proto.FromString(await response.aread()) return wifi_connected_proto @_feature("wifi1") @@ -116,7 +116,7 @@ async def async_get_wifi_guest_access(self) -> dict: self._logger.debug("Getting wifi guest access") wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() response = await self._async_get("WifiGuestAccessGet") - wifi_guest_proto.ParseFromString(await response.aread()) + wifi_guest_proto.FromString(await response.aread()) return self._message_to_dict(wifi_guest_proto) @_feature("wifi1") @@ -125,7 +125,7 @@ def get_wifi_guest_access(self) -> dict: self._logger.debug("Getting wifi guest access") wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() response = self._get("WifiGuestAccessGet") - wifi_guest_proto.ParseFromString(response.read()) + wifi_guest_proto.FromString(response.read()) return self._message_to_dict(wifi_guest_proto) @_feature("wifi1") @@ -135,7 +135,7 @@ async def async_set_wifi_guest_access(self, enable: bool) -> bool: wifi_guest_proto.enable = enable query = await self._async_post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) response = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSetResponse() - response.ParseFromString(await query.aread()) + response.FromString(await query.aread()) return bool(not response.result) @_feature("wifi1") @@ -145,5 +145,5 @@ def set_wifi_guest_access(self, enable: bool) -> bool: wifi_guest_proto.enable = enable query = self._post("WifiGuestAccessSet", data=wifi_guest_proto.SerializeToString()) response = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSetResponse() - response.ParseFromString(query.read()) + response.FromString(query.read()) return bool(not response.result) diff --git a/devolo_plc_api/plcnet_api/plcnetapi.py b/devolo_plc_api/plcnet_api/plcnetapi.py index b22f60e..b0e3f6b 100644 --- a/devolo_plc_api/plcnet_api/plcnetapi.py +++ b/devolo_plc_api/plcnet_api/plcnetapi.py @@ -36,7 +36,7 @@ async def async_get_network_overview(self) -> dict: self._logger.debug("Getting network overview") network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() response = await self._async_get("GetNetworkOverview") - network_overview.ParseFromString(await response.aread()) + network_overview.FromString(await response.aread()) return self._message_to_dict(network_overview) def get_network_overview(self) -> dict: @@ -44,7 +44,7 @@ def get_network_overview(self) -> dict: self._logger.debug("Getting network overview") network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() response = self._get("GetNetworkOverview") - network_overview.ParseFromString(response.content) + network_overview.FromString(response.content) return self._message_to_dict(network_overview) async def identify_device_start(self): @@ -52,19 +52,16 @@ async def identify_device_start(self): identify_device.mac_address = self._mac response = await self._async_post("IdentifyDeviceStart", data=identify_device.SerializeToString()) r = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceResponse() - # TODO: ParseFromString --> AttributeError - # r.ParseFromstring(await response.aread()) + r.FromString(await response.aread()) return MessageToDict(message=r, including_default_value_fields=True, preserving_proto_field_name=True) async def identify_device_stop(self): identify_device = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceStop() identify_device.mac_address = self._mac response = await self._async_post("IdentifyDeviceStop", data=identify_device.SerializeToString()) - # TODO: ParseFromString isn't working. - identify_device.ParseFromString(await response.aread()) + identify_device.FromString(await response.aread()) r = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceResponse() - # TODO: ParseFromString --> AttributeError - # r.ParseFromstring(await response.aread()) + r.FromString(await response.aread()) return MessageToDict(message=r, including_default_value_fields=True, preserving_proto_field_name=True) async def set_user_device_name(self, name): @@ -73,5 +70,5 @@ async def set_user_device_name(self, name): set_user_name.user_device_name = name response = await self._async_post("SetUserDeviceName", data=set_user_name.SerializeToString(), timeout=10.0) r = devolo_idl_proto_plcnetapi_setuserdevicename_pb2.SetUserDeviceNameResponse() - r.ParseFromString(await response.aread()) + r.FromString(await response.aread()) return MessageToDict(message=r, including_default_value_fields=True, preserving_proto_field_name=True) From 990bb83b4e5ce75890f572dc029ff1aac58e7a31 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Thu, 27 Aug 2020 13:02:57 +0200 Subject: [PATCH 77/93] add coveralls --- .github/workflows/pythonpackage.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index c73dedd..275611c 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -29,5 +29,10 @@ jobs: - name: Test with pytest run: | python setup.py test --addopts --cov=devolo_plc_api + - name: Coveralls + run: | + pip install coveralls==1.10.0 + export COVERALLS_REPO_TOKEN=${{ secrets.COVERALLS_TOKEN }} + coveralls From 54cd18b2a6419eccf396f2506e203132476528cc Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Thu, 27 Aug 2020 13:09:39 +0200 Subject: [PATCH 78/93] add badges --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index dfb1279..d81db22 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # devolo PLC API +[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/2Fake/devolo_plc_api/Python%20package)](https://github.com/2Fake/devolo_plc_api/actions?query=workflow%3A%22Python+package%22) +[![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/2Fake/devolo_plc_api)](https://codeclimate.com/github/2Fake/devolo_plc_api) +[![Coverage Status](https://coveralls.io/repos/github/2Fake/devolo_plc_api/badge.svg?branch=development)](https://coveralls.io/github/2Fake/devolo_plc_api?branch=development) + This project implements parts of the devolo PLC devices API in Python. Communication to the devices is formatted in protobuf and the IDLs were kindly provided by devolo. Nevertheless, we might miss updates to the IDLs. If you discover a breakage, please feel free to [report an issue](https://github.com/2Fake/devolo_plc_api/issues). ## System requirements From 4052e76a32881a5b04bd961d542a1d46b124a1fd Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Thu, 27 Aug 2020 16:40:08 +0200 Subject: [PATCH 79/93] Fix _get method --- devolo_plc_api/clients/protobuf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devolo_plc_api/clients/protobuf.py b/devolo_plc_api/clients/protobuf.py index 3959fd7..66ee7ee 100644 --- a/devolo_plc_api/clients/protobuf.py +++ b/devolo_plc_api/clients/protobuf.py @@ -16,7 +16,7 @@ class Protobuf: @property - def url(self): + def url(self) -> str: """ The base URL to query. """ return f"http://{self._ip}:{self._port}/{self._path}/{self._version}/" @@ -35,7 +35,7 @@ def _get(self, sub_url: str, timeout: float = TIMEOUT) -> Response: url = f"{self.url}{sub_url}" self._logger.debug(f"Getting from {url}") try: - return self._session.get(url, auth=DigestAuth(self._user, self._password, timeout=timeout)) # type: ignore + return self._session.get(url, auth=DigestAuth(self._user, self._password), timeout=timeout) # type: ignore except TypeError: raise DevicePasswordProtected("The used password is wrong.") from None From 84a50323ea6ecd5e0ef769c6502d246169684154 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Thu, 27 Aug 2020 16:40:43 +0200 Subject: [PATCH 80/93] Silence mypy --- devolo_plc_api/device_api/deviceapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index 8b3a143..f957bd7 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -32,7 +32,7 @@ def __init__(self, ip: str, session: Client, path: str, version: str, features: self._logger = logging.getLogger(self.__class__.__name__) - def _feature(feature: str, *args, **kwargs): + def _feature(feature: str, *args, **kwargs): # type: ignore """ Decorator to filter unsupported features before querying the device. """ def feature_decorator(method: Callable): def wrapper(self, *args, **kwargs): From 38aa8871ebc9b6a462c395fc00db1e5ed282717b Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Thu, 27 Aug 2020 16:41:27 +0200 Subject: [PATCH 81/93] Add tests for Protobuf --- tests/conftest.py | 1 + tests/fixtures/protobuf.py | 39 ++++++++++++++++++++ tests/mocks/mock_httpx.py | 23 ++++++++++++ tests/test_data.json | 4 +-- tests/test_profobuf.py | 73 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/protobuf.py create mode 100644 tests/mocks/mock_httpx.py create mode 100644 tests/test_profobuf.py diff --git a/tests/conftest.py b/tests/conftest.py index 6bb62d2..91be08e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,6 +7,7 @@ pytest_plugins = ['tests.fixtures.device', 'tests.fixtures.device_api', 'tests.fixtures.plcnet_api', + 'tests.fixtures.protobuf', ] diff --git a/tests/fixtures/protobuf.py b/tests/fixtures/protobuf.py new file mode 100644 index 0000000..82ea91e --- /dev/null +++ b/tests/fixtures/protobuf.py @@ -0,0 +1,39 @@ +import logging + +import pytest + +from devolo_plc_api.clients.protobuf import Protobuf + +from ..mocks.mock_httpx import AsyncClient, Client + + +@pytest.fixture() +def mock_protobuf(request): + protobuf = Protobuf() + protobuf._logger = logging.getLogger("ProtobufMock") + protobuf._ip = request.cls.ip + protobuf._port = 14791 + protobuf._path = request.cls.device_info['_dvl-plcnetapi._tcp.local.']['Path'] + protobuf._version = request.cls.device_info['_dvl-plcnetapi._tcp.local.']['Version'] + protobuf._user = "user" + protobuf._password = "password" + return protobuf + + +@pytest.fixture() +def mock_get(mocker): + mocker.patch("httpx.AsyncClient.get", AsyncClient.get) + mocker.patch("httpx.Client.get", Client.get) + + +@pytest.fixture() +def mock_post(mocker): + mocker.patch("httpx.AsyncClient.post", AsyncClient.post) + mocker.patch("httpx.Client.post", Client.post) + +@pytest.fixture() +def mock_wrong_password(mocker): + mocker.patch("httpx.AsyncClient.get", AsyncClient.wrong_password) + mocker.patch("httpx.Client.get", Client.wrong_password) + mocker.patch("httpx.AsyncClient.post", AsyncClient.wrong_password) + mocker.patch("httpx.Client.post", Client.wrong_password) diff --git a/tests/mocks/mock_httpx.py b/tests/mocks/mock_httpx.py new file mode 100644 index 0000000..865de8e --- /dev/null +++ b/tests/mocks/mock_httpx.py @@ -0,0 +1,23 @@ +from devolo_plc_api.exceptions.device import DevicePasswordProtected + + +class AsyncClient: + async def get(self, url, auth, timeout): + pass + + async def post(self, url, auth, data, timeout): + pass + + async def wrong_password(self, *args, **kwargs): + raise TypeError() + + +class Client: + def get(self, url, auth, timeout): + pass + + def post(self, url, auth, data, timeout): + pass + + def wrong_password(self, *args, **kwargs): + raise TypeError() diff --git a/tests/test_data.json b/tests/test_data.json index e4054b5..1a4672e 100644 --- a/tests/test_data.json +++ b/tests/test_data.json @@ -6,12 +6,12 @@ "SN": "1234567890123456", "MT": "2730", "Product": "dLAN pro 1200+ WiFi ac", - "Path": "/", + "Path": "1234567890abcdef", "Version": "v0", "Features": "wifi1" }, "_dvl-plcnetapi._tcp.local.": { - "Path": "/", + "Path": "1234567890abcdef", "PlcMacAddress": "AABBCCDDEEFF", "PlcTechnology": "hpav", "Version": "v0" diff --git a/tests/test_profobuf.py b/tests/test_profobuf.py new file mode 100644 index 0000000..38e9312 --- /dev/null +++ b/tests/test_profobuf.py @@ -0,0 +1,73 @@ +import httpx +import pytest + +from devolo_plc_api.exceptions.device import DevicePasswordProtected + + +class TestProtobuf: + def test_url(self, request, mock_protobuf): + ip = request.cls.ip + path = request.cls.device_info['_dvl-plcnetapi._tcp.local.']['Path'] + version = request.cls.device_info['_dvl-plcnetapi._tcp.local.']['Version'] + + assert mock_protobuf.url == f"http://{ip}:14791/{path}/{version}/" + + @pytest.mark.asyncio + @pytest.mark.usefixtures("mock_get") + async def test__async_get(self, mocker, mock_protobuf): + mock_protobuf._session = httpx.AsyncClient() + spy = mocker.spy(httpx.AsyncClient, "get") + await mock_protobuf._async_get("LedSettingsGet") + + spy.assert_called_once() + + @pytest.mark.asyncio + @pytest.mark.usefixtures("mock_wrong_password") + async def test__async_get_wrong_password(self, mocker, mock_protobuf): + mock_protobuf._session = httpx.AsyncClient() + with pytest.raises(DevicePasswordProtected): + await mock_protobuf._async_get("LedSettingsGet") + + @pytest.mark.usefixtures("mock_get") + def test__get(self, mocker, mock_protobuf): + mock_protobuf._session = httpx.Client() + spy = mocker.spy(httpx.Client, "get") + mock_protobuf._get("LedSettingsGet") + + spy.assert_called_once() + + @pytest.mark.usefixtures("mock_wrong_password") + def test__get_wrong_password(self, mocker, mock_protobuf): + mock_protobuf._session = httpx.Client() + with pytest.raises(DevicePasswordProtected): + mock_protobuf._get("LedSettingsGet") + + @pytest.mark.asyncio + @pytest.mark.usefixtures("mock_post") + async def test__async_post(self, mocker, mock_protobuf): + mock_protobuf._session = httpx.AsyncClient() + spy = mocker.spy(httpx.AsyncClient, "post") + await mock_protobuf._async_post("LedSettingsGet", "") + + spy.assert_called_once() + + @pytest.mark.asyncio + @pytest.mark.usefixtures("mock_wrong_password") + async def test__async_post_wrong_password(self, mocker, mock_protobuf): + mock_protobuf._session = httpx.AsyncClient() + with pytest.raises(DevicePasswordProtected): + await mock_protobuf._async_post("LedSettingsGet", "") + + @pytest.mark.usefixtures("mock_post") + def test__post(self, mocker, mock_protobuf): + mock_protobuf._session = httpx.Client() + spy = mocker.spy(httpx.Client, "post") + mock_protobuf._post("LedSettingsGet", "") + + spy.assert_called_once() + + @pytest.mark.usefixtures("mock_wrong_password") + def test__post_wrong_password(self, mocker, mock_protobuf): + mock_protobuf._session = httpx.Client() + with pytest.raises(DevicePasswordProtected): + mock_protobuf._post("LedSettingsGet", "") From e7fc50e5c166456828e85c785c175965c3f8a34d Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Thu, 27 Aug 2020 17:14:33 +0200 Subject: [PATCH 82/93] Cosmetic changes --- tests/fixtures/protobuf.py | 1 + tests/mocks/mock_httpx.py | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/fixtures/protobuf.py b/tests/fixtures/protobuf.py index 82ea91e..82fa026 100644 --- a/tests/fixtures/protobuf.py +++ b/tests/fixtures/protobuf.py @@ -31,6 +31,7 @@ def mock_post(mocker): mocker.patch("httpx.AsyncClient.post", AsyncClient.post) mocker.patch("httpx.Client.post", Client.post) + @pytest.fixture() def mock_wrong_password(mocker): mocker.patch("httpx.AsyncClient.get", AsyncClient.wrong_password) diff --git a/tests/mocks/mock_httpx.py b/tests/mocks/mock_httpx.py index 865de8e..ee705bc 100644 --- a/tests/mocks/mock_httpx.py +++ b/tests/mocks/mock_httpx.py @@ -1,6 +1,3 @@ -from devolo_plc_api.exceptions.device import DevicePasswordProtected - - class AsyncClient: async def get(self, url, auth, timeout): pass From 77d3b6358dcb78870217e5c1d47d1d4404afdc6c Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Thu, 27 Aug 2020 17:15:03 +0200 Subject: [PATCH 83/93] Add missing synchronous methods --- devolo_plc_api/device_api/deviceapi.py | 44 ++++++++++++------ devolo_plc_api/plcnet_api/plcnetapi.py | 63 +++++++++++++++++++------- 2 files changed, 76 insertions(+), 31 deletions(-) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index f957bd7..8fa83db 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -96,20 +96,6 @@ def get_wifi_connected_station(self) -> dict: wifi_connected_proto.FromString(response.read()) return self._message_to_dict(wifi_connected_proto) - @_feature("wifi1") - async def async_get_wifi_neighbor_access_points(self): - wifi_neighbor_aps = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiNeighborAPsGet() - response = await self._async_get("WifiNeighborAPsGet", timeout=15.0) - wifi_neighbor_aps.FromString(await response.aread()) - return wifi_neighbor_aps - - @_feature("wifi1") - async def async_get_wifi_repeated_access_points(self): - wifi_connected_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiRepeatedAPsGet() - response = await self._async_get("WifiRepeatedAPsGet") - wifi_connected_proto.FromString(await response.aread()) - return wifi_connected_proto - @_feature("wifi1") async def async_get_wifi_guest_access(self) -> dict: """ Get details about wifi guest access asynchronously. """ @@ -147,3 +133,33 @@ def set_wifi_guest_access(self, enable: bool) -> bool: response = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessSetResponse() response.FromString(query.read()) return bool(not response.result) + + @_feature("wifi1") + async def async_get_wifi_neighbor_access_points(self) -> dict: + """ Get wifi access point in the neighborhood asynchronously. """ + wifi_neighbor_aps = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiNeighborAPsGet() + response = await self._async_get("WifiNeighborAPsGet", timeout=15.0) + wifi_neighbor_aps.FromString(await response.aread()) + return self._message_to_dict(wifi_neighbor_aps) + + @_feature("wifi1") + async def get_wifi_neighbor_access_points(self) -> dict: + """ Get wifi access point in the neighborhood synchronously. """ + wifi_neighbor_aps = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiNeighborAPsGet() + response = self._async_get("WifiNeighborAPsGet", timeout=15.0) + wifi_neighbor_aps.FromString(response.read()) + return self._message_to_dict(wifi_neighbor_aps) + + @_feature("wifi1") + async def async_get_wifi_repeated_access_points(self): + wifi_connected_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiRepeatedAPsGet() + response = await self._async_get("WifiRepeatedAPsGet") + wifi_connected_proto.FromString(await response.aread()) + return self._message_to_dict(wifi_connected_proto) + + @_feature("wifi1") + def get_wifi_repeated_access_points(self): + wifi_connected_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiRepeatedAPsGet() + response = self._get("WifiRepeatedAPsGet") + wifi_connected_proto.FromString(response.read()) + return self._message_to_dict(wifi_connected_proto) diff --git a/devolo_plc_api/plcnet_api/plcnetapi.py b/devolo_plc_api/plcnet_api/plcnetapi.py index b0e3f6b..e5bfd8f 100644 --- a/devolo_plc_api/plcnet_api/plcnetapi.py +++ b/devolo_plc_api/plcnet_api/plcnetapi.py @@ -1,5 +1,4 @@ import logging -from google.protobuf.json_format import MessageToDict from httpx import Client @@ -47,28 +46,58 @@ def get_network_overview(self) -> dict: network_overview.FromString(response.content) return self._message_to_dict(network_overview) - async def identify_device_start(self): + async def async_identify_device_start(self): + """ Make PLC LED of a device blick to identify it asynchronously. """ identify_device = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceStart() identify_device.mac_address = self._mac - response = await self._async_post("IdentifyDeviceStart", data=identify_device.SerializeToString()) - r = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceResponse() - r.FromString(await response.aread()) - return MessageToDict(message=r, including_default_value_fields=True, preserving_proto_field_name=True) + query = await self._async_post("IdentifyDeviceStart", data=identify_device.SerializeToString()) + response = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceResponse() + response.FromString(await query.aread()) + return self._message_to_dict(response) - async def identify_device_stop(self): + def identify_device_start(self): + """ Make PLC LED of a device blick to identify it synchronously. """ + identify_device = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceStart() + identify_device.mac_address = self._mac + query = self._post("IdentifyDeviceStart", data=identify_device.SerializeToString()) + response = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceResponse() + response.FromString(query.read()) + return self._message_to_dict(response) + + async def async_identify_device_stop(self): + """ Stop the PLC LED blicking asynchronously. """ + identify_device = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceStop() + identify_device.mac_address = self._mac + query = await self._async_post("IdentifyDeviceStop", data=identify_device.SerializeToString()) + response = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceResponse() + response.FromString(await query.aread()) + return self._message_to_dict(response) + + def identify_device_stop(self): + """ Stop the PLC LED blicking synchronously. """ identify_device = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceStop() identify_device.mac_address = self._mac - response = await self._async_post("IdentifyDeviceStop", data=identify_device.SerializeToString()) - identify_device.FromString(await response.aread()) - r = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceResponse() - r.FromString(await response.aread()) - return MessageToDict(message=r, including_default_value_fields=True, preserving_proto_field_name=True) + query = self._async_post("IdentifyDeviceStop", data=identify_device.SerializeToString()) + response = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceResponse() + response.FromString(query.read()) + return self._message_to_dict(response) + + async def async_set_user_device_name(self, name): + """ Set device name asynchronously. """ + set_user_name = devolo_idl_proto_plcnetapi_setuserdevicename_pb2.SetUserDeviceName() + set_user_name.mac_address = self._mac + set_user_name.user_device_name = name + query = await self._async_post("SetUserDeviceName", data=set_user_name.SerializeToString(), timeout=10.0) + response = devolo_idl_proto_plcnetapi_setuserdevicename_pb2.SetUserDeviceNameResponse() + response.FromString(await query.aread()) + return self._message_to_dict(response) - async def set_user_device_name(self, name): + def set_user_device_name(self, name): + """ Set device name synchronously. """ set_user_name = devolo_idl_proto_plcnetapi_setuserdevicename_pb2.SetUserDeviceName() set_user_name.mac_address = self._mac set_user_name.user_device_name = name - response = await self._async_post("SetUserDeviceName", data=set_user_name.SerializeToString(), timeout=10.0) - r = devolo_idl_proto_plcnetapi_setuserdevicename_pb2.SetUserDeviceNameResponse() - r.FromString(await response.aread()) - return MessageToDict(message=r, including_default_value_fields=True, preserving_proto_field_name=True) + query = self._async_post("SetUserDeviceName", data=set_user_name.SerializeToString(), timeout=10.0) + response = devolo_idl_proto_plcnetapi_setuserdevicename_pb2.SetUserDeviceNameResponse() + response.FromString(query.read()) + return self._message_to_dict(response) From d65669bf9ccb663d1e1439906408c324444adfb5 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Thu, 27 Aug 2020 20:12:51 +0200 Subject: [PATCH 84/93] Silence mypy --- devolo_plc_api/clients/protobuf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devolo_plc_api/clients/protobuf.py b/devolo_plc_api/clients/protobuf.py index 66ee7ee..1a1c1ff 100644 --- a/devolo_plc_api/clients/protobuf.py +++ b/devolo_plc_api/clients/protobuf.py @@ -18,7 +18,7 @@ class Protobuf: @property def url(self) -> str: """ The base URL to query. """ - return f"http://{self._ip}:{self._port}/{self._path}/{self._version}/" + return f"http://{self._ip}:{self._port}/{self._path}/{self._version}/" # type: ignore async def _async_get(self, sub_url: str, timeout: float = TIMEOUT) -> Response: From 42032e0a4f33446e794ea2f1f8538b1f9b71ddf7 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Thu, 27 Aug 2020 20:13:20 +0200 Subject: [PATCH 85/93] Fix sync method --- devolo_plc_api/device_api/deviceapi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index 8fa83db..43d5157 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -143,10 +143,10 @@ async def async_get_wifi_neighbor_access_points(self) -> dict: return self._message_to_dict(wifi_neighbor_aps) @_feature("wifi1") - async def get_wifi_neighbor_access_points(self) -> dict: + def get_wifi_neighbor_access_points(self) -> dict: """ Get wifi access point in the neighborhood synchronously. """ wifi_neighbor_aps = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiNeighborAPsGet() - response = self._async_get("WifiNeighborAPsGet", timeout=15.0) + response = self._get("WifiNeighborAPsGet", timeout=15.0) wifi_neighbor_aps.FromString(response.read()) return self._message_to_dict(wifi_neighbor_aps) From 91a8e3804ad170e7c33a5530f898b1f6084777e4 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Thu, 27 Aug 2020 20:13:46 +0200 Subject: [PATCH 86/93] Prettify docstrings --- devolo_plc_api/plcnet_api/plcnetapi.py | 66 +++++++++++++++++++------- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/devolo_plc_api/plcnet_api/plcnetapi.py b/devolo_plc_api/plcnet_api/plcnetapi.py index e5bfd8f..4ec88f6 100644 --- a/devolo_plc_api/plcnet_api/plcnetapi.py +++ b/devolo_plc_api/plcnet_api/plcnetapi.py @@ -25,13 +25,17 @@ def __init__(self, ip: str, session: Client, path: str, version: str, mac: str): self._path = path self._version = version self._mac = mac - self._user = None # PLC APi is not password protected. - self._password = None # PLC APi is not password protected. + self._user = None # PLC API is not password protected. + self._password = None # PLC API is not password protected. self._logger = logging.getLogger(self.__class__.__name__) async def async_get_network_overview(self) -> dict: - """ Get a PLC network overview asynchronously. """ + """ + Get a PLC network overview asynchronously. + + :return: Network overview + """ self._logger.debug("Getting network overview") network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() response = await self._async_get("GetNetworkOverview") @@ -39,7 +43,11 @@ async def async_get_network_overview(self) -> dict: return self._message_to_dict(network_overview) def get_network_overview(self) -> dict: - """ Get a PLC network overview synchronously. """ + """ + Get a PLC network overview synchronously. + + :return: Network overview + """ self._logger.debug("Getting network overview") network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() response = self._get("GetNetworkOverview") @@ -47,57 +55,83 @@ def get_network_overview(self) -> dict: return self._message_to_dict(network_overview) async def async_identify_device_start(self): - """ Make PLC LED of a device blick to identify it asynchronously. """ + """ + Make PLC LED of a device blick to identify it asynchronously. + + :return: True, if identifying was successfully started, otherwise False + """ identify_device = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceStart() identify_device.mac_address = self._mac query = await self._async_post("IdentifyDeviceStart", data=identify_device.SerializeToString()) response = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceResponse() response.FromString(await query.aread()) - return self._message_to_dict(response) + return bool(not response.result) def identify_device_start(self): - """ Make PLC LED of a device blick to identify it synchronously. """ + """ + Make PLC LED of a device blick to identify it synchronously. + + :return: True, if identifying was successfully started, otherwise False + """ identify_device = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceStart() identify_device.mac_address = self._mac query = self._post("IdentifyDeviceStart", data=identify_device.SerializeToString()) response = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceResponse() response.FromString(query.read()) - return self._message_to_dict(response) + return bool(not response.result) async def async_identify_device_stop(self): - """ Stop the PLC LED blicking asynchronously. """ + """ + Stop the PLC LED blicking asynchronously. + + :return: True, if identifying was successfully stopped, otherwise False + """ identify_device = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceStop() identify_device.mac_address = self._mac query = await self._async_post("IdentifyDeviceStop", data=identify_device.SerializeToString()) response = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceResponse() response.FromString(await query.aread()) - return self._message_to_dict(response) + return bool(not response.result) def identify_device_stop(self): - """ Stop the PLC LED blicking synchronously. """ + """ + Stop the PLC LED blicking synchronously. + + :return: True, if identifying was successfully stopped, otherwise False + """ identify_device = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceStop() identify_device.mac_address = self._mac query = self._async_post("IdentifyDeviceStop", data=identify_device.SerializeToString()) response = devolo_idl_proto_plcnetapi_identifydevice_pb2.IdentifyDeviceResponse() response.FromString(query.read()) - return self._message_to_dict(response) + return bool(not response.result) async def async_set_user_device_name(self, name): - """ Set device name asynchronously. """ + """ + Set device name asynchronously. + + :param name: Name, the device shall have + :return: True, if the device was successfully renamed, otherwise False + """ set_user_name = devolo_idl_proto_plcnetapi_setuserdevicename_pb2.SetUserDeviceName() set_user_name.mac_address = self._mac set_user_name.user_device_name = name query = await self._async_post("SetUserDeviceName", data=set_user_name.SerializeToString(), timeout=10.0) response = devolo_idl_proto_plcnetapi_setuserdevicename_pb2.SetUserDeviceNameResponse() response.FromString(await query.aread()) - return self._message_to_dict(response) + return bool(not response.result) def set_user_device_name(self, name): - """ Set device name synchronously. """ + """ + Set device name synchronously. + + :param name: Name, the device shall have + :return: True, if the device was successfully renamed, otherwise False + """ set_user_name = devolo_idl_proto_plcnetapi_setuserdevicename_pb2.SetUserDeviceName() set_user_name.mac_address = self._mac set_user_name.user_device_name = name query = self._async_post("SetUserDeviceName", data=set_user_name.SerializeToString(), timeout=10.0) response = devolo_idl_proto_plcnetapi_setuserdevicename_pb2.SetUserDeviceNameResponse() response.FromString(query.read()) - return self._message_to_dict(response) + return bool(not response.result) From fa01ba4853f2835ab0a43a3af603fe30f11c5923 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Thu, 27 Aug 2020 20:14:30 +0200 Subject: [PATCH 87/93] Add test__message_to_dict --- tests/fixtures/protobuf.py | 5 +++++ tests/test_profobuf.py | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/tests/fixtures/protobuf.py b/tests/fixtures/protobuf.py index 82fa026..6f17036 100644 --- a/tests/fixtures/protobuf.py +++ b/tests/fixtures/protobuf.py @@ -38,3 +38,8 @@ def mock_wrong_password(mocker): mocker.patch("httpx.Client.get", Client.wrong_password) mocker.patch("httpx.AsyncClient.post", AsyncClient.wrong_password) mocker.patch("httpx.Client.post", Client.wrong_password) + + +@pytest.fixture() +def mock_message_to_dict(mocker): + mocker.patch("google.protobuf.json_format.MessageToDict", return_value=None) diff --git a/tests/test_profobuf.py b/tests/test_profobuf.py index 38e9312..347334c 100644 --- a/tests/test_profobuf.py +++ b/tests/test_profobuf.py @@ -1,5 +1,6 @@ import httpx import pytest +import google.protobuf.json_format from devolo_plc_api.exceptions.device import DevicePasswordProtected @@ -42,6 +43,13 @@ def test__get_wrong_password(self, mocker, mock_protobuf): with pytest.raises(DevicePasswordProtected): mock_protobuf._get("LedSettingsGet") + @pytest.mark.usefixtures("mock_message_to_dict") + def test__message_to_dict(self, mocker, mock_protobuf): + spy = mocker.spy(google.protobuf.json_format, "MessageToDict") + mock_protobuf._message_to_dict("") + + spy.assert_called_once() + @pytest.mark.asyncio @pytest.mark.usefixtures("mock_post") async def test__async_post(self, mocker, mock_protobuf): From 54787dc20df66370a038c8ce22ab1ca9ab98a356 Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Thu, 27 Aug 2020 22:41:17 +0200 Subject: [PATCH 88/93] Switch back to ParseFromString where needed --- devolo_plc_api/device_api/deviceapi.py | 20 ++++++++++---------- devolo_plc_api/plcnet_api/plcnetapi.py | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index 43d5157..b9a18a7 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -50,7 +50,7 @@ async def async_get_led_setting(self): led_setting = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsGet() response = await self._async_get("LedSettingsGet") led_setting.FromString(await response.aread()) - return self._message_to_dict(message=led_setting) + return self._message_to_dict(led_setting) @_feature("led") def get_led_setting(self): @@ -58,7 +58,7 @@ def get_led_setting(self): led_setting = devolo_idl_proto_deviceapi_ledsettings_pb2.LedSettingsGet() response = self._get("LedSettingsGet") led_setting.FromString(response.read()) - return self._message_to_dict(message=led_setting) + return self._message_to_dict(led_setting) @_feature("led") async def async_set_led_setting(self, enable: bool) -> bool: @@ -85,7 +85,7 @@ async def async_get_wifi_connected_station(self) -> dict: """ Get wifi stations connected to the device asynchronously. """ wifi_connected_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiConnectedStationsGet() response = await self._async_get("WifiConnectedStationsGet") - wifi_connected_proto.FromString(await response.aread()) + wifi_connected_proto.ParseFromString(await response.aread()) return self._message_to_dict(wifi_connected_proto) @_feature("wifi1") @@ -93,7 +93,7 @@ def get_wifi_connected_station(self) -> dict: """ Get wifi stations connected to the device synchronously. """ wifi_connected_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiConnectedStationsGet() response = self._get("WifiConnectedStationsGet") - wifi_connected_proto.FromString(response.read()) + wifi_connected_proto.ParseFromString(response.read()) return self._message_to_dict(wifi_connected_proto) @_feature("wifi1") @@ -102,7 +102,7 @@ async def async_get_wifi_guest_access(self) -> dict: self._logger.debug("Getting wifi guest access") wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() response = await self._async_get("WifiGuestAccessGet") - wifi_guest_proto.FromString(await response.aread()) + wifi_guest_proto.ParseFromString(await response.aread()) return self._message_to_dict(wifi_guest_proto) @_feature("wifi1") @@ -111,7 +111,7 @@ def get_wifi_guest_access(self) -> dict: self._logger.debug("Getting wifi guest access") wifi_guest_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiGuestAccessGet() response = self._get("WifiGuestAccessGet") - wifi_guest_proto.FromString(response.read()) + wifi_guest_proto.ParseFromString(response.read()) return self._message_to_dict(wifi_guest_proto) @_feature("wifi1") @@ -139,7 +139,7 @@ async def async_get_wifi_neighbor_access_points(self) -> dict: """ Get wifi access point in the neighborhood asynchronously. """ wifi_neighbor_aps = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiNeighborAPsGet() response = await self._async_get("WifiNeighborAPsGet", timeout=15.0) - wifi_neighbor_aps.FromString(await response.aread()) + wifi_neighbor_aps.ParseFromString(await response.aread()) return self._message_to_dict(wifi_neighbor_aps) @_feature("wifi1") @@ -147,19 +147,19 @@ def get_wifi_neighbor_access_points(self) -> dict: """ Get wifi access point in the neighborhood synchronously. """ wifi_neighbor_aps = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiNeighborAPsGet() response = self._get("WifiNeighborAPsGet", timeout=15.0) - wifi_neighbor_aps.FromString(response.read()) + wifi_neighbor_aps.ParseFromString(response.read()) return self._message_to_dict(wifi_neighbor_aps) @_feature("wifi1") async def async_get_wifi_repeated_access_points(self): wifi_connected_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiRepeatedAPsGet() response = await self._async_get("WifiRepeatedAPsGet") - wifi_connected_proto.FromString(await response.aread()) + wifi_connected_proto.ParseFromString(await response.aread()) return self._message_to_dict(wifi_connected_proto) @_feature("wifi1") def get_wifi_repeated_access_points(self): wifi_connected_proto = devolo_idl_proto_deviceapi_wifinetwork_pb2.WifiRepeatedAPsGet() response = self._get("WifiRepeatedAPsGet") - wifi_connected_proto.FromString(response.read()) + wifi_connected_proto.ParseFromString(response.read()) return self._message_to_dict(wifi_connected_proto) diff --git a/devolo_plc_api/plcnet_api/plcnetapi.py b/devolo_plc_api/plcnet_api/plcnetapi.py index 4ec88f6..bd27bb8 100644 --- a/devolo_plc_api/plcnet_api/plcnetapi.py +++ b/devolo_plc_api/plcnet_api/plcnetapi.py @@ -39,7 +39,7 @@ async def async_get_network_overview(self) -> dict: self._logger.debug("Getting network overview") network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() response = await self._async_get("GetNetworkOverview") - network_overview.FromString(await response.aread()) + network_overview.ParseFromString(await response.aread()) return self._message_to_dict(network_overview) def get_network_overview(self) -> dict: @@ -51,7 +51,7 @@ def get_network_overview(self) -> dict: self._logger.debug("Getting network overview") network_overview = devolo_idl_proto_plcnetapi_getnetworkoverview_pb2.GetNetworkOverview() response = self._get("GetNetworkOverview") - network_overview.FromString(response.content) + network_overview.ParseFromString(response.content) return self._message_to_dict(network_overview) async def async_identify_device_start(self): From 6c00d7757f856634dfce7ef5a47fcec07c79b52b Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Thu, 27 Aug 2020 22:42:29 +0200 Subject: [PATCH 89/93] Add test for async_get_led_setting --- tests/test_deviceapi.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/test_deviceapi.py diff --git a/tests/test_deviceapi.py b/tests/test_deviceapi.py new file mode 100644 index 0000000..3e8dc3c --- /dev/null +++ b/tests/test_deviceapi.py @@ -0,0 +1,26 @@ +from unittest.mock import patch + +import pytest +from asynctest import CoroutineMock +from httpx import AsyncClient, Client, Response + +from devolo_plc_api.device_api.deviceapi import DeviceApi + + +class TestDeviceApi: + + @pytest.mark.asyncio + async def test_async_get_led_setting(self, request): + ip = request.cls.ip + session = AsyncClient() + path = request.cls.device_info['_dvl-deviceapi._tcp.local.']['Path'] + version = request.cls.device_info['_dvl-deviceapi._tcp.local.']['Version'] + features = "led" + password = "password" + + with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=CoroutineMock(return_value=Response)), \ + patch("httpx.Response.aread", new=CoroutineMock(return_value=b"")): + device_api = DeviceApi(ip, session, path, version, features, password) + led_setting = await device_api.async_get_led_setting() + + assert led_setting['state'] == "LED_ON" From 68aedf6cbb04510afc00b3db4fc0c79e0425a88a Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Fri, 28 Aug 2020 08:09:23 +0200 Subject: [PATCH 90/93] fix test__message_to_dict --- tests/test_profobuf.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_profobuf.py b/tests/test_profobuf.py index 347334c..d3d4c21 100644 --- a/tests/test_profobuf.py +++ b/tests/test_profobuf.py @@ -1,7 +1,8 @@ +import google.protobuf.json_format import httpx import pytest -import google.protobuf.json_format +from devolo_plc_api.device_api.devolo_idl_proto_deviceapi_ledsettings_pb2 import LedSettingsSetResponse from devolo_plc_api.exceptions.device import DevicePasswordProtected @@ -45,8 +46,9 @@ def test__get_wrong_password(self, mocker, mock_protobuf): @pytest.mark.usefixtures("mock_message_to_dict") def test__message_to_dict(self, mocker, mock_protobuf): - spy = mocker.spy(google.protobuf.json_format, "MessageToDict") - mock_protobuf._message_to_dict("") + + spy = mocker.spy(google.protobuf.json_format._Printer, "_MessageToJsonObject") + mock_protobuf._message_to_dict(LedSettingsSetResponse()) spy.assert_called_once() From 452d9014b1627967b6aed7d04e4f0b9b5aec9d0c Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Fri, 28 Aug 2020 08:39:03 +0200 Subject: [PATCH 91/93] remove unused fixture --- tests/test_profobuf.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_profobuf.py b/tests/test_profobuf.py index d3d4c21..e673afc 100644 --- a/tests/test_profobuf.py +++ b/tests/test_profobuf.py @@ -44,9 +44,7 @@ def test__get_wrong_password(self, mocker, mock_protobuf): with pytest.raises(DevicePasswordProtected): mock_protobuf._get("LedSettingsGet") - @pytest.mark.usefixtures("mock_message_to_dict") def test__message_to_dict(self, mocker, mock_protobuf): - spy = mocker.spy(google.protobuf.json_format._Printer, "_MessageToJsonObject") mock_protobuf._message_to_dict(LedSettingsSetResponse()) From 7a24a6922241fcfcc1c92b050f2c473cda203f80 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Fri, 28 Aug 2020 08:39:26 +0200 Subject: [PATCH 92/93] optimize test test_async_get_led_setting --- tests/test_deviceapi.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/test_deviceapi.py b/tests/test_deviceapi.py index 3e8dc3c..be4dade 100644 --- a/tests/test_deviceapi.py +++ b/tests/test_deviceapi.py @@ -2,25 +2,27 @@ import pytest from asynctest import CoroutineMock -from httpx import AsyncClient, Client, Response +from google.protobuf.json_format import MessageToDict +from httpx import AsyncClient, Response from devolo_plc_api.device_api.deviceapi import DeviceApi +from devolo_plc_api.device_api.devolo_idl_proto_deviceapi_ledsettings_pb2 import LedSettingsGet class TestDeviceApi: @pytest.mark.asyncio async def test_async_get_led_setting(self, request): - ip = request.cls.ip - session = AsyncClient() - path = request.cls.device_info['_dvl-deviceapi._tcp.local.']['Path'] - version = request.cls.device_info['_dvl-deviceapi._tcp.local.']['Version'] - features = "led" - password = "password" - with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=CoroutineMock(return_value=Response)), \ patch("httpx.Response.aread", new=CoroutineMock(return_value=b"")): - device_api = DeviceApi(ip, session, path, version, features, password) + device_api = DeviceApi(request.cls.ip, + AsyncClient(), + request.cls.device_info['_dvl-deviceapi._tcp.local.']['Path'], + request.cls.device_info['_dvl-deviceapi._tcp.local.']['Version'], + "led", + "password") led_setting = await device_api.async_get_led_setting() - assert led_setting['state'] == "LED_ON" + assert led_setting == MessageToDict(LedSettingsGet(), + including_default_value_fields=True, + preserving_proto_field_name=True) From b234c84aa51de0b84606b0d3d77f3573dfbba097 Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Fri, 28 Aug 2020 08:47:25 +0200 Subject: [PATCH 93/93] update changelog --- docs/CHANGELOG.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1bd3836..3a5c0b9 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,9 +4,20 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [v0.1.0] - 28.08.2020 ### Added -- Get PLC data rates +#### Device API +- Get LED settings +- Set LED settings +- Get connected wifi clients - Get details about wifi guest access +- Enable or disable guest wifi +- Get visible wifi access points +- Get details about master wifi (repeater only) + +#### PLC API +- Get details about your powerline network +- Start and stop identifying your PLC device +- Rename your device