def respond_to_search(self, addr: Tuple[str, int], discover_pattern: str, mx: float = 0.) -> None: """Build and send an appropriate response to an SSDP search request. Args: addr: Address sending search request """ date_str = formatdate(timeval=None, localtime=False, usegmt=True) for device in self.devices: name = device.get('name') ip_address = device.get('ip_address') port = device.get('port') location = f'http://{ip_address}:{port}/setup.xml' serial = make_serial(name) usn = (f'uuid:Socket-1_0-{serial}::' f'{discover_pattern.lstrip("ST: ")}') response = '\n'.join([ 'HTTP/1.1 200 OK', 'CACHE-CONTROL: max-age=86400', f'DATE: {date_str}', 'EXT:', f'LOCATION: {location}', 'OPT: "http://schemas.upnp.org/upnp/1/0/"; ns=01', f'01-NLS: {uuid.uuid4()}', 'SERVER: Fauxmo, UPnP/1.0, Unspecified', f'{discover_pattern}', f'USN: {usn}', ]) + '\n\n' asyncio.ensure_future( self._send_async_response(response.encode('utf8'), addr, mx))
def respond_to_search(self, addr: Tuple[str, int]) -> None: """Build and send an appropriate response to an SSDP search request. Args: addr: Address sending search request """ date_str = formatdate(timeval=None, localtime=False, usegmt=True) for device in self.devices: name = device.get('name') ip_address = device.get('ip_address') port = device.get('port') location = f'http://{ip_address}:{port}/setup.xml' serial = make_serial(name) response = '\n'.join([ 'HTTP/1.1 200 OK', 'CACHE-CONTROL: max-age=86400', f'DATE: {date_str}', 'EXT:', f'LOCATION: {location}', 'OPT: "http://schemas.upnp.org/upnp/1/0/"; ns=01', f'01-NLS: {uuid.uuid4()}', 'SERVER: Fauxmo, UPnP/1.0, Unspecified', 'ST: urn:Belkin:device:**', f'USN: uuid:Socket-1_0-{serial}::urn:Belkin:device:**', ]) + '\n\n' logger.debug(f"Sending response to {addr}:\n{response}") self.transport.sendto(response.encode(), addr) random.shuffle(self.devices)
def respond_to_search(self, addr): """Build and send an appropriate response to an SSDP search request.""" date_str = formatdate(timeval=None, localtime=False, usegmt=True) for device in self.devices: name = device.get('name') ip_address = device.get('ip_address') port = device.get('port') location = 'http://{}:{}/setup.xml'.format(ip_address, port) serial = make_serial(name) response = '\r\n'.join([ 'HTTP/1.1 200 OK', 'CACHE-CONTROL: max-age=86400', 'DATE: {}'.format(date_str), 'EXT:', 'LOCATION: {}'.format(location), 'OPT: "http://schemas.upnp.org/upnp/1/0/"; ns=01', '01-NLS: {}'.format(uuid.uuid4()), 'SERVER: Unspecified, UPnP/1.0, Unspecified', 'ST: urn:Belkin:device:**', 'USN: uuid:Socket-1_0-{}::urn:Belkin:device:**'.format(serial) ]) + 2 * '\r\n' logger.debug("Sending response to {}:\n{}".format(addr, response)) self.transport.sendto(response.encode(), addr)
def __init__(self, name: str, plugin: FauxmoPlugin) -> None: """Initialize a Fauxmo device. Args: name: How you want to call the device, e.g. "bedroom light" plugin: Fauxmo plugin """ self.name = name self.serial = make_serial(name) self.plugin = plugin self.transport: asyncio.Transport = None
def __init__(self, name, action_handler): """Initialize a Fauxmo device. Args: name (str): How you want to call the device, e.g. "bedroom light" action_handler (fauxmo.handler): Fauxmo action handler object """ self.name = name self.serial = make_serial(name) self.action_handler = action_handler
def respond_to_search( self, addr: Tuple[str, int], discover_pattern: str, mx: float = 0.0 ) -> None: """Build and send an appropriate response to an SSDP search request. Args: addr: Address sending search request """ date_str = formatdate(timeval=None, localtime=False, usegmt=True) for device in self.devices: name = device.get("name") ip_address = device.get("ip_address") port = device.get("port") location = f"http://{ip_address}:{port}/setup.xml" serial = make_serial(name) usn = ( f"uuid:Socket-1_0-{serial}::" f'{discover_pattern.lstrip("ST: ")}' ) response = (Fauxmo.NEWLINE).join( [ "HTTP/1.1 200 OK", "CACHE-CONTROL: max-age=86400", f"DATE: {date_str}", "EXT:", f"LOCATION: {location}", 'OPT: "http://schemas.upnp.org/upnp/1/0/"; ns=01', f"01-NLS: {uuid.uuid4()}", "SERVER: Fauxmo, UPnP/1.0, Unspecified", f"{discover_pattern}", f"USN: {usn}", ] ) + (2 * Fauxmo.NEWLINE) asyncio.ensure_future( self._send_async_response(response.encode("utf8"), addr, mx) )