Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 49 additions & 21 deletions homeassistant/components/abode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
CONF_USERNAME,
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.dispatcher import dispatcher_send
from homeassistant.helpers.entity import Entity
Expand Down Expand Up @@ -119,7 +120,7 @@ async def async_setup_entry(hass, config_entry):

except (AbodeException, ConnectTimeout, HTTPError) as ex:
LOGGER.error("Unable to connect to Abode: %s", str(ex))
return False
raise ConfigEntryNotReady

for platform in ABODE_PLATFORMS:
hass.async_create_task(
Expand Down Expand Up @@ -271,36 +272,72 @@ def event_callback(event, event_json):
)


class AbodeDevice(Entity):
class AbodeEntity(Entity):
"""Representation of an Abode entity."""

def __init__(self, data):
"""Initialize Abode entity."""
self._data = data
self._available = True

@property
def available(self):
"""Return the available state."""
return self._available

@property
def should_poll(self):
"""Return the polling state."""
return self._data.polling

async def async_added_to_hass(self):
"""Subscribe to Abode connection status updates."""
self.hass.async_add_job(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hass.async_add_job is legacy for general use. Either use hass.async_create_task to schedule coroutines or hass.async_add_executor_job to schedule functions that need to run in the executor thread pool.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix this in a new PR, thanks!

self._data.abode.events.add_connection_status_callback,
self.unique_id,
self._update_connection_status,
)

self.hass.data[DOMAIN].entity_ids.add(self.entity_id)

async def async_will_remove_from_hass(self):
"""Unsubscribe from Abode connection status updates."""
self.hass.async_add_job(
self._data.abode.events.remove_connection_status_callback, self.unique_id,
)

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


class AbodeDevice(AbodeEntity):
"""Representation of an Abode device."""

def __init__(self, data, device):
"""Initialize Abode device."""
self._data = data
super().__init__(data)
self._device = device

async def async_added_to_hass(self):
"""Subscribe to device events."""
await super().async_added_to_hass()
self.hass.async_add_job(
self._data.abode.events.add_device_callback,
self._device.device_id,
self._update_callback,
)
self.hass.data[DOMAIN].entity_ids.add(self.entity_id)

async def async_will_remove_from_hass(self):
"""Unsubscribe from device events."""
await super().async_will_remove_from_hass()
self.hass.async_add_job(
self._data.abode.events.remove_all_device_callbacks, self._device.device_id
)

@property
def should_poll(self):
"""Return the polling state."""
return self._data.polling

def update(self):
"""Update device and automation states."""
"""Update device state."""
self._device.refresh()

@property
Expand Down Expand Up @@ -339,23 +376,14 @@ def _update_callback(self, device):
self.schedule_update_ha_state()


class AbodeAutomation(Entity):
class AbodeAutomation(AbodeEntity):
"""Representation of an Abode automation."""

def __init__(self, data, automation):
"""Initialize for Abode automation."""
self._data = data
super().__init__(data)
self._automation = automation

async def async_added_to_hass(self):
"""Set up automation entity."""
self.hass.data[DOMAIN].entity_ids.add(self.entity_id)

@property
def should_poll(self):
"""Return the polling state."""
return self._data.polling

def update(self):
"""Update automation state."""
self._automation.refresh()
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/abode/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Abode",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/abode",
"requirements": ["abodepy==0.18.1"],
"requirements": ["abodepy==0.19.0"],
"dependencies": [],
"codeowners": ["@shred86"]
}
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ WazeRouteCalculator==0.12
YesssSMS==0.4.1

# homeassistant.components.abode
abodepy==0.18.1
abodepy==0.19.0

# homeassistant.components.mcp23017
adafruit-blinka==3.9.0
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RtmAPI==0.7.2
YesssSMS==0.4.1

# homeassistant.components.abode
abodepy==0.18.1
abodepy==0.19.0

# homeassistant.components.androidtv
adb-shell==0.1.1
Expand Down