I have a few apps that create and maintain sensors. Usually they follow this general setup.
Main app creates and initialised the sensor like this:
self.attribute = {}
if "unit_of_measurement" in self.args:
self.attribute.update({"unit_of_measurement": self.args["unit_of_measurement"]})
if "friendly_name" in self.args:
self.attribute.update({"friendly_name": self.args["friendly_name"]})
if "device_class" in self.args:
self.attribute.update({"device_class": self.args["device_class"]})
if "icon" in self.args:
self.attribute.update({"icon": self.args["icon"]})
# Set specific attribute
self.attribute.update({"level": 0})
self.attribute.update({"warning": ""})
self.attribute.update({"temperature": ""})
self.attribute.update({"humidity": ""})
# Initialise the sensor with the default value
self.set_state(self.args["actuator"], attributes=self.attribute, state="Unknown")
Later on this app or any other might update the sensor with code like this:
self.set_state(self.args["actuator"], state=round(heatIndexC, 2))
The problem I have now is that all the attributes I have defined before (like friendly name) are gone. The set state does update the value of the sensor, but this update wipes out all the previously defined attributes. To solve this I have to update all attributes when updating the state, but that does not work when the sensor is updates from multiple apps.
I am on version 4.0.3 of appdaemon and it seems this behaviour did not show up on version 3.
Am I missing anything that would trigger this ?