MisterWil / abodepy

A thin Python wrapper for the Abode alarm API
MIT License
49 stars 17 forks source link

AbodeEventController being created before login validated #77

Open shred86 opened 3 years ago

shred86 commented 3 years ago

I'm working on adding the MFA config flow for the Abode integration and I noticed something that we should maybe change.

Right now, AbodeEventController is being instantiated towards the beginning of initializing the Abode class.

This results in is each time we try to log into Abode by instantiating the Abode class from HA, it creates an instance of AbodeEventController even if the login fails (i.e. invalid credentials). Each time AbodeEventController is instantiated, a bunch of callbacks are added:

2020-11-25 18:11:15 DEBUG (SyncWorker_6) [abodepy.socketio] Adding callback for event name: started
2020-11-25 18:11:15 DEBUG (SyncWorker_6) [abodepy.socketio] Adding callback for event name: connected
2020-11-25 18:11:15 DEBUG (SyncWorker_6) [abodepy.socketio] Adding callback for event name: disconnected
2020-11-25 18:11:15 DEBUG (SyncWorker_6) [abodepy.socketio] Adding callback for event name: com.goabode.device.update
2020-11-25 18:11:15 DEBUG (SyncWorker_6) [abodepy.socketio] Adding callback for event name: com.goabode.gateway.mode
2020-11-25 18:11:15 DEBUG (SyncWorker_6) [abodepy.socketio] Adding callback for event name: com.goabode.gateway.timeline
2020-11-25 18:11:15 DEBUG (SyncWorker_6) [abodepy.socketio] Adding callback for event name: com.goabode.automation

I'm not sure if this is really that big of an issue but it seems like this is something that should occur after a valid connection is established or confirmed. An easy solution would be to move this after the self.login() method here. However, if you were able to create an instance of Abode and pass in auto_login=False, then it would self._event_controller would never be set. That being said, I'm not even sure if that's a valid use case.

Thoughts?