MQTT auto discovery and "expire_after"

Hi,

I have an Adafruit Feather ESP32-S2 and I’m using Circuitpython to connect to Home Assistant using MQTT autodiscovery. Everything works fine, however when the connection unexpectly drops I was hoping the status of the light would eventually go to ‘unavailable’. At the moment, this is not the case. It just retains the last state. I thought the ‘expire_after’ key/value pair would do the trick. Does somebody have clue?

My discovery message + publish/subscribe topics:

self.client_id = os.getenv('CIRCUITPY_MQTT_ID')
self.availability_prefix = f"homeassistant/{self.client_id}"
self.light_prefix = f"homeassistant/light/{self.client_id}"

msg_light = {
            "expire_after": 90,
            "name": f"{self.client_name} Light",
            "command_topic": f"{self.light_prefix}/set",
            "state_topic": f"{self.light_prefix}/state",
            "availability_topic": f"{self.availability_prefix}/status",
            "availability_mode ": f"all",
            "brightness_command_topic": f"{self.light_prefix}/brightness/set",
            "brightness_state_topic": f"{self.light_prefix}/brightness/state",
            "brightness_scale": 100,
            "on_command_type": "last",
            "unique_id": f"{self.client_id}_light",
            "device": {
                "identifiers": self.client_id,
                "name": self.client_name,
                "model": "Adafruit ESP32-S2 Feather",
                "sw_version": self.sw_version}
        }

mqtt_client.publish(topic=f"{self.light_prefix}/config", msg=f"{json.dumps(msg_light)}", qos=0,retain=True)
mqtt_client.subscribe(topic=f"{self.light_prefix}/set")
mqtt_client.subscribe(topic=f"{self.light_prefix}/brightness/set")

Last will message called before initial connect (not sure if this is applicable here):

mqtt_client.will_set(topic=f"{self.availability_prefix}/status", payload="offline", qos=0, retain=False)

I update the availability in a 10s loop as long as there is a connection:

mqtt_client.publish(topic=f"{self.availability_prefix}/status", msg="online", qos=0, retain=False)