Centralize bond update state logic (#38093)

* Refactor bond integration to centralize update state logic in single superclass

* Refactor bond integration to centralize update state logic in single superclass
This commit is contained in:
Eugene Prystupa authored and GitHub committed 2020-07-23 04:15:27 +02:00
1 parent 3480fb6996
commit a756d1e637
5 files changed
+31 -30

No files matched your search

+12 -1
View File
@@ -1,13 +1,15 @@
"""An abstract class common to all Bond entities."""
from abc import abstractmethod
from typing import Any, Dict, Optional
from homeassistant.const import ATTR_NAME
from homeassistant.helpers.entity import Entity
from .const import DOMAIN
from .utils import BondDevice, BondHub
class BondEntity:
class BondEntity(Entity):
"""Generic Bond entity encapsulating common features of any Bond controlled device."""
def __init__(self, hub: BondHub, device: BondDevice):
@@ -38,3 +40,12 @@ class BondEntity:
def assumed_state(self) -> bool:
"""Let HA know this entity relies on an assumed state tracked by Bond."""
return True
async def async_update(self):
"""Fetch assumed state of the cover from the hub using API."""
state: dict = await self._hub.bond.device_state(self._device.device_id)
self._apply_state(state)
@abstractmethod
def _apply_state(self, state: dict):
raise NotImplementedError