Example #1
0
 def datagram_received(self, data, addr):
     response = unpack_lifx_message(data)
     response.ip_addr = addr[0]
     if type(response) == StateService and response.service == 1 : #Only look for UDP services
         #if self.parent.log:
             #self.parent.log.debug("DISC: " + str(response))
         #Discovered
         if response.target_addr not in self.lights and response.target_addr != BROADCAST_MAC:
             self.lights.append(response.target_addr)
             if self.ipv6prefix:
                 coro = self.loop.create_datagram_endpoint(
                     partial(Light,self.loop,response.target_addr, response.ip_addr, response.port, parent=self),
                     family = socket.AF_INET6, remote_addr=(mac_to_ipv6_linklocal(response.target_addr,self.ipv6prefix), response.port))
             else:
                 coro = self.loop.create_datagram_endpoint(
                     partial(Light,self.loop,response.target_addr, response.ip_addr, response.port,parent=self),
                     family = socket.AF_INET, remote_addr=(response.ip_addr, response.port))
             
             self.light_tp[response.target_addr] = self.loop.create_task(coro)
            
     elif type(response) == LightState and response.target_addr != BROADCAST_MAC:
         if response.target_addr not in self.lights :
             #looks like the lights are volunteering LigthState after booting 
             self.lights.append(response.target_addr)
             if self.ipv6prefix:
                 coro = self.loop.create_datagram_endpoint(
                     partial(Light,self.loop,response.target_addr, response.ip_addr, UDP_BROADCAST_PORT, parent=self),
                     family = socket.AF_INET6, remote_addr=(mac_to_ipv6_linklocal(response.target_addr,self.ipv6prefix), UDP_BROADCAST_PORT))
             else:
                 coro = self.loop.create_datagram_endpoint(
                     partial(Light,self.loop,response.target_addr, response.ip_addr, UDP_BROADCAST_PORT,parent=self),
                     family = socket.AF_INET, remote_addr=(response.ip_addr, UDP_BROADCAST_PORT))
             
             self.light_tp[response.target_addr] = self.loop.create_task(coro)
Example #2
0
 def datagram_received(self, data, addr):
     response = unpack_lifx_message(data)
     #if self.log:
         #self.log.debug("RECV: " + str(response))
     if response.seq_num in self.message:
         response_type,myevent,callb = self.message[response.seq_num]
         
         if type(response) == response_type:
             if response.origin == 1 and response.source_id == self.source_id:
                 self.ip_addr = addr
                 if "State" in response.__class__.__name__:
                     setmethod="resp_set_"+response.__class__.__name__.replace("State","").lower()
                     if setmethod in dir(self) and callable(getattr(self,setmethod)):
                         getattr(self,setmethod)(response)   
                 if callb:
                     callb(self,response)
                 myevent.set()
             del(self.message[response.seq_num])
         elif type(response) == Acknowledgement:
             pass
         else: #Total fuck up
             del(self.message[response.seq_num])