Skip to content

Error handling when device returns unexpected data #6

Description

@gtdiehl

I really haven't had any problems with the Home Assistant rainforest_eagle sensor calling uEagle.

Though today I was debugging an issue and found that I had to use tcpflow or wget to look into what is going on when the command is sent to the Eagle device during the hwtest() method in the Home Assistant rainforest_eagle sensor code.

When a command is sent to the Eagle and authentication fails it seems this line of code expects a JSON response but will fail as the Eagle will instead return HTML data instead

data = json.loads(response_text)

I don't know in other reproducible cases where the Eagle will return HTML data rather than JSON but authentication failure is one.

For example when running get_network_info() with correct credentials this is the response I get:

{
  "Response": {
    "Text": "Command processed",
    "MainTag": "Command",
    "Command": "get_network_info"
  }
}

But when the credentials are incorrect this is the response I get back.

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <title>401 - Unauthorized</title>
 </head>
 <body>
  <h1>401 - Unauthorized</h1>
 </body>
</html>

I captured the responses using tcpflow

When the authentication failure occurs the only message that is returned back to Home Assistant is:
Expecting value: line 1 column 1 (char 0)

I wouldn't want the complete raw response to be returned to Home Assistant but given I don't know of other scenarios where this kind of failure can occur probably need some generic error with the response from the Eagle to be returned to Home Assistant?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions