Open carrel-gr opened 2 months ago
I can reproduce this with select.speed
entity from the demo integration, so it's not really got anything to do with MQTT.
It looks like on disconnect/reconnect the entire device page is torn down and recreated, and the first updated pass of a mwc select entity fires a valueChanged event when populating the initial value of the combobox. Then we pick this up and pass it on to call the service to change the entity value.
Might be a tricky bug to fix.
Checklist
Describe the issue you are experiencing
If the UI disconnects while displaying a "select" sensor entity, then when it reconnects, it can erroneously update that entity with stale data.
The issue arises with my MQTT auto-discovered device. It has a "select" sensor entity so that either the device can change the state or the UI can. When the UI is connected, this all works correctly. However, IF I have a UI page open that displays this "select" entity, and then I put that browser tab in the background, then after 5 minutes (as per profile settings) the UI will disconnect. Then IF the device (not the UI) changes the state, and following that I reopen the tab that shows the "select", the UI will update the entity state with the old/stale UI data.
Of note: I also have a "box" sensor entity and this does NOT have this issue. On reconnect, the box entity is properly updated with the latest device state (which was delivered via MQTT). The UI does not send old/state UI state to the device.
Also of note: If the entity state doesn't change, then when the UI reconnects, the UI does NOT attempt to send an update. So it does appear that the UI is indeed reading the new device state (via MQTT). However, when the device state and the UI state are not equal, it is erroneously choosing to update the device's entity state to the older/stale UI state.
Also, if I put the UI tab in the background for less than 5 minutes (so it doesn't disconnect) then this issue doesn't happen. Instead, when the device updates the entity state (via MQTT) the UI simply notices the change and updates its state appropriately.
Also, if the select entity is NOT currently being displayed in a tab, then there are no problems switching to a page that shows the select entity. (And disconnecting or not disconnecting makes no difference to this.)
I see this in chrome tabs as well as in the Android app.
Describe the behavior you expected
The UI should not send old/stale state for a "select" entity to a device on UI reconnect.
Steps to reproduce the issue
What version of Home Assistant Core has the issue?
2024.7.3
What was the last working version of Home Assistant Core?
No response
In which browser are you experiencing the issue with?
Google Chrome 126.0.6478.183
Which operating system are you using to run this browser?
macOS Sonoma 14.5
State of relevant entities
No response
Problem-relevant frontend configuration
Javascript errors shown in your browser console/inspector
Additional information
The issue was discussed in the forums in this post: https://community.home-assistant.io/t/is-this-a-bug-with-select/752416
There is a somewhat useful screenshot there as well as further descriptions.