(host)
Returns the device status as a named tuple.
Returns the device status as a named tuple.
Returns the device status as a named tuple .
def get_device_status(host):
    """ Returns the device status as a named tuple. """

    try:
        req = CC_SESSION.get(
            FORMAT_BASE_URL.format(host) + "/ssdp/device-desc.xml")

        status_el = ET.fromstring(req.text.encode("UTF-8"))

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

        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)

    except (requests.exceptions.RequestException, ET.ParseError):
        return None
def get_device_status ( host ) : try : req = CC_SESSION . get ( FORMAT_BASE_URL . format ( host ) + "/ssdp/device-desc.xml" ) status_el = ET . fromstring ( req . text . encode ( "UTF-8" ) ) device_info_el = status_el . find ( XML_NS_UPNP_DEVICE + "device" ) api_version_el = status_el . find ( XML_NS_UPNP_DEVICE + "specVersion" ) 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 ) except ( requests . exceptions . RequestException , ET . ParseError ) : return None