Closed user-08-151 closed 1 month ago
I have the same issue as reported above. Based on a similar report in the tuya-local integration, I suspect there was some change in the APIs with the latest HA release.
https://github.com/make-all/tuya-local/issues/1871
https://community.home-assistant.io/t/custom-component-hp-printer/147127/303?page=16
I'm getting the same error. According to Google's Gemini, here is the issue:
Background Tasks: Home Assistant uses asynchronous programming to manage different tasks efficiently. The async_create_task function is meant to be used within the main Home Assistant event loop for proper scheduling and execution.
The Problem: The 'dreo' integration seems to be calling async_create_task from a separate thread. This can lead to unexpected behavior, potential conflicts with Home Assistant's internal processes, and issues with the integration itself
The last line of the traceback pinpoints the exact problem: custom_components/dreo/basedevice.py, line 53, where the async_schedule_update_ha_state(True) call is being made within a thread.
Solution
Temporary Workaround: Potentially attempt a temporary edit in custom_components/dreo/basedevice.py, line 53, if necessary. However, proceed with extreme caution and create backups.
How to fix the problem yourself for the first time
"""BaseDevice utilities for Dreo Component."""
import logging
from .pydreo.pydreobasedevice import PyDreoBaseDevice
from .haimports import * # pylint: disable=W0401,W0614
from .const import (
LOGGER,
DOMAIN
)
_LOGGER = logging.getLogger(LOGGER)
class DreoBaseDeviceHA(Entity):
"""Base class for Dreo Entity Representations."""
def __init__(self, pydreo_base_device: PyDreoBaseDevice) -> None:
"""Initialize the Dreo device."""
self.device = pydreo_base_device
self._attr_unique_id = self.device.sn
self._attr_name = pydreo_base_device.name
@property
def device_info(self) -> DeviceInfo:
"""Return the device info."""
return DeviceInfo(
identifiers={
# Serial numbers are unique identifiers within a specific domain
(DOMAIN, self.device.sn)
},
name=self.device.name,
manufacturer="Dreo",
model=self.device.model
)
@property
def available(self) -> bool:
"""Return True if device is available."""
# return self.device.connection_status == "online"
return True
@property
def should_poll(self):
return False
def async_added_to_hass(self):
"""Register callbacks."""
def update_state():
# Tell HA we're ready to update
self.schedule_update_ha_state(True)
self.device.add_attr_callback(update_state)
How to fix the problem yourself for the first time
- Make a full Home Assistant backup
Thanks for doing this. This worked out great for me.
How to fix the problem yourself for the first time
- Make a full Home Assistant backup
- Using Visual Studio Code, edit custom_components/dreo/basedevice.py
- Replace the entire code with my code
- Restart Home Assistant
- Have fun π
- Nevertheless, install @JeffSteinbok 's hotfix as soon as it is available π
"""BaseDevice utilities for Dreo Component.""" import logging from .pydreo.pydreobasedevice import PyDreoBaseDevice from .haimports import * # pylint: disable=W0401,W0614 from .const import ( LOGGER, DOMAIN ) _LOGGER = logging.getLogger(LOGGER) class DreoBaseDeviceHA(Entity): """Base class for Dreo Entity Representations.""" def __init__(self, pydreo_base_device: PyDreoBaseDevice) -> None: """Initialize the Dreo device.""" self.device = pydreo_base_device self._attr_unique_id = self.device.sn self._attr_name = pydreo_base_device.name @property def device_info(self) -> DeviceInfo: """Return the device info.""" return DeviceInfo( identifiers={ # Serial numbers are unique identifiers within a specific domain (DOMAIN, self.device.sn) }, name=self.device.name, manufacturer="Dreo", model=self.device.model ) @property def available(self) -> bool: """Return True if device is available.""" # return self.device.connection_status == "online" return True @property def should_poll(self): return False def async_added_to_hass(self): """Register callbacks.""" def update_state(): # Tell HA we're ready to update self.schedule_update_ha_state(True) self.device.add_attr_callback(update_state)
Hi guys, I noticed that when you restart the server or Home Assistant, the Dreo entities may show up as unavailable. You can easily solve this by briefly switching the respective fans on or off in the Dreo app. The entities will then be available again in Home Assistant as normal until the next restart.
Home Assistant Supervised Installed (x64) Version 2024.5.2 Works in: β Home Assistant Main β Node Red β HomeKit (Own Node)
Thanks folks. I'll have a look this weekend. Sorry, been busy at work.
@VOSsec Any chance you could push a PR with your change? I can verify it and make a release.
Good Morning (π©πͺ) @JeffSteinbok, I tried to open a PR but got the following error "Pull request creation failed. Validation failed: must be a collaborator"
@VOSsec excellent! That solves a problem I've been having with creating conditional tests for entity state. Thank you digging into this.
I think you have to fork the repo and then submit the pull request
-Jeff
On May 7, 2024, at 9:27β―PM, Tobias M. @.***> wrote:
ο»Ώ
Good Morning (π©πͺ) @JeffSteinbokhttps://github.com/JeffSteinbok, I tried to open a PR but got the following error "Pull request creation failed. Validation failed: must be a collaborator"
β Reply to this email directly, view it on GitHubhttps://github.com/JeffSteinbok/hass-dreo/issues/87#issuecomment-2099716518, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABX5XT3AOH7MDWLC7V5M4PTZBGSRNAVCNFSM6AAAAABHDOCWH2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJZG4YTMNJRHA. You are receiving this because you were mentioned.Message ID: @.***>
Let me see what I can do real quick.
Ok, so your fix doesn't quite work. When things load up, they aren't updated. I have to go see what's going on here before I publish this.
Fixed in version 0.6.4
I'm getting following error when trying to power on a Dreao fan from a dashboard:
While the fan is started the state is never updated within Home Assistant.
The issue seems to be solved when replacing the call of the async method (https://github.com/JeffSteinbok/hass-dreo/blob/main/custom_components/dreo/basedevice.py#L53) with the sync one
self.schedule_update_ha_state(True)
- but since I'm not too familiar with Home Assistant, I'm not sure if that is the right solution.