This commit is contained in:
Paulus Schoutsen 2019-07-31 12:25:30 -07:00
parent da05dfe708
commit 4de97abc3a
2676 changed files with 163166 additions and 140084 deletions

View file

@ -2,29 +2,34 @@
import logging
from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_HS_COLOR, SUPPORT_BRIGHTNESS,
SUPPORT_COLOR, SUPPORT_COLOR_TEMP, Light)
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_HS_COLOR,
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
SUPPORT_COLOR_TEMP,
Light,
)
from . import KNOWN_DEVICES, HomeKitEntity
_LOGGER = logging.getLogger(__name__)
async def async_setup_platform(
hass, config, async_add_entities, discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Legacy set up platform."""
pass
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up Homekit lightbulb."""
hkid = config_entry.data['AccessoryPairingID']
hkid = config_entry.data["AccessoryPairingID"]
conn = hass.data[KNOWN_DEVICES][hkid]
def async_add_service(aid, service):
if service['stype'] != 'lightbulb':
if service["stype"] != "lightbulb":
return False
info = {'aid': aid, 'iid': service['iid']}
info = {"aid": aid, "iid": service["iid"]}
async_add_entities([HomeKitLight(conn, info)], True)
return True
@ -47,6 +52,7 @@ class HomeKitLight(HomeKitEntity, Light):
"""Define the homekit characteristics the entity cares about."""
# pylint: disable=import-error
from homekit.model.characteristics import CharacteristicsTypes
return [
CharacteristicsTypes.ON,
CharacteristicsTypes.BRIGHTNESS,
@ -115,29 +121,39 @@ class HomeKitLight(HomeKitEntity, Light):
characteristics = []
if hs_color is not None:
characteristics.append({'aid': self._aid,
'iid': self._chars['hue'],
'value': hs_color[0]})
characteristics.append({'aid': self._aid,
'iid': self._chars['saturation'],
'value': hs_color[1]})
characteristics.append(
{"aid": self._aid, "iid": self._chars["hue"], "value": hs_color[0]}
)
characteristics.append(
{
"aid": self._aid,
"iid": self._chars["saturation"],
"value": hs_color[1],
}
)
if brightness is not None:
characteristics.append({'aid': self._aid,
'iid': self._chars['brightness'],
'value': int(brightness * 100 / 255)})
characteristics.append(
{
"aid": self._aid,
"iid": self._chars["brightness"],
"value": int(brightness * 100 / 255),
}
)
if temperature is not None:
characteristics.append({'aid': self._aid,
'iid': self._chars['color-temperature'],
'value': int(temperature)})
characteristics.append({'aid': self._aid,
'iid': self._chars['on'],
'value': True})
characteristics.append(
{
"aid": self._aid,
"iid": self._chars["color-temperature"],
"value": int(temperature),
}
)
characteristics.append(
{"aid": self._aid, "iid": self._chars["on"], "value": True}
)
await self._accessory.put_characteristics(characteristics)
async def async_turn_off(self, **kwargs):
"""Turn the specified light off."""
characteristics = [{'aid': self._aid,
'iid': self._chars['on'],
'value': False}]
characteristics = [{"aid": self._aid, "iid": self._chars["on"], "value": False}]
await self._accessory.put_characteristics(characteristics)