victronenergy / node-red-contrib-victron

MIT License
90 stars 18 forks source link

Use a serviceId instead of a serialized JSON object as a key in html files #21

Closed pkronstrom closed 5 years ago

pkronstrom commented 5 years ago

Nodes' HTML files currently use a serialized service JSON object as a value in select boxes. This makes it easy to update the node labels on edit save.

This, however, does not work well when some metadata changes in the service object (e.g. for relays, the REST endpoint might render a disabled: true or a custom warning message for the service).

{
  "service": "com.victronenergy.system",
  "name": "Venus device (0)",
  "paths": [
  {
    "name": "State (on/off)",
    "path": "/Relay/0/State"
  }
  ],
  "disabled": true,
  "warning": "This relay is reserved for alarm function. Please navigate to Settings > Relay and change it to manual."
  }

If a previously configured node has even a slightest change in the warning text or disabled status, the node-red frontend logic doesn't recognize the service as the same.


The way I see this is that the verious services need to be uniquely identified so that we can reliably restore previously deployed nodes. A unique identifier would be dbus service+path string (in case of Relays), for example. For batteries, the service alone is enough.

Instead of saving the whole JSON object as the value, we should only store the necessary identifiers to the select values and separate the service data to either html data-attributes or simply save the previously selected object (or previously received data) as a separate variable.

pkronstrom commented 5 years ago

Change in https://github.com/victronenergy/node-red-contrib-victron/commit/a0cfbe0909b6fe7591a7ce4b54a65c5c4aae5d4b