dalinicus / homeassistant-acinfinity

AC Infinity integration for Home Assistant for UIS based controllers
MIT License
75 stars 4 forks source link

PATCH calls to AC Infinity API cause subsiquent requests to API to fail or timeout for a period of time. #39

Closed almighty059 closed 1 month ago

almighty059 commented 9 months ago

When changing modes I started having the following error message appear at the bottom of the screen...

Screenshot 2023-11-25 175308

This is what the log says...

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/commands.py:230
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 5:39:53 PM (6 occurrences)
Last logged: 5:53:00 PM

[281473424745280] {'msg': 'Something went wrong with your request.\nPlease try again later.', 'code': 100001}
[281472154391232] {'msg': 'Something went wrong with your request.\nPlease try again later.', 'code': 100001}
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 230, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 235, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 876, in entity_service_call
    response_data = await _handle_entity_call(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 948, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/select/__init__.py", line 106, in async_select_option
    await entity.async_select_option(option)
  File "/config/custom_components/ac_infinity/select.py", line 49, in async_select_option
    await self.set_setting_value(
  File "/config/custom_components/ac_infinity/__init__.py", line 148, in set_setting_value
    await coordinator.ac_infinity.set_device_port_setting(
  File "/config/custom_components/ac_infinity/ac_infinity.py", line 219, in set_device_port_setting
    await self.set_device_port_settings(device_id, port_id, [(setting, value)])
  File "/config/custom_components/ac_infinity/ac_infinity.py", line 228, in set_device_port_settings
    await self._client.set_device_port_settings(
  File "/config/custom_components/ac_infinity/client.py", line 105, in set_device_port_settings
    _ = await self.__post(API_URL_ADD_DEV_MODE, payload, headers)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/ac_infinity/client.py", line 119, in __post
    raise ACInfinityClientRequestFailed(json)
custom_components.ac_infinity.client.ACInfinityClientRequestFailed: {'msg': 'Something went wrong with your request.\nPlease try again later.', 'code': 100001}
almighty059 commented 9 months ago

I deleted the entire integration and then re-downloaded it and installed it but I'm still getting the same error message. I have the update set to 30 seconds and when I change modes there's a long pause and then the mode changes and then the error message appears or the error message appears and then the mode changes.

almighty059 commented 9 months ago

The same error is happening when I try to change other things besides the mode such as ON SPEED and OFF SPEED. I haven't tested everything but so far it seems to be happening with everything I try to change.

dalinicus commented 9 months ago

looks like your requests to the API are timing out. I've noticed during development that the occasional request to the API would time out after an update operation, so I threw in some retry logic. As I can see from the logs, it attempts to make the call 3 times before giving up. Not sure why its happening more frequently for you... but that's the dangers of using a non-public API I guess :( It's essentially a black box, so how to "properly" call it has to be reverse engineered and any errors that occur are essentially invisible.

I'll convert this into a bug to investigate why patch (update) calls to the API cause it to hang on subsequent calls.

One thing you can try is remove and re-add your Controller 69 from the AC Infinity app. See if that doesn't clear any bad data on their end that may be causing issues.

almighty059 commented 9 months ago

I'll try that to see what happens. And I don't know if it matters but the App itself is lagging when changing modes and settings. I get an error that says to try again at a later time but then the error clears and the change goes through.

almighty059 commented 9 months ago

@dalinicus deleting the device from the app and the integration and adding it back worked. I'm no longer getting the error. Thanks.

zpriddy commented 8 months ago

I am having the same issue - when it stops responding, if I control it from the AC Infinity app.. it will start to work again after a reload.. but it keeps happening…

I will try to delete it from the app and re-add it

dalinicus commented 8 months ago

Would you mind providing what device modes your using, and what settings your frequently changing? It would help me debug; I can throw a traffic spy on my phone and see if the app is sending values that the integration is missing. Some of them (like temperature in auto mode) requires multiple values be to changed for it to work properly, and I could have missed it.

Vandewaetere commented 7 months ago

@dalinicus I am mainly updating the 'mode' (on or off) and the 'on fan speed' from HA. See also #47

bert-the-dog commented 5 months ago

Nothing really new to add, just to say i'm also getting this. For me, it's the changing of the fan on power value that does it. It still seems to update in the log when i change the speed in the app. However, this last time I've not been changing any settings for the last week or so & its still started to do it.

Like zpriddy above, the app itself seems to play up when this is happening & removing & adding it seems to sort it. It seems like it could be AC app issue? there's plenty of posts about problems with it elsewhere.

Also thanks for making this integration, really makes it easier to manage everything

almighty059 commented 3 months ago

@bert-the-dog it might be an AC app issue. It occasionally happens to me too. I can't really narrow it down to what exactly it is. AC should be coming out with a new version of the app sometime soon because the current version of the app doesn't handle all of the features of the new fan. And FYI if you have an old fan they'll swap it out for the new version which has some major improvements.

maziggy commented 1 month ago

I hame the same issue since two days now. Just deleted the controller from the app and I'm not able to add it again. The app finds the controller, connects via BT and set the WIFI details. This seems to be successfull because after that the controller is connected to the WIFI network. But then it stucks and don't add the controller to the inventory.

Any ideas please?

Jul 30 19:57:26 hass homeassistant[709]: 2024-07-30 19:57:26.206 DEBUG (MainThread) [custom_components.ac_infinity.core] Refreshing data from data update coordinator Jul 30 19:57:26 hass homeassistant[709]: 2024-07-30 19:57:26.564 DEBUG (MainThread) [custom_components.ac_infinity.core] Finished fetching ac_infinity data in 0.358 seconds (success: True) Jul 30 19:57:29 hass homeassistant[709]: 2024-07-30 19:57:29.892 INFO (MainThread) [custom_components.ac_infinity.number] User requesting value update of entity "ac_infinity_3C84272B8046_port_1_offSpead" to "5.0" Jul 30 19:57:30 hass homeassistant[709]: 2024-07-30 19:57:30.211 WARNING (MainThread) [custom_components.ac_infinity.core] Unable to update settings. Retry attempt 1/2 Jul 30 19:57:31 hass homeassistant[709]: 2024-07-30 19:57:31.205 DEBUG (MainThread) [custom_components.ac_infinity.core] Refreshing data from data update coordinator Jul 30 19:57:31 hass homeassistant[709]: 2024-07-30 19:57:31.510 DEBUG (MainThread) [custom_components.ac_infinity.core] Finished fetching ac_infinity data in 0.304 seconds (success: True) Jul 30 19:57:31 hass homeassistant[709]: 2024-07-30 19:57:31.512 WARNING (MainThread) [custom_components.ac_infinity.core] Unable to update settings. Retry attempt 2/2 Jul 30 19:57:32 hass systemd[1]: run-docker-runtime\x2drunc-moby-1a2a558dbb23cc68ddce80260bd6960482802c5f5517c3007828cb551031a514-runc.Gs4TJd.mount: Deactivated successfully. Jul 30 19:57:32 hass homeassistant[709]: 2024-07-30 19:57:32.833 ERROR (MainThread) [custom_components.ac_infinity.core] Unable to update settings. Retry attempt limit exceeded Jul 30 19:57:32 hass homeassistant[709]: Traceback (most recent call last): Jul 30 19:57:32 hass homeassistant[709]: File "/config/custom_components/ac_infinity/core.py", line 464, in update_port_settings Jul 30 19:57:32 hass homeassistant[709]: await self._client.set_device_mode_settings( Jul 30 19:57:32 hass homeassistant[709]: File "/config/custom_components/ac_infinity/client.py", line 95, in set_device_mode_settings Jul 30 19:57:32 hass homeassistant[709]: settings = await self.get_device_mode_settings_list(device_id, port_id) Jul 30 19:57:32 hass homeassistant[709]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Jul 30 19:57:32 hass homeassistant[709]: File "/config/custom_components/ac_infinity/client.py", line 80, in get_device_mode_settings_list Jul 30 19:57:32 hass homeassistant[709]: json = await self.post( Jul 30 19:57:32 hass homeassistant[709]: ^^^^^^^^^^^^^^^^^^ Jul 30 19:57:32 hass homeassistant[709]: File "/config/custom_components/ac_infinity/client.py", line 235, in post Jul 30 19:57:32 hass homeassistant[709]: raise ACInfinityClientRequestFailed(json) Jul 30 19:57:32 hass homeassistant[709]: custom_components.ac_infinity.client.ACInfinityClientRequestFailed: {'msg': 'Data saving failed. Please try again later.', 'code': 403} Jul 30 19:57:32 hass homeassistant[709]: 2024-07-30 19:57:32.834 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139833259243936] Unexpected exception Jul 30 19:57:32 hass homeassistant[709]: Traceback (most recent call last): Jul 30 19:57:32 hass homeassistant[709]: File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 241, in handle_call_service Jul 30 19:57:32 hass homeassistant[709]: response = await hass.services.async_call( Jul 30 19:57:32 hass homeassistant[709]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Jul 30 19:57:32 hass homeassistant[709]: File "/usr/src/homeassistant/homeassistant/core.py", line 2731, in async_call Jul 30 19:57:32 hass homeassistant[709]: response_data = await coro Jul 30 19:57:32 hass homeassistant[709]: ^^^^^^^^^^ Jul 30 19:57:32 hass homeassistant[709]: File "/usr/src/homeassistant/homeassistant/core.py", line 2774, in _execute_service Jul 30 19:57:32 hass homeassistant[709]: return await target(service_call) Jul 30 19:57:32 hass homeassistant[709]: ^^^^^^^^^^^^^^^^^^^^^^^^^^ Jul 30 19:57:32 hass homeassistant[709]: File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 999, in entity_service_call Jul 30 19:57:32 hass homeassistant[709]: single_response = await _handle_entity_call( Jul 30 19:57:32 hass homeassistant[709]: ^^^^^^^^^^^^^^^^^^^^^^^^^^ Jul 30 19:57:32 hass homeassistant[709]: File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1071, in _handle_entity_call Jul 30 19:57:32 hass homeassistant[709]: result = await task Jul 30 19:57:32 hass homeassistant[709]: ^^^^^^^^^^ Jul 30 19:57:32 hass homeassistant[709]: File "/usr/src/homeassistant/homeassistant/components/number/init.py", line 120, in async_set_value Jul 30 19:57:32 hass homeassistant[709]: await entity.async_set_native_value(native_value) Jul 30 19:57:32 hass homeassistant[709]: File "/config/custom_components/ac_infinity/number.py", line 464, in async_set_native_value Jul 30 19:57:32 hass homeassistant[709]: await self.entity_description.set_value_fn(self, self.port, value) Jul 30 19:57:32 hass homeassistant[709]: File "/config/custom_components/ac_infinity/core.py", line 444, in update_port_setting Jul 30 19:57:32 hass homeassistant[709]: await self.update_port_settings( Jul 30 19:57:32 hass homeassistant[709]: File "/config/custom_components/ac_infinity/core.py", line 464, in update_port_settings Jul 30 19:57:32 hass homeassistant[709]: await self._client.set_device_mode_settings( Jul 30 19:57:32 hass homeassistant[709]: File "/config/custom_components/ac_infinity/client.py", line 95, in set_device_mode_settings Jul 30 19:57:32 hass homeassistant[709]: settings = await self.get_device_mode_settings_list(device_id, port_id) Jul 30 19:57:32 hass homeassistant[709]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Jul 30 19:57:32 hass homeassistant[709]: File "/config/custom_components/ac_infinity/client.py", line 80, in get_device_mode_settings_list Jul 30 19:57:32 hass homeassistant[709]: json = await self.post( Jul 30 19:57:32 hass homeassistant[709]: ^^^^^^^^^^^^^^^^^^ Jul 30 19:57:32 hass homeassistant[709]: File "/config/custom_components/ac_infinity/client.py", line 235, in post Jul 30 19:57:32 hass homeassistant[709]: raise ACInfinityClientRequestFailed(json) Jul 30 19:57:32 hass homeassistant[709]: custom_components.ac_infinity.client.ACInfinityClientRequestFailed: {'msg': 'Data saving failed. Please try again later.', 'code': 403} Jul 30 19:57:36 hass homeassistant[709]: 2024-07-30 19:57:36.206 DEBUG (MainThread) [custom_components.ac_infinity.core] Refreshing data from data update coordinator Jul 30 19:57:36 hass homeassistant[709]: 2024-07-30 19:57:36.534 DEBUG (MainThread) [custom_components.ac_infinity.core] Finished fetching ac_infinity data in 0.329 seconds (success: True) Jul 30 19:57:41 hass homeassistant[709]: 2024-07-30 19:57:41.206 DEBUG (MainThread) [custom_components.ac_infinity.core] Refreshing data from data update coordinator Jul 30 19:57:41 hass homeassistant[709]: 2024-07-30 19:57:41.555 DEBUG (MainThread) [custom_components.ac_infinity.core] Finished fetching ac_infinity data in 0.348 seconds (success: True)

maziggy commented 1 month ago

Just asked customer support.

"It appears to be a server overload issue. We are trying to resolve that shortly."

Kaeroe commented 1 month ago

There seriously needs to be some kind of local control project started.. with the almost constant timeout failures and now 2 days of uncontrollable devices due to their "scheduled"server maintenance.. so scheduled that it began half a day before any notification My poor pet toad was getting completely drenched by their humidifier turning on from my automation but not able to turn off.. had to disconnect from the mains and use a manual fan to try and dry out his enclosure a bit.

dalinicus commented 1 month ago

There seriously needs to be some kind of local control project started..

When I was first developing the initial integration, there was a forum thread of users looking into Bluetooth support for the 67 models. They didn't look like they were making much progress, which is why I started this project. I haven't followed up since to see if they were successful.

Based on our observations over the last 9 months, and the amount of experimental coding I've done, I think we can confidently conclude that the issues reported above are results of instability in the API rather than this integration. As there is really nothing we can do on the integration side to resolve this, I'm going to close this Issue for now. If I'm missing any valid takeaways above, please salvage them to a new Issue.