Add additional logging to rest sensor (#32068)

pull/32511/head
Alok Saboo 2020-02-21 15:11:25 -05:00 committed by GitHub
parent f32411e394
commit 2fb66fd866
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -201,11 +201,13 @@ class RestSensor(Entity):
self.rest.update()
value = self.rest.data
_LOGGER.debug("Data fetched from resource: %s", value)
content_type = self.rest.headers.get("content-type")
if content_type and content_type.startswith("text/xml"):
try:
value = json.dumps(xmltodict.parse(value))
_LOGGER.debug("JSON converted from XML: %s", value)
except ExpatError:
_LOGGER.warning(
"REST xml result could not be parsed and converted to JSON."