You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So d162e54 goes in the direction I intended the interface to go but I think I'll restore the old interface at least until the next release but mark it as deprecated.
Hey @lexruee my primary reason it's class based to you need to create a class to listen to events or use some hackery to pass your handler methods in some other way - I think we can do better. I'm looking for some ideas other than what I implemented in d162e54 because I'm not entirely happy with it though.
Right now the secondary, experimental, listener system looks like this:
defhandler(zeroconf, service_type, name, state_change):
pass# then you can do thisbrowser=ServiceBrowser(zeroconf, '_http._tcp.local.', handlers=[handler])
# or thatbrowser=ServiceBrowser(zeroconf, '_http._tcp.local.')
browser.service_state_changed.register_handler(handler)
It doesn't require you to create a class to have a handler but I'm not sure how Pythonic it is. As another alternative I'm thinking about is to expose an interface returning iterators, such iterators would yield events discovered by the ServiceBrowser:
In my opinion it's fine to have a generic service state handler.
But I would also provide a shortcut to register specific event handlers like 'add_service' or 'remove_service' which are called if such an event occurs. In that case you could avoid to write a generic event handler where you need if-elsif-else statements to distinguish between events.
And instead I of exposing the 'service_state_changed.' property to register new handlers I would use a method like 'register_listener'.
However, that's just my opinion :-) (based on java / ruby experience)
Activity
jstasiak commentedon Feb 15, 2015
So d162e54 goes in the direction I intended the interface to go but I think I'll restore the old interface at least until the next release but mark it as deprecated.
lexruee commentedon Feb 16, 2015
@jstasiak Hi! I'm curious. What's the reason to change the listener system?
jstasiak commentedon Feb 17, 2015
Hey @lexruee my primary reason it's class based to you need to create a class to listen to events or use some hackery to pass your handler methods in some other way - I think we can do better. I'm looking for some ideas other than what I implemented in d162e54 because I'm not entirely happy with it though.
lexruee commentedon Feb 17, 2015
@jstasiak The old implementation uses the observer pattern applied on the ServiceBrowser. But I can understand why one could argue not use it. Link
Do you have in mind to implement something like that:
Anyways, I'm new to python, so I don't know the pythonic way :-).
jstasiak commentedon Feb 20, 2015
Right now the secondary, experimental, listener system looks like this:
It doesn't require you to create a class to have a handler but I'm not sure how Pythonic it is. As another alternative I'm thinking about is to expose an interface returning iterators, such iterators would yield events discovered by the
ServiceBrowser:lexruee commentedon Feb 20, 2015
In my opinion it's fine to have a generic service state handler.
But I would also provide a shortcut to register specific event handlers like 'add_service' or 'remove_service' which are called if such an event occurs. In that case you could avoid to write a generic event handler where you need if-elsif-else statements to distinguish between events.
And instead I of exposing the 'service_state_changed.' property to register new handlers I would use a method like 'register_listener'.
However, that's just my opinion :-) (based on java / ruby experience)
jstasiak commentedon Mar 29, 2015
@lexruee Thanks for the notes, I'll definitely keep this in mind
jstasiak commentedon Dec 1, 2015
Closing as I have no plan to do this at the moment.
Merge pull request python-zeroconf#3 from dylanmccall/replace-ifcfg-w…