Refactor bond integration to be completely async (#38066)
This commit is contained in:
1 parent
15fe727f2c
commit
3480fb6996
16 files changed
+251
-259
No files matched your search
@@ -1,13 +1,13 @@
|
||||
"""Support for Bond generic devices."""
|
||||
from typing import Any, Callable, List, Optional
|
||||
|
||||
from bond import DeviceTypes
|
||||
from bond_api import Action, DeviceType
|
||||
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from ..switch import SwitchEntity
|
||||
from .const import DOMAIN
|
||||
from .entity import BondEntity
|
||||
from .utils import BondDevice, BondHub
|
||||
@@ -24,7 +24,7 @@ async def async_setup_entry(
|
||||
switches = [
|
||||
BondSwitch(hub, device)
|
||||
for device in hub.devices
|
||||
if device.type == DeviceTypes.GENERIC_DEVICE
|
||||
if DeviceType.is_generic(device.type)
|
||||
]
|
||||
|
||||
async_add_entities(switches, True)
|
||||
@@ -44,15 +44,15 @@ class BondSwitch(BondEntity, SwitchEntity):
|
||||
"""Return True if power is on."""
|
||||
return self._power == 1
|
||||
|
||||
def turn_on(self, **kwargs: Any) -> None:
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the device on."""
|
||||
self._hub.bond.turnOn(self._device.device_id)
|
||||
await self._hub.bond.action(self._device.device_id, Action.turn_on())
|
||||
|
||||
def turn_off(self, **kwargs: Any) -> None:
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the device off."""
|
||||
self._hub.bond.turnOff(self._device.device_id)
|
||||
await self._hub.bond.action(self._device.device_id, Action.turn_off())
|
||||
|
||||
def update(self):
|
||||
async def async_update(self):
|
||||
"""Fetch assumed state of the device from the hub using API."""
|
||||
state: dict = self._hub.bond.getDeviceState(self._device.device_id)
|
||||
state: dict = await self._hub.bond.device_state(self._device.device_id)
|
||||
self._power = state.get("power")
|
||||
Reference in new issue
Block a user