mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Add Abode entity available property (#32923)
* Add available property and raise exception * Add entity available property * Refactoring and fixes * Refactoring and fix for multi sensor * Bump abodepy version
This commit is contained in:
parent
4e6fd19624
commit
b8e9e3af2f
@ -19,6 +19,7 @@ from homeassistant.const import (
|
|||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
)
|
)
|
||||||
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.helpers.dispatcher import dispatcher_send
|
from homeassistant.helpers.dispatcher import dispatcher_send
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
@ -119,7 +120,7 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
|
|
||||||
except (AbodeException, ConnectTimeout, HTTPError) as ex:
|
except (AbodeException, ConnectTimeout, HTTPError) as ex:
|
||||||
LOGGER.error("Unable to connect to Abode: %s", str(ex))
|
LOGGER.error("Unable to connect to Abode: %s", str(ex))
|
||||||
return False
|
raise ConfigEntryNotReady
|
||||||
|
|
||||||
for platform in ABODE_PLATFORMS:
|
for platform in ABODE_PLATFORMS:
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
@ -271,36 +272,72 @@ def setup_abode_events(hass):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class AbodeDevice(Entity):
|
class AbodeEntity(Entity):
|
||||||
"""Representation of an Abode device."""
|
"""Representation of an Abode entity."""
|
||||||
|
|
||||||
def __init__(self, data, device):
|
def __init__(self, data):
|
||||||
"""Initialize Abode device."""
|
"""Initialize Abode entity."""
|
||||||
self._data = data
|
self._data = data
|
||||||
self._device = device
|
self._available = True
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
@property
|
||||||
"""Subscribe to device events."""
|
def available(self):
|
||||||
self.hass.async_add_job(
|
"""Return the available state."""
|
||||||
self._data.abode.events.add_device_callback,
|
return self._available
|
||||||
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."""
|
|
||||||
self.hass.async_add_job(
|
|
||||||
self._data.abode.events.remove_all_device_callbacks, self._device.device_id
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
"""Return the polling state."""
|
"""Return the polling state."""
|
||||||
return self._data.polling
|
return self._data.polling
|
||||||
|
|
||||||
|
async def async_added_to_hass(self):
|
||||||
|
"""Subscribe to Abode connection status updates."""
|
||||||
|
self.hass.async_add_job(
|
||||||
|
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."""
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update device and automation states."""
|
"""Update device state."""
|
||||||
self._device.refresh()
|
self._device.refresh()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -339,23 +376,14 @@ class AbodeDevice(Entity):
|
|||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
|
|
||||||
class AbodeAutomation(Entity):
|
class AbodeAutomation(AbodeEntity):
|
||||||
"""Representation of an Abode automation."""
|
"""Representation of an Abode automation."""
|
||||||
|
|
||||||
def __init__(self, data, automation):
|
def __init__(self, data, automation):
|
||||||
"""Initialize for Abode automation."""
|
"""Initialize for Abode automation."""
|
||||||
self._data = data
|
super().__init__(data)
|
||||||
self._automation = automation
|
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):
|
def update(self):
|
||||||
"""Update automation state."""
|
"""Update automation state."""
|
||||||
self._automation.refresh()
|
self._automation.refresh()
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Abode",
|
"name": "Abode",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/abode",
|
"documentation": "https://www.home-assistant.io/integrations/abode",
|
||||||
"requirements": ["abodepy==0.18.1"],
|
"requirements": ["abodepy==0.19.0"],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": ["@shred86"]
|
"codeowners": ["@shred86"]
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ WazeRouteCalculator==0.12
|
|||||||
YesssSMS==0.4.1
|
YesssSMS==0.4.1
|
||||||
|
|
||||||
# homeassistant.components.abode
|
# homeassistant.components.abode
|
||||||
abodepy==0.18.1
|
abodepy==0.19.0
|
||||||
|
|
||||||
# homeassistant.components.mcp23017
|
# homeassistant.components.mcp23017
|
||||||
adafruit-blinka==3.9.0
|
adafruit-blinka==3.9.0
|
||||||
|
@ -26,7 +26,7 @@ RtmAPI==0.7.2
|
|||||||
YesssSMS==0.4.1
|
YesssSMS==0.4.1
|
||||||
|
|
||||||
# homeassistant.components.abode
|
# homeassistant.components.abode
|
||||||
abodepy==0.18.1
|
abodepy==0.19.0
|
||||||
|
|
||||||
# homeassistant.components.androidtv
|
# homeassistant.components.androidtv
|
||||||
adb-shell==0.1.1
|
adb-shell==0.1.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user