cdpuk / ha-bestway

Home Assistant integration for Bestway / Lay-Z-Spa hot tubs
MIT License
73 stars 18 forks source link

Data Update Errors #77

Closed jeffh0821 closed 2 weeks ago

jeffh0821 commented 1 month ago

Version of the custom_component

1.6.0 HA Version: 2024.10.0

Bestway device

Bestway MCU Hardware Version: P4960011 Bestway MCU Software Version: D4H90227 Bestway Protocol Version: 3 Bestway Wi-Fi Hardware Version: 0ESP32C3 Bestway Wi-Fi Software Version: 04X3000B

Describe the bug

Lots of data update errors in the HA logs since installing using this integration. Note: it's working, but noisy.

Logs

Logger: custom_components.bestway.coordinator
Source: custom_components/bestway/coordinator.py:36
integration: Bestway ([documentation](https://github.com/cdpuk/ha-bestway), [issues](https://github.com/cdpuk/ha-bestway/issues))
First occurred: October 3, 2024 at 5:13:51 PM (55 occurrences)
Last logged: 12:27:48 PM

Data update failed
Traceback (most recent call last):
  File "/config/custom_components/bestway/bestway/api.py", line 76, in _raise_for_status
    api_error = await response.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 1243, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 502, message='Attempt to decode JSON with unexpected mimetype: text/plain; charset=utf-8', url='https://usapi.gizwits.com/app/bindings'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/bestway/coordinator.py", line 36, in _async_update_data
    await self.api.refresh_bindings()
  File "/config/custom_components/bestway/bestway/api.py", line 140, in refresh_bindings
    device.device_id: device for device in await self._get_devices()
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/bestway/bestway/api.py", line 145, in _get_devices
    api_data = await self._do_get(f"{self._api_root}/app/bindings")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/bestway/bestway/api.py", line 436, in _do_get
    await _raise_for_status(response)
  File "/config/custom_components/bestway/bestway/api.py", line 78, in _raise_for_status
    response.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1121, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 502, message='Bad Gateway', url='https://usapi.gizwits.com/app/bindings'

and

Logger: custom_components.bestway.coordinator
Source: custom_components/bestway/coordinator.py:37
integration: Bestway ([documentation](https://github.com/cdpuk/ha-bestway), [issues](https://github.com/cdpuk/ha-bestway/issues))
First occurred: October 3, 2024 at 5:02:22 PM (46 occurrences)
Last logged: 12:27:19 PM

Data update failed
Traceback (most recent call last):
  File "/config/custom_components/bestway/bestway/api.py", line 76, in _raise_for_status
    api_error = await response.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 1243, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 502, message='Attempt to decode JSON with unexpected mimetype: text/plain; charset=utf-8', url='https://usapi.gizwits.com/app/devdata/38AAsh8iG06FZKTTepPBuj/latest'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/bestway/coordinator.py", line 37, in _async_update_data
    return await self.api.fetch_data()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/bestway/bestway/api.py", line 168, in fetch_data
    latest_data = await self._do_get(
                  ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/bestway/bestway/api.py", line 436, in _do_get
    await _raise_for_status(response)
  File "/config/custom_components/bestway/bestway/api.py", line 78, in _raise_for_status
    response.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1121, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 502, message='Bad Gateway', url='https://usapi.gizwits.com/app/devdata/38AAsh8iG06FZKTTepPBuj/latest'
cdpuk commented 2 weeks ago

There's certainly something that can be done to clean up the noise in the logs, however the HTTP 502 error indicates a problem at the Bestway end, which is quite common.

When this happens, how long does it take to recover? Are these just one off issues? Or do they come in waves of minutes, hours, etc?

cdpuk commented 2 weeks ago

Closing this for now. Noise should be better as of version 1.6.2. If the 502 responses turn out to be truly one-offs, then perhaps something can be done to improve reliability.

jeffh0821 commented 2 weeks ago

Thanks. I will see if I can correlate the 502s to anything or see if they come in "waves".