Device Registry (#15980)

* First draft

* Generate device id

* No obscure registry

* Dont store config_entry_id in device

* Storage

* Small mistake on rebase

* Do storage more like entity registry

* Improve device identification

* Add tests

* Remove deconz device support from PR

* Fix hound comments, voff!

* Fix comments and clean up

* Fix proper indentation

* Fix pydoc issues

* Fix mochad component to not use self.device

* Fix mochad light platform to not use self.device

* Fix TankUtilitySensor to not use self.device

* Fix Soundtouch to not use self.device

* Fix Plex to not use self.device

* Fix Emby to not use self.device

* Fix Heatmiser to not use self.device

* Fix Wemo lights to not use self.device

* Fix Lifx to not use self.device

* Fix Radiotherm to not use self.device

* Fix Juicenet to not use self.device

* Fix Qwikswitch to not use self.device

* Fix Xiaomi miio to not use self.device

* Fix Nest to not use self.device

* Fix Tellduslive to not use self.device

* Fix Knx to not use self.device

* Clean up a small mistake in soundtouch

* Fix comment from Ballob

* Fix bad indentation

* Fix indentatin

* Lint

* Remove unused variable

* Lint
This commit is contained in:
Robert Svensson 2018-08-22 10:46:37 +02:00 committed by Paulus Schoutsen
parent 7e7f9bc6ac
commit 0009be595c
40 changed files with 538 additions and 331 deletions

View file

@ -389,7 +389,7 @@ class LIFXLight(Light):
def __init__(self, device, effects_conductor):
"""Initialize the light."""
self.device = device
self.light = device
self.effects_conductor = effects_conductor
self.registered = True
self.postponed_update = None
@ -403,28 +403,28 @@ class LIFXLight(Light):
@property
def unique_id(self):
"""Return a unique ID."""
return self.device.mac_addr
return self.light.mac_addr
@property
def name(self):
"""Return the name of the device."""
return self.device.label
return self.light.label
@property
def who(self):
"""Return a string identifying the device."""
return "%s (%s)" % (self.device.ip_addr, self.name)
return "%s (%s)" % (self.light.ip_addr, self.name)
@property
def min_mireds(self):
"""Return the coldest color_temp that this light supports."""
kelvin = lifx_features(self.device)['max_kelvin']
kelvin = lifx_features(self.light)['max_kelvin']
return math.floor(color_util.color_temperature_kelvin_to_mired(kelvin))
@property
def max_mireds(self):
"""Return the warmest color_temp that this light supports."""
kelvin = lifx_features(self.device)['min_kelvin']
kelvin = lifx_features(self.light)['min_kelvin']
return math.ceil(color_util.color_temperature_kelvin_to_mired(kelvin))
@property
@ -432,7 +432,7 @@ class LIFXLight(Light):
"""Flag supported features."""
support = SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION | SUPPORT_EFFECT
device_features = lifx_features(self.device)
device_features = lifx_features(self.light)
if device_features['min_kelvin'] != device_features['max_kelvin']:
support |= SUPPORT_COLOR_TEMP
@ -441,12 +441,12 @@ class LIFXLight(Light):
@property
def brightness(self):
"""Return the brightness of this light between 0..255."""
return convert_16_to_8(self.device.color[2])
return convert_16_to_8(self.light.color[2])
@property
def color_temp(self):
"""Return the color temperature."""
_, sat, _, kelvin = self.device.color
_, sat, _, kelvin = self.light.color
if sat:
return None
return color_util.color_temperature_kelvin_to_mired(kelvin)
@ -454,12 +454,12 @@ class LIFXLight(Light):
@property
def is_on(self):
"""Return true if device is on."""
return self.device.power_level != 0
return self.light.power_level != 0
@property
def effect(self):
"""Return the name of the currently running effect."""
effect = self.effects_conductor.effect(self.device)
effect = self.effects_conductor.effect(self.light)
if effect:
return 'lifx_effect_' + effect.name
return None
@ -497,7 +497,7 @@ class LIFXLight(Light):
async def set_state(self, **kwargs):
"""Set a color on the light and turn it on/off."""
async with self.lock:
bulb = self.device
bulb = self.light
await self.effects_conductor.stop([bulb])
@ -545,12 +545,12 @@ class LIFXLight(Light):
async def set_power(self, ack, pwr, duration=0):
"""Send a power change to the device."""
await ack(partial(self.device.set_power, pwr, duration=duration))
await ack(partial(self.light.set_power, pwr, duration=duration))
async def set_color(self, ack, hsbk, kwargs, duration=0):
"""Send a color change to the device."""
hsbk = merge_hsbk(self.device.color, hsbk)
await ack(partial(self.device.set_color, hsbk, duration=duration))
hsbk = merge_hsbk(self.light.color, hsbk)
await ack(partial(self.light.set_color, hsbk, duration=duration))
async def default_effect(self, **kwargs):
"""Start an effect with default parameters."""
@ -563,7 +563,7 @@ class LIFXLight(Light):
async def async_update(self):
"""Update bulb status."""
if self.available and not self.lock.locked():
await AwaitAioLIFX().wait(self.device.get_color)
await AwaitAioLIFX().wait(self.light.get_color)
class LIFXWhite(LIFXLight):
@ -600,7 +600,7 @@ class LIFXColor(LIFXLight):
@property
def hs_color(self):
"""Return the hs value."""
hue, sat, _, _ = self.device.color
hue, sat, _, _ = self.light.color
hue = hue / 65535 * 360
sat = sat / 65535 * 100
return (hue, sat) if sat else None
@ -611,7 +611,7 @@ class LIFXStrip(LIFXColor):
async def set_color(self, ack, hsbk, kwargs, duration=0):
"""Send a color change to the device."""
bulb = self.device
bulb = self.light
num_zones = len(bulb.color_zones)
zones = kwargs.get(ATTR_ZONES)
@ -659,7 +659,7 @@ class LIFXStrip(LIFXColor):
while self.available and zone < top:
# Each get_color_zones can update 8 zones at once
resp = await AwaitAioLIFX().wait(partial(
self.device.get_color_zones,
self.light.get_color_zones,
start_index=zone))
if resp:
zone += 8