Page 1 of 1

I have developed a cool python library

Posted: Saturday 15 December 2018 20:54
by kdschlosser
I developed a pretty nifty python library that possibly someone might be willing to code a Domoticz interface for

https://github.com/kdschlosser/UPNP_Device

it basically scans a network discovering all UPNP devices. and builds a python object that represents the device (based on IP) it supports embedded devices and nested upnp service. maps out the data types and builds methods for the upnp function calls. check to ensure the proper data type is being used. provides return data types and names for the returned data, as well as parameter names. It is a pretty quick implementation discovers all devices typically in less then 4 seconds.

maybe it could be useful.

Re: I have developed a cool python library

Posted: Sunday 16 December 2018 9:23
by devros
Hi, looks good any info in install and usage ? Looks like setup.py is missing

Re: I have developed a cool python library

Posted: Monday 17 December 2018 9:22
by kdschlosser
I need to create a new branch and merge my most recent changes. I forgot to do that.

I will have it updated in a second.

Re: I have developed a cool python library

Posted: Monday 17 December 2018 9:50
by kdschlosser
the usage is really simple.

Code: Select all

import UPNP_Device

for device in UPNP_Device.discover():
    print(device)
    
or if you have a static IP of a device you want to specifically target

Code: Select all

import UPNP_Device

for device in UPNP_Device.discover(ip='192.168.1.1'):
    print(device)
you can also adjust the timeout

Code: Select all

import UPNP_Device

for device in UPNP_Device.discover(timeout=10):
    print(device)
doing the print will spit out the information for every service/device/method/data type basically all of the information you would want to know.

You can iterate over specific devices and services like so

Code: Select all

import UPNP_Device

for device in UPNP_Device.discover(timeout=10):
    for service in device.services:
        print(service.__name__)
with UPNP the devices and services can be nested.

Code: Select all

import UPNP_Device

for device in UPNP_Device.discover(timeout=10):
    for service in device.services:
        print(service.__name__)
        for service in service.services:
            print('   ', service.__name__)
    
    for embedded_device in device.devices:
        print embedded_device.__name__
        for service in embedded_device.services:
            print('   ', serviice.__name__)

and if you want to iterate the functions of a service

Code: Select all

import UPNP_Device

for device in UPNP_Device.discover(timeout=10):
    for service in device.services:
        print(service.__name__)
        for action in service.actions:
            print('   ', action.__name__)

I can get into quite a bit of detail on how to get the data types for the parameters that are used in the functions if needed. But that is a good start there. You should be able to tinker about a bit.