Skip to content

Add callback for abode connection status#67

Merged
MisterWil merged 8 commits intoMisterWil:masterfrom
shred86:minor_fixes
Apr 3, 2020
Merged

Add callback for abode connection status#67
MisterWil merged 8 commits intoMisterWil:masterfrom
shred86:minor_fixes

Conversation

@shred86
Copy link
Contributor

@shred86 shred86 commented Mar 16, 2020

This is a work in progress but I wanted to make this PR to be able to get some feedback. I'm attempting to add support for setting the entity available property in Home Assistant for abode devices/automations. Basically, when available is True, the entities are available to use and when False, the entities are greyed out in the HA UI and can't be used. Here's an overview on my initial thought at implementation:

  • Use the existing _on_socket_connect and _on_socket_disconnect callbacks in the AbodeEventController class in event_controller.py. These are called when the web socket connection to the Abode server is connected and disconnected.
  • Create a new property self._is_connected on the AbodeEventController that is set to False by default. This will True when _on_socket_connect is called and False when _on_socket_disconnect is called. A property method is_connected is also created to return self._is_connected for accessing outside the class.
  • Create a new method add_connection_status_callback that appends callbacks to a newly added empty list self._connection_status_callback.

From the Home Assistant side, I'm simply calling add_connection_status_callback for each instance of AbodeDevice (in the abode HA integration). This in turn adds a simple callback method:

    def _update_connection_status(self):
        """Update the device available property."""
        self._available = self._data.abode.events.connected
        self.schedule_update_ha_state()

When _on_socket_connect is called, it will call the callback above for every Abode device in Home Assistant which will set the self._available property based on the self._is_connected boolean.

Everything is working as expected during testing but I'd like to get some other opinions.

@shred86 shred86 changed the title Add callback for abode connection status [Work In Progress] Add callback for abode connection status Mar 16, 2020
@shred86 shred86 changed the title [Work In Progress] Add callback for abode connection status [WIP] Add callback for abode connection status Mar 16, 2020
@shred86 shred86 changed the title [WIP] Add callback for abode connection status Add callback for abode connection status Mar 17, 2020
@shred86
Copy link
Contributor Author

shred86 commented Mar 28, 2020

Finally figured out a fix to the issue I was having. Ended up removing a lot of unnecessary code too with how it's implemented. Should be good to go now, although I can't figure out why Travis CI is failing:

ERROR: InvocationError for command /home/travis/build/MisterWil/abodepy/.tox/py37/bin/py.test --timeout=30 --cov=abodepy --cov-report term-missing -s (exited with code 3)

@MisterWil MisterWil merged commit f4758e5 into MisterWil:master Apr 3, 2020
@shred86 shred86 deleted the minor_fixes branch July 18, 2020 16:18
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

Successfully merging this pull request may close these issues.

2 participants