diff --git a/homeassistant/components/onvif/device.py b/homeassistant/components/onvif/device.py index 2e0f1ca8c6f..f93529ea612 100644 --- a/homeassistant/components/onvif/device.py +++ b/homeassistant/components/onvif/device.py @@ -12,7 +12,7 @@ from httpx import RequestError import onvif from onvif import ONVIFCamera from onvif.exceptions import ONVIFError -from zeep.exceptions import Fault, TransportError, XMLParseError +from zeep.exceptions import Fault, TransportError, XMLParseError, XMLSyntaxError from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -286,7 +286,21 @@ class ONVIFDevice: async def async_get_device_info(self) -> DeviceInfo: """Obtain information about this device.""" device_mgmt = self.device.create_devicemgmt_service() - device_info = await device_mgmt.GetDeviceInformation() + manufacturer = None + model = None + firmware_version = None + serial_number = None + try: + device_info = await device_mgmt.GetDeviceInformation() + except (XMLParseError, XMLSyntaxError, TransportError) as ex: + # Some cameras have invalid UTF-8 in their device information (TransportError) + # and others have completely invalid XML (XMLParseError, XMLSyntaxError) + LOGGER.warning("%s: Failed to fetch device information: %s", self.name, ex) + else: + manufacturer = device_info.Manufacturer + model = device_info.Model + firmware_version = device_info.FirmwareVersion + serial_number = device_info.SerialNumber # Grab the last MAC address for backwards compatibility mac = None @@ -306,10 +320,10 @@ class ONVIFDevice: ) return DeviceInfo( - device_info.Manufacturer, - device_info.Model, - device_info.FirmwareVersion, - device_info.SerialNumber, + manufacturer, + model, + firmware_version, + serial_number, mac, )