# pylint: disable=no-value-for-parameter
import logging
from aiohap import Accessory, Category, services
from .base import BooleanLink, FloatLink, Link, PercentageFloatLink, PercentageIntLink
logger = logging.getLogger(__name__)
[docs]class LightAccessory(Accessory):
category = Category.LIGHTBULB
info = services.AccessoryInformation
light = services.Lightbulb
[docs]class LightLink(Link):
meadow_service_type = 'light'
def _get_features(self, md_light):
if 'brightness' in md_light.characteristics:
yield 'light:brightness'
if 'hue' in md_light.characteristics:
yield 'light:hue'
if 'saturation' in md_light.characteristics:
yield 'light:saturation'
def _create_link(self):
super()._create_link()
self._md_light = self._md_service
self._hk_light = LightAccessory(self._md_light.name,
include=tuple(self._get_features(self._md_light)))
self.sublinks.append(
BooleanLink(self._md_light.is_on, self._hk_light.light.on, default=False))
if 'brightness' in self._md_light.characteristics:
self.sublinks.append(
PercentageIntLink(self._md_light.brightness,
self._hk_light.light.brightness,
default=0))
if 'hue' in self._md_light.characteristics:
self.sublinks.append(
FloatLink(self._md_light.hue, self._hk_light.light.hue, default=0.0))
if 'saturation' in self._md_light.characteristics:
self.sublinks.append(
PercentageFloatLink(self._md_light.saturation,
self._hk_light.light.saturation,
default=1.0))
self._fill_accessory_info(self._hk_light)
self.bridge.accessory_server.add_accessory(self._hk_light)