Exemplo n.º 1
0
 def verify(self, messages):
     assertions = self._assertions
     for message in messages:
         messageData = SSDP.parseMessage(message)
         for assertion in assertions:
             if compareMessages(messageData, assertion):
                 assertions.remove(assertion)
                 break
         else:
             return False
     return len(assertions) == 0
Exemplo n.º 2
0
	def verify(self, messages):
		assertions = self._assertions
		for message in messages:
			messageData = SSDP.parseMessage(message)
			for assertion in assertions:
				if compareMessages(messageData, assertion):
					assertions.remove(assertion)
					break
			else:
				return False
		return len(assertions) == 0
Exemplo n.º 3
0
	def test_rootDeviceWithChildDeviceAndServiceWithChildService(self):
		root = SSDP.Device("thisisauuid1", "thisisaurn1", location="127.0.0.1", bootId=0)
		childDevice = SSDP.Device("thisisauuid2", "thisisaurn2", bootId=1)
		childDevice.addService(SSDP.Service("thisisaserviceurn1"))
		root.addDevice(childDevice)
		root.addService(SSDP.Service("thisisaserviceurn2"))
		
		ssdpAssert = SSDPAssert()
		ssdpAssert.addAssert("NOTIFY * HTTP/1.1", {"NTS": "ssdp:alive",
													"CACHE-CONTROL": "max-age - 5",
													"LOCATION": "127.0.0.1",
													"NT": "upnp:rootdevice",
													"USN": "uuid:thisisauuid1::upnp:rootdevice",
													"BOOTID.UPNP.ORG": "0"})
		ssdpAssert.addAssert("NOTIFY * HTTP/1.1", {"NTS": "ssdp:alive",
													"CACHE-CONTROL": "max-age - 5",
													"LOCATION": "127.0.0.1",
													"NT": "uuid:thisisauuid1",
													"USN": "uuid:thisisauuid1",
													"BOOTID.UPNP.ORG": "0"})
		ssdpAssert.addAssert("NOTIFY * HTTP/1.1", {"NTS": "ssdp:alive",
													"CACHE-CONTROL": "max-age - 5",
													"LOCATION": "127.0.0.1",
													"NT": "urn:thisisaurn1",
													"USN": "uuid:thisisauuid1::urn:thisisaurn1",
													"BOOTID.UPNP.ORG": "0"})
		ssdpAssert.addAssert("NOTIFY * HTTP/1.1", {"NTS": "ssdp:alive",
													"CACHE-CONTROL": "max-age - 5",
													"LOCATION": "127.0.0.1",
													"NT": "uuid:thisisauuid2",
													"USN": "uuid:thisisauuid2",
													"BOOTID.UPNP.ORG": "0"})
		ssdpAssert.addAssert("NOTIFY * HTTP/1.1", {"NTS": "ssdp:alive",
													"CACHE-CONTROL": "max-age - 5",
													"LOCATION": "127.0.0.1",
													"NT": "urn:thisisaurn2",
													"USN": "uuid:thisisauuid2::urn:thisisaurn2",
													"BOOTID.UPNP.ORG": "0"})
		ssdpAssert.addAssert("NOTIFY * HTTP/1.1", {"NTS": "ssdp:alive",
													"CACHE-CONTROL": "max-age - 5",
													"LOCATION": "127.0.0.1",
													"NT": "urn:thisisaserviceurn1",
													"USN": "uuid:thisisauuid2::urn:thisisaserviceurn1",
													"BOOTID.UPNP.ORG": "0"})
		ssdpAssert.addAssert("NOTIFY * HTTP/1.1", {"NTS": "ssdp:alive",
													"CACHE-CONTROL": "max-age - 5",
													"LOCATION": "127.0.0.1",
													"NT": "urn:thisisaserviceurn2",
													"USN": "uuid:thisisauuid1::urn:thisisaserviceurn2",
													"BOOTID.UPNP.ORG": "0"})
		
		messages = SSDP.renderAliveMessages(root, maxAge=5)
		self.assertTrue(ssdpAssert.verify(messages))
Exemplo n.º 4
0
    def index(self):
        if not self.loaded:
            # find bridge and load
            resp = SSDP.discover()
            content = ''
            bridges = []
            http = httplib2.Http()
            try:
                for r in resp:
                    # Maybe this fixed the KeyError seen in http://www.everyhue.com/?page_id=38#/discussion/comment/1728 ?
                    if r in resp.keys():
                        loc = resp[r].getheader('location')
                        if loc != None:
                            response, desc = http.request(loc, method="GET")
                            if response[
                                    'status'] == '200' and 'Philips hue' in desc:
                                bridges.append(r[0])
            except KeyError as e:
                cherrypy.log(
                    "KeyError during parsing of SSDP responses on key: {0}".
                    format(e.message))
                cherrypy.log("Received responses from: ")
                for r in resp.keys():
                    cherrypy.log(str(r))
                return "KeyError during parsing of SSDP responses on key: {0}".format(
                    e.message)

            if len(bridges) > 0:
                # TODO: Make a menu to select one of multiple bridges, for now just use the first one you find.
                #if len(bridges) == 1:
                # we only found one bridge, use it!
                cherrypy.log("Found bridge @ {}".format(bridges[0]))
                self.startup(bridges[0])
                self.loaded = True
                content = self.plugins.HueControl.index()
                #else:
                #    return "More than one bridge found. We (currently) do not support multiple bridges!"
            else:
                content = "No bridges found!"

            return content
        else:
            return self.plugins.HueControl.index()
Exemplo n.º 5
0
 def index(self):
     if not self.loaded:
         # find bridge and load
         resp = SSDP.discover()
         content = ''
         bridges = []
         http = httplib2.Http()
         try:
             for r in resp:
                 # Maybe this fixed the KeyError seen in http://www.everyhue.com/?page_id=38#/discussion/comment/1728 ?
                 if r in resp.keys():
                     loc = resp[r].getheader('location')
                     if loc != None:
                         response, desc = http.request(loc, method="GET")
                         if response['status'] == '200' and 'Philips hue' in desc:
                             bridges.append(r[0])
         except KeyError as e:
             cherrypy.log("KeyError during parsing of SSDP responses on key: {0}".format(e.message))
             cherrypy.log("Received responses from: ")
             for r in resp.keys():
                 cherrypy.log(str(r))
             return "KeyError during parsing of SSDP responses on key: {0}".format(e.message)
                     
         if len(bridges) > 0:    
             # TODO: Make a menu to select one of multiple bridges, for now just use the first one you find.
             #if len(bridges) == 1:
             # we only found one bridge, use it!
             cherrypy.log("Found bridge @ {}".format(bridges[0]))
             self.startup(bridges[0])
             self.loaded = True
             content = self.plugins.HueControl.index()
             #else:
             #    return "More than one bridge found. We (currently) do not support multiple bridges!"
         else:
             content = "No bridges found!"
                         
         return content
     else:
         return self.plugins.HueControl.index()
Exemplo n.º 6
0
    def test_rootDeviceWithChildDeviceAndServiceWithChildService(self):
        root = SSDP.Device("thisisauuid1",
                           "thisisaurn1",
                           location="127.0.0.1",
                           bootId=0)
        childDevice = SSDP.Device("thisisauuid2", "thisisaurn2", bootId=1)
        childDevice.addService(SSDP.Service("thisisaserviceurn1"))
        root.addDevice(childDevice)
        root.addService(SSDP.Service("thisisaserviceurn2"))

        ssdpAssert = SSDPAssert()
        ssdpAssert.addAssert(
            "NOTIFY * HTTP/1.1", {
                "NTS": "ssdp:alive",
                "CACHE-CONTROL": "max-age - 5",
                "LOCATION": "127.0.0.1",
                "NT": "upnp:rootdevice",
                "USN": "uuid:thisisauuid1::upnp:rootdevice",
                "BOOTID.UPNP.ORG": "0"
            })
        ssdpAssert.addAssert(
            "NOTIFY * HTTP/1.1", {
                "NTS": "ssdp:alive",
                "CACHE-CONTROL": "max-age - 5",
                "LOCATION": "127.0.0.1",
                "NT": "uuid:thisisauuid1",
                "USN": "uuid:thisisauuid1",
                "BOOTID.UPNP.ORG": "0"
            })
        ssdpAssert.addAssert(
            "NOTIFY * HTTP/1.1", {
                "NTS": "ssdp:alive",
                "CACHE-CONTROL": "max-age - 5",
                "LOCATION": "127.0.0.1",
                "NT": "urn:thisisaurn1",
                "USN": "uuid:thisisauuid1::urn:thisisaurn1",
                "BOOTID.UPNP.ORG": "0"
            })
        ssdpAssert.addAssert(
            "NOTIFY * HTTP/1.1", {
                "NTS": "ssdp:alive",
                "CACHE-CONTROL": "max-age - 5",
                "LOCATION": "127.0.0.1",
                "NT": "uuid:thisisauuid2",
                "USN": "uuid:thisisauuid2",
                "BOOTID.UPNP.ORG": "0"
            })
        ssdpAssert.addAssert(
            "NOTIFY * HTTP/1.1", {
                "NTS": "ssdp:alive",
                "CACHE-CONTROL": "max-age - 5",
                "LOCATION": "127.0.0.1",
                "NT": "urn:thisisaurn2",
                "USN": "uuid:thisisauuid2::urn:thisisaurn2",
                "BOOTID.UPNP.ORG": "0"
            })
        ssdpAssert.addAssert(
            "NOTIFY * HTTP/1.1", {
                "NTS": "ssdp:alive",
                "CACHE-CONTROL": "max-age - 5",
                "LOCATION": "127.0.0.1",
                "NT": "urn:thisisaserviceurn1",
                "USN": "uuid:thisisauuid2::urn:thisisaserviceurn1",
                "BOOTID.UPNP.ORG": "0"
            })
        ssdpAssert.addAssert(
            "NOTIFY * HTTP/1.1", {
                "NTS": "ssdp:alive",
                "CACHE-CONTROL": "max-age - 5",
                "LOCATION": "127.0.0.1",
                "NT": "urn:thisisaserviceurn2",
                "USN": "uuid:thisisauuid1::urn:thisisaserviceurn2",
                "BOOTID.UPNP.ORG": "0"
            })

        messages = SSDP.renderAliveMessages(root, maxAge=5)
        self.assertTrue(ssdpAssert.verify(messages))
Exemplo n.º 7
0
 def test_constructor_configId2p24_ThrowValueError(self):
     self.assertRaises(ValueError,
                       lambda: SSDP.Device("fake", "fake", configId=2**24))
Exemplo n.º 8
0
 def test_constructor_bootId2p31_ThrowValueError(self):
     self.assertRaises(ValueError,
                       lambda: SSDP.Device("fake", "fake", bootId=2**31))
Exemplo n.º 9
0
 def test_updateBootId_bootIdRollOverAtMax(self):
     device = SSDP.Device("fake", "fake", bootId=2**31 - 1)
     device.updateBootId()
     self.assertEqual(0, device.bootId)
Exemplo n.º 10
0
 def test_updateBootId_bootIdDifferent(self):
     device = SSDP.Device("fake", "fake")
     initialBootId = device.bootId
     device.updateBootId()
     self.assertNotEqual(initialBootId, device.bootId)
Exemplo n.º 11
0
def refresh():
    global deviceArray

    deviceArray = None
    SSDP.refreshDevices()
Exemplo n.º 12
0
def init():
    SSDP.DeviceUpdateMethod = deviceAdded
    SSDP.refreshDevices()