arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
22.23k stars 4.81k forks source link

Berry persist.save() does not save changes to arrays #22187

Closed andrew01144 closed 1 month ago

andrew01144 commented 1 month ago

PROBLEM DESCRIPTION

A clear and concise description of what the problem is.

In Berry, persist.save() should save the new state of of an array to _persist.json if its state has changed. It does not. This used to work on V12.0.2. Does not work on V14.2.0

Workaround: update a simple variable before doing persist.save().

REQUESTED INFORMATION

Make sure your have performed every step and checked the applicable boxes before submitting your issue. Thank you!

- [ ] If using rules, provide the output of this command: `Backlog Rule1; Rule2; Rule3`:
```lua
  Rules output here:
- [ ] Set `weblog` to 4 and then, when you experience your issue, provide the output of the Console log:
```lua
  Console output here:
n/a

TO REPRODUCE

Steps to reproduce the behavior:

I find this easiest to replicate by pasting each of these Berry lines, one at a time, into the Berry scripting console.

import persist
persist.a1 = [1,2,3,4]
persist.save()
# look at _persist.json - ok
persist.a1[2] = 44
persist.save()
# look at _persist.json - Error - a1[] has not been updated
persist.tx = tasmota.millis()
persist.save()
# look at _persist.json - ok, a1 has been updated
persist.a1[2] = 88
persist.tx = tasmota.millis()   # workaround, update a simple variable
persist.save()
# look at _persist.json - ok, a1 has been updated

EXPECTED BEHAVIOUR

A clear and concise description of what you expected to happen.

persist.save() should save the new state of a1[] to _persist.json if the state has changed. This used to work on V12.0.2. Does not work on V14.2.0

Workaround: update a simple variable before doing persist.save().

SCREENSHOTS

If applicable, add screenshots to help explain your problem.

ADDITIONAL CONTEXT

Add any other context about the problem here.

(Please, remember to close the issue when the problem has been addressed)

s-hadinger commented 1 month ago

There is no easy way for persist module to detect changes in sub-objects like lists or arrays. There are now 2 options:

Now included in: https://github.com/arendst/Tasmota/pull/22246

andrew01144 commented 1 month ago

Thanks!