MisterWil / abodepy

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

Add callback for abode connection status #67

Closed shred86 closed 4 years ago

shred86 commented 4 years ago

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:

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 commented 4 years ago

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)