Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to using Paho MQTT v2 API calls #3

Closed
esand opened this issue Apr 4, 2024 · 5 comments
Closed

Update to using Paho MQTT v2 API calls #3

esand opened this issue Apr 4, 2024 · 5 comments

Comments

@esand
Copy link
Contributor

esand commented Apr 4, 2024

Request to update code to use the new Paho MQTT v2 API calls.

I have taken my uneducated attempt at changing the code here: https://github.com/esand/dahuavto2mqtt.

The reason codes changed from a straight int to a ReasonCode type which can be an int, or a list/dict of ints for multiple codes. Supposedly you can use .getName() to get the text description for the code(s), so I modified the code to remove the call to the const list of defined error codes. My understanding of Python is zero though, so I'm not sure if I did it right or not 😄

My hope is that the work I did in my fork helps you in updating your repo correctly.

@esand
Copy link
Contributor Author

esand commented Apr 4, 2024

For reference, full changes here: https://github.com/eclipse/paho.mqtt.python/releases/tag/v2.0.0

Realized that there might be an issue with conflicting logger definitions?

@baudneo
Copy link
Owner

baudneo commented Apr 6, 2024

I'll take a look at this today and try and integrate V2. May need testing for backwards compatibility (maybe not though since it's a docker image).

@baudneo
Copy link
Owner

baudneo commented Apr 6, 2024

For reference, full changes here: https://github.com/eclipse/paho.mqtt.python/releases/tag/v2.0.0

Realized that there might be an issue with conflicting logger definitions?

The logger aspect is in relation to sub-classing. So, not a global level logger like this script has but a class property.

Example:

import paho.mqtt.client as mqtt

class MyClientClass(mqtt.Client):
    _logger = 10  # this is an attribute of a sub-class of mqtt.Client
    hw = "Hello World!"

    @property
    def logger(self)
        """This is a property to control accessing the attr, since this is a subclass, a conflict will arise rather than overriding if things arent handled properly"""
        # You can do some additonal logic before returning a result
        self.logger += 5
        return self._logger

    @logger.setter
    def logger(self, value):
        if not isinstance(value, int):
            raise TypeError(f"The supplied value is the wrong type: {type(value)}, must be int.")
        self._logger = value

if __name__ == "__main__":
    x = MyClientClass()
    print(f"{x.logger = } // {x.hw = }")

from the release notes:

Possible breaking change: Add properties to access most Client attribute. Closes eclipse-paho/paho.mqtt.python#764.
Since this add new properties like logger, if a sub-class defined logger, the two logger
will conflict.

@baudneo
Copy link
Owner

baudneo commented Apr 6, 2024

Should be good to go. New image is pushed, everything seems to be working ok on my end.

@esand
Copy link
Contributor Author

esand commented Apr 6, 2024

Thanks! Builds fine on my end too and it's up and running, but haven't tested events yet. If anything comes up, I'll file a separate issue.

Thanks so much for the work on this!

@esand esand closed this as completed Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants