How to use the pychromecast.PyChromecastException function in PyChromecast

To help you get started, we’ve selected a few PyChromecast examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github balloob / pychromecast / pychromecast.py View on Github external
or else the current running app. """
    # /apps/ will redirect to the active app
    url = (FORMAT_APP_PATH.format(host, app_id) if app_id
                        else FORMAT_BASE_URL.format(host) + "/apps/")

    try:
        status_el = ET.fromstring(CC_SESSION.get(url).text)
        options = status_el.find(XML_NS_DIAL + "options").attrib

    except requests.exceptions.RequestException as error:
        # If the host is incorrect and thus triggers
        # a RequestException reraise it
        raise error

    except:
        raise PyChromecastException("Error parsing app status XML")

    name = _read_xml_element(status_el, XML_NS_DIAL,
                                    "name", "Unknown application")
    state = _read_xml_element(status_el, XML_NS_DIAL,
                                    "state", "unknown")

    return AppStatus(name, state, options)
github balloob / pychromecast / pychromecast.py View on Github external
""" Returns the device status as a named tuple. """

    try:
        status_el = ET.fromstring(CC_SESSION.get(
            FORMAT_BASE_URL.format(host) + "/ssdp/device-desc.xml").text)

        device_info_el = status_el.find(XML_NS_UPNP_DEVICE + "device")
        api_version_el = status_el.find(XML_NS_UPNP_DEVICE + "specVersion")

    except requests.exceptions.RequestException as error:
        # If the host is incorrect and thus triggers a
        # RequestException reraise it
        raise error

    except:
        raise PyChromecastException("Error parsing device status XML")


    friendly_name = _read_xml_element(device_info_el, XML_NS_UPNP_DEVICE,
                                        "friendlyName", "Unknown Chromecast")
    model_name = _read_xml_element(device_info_el, XML_NS_UPNP_DEVICE,
                                        "modelName", "Unknown model name")
    manufacturer = _read_xml_element(device_info_el, XML_NS_UPNP_DEVICE,
                                        "manufacturer", "Unknown manufacturer")

    api_version = (int(_read_xml_element(api_version_el, XML_NS_UPNP_DEVICE,
                                        "major", -1)),
                   int(_read_xml_element(api_version_el, XML_NS_UPNP_DEVICE,
                                        "minor", -1)))

    return DeviceStatus(friendly_name, model_name, manufacturer, api_version)