custom-components / pyscript

Pyscript adds rich Python scripting to HASS
Apache License 2.0
873 stars 46 forks source link

attribute changes not detected #578

Open Kaptensanders opened 8 months ago

Kaptensanders commented 8 months ago

Hi, have had a headscratcher with this one. Not 100% sure if the error is with pyscript or HA, but the workaround is done from pyscript so...

Using HA Core, 2023.10.5 Frontend 20231005.0 Pyscript 1.5.0

changes to entity attributes (like pyscript.myentity) from pyscript code, are only detected and available to the frontend when they are made on the top-level of the attributes data structure.

#pyscript.myentity attributes:
{
  "key1" : "changes to this one is detected",
  "key2" : { "key21": "changes here are not detected" }
}

The data is for sure changed, and is published to the frontend after a delay when attributes data has been refreshed for some reason, but it seems either pyscript or homeassistant does not discover that the data has been modified and forces a refresh to the frontend immediately.

The only way I found around this was to replace the entire attributes dict with a deepcopy to the state.set function.

Thanks for all the work! Anders