tlskinneriv / hassio-addons

MIT License
8 stars 3 forks source link

Supervisor failed #1

Closed wsguede closed 2 years ago

wsguede commented 2 years ago

Hey First thanks for the work you and @dancwilliams have put into these integrations. Going to make everything nice and easy for many people in the future.

That said, I moved from @dancwilliams build to this build, and something seems to not be working. With his, i was getting just the 200's from the /data/report/... call in the logs.

With this build I seem to be getting some 500's when the data is pushed to supervisor?

Failed to send {} to http://supervisor/core/api/services/awnet_local/update with headers {'Authorization': 'Bearer superSecretToken', 'content-type': 'application/json'}; b'500 Internal Server Error\n\nServer got itself in trouble'
[28/Jan/2022 13:32:32] "GET /data/report/stationtype=AMBWeatherV4.3.2&PASSKEY=ma:ca:dd:rs&dateutc=2022-01-28+19:32:31&tempinf=61.7&humidityin=21&baromrelin=30.098&baromabsin=29.581&tempf=57.0&battout=1&humidity=25&winddir=357&windspeedmph=0.0&windgustmph=0.0&maxdailygust=0.0&hourlyrainin=0.000&eventrainin=0.000&dailyrainin=0.000&weeklyrainin=0.000&monthlyrainin=0.000&totalrainin=1.461&solarradiation=0.00&uv=0&temp1f=30.0&humidity1=41&batt1=1&batt_co2=1 HTTP/1.1" 200 0

any thoughts?

wsguede commented 2 years ago

I do have the integration installed image

wsguede commented 2 years ago

More info from the HA logs

2022-01-28 13:36:32 ERROR (MainThread) [aiohttp.server] Error handling request
... bunch of awaits...
File "/config/custom_components/awnet_local/__init__.py", line 51, in async_handle_update
mac = format_mac(call.data.get('PASSKEY', None))
File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 131, in format_mac
if len(to_test) == 17 and to_test.count(":") == 5:
TypeError: object of type 'NoneType' has no len()
tlskinneriv commented 2 years ago

Looks like I may need some better sanitization on the MAC address for the integration. Can you double-check the format of the MAC address on your integration? If HA processed it properly on input, then it should have come out looking like this:

image

except that it will be your MAC separated by colons. I received the same 500 error from the add-on when I inputted a badly formatted MAC.

Also, what version of HA are you running?

wsguede commented 2 years ago

yeah the mac address thats in the passkey is the same mac address i used in the local integration, which is the same mac address that is in my router.

ma:ca:dd:rs <--- not my mac address

wsguede commented 2 years ago

E8:DB:84:00:00:00 <--- this is a better representation of my mac

the last 3 sets removed.

wsguede commented 2 years ago

wondering if the C version sends data differently? (i have the b) TypeError: object of type 'NoneType' has no len() <-- makes me feel like call.data.get('PASSKEY', None) is not returning something.

is data = body? it looks like my passkey is for sure in the query params. Dont know what gets sent in the body of the post though, so it could still be there.

how do i turn debug logs on?

wsguede commented 2 years ago

Version | core-2021.12.10

wsguede commented 2 years ago
// code
 _LOGGER.error(f"Failed to send {payload_json} to {url} with headers {head}; {response.content}")

// log
Failed to send {} to http://supervisor/core/api/services/awnet_local/update with headers {'Authorization': 'Bearer superSecretToken', 'content-type': 'application/json'}; b'500 Internal Server Error\n\nServer got itself in trouble'

^ this also makes me feel like the payload failed to send actual data?

wsguede commented 2 years ago

Better Problem Statement

By default the awnet app has the Path as /data/report/ The app is NOT smart enough to know that it needs to add a ? before the query params. SO you get a log that looks like

[28/Jan/2022 13:32:32] "GET /data/report/stationtype=AMBWeatherV4.3.2&PASSKEY=ma:ca:dd:rs...

When the code looks for the query params its probably looking for everything after the ?. As you can see there is no ?

Solution

Change the path in the awnet to ? Doing /data/report? probably works too as this code just asks for the query params and doesnt look at the path.

tlskinneriv commented 2 years ago

While this is in the DOCS.md file, I will update it to make it more clear since it's just a single '?' sitting there right now. Thanks for the extra info!

wsguede commented 2 years ago

@tlskinneriv ah yes!

I thought I saw this requirement somewhere, but I couldnt remember where specifically? Normally the main readme page is the goto page; At least to link to more docs.

I did look at the awnet readme as well, but I dont think it has the link to docs.md either?

At the end of the day someone might bump into this issue, and come to the issues to find a solution, and we have it here. So thats a win. Thanks again for the support and the initial work you and @dancwilliams did with the project.