Skip to content

Commit

Permalink
Update tradfri.py (#10991)
Browse files Browse the repository at this point in the history
  • Loading branch information
pvizeli authored Dec 6, 2017
1 parent e66268d commit 9cff6c7
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions homeassistant/components/light/tradfri.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def brightness(self):
@asyncio.coroutine
def async_turn_off(self, **kwargs):
"""Instruct the group lights to turn off."""
self.hass.async_add_job(self._api(self._group.set_state(0)))
yield from self._api(self._group.set_state(0))

@asyncio.coroutine
def async_turn_on(self, **kwargs):
Expand All @@ -112,10 +112,10 @@ def async_turn_on(self, **kwargs):
if kwargs[ATTR_BRIGHTNESS] == 255:
kwargs[ATTR_BRIGHTNESS] = 254

self.hass.async_add_job(self._api(
self._group.set_dimmer(kwargs[ATTR_BRIGHTNESS], **keys)))
yield from self._api(
self._group.set_dimmer(kwargs[ATTR_BRIGHTNESS], **keys))
else:
self.hass.async_add_job(self._api(self._group.set_state(1)))
yield from self._api(self._group.set_state(1))

@callback
def _async_start_observe(self, exc=None):
Expand All @@ -140,11 +140,11 @@ def _refresh(self, group):
self._group = group
self._name = group.name

@callback
def _observe_update(self, tradfri_device):
"""Receive new state data for this light."""
self._refresh(tradfri_device)

self.hass.async_add_job(self.async_update_ha_state())
self.async_schedule_update_ha_state()


class TradfriLight(Light):
Expand Down Expand Up @@ -238,8 +238,7 @@ def rgb_color(self):
@asyncio.coroutine
def async_turn_off(self, **kwargs):
"""Instruct the light to turn off."""
self.hass.async_add_job(self._api(
self._light_control.set_state(False)))
yield from self._api(self._light_control.set_state(False))

@asyncio.coroutine
def async_turn_on(self, **kwargs):
Expand All @@ -250,17 +249,17 @@ def async_turn_on(self, **kwargs):
for ATTR_RGB_COLOR, this also supports Philips Hue bulbs.
"""
if ATTR_RGB_COLOR in kwargs and self._light_data.hex_color is not None:
self.hass.async_add_job(self._api(
yield from self._api(
self._light.light_control.set_rgb_color(
*kwargs[ATTR_RGB_COLOR])))
*kwargs[ATTR_RGB_COLOR]))

elif ATTR_COLOR_TEMP in kwargs and \
self._light_data.hex_color is not None and \
self._temp_supported:
kelvin = color_util.color_temperature_mired_to_kelvin(
kwargs[ATTR_COLOR_TEMP])
self.hass.async_add_job(self._api(
self._light_control.set_kelvin_color(kelvin)))
yield from self._api(
self._light_control.set_kelvin_color(kelvin))

keys = {}
if ATTR_TRANSITION in kwargs:
Expand All @@ -270,12 +269,12 @@ def async_turn_on(self, **kwargs):
if kwargs[ATTR_BRIGHTNESS] == 255:
kwargs[ATTR_BRIGHTNESS] = 254

self.hass.async_add_job(self._api(
yield from self._api(
self._light_control.set_dimmer(kwargs[ATTR_BRIGHTNESS],
**keys)))
**keys))
else:
self.hass.async_add_job(self._api(
self._light_control.set_state(True)))
yield from self._api(
self._light_control.set_state(True))

@callback
def _async_start_observe(self, exc=None):
Expand Down Expand Up @@ -318,10 +317,11 @@ def _refresh(self, light):
self._temp_supported = self._light.device_info.manufacturer \
in ALLOWED_TEMPERATURES

@callback
def _observe_update(self, tradfri_device):
"""Receive new state data for this light."""
self._refresh(tradfri_device)
self._rgb_color = color_util.rgb_hex_to_rgb_list(
self._light_data.hex_color_inferred
)
self.hass.async_add_job(self.async_update_ha_state())
self.async_schedule_update_ha_state()

0 comments on commit 9cff6c7

Please sign in to comment.