Appdaemon set state loosing attribute details

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 ?

I faced the same “issue”, but explained it to myself that there is just one state in an entity and the attributes are attributes of this state. So if I change the state, I also change the attributes. The HA Rest API has exactly the same behavior.
I also mitigated this by getting the whole state, including all attributes, change the one I want to change and write back to whole stuff.
I do not know whats the source of your sensor, but you could perhaps make a king of config file, somewhere readable for AD, and write all the standard attributes of your sensor in it. You can than read the sensor attributes from every app from this config file and store it back to the entity.