Whytey / moebot-hass-integration

A HomeAssistant integration for MoeBot (and compatible) TUYA mowers.
8 stars 0 forks source link

Moebot status unavailable #19

Closed i8nemo closed 2 months ago

i8nemo commented 2 months ago

This integration has been working fine for the past 9 months, however today after upgrading my HA Core to 2024.5.0 the device has become unavailable. After restarting multiple time the integration and reinstalling it. No change. Following debug details found.

2024-05-03 14:30:25.738 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to sleep inside the event loop by custom integration 'moebot' at custom_components/moebot/config_flow.py, line 35: d = MoeBot(data["device_id"], data["ip_address"], data["local_key"]) (offender: /usr/local/lib/python3.12/site-packages/tinytuya/core.py, line 1190: time.sleep(self.sendWait) # give device time to respond), please create a bug report at https://github.com/Whytey/moebot-hass-integration/issues 2024-05-03 14:30:25.804 WARNING (ImportExecutor_0) [homeassistant.const] DEVICE_CLASS_BATTERY was used from moebot, this is a deprecated constant which will be removed in HA Core 2025.1. Use SensorDeviceClass.BATTERY instead, please report it to the author of the 'moebot' custom integration 2024-05-03 14:30:25.912 WARNING (pymoebot) [homeassistant.helpers.frame] Detected that custom integration 'moebot' calls async_write_ha_state from a thread at custom_components/moebot/init.py, line 67: self.async_write_ha_state(), please report it to the author of the 'moebot' custom integration 2024-05-03 14:30:25.912 ERROR (pymoebot) [root] Uncaught thread exception Traceback (most recent call last): File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner self.run() File "/usr/local/lib/python3.12/threading.py", line 1010, in run self._target(*self._args, **self._kwargs) File "/usr/local/lib/python3.12/site-packages/pymoebot/init.py", line 92, in loop self.parse_payload(data) File "/usr/local/lib/python3.12/site-packages/pymoebot/init.py", line 70, in parse_payload listener(data) File "/config/custom_components/moebot/init.py", line 67, in listener self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1008, in async_write_ha_state self.hass.verify_event_loop_thread("async_write_ha_state") File "/usr/src/homeassistant/homeassistant/core.py", line 440, in verify_event_loop_thread frame.report( File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 162, in report _report_integration(what, integration_frame, level, error_if_integration) File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 203, in _report_integration raise RuntimeError( RuntimeError: Detected that custom integration 'moebot' calls async_write_ha_state from a thread at custom_components/moebot/init__.py, line 67: self.async_write_ha_state(). Please report it to the author of the 'moebot' custom integration. home-assistant_moebot_2024-05-03T04-33-03.219Z.log

PeteRepeat77 commented 2 months ago

Same here. Haven't checked the logs but it's unavailable like you

Whytey commented 2 months ago

Thanks for logging the issue. I am waaaay behind on Home Assistant updates and so I haven't seen this issue. I will have to spin up a VM with 2024.05 and see what is happening.

Doing a quick Google points me to https://community.home-assistant.io/t/how-to-fix-custom-integration-brematic-calls-async-write-ha-state/722238

Whytey commented 2 months ago

Have confirmed - by following the suggestion above, I was able to run up a 2024.05 instance.

I will need to do some further testing to make sure the code is backwards compatible but feel free to hack the change into your code in custom_components/moebot/__init__.py line 67, if you need to get it back up and running quickly.

image

PeteRepeat77 commented 2 months ago

That was a quick response.

Just to clarify, it's the self.schedule_update_ha_state() and # line 67 out.

I'll try the hack and let you know

PeteRepeat77 commented 2 months ago

Confirmed # line 67 out and adding the extra line of code worked for me to.

Whytey commented 2 months ago

Note: I checked the same change on my production version (2023.09.5; don't hate me for being behind) and it also worked. I have pushed an updated and closed the ticket.