Пример #1
0
 def loadDevices(self):
     deviceManager = DeviceManager(self.context)
     for dev in TPLinkSmartHomeProtocol.discover():
         plug = SmartPlug(dev['ip'])
         deviceManager.addDevice(TPLinkDevice(plug))
     deviceManager.finishedLoading('tplink')
Пример #2
0
import logging
from pprint import pprint as pp

from pyHS100 import TPLinkSmartHomeProtocol
logging.basicConfig(level=logging.DEBUG)

for dev in TPLinkSmartHomeProtocol.discover():
    print("Found device!")
    pp(dev)
Пример #3
0
GPIO.setmode(GPIO.BCM)
for port in GPIO_PORTS:
    print("Setting up port: %d" % (port))
    GPIO.setup(port, GPIO.IN, pull_up_down=GPIO.PUD_UP)

##### wait for the network to be established

##### find Plug
devToFind = 'Smart Plug 1'
devIP = ""
foundDev = False

print("Now searching for device: %s" % (devToFind))
while not foundDev:
    try:
        devs = TPLinkSmartHomeProtocol.discover(timeout=timeout)
    except IOError as e:
        if e.errno == 101:  # Network Unreachable
            devs = {}
        else:
            raise
    for devId in devs:
        alias = devId['sys_info']['system']['get_sysinfo']['alias']
        if alias == devToFind:
            devIP = devId['ip']
            foundDev = True

if foundDev:
    print("Setting up control loop with %s: %s" % (devToFind, devIP))
    plug = SmartPlug(devIP)
Пример #4
0
def discover(timeout):
    """Discover devices in the network."""
    click.echo("Discovering devices for %s seconds" % timeout)
    for dev in TPLinkSmartHomeProtocol.discover(timeout=timeout):
        print("Found device: %s" % pformat(dev))