home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.82k stars 30.08k forks source link

APSystems integration fails setup due to unexpected `text/html` mime-type #126270

Open Ocramius opened 1 week ago

Ocramius commented 1 week ago

The problem

I'm currently setting up an APSystem EZ1D via the APSystems integration.

The device is up and running, but it can't be picked up by HA:

image

A local request works just fine, and shows that the response has Content-Type: application/json

 curl -v http://192.168.1.225:8050/getDeviceInfo
*   Trying 192.168.1.225:8050...
* Connected to 192.168.1.225 (192.168.1.225) port 8050
> GET /getDeviceInfo HTTP/1.1
> Host: 192.168.1.225:8050
> User-Agent: curl/8.9.1
> Accept: */*
> 
* Request completely sent off
< HTTP/1.1 200 OK
< Content-Type: application/json
< Content-Length: 181
< 
* Connection #0 to host 192.168.1.225 left intact
{"data":{"deviceId":"<SNIP>","devVer":"EZ1D 1.0.1","ssid":"<SNIP>","ipAddr":"192.168.1.225","minPower":"80","maxPower":"1800"},"message":"SUCCESS","deviceId":"<SNIP>"}

What version of Home Assistant Core has the issue?

core-2024.9.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

No response

Link to integration documentation on our website

https://www.home-assistant.io/integrations/apsystems

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: aiohttp.server
Source: /usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py:433
First occurred: 17:01:08 (1 occurrences)
Last logged: 17:01:08

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 462, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/sentry_sdk/integrations/aiohttp.py", line 139, in sentry_app_handle
    reraise(*_capture_exception(hub))
  File "/usr/local/lib/python3.12/site-packages/sentry_sdk/_compat.py", line 127, in reraise
    raise value
  File "/usr/local/lib/python3.12/site-packages/sentry_sdk/integrations/aiohttp.py", line 129, in sentry_app_handle
    response = await old_handle(self, request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 537, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 210, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 74, in wrapper
    return await method(view, request, data, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 366, in async_configure
    result = await self._async_configure(flow_id, user_input)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 413, in _async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 516, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/apsystems/config_flow.py", line 43, in async_step_user
    device_info = await api.get_device_info()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/APsystemsEZ1/__init__.py", line 128, in get_device_info
    response = await self._request("getDeviceInfo")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/APsystemsEZ1/__init__.py", line 86, in _request
    data = await resp.json()
           ^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/aiohttp_client.py", line 80, in json
    return await super().json(*args, loads=loads, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1199, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 431, message='Attempt to decode JSON with unexpected mimetype: text/html', url='http://192.168.1.225:8050/getDeviceInfo'


### Additional information

_No response_
home-assistant[bot] commented 1 week ago

Hey there @mawoka-myblock, @sonnenladengmbh, mind taking a look at this issue as it has been labeled with an integration (apsystems) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `apsystems` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign apsystems` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


apsystems documentation apsystems source (message by IssueLinks)

mawoka-myblock commented 1 week ago

No clue where this is coming from, as it doesn't seem to be a problem of this library. I'll keep this issue open, so others, please reply and tell me when you also experience that, thanks!

Ocramius commented 1 week ago

Things I noticed so far:

mawoka-myblock commented 1 week ago

Things I noticed so far:

* `"devVer":"EZ1D 1.0.1"` - wondering if there's a way to force a firmware upgrade?

* perhaps some caching on the client-side, while the inverter was still booting up / serving text contents?

Thanks for bringing that up, though I can't tell you anything regarding the firmware update. Could be that this is even the most recent one.

Ocramius commented 1 week ago

Wondering here: is there any sort of logging that I can run, to see more detail in the request/response cycle on aiohttp somehow?

Somewhere around here?

https://github.com/SonnenladenGmbH/APsystems-EZ1-API/blob/123f6a880fb2278d732a51780cd806073dcfddac/APsystemsEZ1/__init__.py#L85-L86

I could try wiresharking my way through too, but that could take ages :D

Also fun side-effect of working with these devices: can only do so while they are running (during the day), because the inverters completely shut down when there's no PV power :D

mawoka-myblock commented 1 week ago

Wondering here: is there any sort of logging that I can run, to see more detail in the request/response cycle on aiohttp somehow?

Somewhere around here?

SonnenladenGmbH/APsystems-EZ1-API@123f6a8/APsystemsEZ1/init.py#L85-L86

I could try wiresharking my way through too, but that could take ages :D

Also fun side-effect of working with these devices: can only do so while they are running (during the day), because the inverters completely shut down when there's no PV power :D

You could just throw a print resp.headers and print data in there and look at HA's console. I'd also help debugging if i would encounter this issue, though I don't. Regarding the night-offline-thing: I know exactly what you're talking about. You could in theory plug a 24v power supply into one of the solar input. That way, it's always online.