Skip to content

Publish on graceful disconnect #301

@daenney

Description

@daenney

Is your feature request related to a problem? Please describe.

As part of using the MQTT integration in Home-Assistant, I want to signal the unavailability of a device when I disconnect. This requires publishing a payload to a specific topic.

I'm using the LWT for this, but LWT is only triggered for ungraceful disconnects. However, when the context is cancelled, Paho has no facility to publish extra messages during a graceful disconnect.

Describe the solution you'd like

I'd like to have something like OnClientDisconnect, similar to OnClientError, but that only triggers for graceful disconnect. This function should execute as the last thing before the connection to the broker is closed.

Describe alternatives you've considered

I'm currently setting the DisconnectPacketBuilder to a function that always returns nil. This causes every disconnect to be ungraceful from the broker's perspective and thus results in the LWT always getting sent. This feels hacky and unintended.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions