Refactor bond integration to be completely async (#38066)

This commit is contained in:
Eugene Prystupa authored and GitHub committed 2020-07-22 20:22:25 -05:00
1 parent 15fe727f2c
commit 3480fb6996
16 files changed
+251 -259

No files matched your search

+9 -15
View File
@@ -2,7 +2,7 @@
from typing import List, Optional
from bond import Actions, Bond
from bond_api import Action, Bond
class BondDevice:
@@ -27,18 +27,12 @@ class BondDevice:
def supports_speed(self) -> bool:
"""Return True if this device supports any of the speed related commands."""
actions: List[str] = self._attrs["actions"]
return bool([action for action in actions if action in [Actions.SET_SPEED]])
return bool([action for action in actions if action in [Action.SET_SPEED]])
def supports_direction(self) -> bool:
"""Return True if this device supports any of the direction related commands."""
actions: List[str] = self._attrs["actions"]
return bool(
[
action
for action in actions
if action in [Actions.SET_DIRECTION, Actions.TOGGLE_DIRECTION]
]
)
return bool([action for action in actions if action in [Action.SET_DIRECTION]])
def supports_light(self) -> bool:
"""Return True if this device supports any of the light related commands."""
@@ -47,7 +41,7 @@ class BondDevice:
[
action
for action in actions
if action in [Actions.TURN_LIGHT_ON, Actions.TOGGLE_LIGHT]
if action in [Action.TURN_LIGHT_ON, Action.TURN_LIGHT_OFF]
]
)
@@ -61,17 +55,17 @@ class BondHub:
self._version: Optional[dict] = None
self._devices: Optional[List[BondDevice]] = None
def setup(self):
async def setup(self):
"""Read hub version information."""
self._version = self.bond.getVersion()
self._version = await self.bond.version()
# Fetch all available devices using Bond API.
device_ids = self.bond.getDeviceIds()
device_ids = await self.bond.devices()
self._devices = [
BondDevice(
device_id,
self.bond.getDevice(device_id),
self.bond.getProperties(device_id),
await self.bond.device(device_id),
await self.bond.device_properties(device_id),
)
for device_id in device_ids
]