-
Notifications
You must be signed in to change notification settings - Fork 1k
umqtt.robust: let reconnect() call the connect() method of the top class #195
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
base: master
Are you sure you want to change the base?
Conversation
This allow overriding of the connect() method by a subclass.
6 years later... I was researching before making the exact same PR. Having read all of the comments on #186, I agree that users of To that end, my from umqtt import robust
class MQTTClient(robust.MQTTClient):
def connect(self, clean_session=True):
res = super().connect(clean_session)
if not res:
self.after_connect()
return res
def after_connect():
#use for mqtt subscribe
return @pfalcon and @dpgeorge: FYA - no extra code, no broadening of the scope of the module, behaviour identical to the current |
@andrewleech, fancy reviewing / merging this PR? Do you see any pitfalls? |
I actually think it looks really strange to call self.connect when there is no actual self.connect function, it's confusing. I can guarantee new users coming to this module won't understand the need for this, at least not without examples / docs. I think if the end goal is to make it easier for users to make reconnect re-subscribe as needed, assuming this is a common need, scaffolding to do exactly that should be added instead. |
I appreciate the review, and still think the PR, as is, has merit. Addressing the general thrust of your critique... Strange and confusingAgreed, to the uninitiated, the reference to The end goalDepending upon who you cite, the 'end goal' can differ quite a lot. Expanding robust's scope has been debated at length, particularly in #186, and I'm generally content with its present scope (my interpretation):
A common enough wish is that robust would provide automated re-subscription when a clean session is returned from OutcomesThis PR makes implementing re-subscription more compact: without it, the user has to override I think it bears repeating that this change doesn't increase code size and doesn't alter existing built-in behaviour. An elegant solution that makes it easier for users to leverage robust whilst building upon it.
This is a separate issue IMHO. It has merit and I think people would use it, but I think it would form part of a third umqtt module. I'd be happy to collaborate because that's effectively what I'm implementing - just think it should stay clear of robust. |
When you mention a possible third version, well to be honest I've never used this robust module because any time I want to use mqtt I go straight to https://github.com/peterhinch/micropython-mqtt and in particular his async version. Regardless, I appreciate the argument that this change here keeps it lean, and with an example and/or docs it has merit in terms of a cheap increase in flexibility. |
Not sure, why
reconnect()
callconnect()
of the base class (super().connect(False)
).Here are my reasons to change this:
umqtt.robust
did not implement a newconnect()
methodconnect()
can now be easily overwritten by a subclass. Allow, e.g., the implementation of aafter_connect()
method as suggested in #3186 (comment):