Add Bond hub as a device for bond entities (#37772)

* Introduce Bond Hub concept

* Read Hub version information when setting up entry

* Link entities to Hub using via_device

* Add test to verify created Hub device properties
This commit is contained in:
Eugene Prystupa authored and GitHub committed 2020-07-12 11:31:53 -05:00
1 parent 6826a8829c
commit c6ab2c5d0a
7 files changed
+136 -50

No files matched your search

+36 -10
View File
@@ -1,11 +1,9 @@
"""Reusable utilities for the Bond component."""
from typing import List
from typing import List, Optional
from bond import Bond
from homeassistant.core import HomeAssistant
class BondDevice:
"""Helper device class to hold ID and attributes together."""
@@ -31,10 +29,38 @@ class BondDevice:
return command in actions
def get_bond_devices(hass: HomeAssistant, bond: Bond) -> List[BondDevice]:
"""Fetch all available devices using Bond API."""
device_ids = bond.getDeviceIds()
devices = [
BondDevice(device_id, bond.getDevice(device_id)) for device_id in device_ids
]
return devices
class BondHub:
"""Hub device representing Bond Bridge."""
def __init__(self, bond: Bond):
"""Initialize Bond Hub."""
self.bond: Bond = bond
self._version: Optional[dict] = None
def setup(self):
"""Read hub version information."""
self._version = self.bond.getVersion()
def get_bond_devices(self) -> List[BondDevice]:
"""Fetch all available devices using Bond API."""
device_ids = self.bond.getDeviceIds()
devices = [
BondDevice(device_id, self.bond.getDevice(device_id))
for device_id in device_ids
]
return devices
@property
def bond_id(self) -> str:
"""Return unique Bond ID for this hub."""
return self._version["bondid"]
@property
def target(self) -> str:
"""Return this hub model."""
return self._version.get("target")
@property
def fw_ver(self) -> str:
"""Return this hub firmware version."""
return self._version.get("fw_ver")