Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, url, mac, rediscovery_enabled=True):
"""Create a WeMo device."""
self._state = None
self.basic_state_params = {}
base_url = url.rsplit('/', 1)[0]
parsed_url = urlparse(url)
self.host = parsed_url.hostname
self.port = parsed_url.port
self.retrying = False
self.mac = mac
self.rediscovery_enabled = rediscovery_enabled
xml = requests.get(url, timeout=10)
self._config = deviceParser.parseString(xml.content).device
service_list = self._config.serviceList
self.services = {}
for svc in service_list.service:
svcname = svc.get_serviceType().split(':')[-2]
service = Service(self, svc, base_url)
service.eventSubURL = base_url + svc.get_eventSubURL()
self.services[svcname] = service
setattr(self, svcname, service)
def device_from_description(description_url, mac, rediscovery_enabled=True):
"""Return object representing WeMo device running at host, else None."""
xml = requests.get(description_url, timeout=10)
uuid = deviceParser.parseString(xml.content).device.UDN
device_mac = mac or deviceParser.parseString(xml.content).device.macAddress
if device_mac is None:
LOG.debug(
'No MAC address was supplied or found in setup xml at: %s.',
description_url)
return device_from_uuid_and_location(
uuid, device_mac, description_url,
rediscovery_enabled=rediscovery_enabled)
def device_from_host(host):
""" Returns object representing WeMo device running at host, else None. """
xml_url = "http://{}:49153/setup.xml".format(host)
try:
xml = requests.get(xml_url, timeout=10)
uuid = deviceParser.parseString(xml.content).device.UDN
return device_from_uuid_and_location(uuid, xml_url)
except Exception: # pylint: disable=broad-except
return None
def device_from_description(description_url, mac, rediscovery_enabled=True):
"""Return object representing WeMo device running at host, else None."""
xml = requests.get(description_url, timeout=10)
uuid = deviceParser.parseString(xml.content).device.UDN
device_mac = mac or deviceParser.parseString(xml.content).device.macAddress
if device_mac is None:
LOG.debug(
'No MAC address was supplied or found in setup xml at: %s.',
description_url)
return device_from_uuid_and_location(
uuid, device_mac, description_url,
rediscovery_enabled=rediscovery_enabled)