Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update risco to use CoordinatorEntity #39456

Merged
merged 1 commit into from Aug 30, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/components/risco/alarm_control_panel.py
Expand Up @@ -65,7 +65,7 @@ def __init__(self, coordinator, partition_id, code, options):
"""Init the partition."""
super().__init__(coordinator)
self._partition_id = partition_id
self._partition = self._coordinator.data.partitions[self._partition_id]
self._partition = self.coordinator.data.partitions[self._partition_id]
self._code = code
self._code_arm_required = options[CONF_CODE_ARM_REQUIRED]
self._code_disarm_required = options[CONF_CODE_DISARM_REQUIRED]
Expand All @@ -76,7 +76,7 @@ def __init__(self, coordinator, partition_id, code, options):
self._supported_states |= STATES_TO_SUPPORTED_FEATURES[state]

def _get_data_from_coordinator(self):
self._partition = self._coordinator.data.partitions[self._partition_id]
self._partition = self.coordinator.data.partitions[self._partition_id]

@property
def device_info(self):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/risco/binary_sensor.py
Expand Up @@ -39,7 +39,7 @@ def __init__(self, coordinator, zone_id, zone):
self._zone = zone

def _get_data_from_coordinator(self):
self._zone = self._coordinator.data.zones[self._zone_id]
self._zone = self.coordinator.data.zones[self._zone_id]

@property
def device_info(self):
Expand Down
29 changes: 4 additions & 25 deletions homeassistant/components/risco/entity.py
@@ -1,24 +1,10 @@
"""A risco entity base class."""
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.update_coordinator import CoordinatorEntity


class RiscoEntity(Entity):
class RiscoEntity(CoordinatorEntity):
"""Risco entity base class."""

def __init__(self, coordinator):
"""Init the instance."""
self._coordinator = coordinator

@property
def should_poll(self):
"""No need to poll. Coordinator notifies entity of updates."""
return False

@property
def available(self):
"""Return if entity is available."""
return self._coordinator.last_update_success

def _get_data_from_coordinator(self):
raise NotImplementedError

Expand All @@ -29,17 +15,10 @@ def _refresh_from_coordinator(self):
async def async_added_to_hass(self):
"""When entity is added to hass."""
self.async_on_remove(
self._coordinator.async_add_listener(self._refresh_from_coordinator)
self.coordinator.async_add_listener(self._refresh_from_coordinator)
Copy link
Contributor

@OnFreund OnFreund Aug 30, 2020

Choose a reason for hiding this comment

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

won't this result in two calls to async_write_ha_state() (one directly from CoordinatorEntity and the other from RiscoEntity._refresh_from_coordinator())?

Copy link
Contributor

Choose a reason for hiding this comment

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

not if super isnt called in risco method

Copy link
Contributor

Choose a reason for hiding this comment

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

Good call!

)

@property
def _risco(self):
"""Return the Risco API object."""
return self._coordinator.risco

async def async_update(self):
"""Update the entity.

Only used by the generic entity update service.
"""
await self._coordinator.async_request_refresh()
return self.coordinator.risco