Xiaomi Home Assistant Bug: Device Status Not Updating in Real-Time
in Post with 0 comment

## Overview of the Issue
The Xiaomi Home Assistant plugin version 0.4.3 is experiencing a bug where device statuses are not updating in real-time within Home Assistant 2025.10.x. Despite successful login to the Xiaomi account, device discovery, and establishment of a WebSocket connection, changes to device statuses are not reflected in Home Assistant, causing the interface to display outdated information.

## Reproduction Steps
To replicate this issue, follow these steps:
1. Use Home Assistant Core version 2025.9.3 or newer.
2. Install the Xiaomi Home plugin version 0.4.3.
3. Configure your Xiaomi account, ensuring it includes multiple MIoT devices such as switches and lights.
4. Change the status of a device using the Mi Home app or through physical means (e.g., turning on a switch).
5. Observe the Home Assistant interface; the status should not update.

## Expected Behavior
Device statuses should update immediately in Home Assistant following any external changes.

## Actual Behavior
The status remains unchanged, potentially causing automations to fail, and a `RuntimeError: Attribute hass is None` error appears in the logs.

## Key Logs from Version 0.4.3
```log
2025-10-16 09:45:10.120 DEBUG (MainThread) [custom_components.xiaomi_home.xiaomi_cloud] Login successful
2025-10-16 09:45:11.890 DEBUG (MainThread) [custom_components.xiaomi_home.xiaomi_cloud] Found 34 devices
2025-10-16 09:45:12.001 INFO (MainThread) [custom_components.xiaomi_home.miot_cloud] WebSocket connected
2025-10-16 09:45:12.331 DEBUG (MainThread) [custom_components.xiaomi_home.miot_cloud] Received property change: {'did': '578571816', 'siid': 3, 'piid': 1, 'value': 1}
2025-10-16 09:45:12.333 ERROR (MainThread) [custom_components.xiaomi_home.miot_cloud] Exception in _handle_property_change: RuntimeError: Attribute hass is None for
```

## Troubleshooting
Given the error `RuntimeError: Attribute hass is None`, the issue seems to stem from the integration's inability to properly handle the Home Assistant instance when updating device statuses. This could be due to a missing initialization or a timing issue where the `hass` attribute is accessed before it is fully set up.

## Conclusion
The Xiaomi Home Assistant plugin version 0.4.3 contains a critical bug that prevents real-time updates of device statuses within Home Assistant. This issue persists from version 0.4.2 and needs to be addressed to ensure seamless functionality and automation reliability. Further investigation into the initialization and access of the `hass` attribute during device status updates is necessary to resolve this bug.

## Recommendation
Until this bug is fixed, users may need to rely on polling or other workaround methods to update device statuses, which can be less efficient and reliable than real-time updates. It's crucial for developers to prioritize this issue to maintain the integrity and usability of the Xiaomi Home Assistant integration.

The article has been posted for too long and comments have been automatically closed.