Add support for dimmable bond lights (#38203)

* Add support for dimmable lights

* Fix formatting

* Add supported features test on Bond Light

* Add more tests to bond light and fixes comments

* Fix rebase conflict resolution

* Apply suggestions from code review

Co-authored-by: Chris Talkington <chris@talkingtontech.com>
This commit is contained in:
Marcio Granzotto RodriguesandChris Talkington authored and GitHub committed 2020-07-29 20:01:59 -05:00
1 parent fa9866db96
commit 8ab1b41974
4 files changed
+106 -9

No files matched your search

+27 -2
View File
@@ -47,20 +47,45 @@ class BondLight(BondEntity, LightEntity):
def __init__(self, hub: BondHub, device: BondDevice):
"""Create HA entity representing Bond fan."""
super().__init__(hub, device)
self._brightness: Optional[int] = None
self._light: Optional[int] = None
def _apply_state(self, state: dict):
self._light = state.get("light")
self._brightness = state.get("brightness")
@property
def supported_features(self) -> Optional[int]:
"""Flag supported features."""
features = 0
if self._device.supports_set_brightness():
features |= SUPPORT_BRIGHTNESS
return features
@property
def is_on(self) -> bool:
"""Return if light is currently on."""
return self._light == 1
@property
def brightness(self) -> int:
"""Return the brightness of this light between 1..255."""
brightness_value = (
round(self._brightness * 255 / 100) if self._brightness else None
)
return brightness_value
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the light."""
await self._hub.bond.action(self._device.device_id, Action.turn_light_on())
brightness = kwargs.get(ATTR_BRIGHTNESS)
if brightness:
await self._hub.bond.action(
self._device.device_id,
Action(Action.SET_BRIGHTNESS, round((brightness * 100) / 255)),
)
else:
await self._hub.bond.action(self._device.device_id, Action.turn_light_on())
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn off the light."""
+2 -6
View File
@@ -3,10 +3,6 @@
"name": "Bond",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/bond",
"requirements": [
"bond-api==0.1.7"
],
"codeowners": [
"@prystupa"
]
"requirements": ["bond-api==0.1.7"],
"codeowners": ["@prystupa"]
}
+5
View File
@@ -60,6 +60,11 @@ class BondDevice:
]
)
def supports_set_brightness(self) -> bool:
"""Return True if this device supports setting a light brightness."""
actions: List[str] = self._attrs["actions"]
return bool([action for action in actions if action in [Action.SET_BRIGHTNESS]])
class BondHub:
"""Hub device representing Bond Bridge."""