hass-core/homeassistant/components/bond/utils.py
Chris Talkington fb420d5952
Apply more suggestions from bond code review (#37592)
* apply more suggestions from bond code review

* Update cover.py

* Update test_cover.py

* Update test_cover.py

* Update test_cover.py

* Update cover.py

* Update utils.py

* Update test_cover.py

* Update test_utils.py

* Delete test_utils.py

* Update cover.py

* Update test_cover.py

* Update test_cover.py
2020-07-08 16:28:53 -05:00

35 lines
943 B
Python

"""Reusable utilities for the Bond component."""
from typing import List
from bond import Bond
from homeassistant.core import HomeAssistant
class BondDevice:
"""Helper device class to hold ID and attributes together."""
def __init__(self, device_id: str, attrs: dict):
"""Create a helper device from ID and attributes returned by API."""
self.device_id = device_id
self._attrs = attrs
@property
def name(self):
"""Get the name of this device."""
return self._attrs["name"]
@property
def type(self):
"""Get the type of this device."""
return self._attrs["type"]
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