mirror of
https://github.com/home-assistant/core.git
synced 2025-06-20 04:57:08 +00:00
Improve yeelight imports (#22804)
This commit is contained in:
parent
7a8aa79f19
commit
abb531c06b
@ -185,8 +185,8 @@ class YeelightDevice:
|
|||||||
@property
|
@property
|
||||||
def bulb(self):
|
def bulb(self):
|
||||||
"""Return bulb device."""
|
"""Return bulb device."""
|
||||||
import yeelight
|
|
||||||
if self._bulb_device is None:
|
if self._bulb_device is None:
|
||||||
|
import yeelight
|
||||||
try:
|
try:
|
||||||
self._bulb_device = yeelight.Bulb(self._ipaddr,
|
self._bulb_device = yeelight.Bulb(self._ipaddr,
|
||||||
model=self._model)
|
model=self._model)
|
||||||
@ -241,33 +241,27 @@ class YeelightDevice:
|
|||||||
|
|
||||||
def turn_on(self, duration=DEFAULT_TRANSITION, light_type=None):
|
def turn_on(self, duration=DEFAULT_TRANSITION, light_type=None):
|
||||||
"""Turn on device."""
|
"""Turn on device."""
|
||||||
import yeelight
|
from yeelight import BulbException
|
||||||
|
|
||||||
if not light_type:
|
|
||||||
light_type = yeelight.enums.LightType.Main
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.bulb.turn_on(duration=duration, light_type=light_type)
|
self.bulb.turn_on(duration=duration, light_type=light_type)
|
||||||
except yeelight.BulbException as ex:
|
except BulbException as ex:
|
||||||
_LOGGER.error("Unable to turn the bulb on: %s", ex)
|
_LOGGER.error("Unable to turn the bulb on: %s", ex)
|
||||||
return
|
return
|
||||||
|
|
||||||
def turn_off(self, duration=DEFAULT_TRANSITION, light_type=None):
|
def turn_off(self, duration=DEFAULT_TRANSITION, light_type=None):
|
||||||
"""Turn off device."""
|
"""Turn off device."""
|
||||||
import yeelight
|
from yeelight import BulbException
|
||||||
|
|
||||||
if not light_type:
|
|
||||||
light_type = yeelight.enums.LightType.Main
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.bulb.turn_off(duration=duration, light_type=light_type)
|
self.bulb.turn_off(duration=duration, light_type=light_type)
|
||||||
except yeelight.BulbException as ex:
|
except BulbException as ex:
|
||||||
_LOGGER.error("Unable to turn the bulb off: %s", ex)
|
_LOGGER.error("Unable to turn the bulb off: %s", ex)
|
||||||
return
|
return
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Read new properties from the device."""
|
"""Read new properties from the device."""
|
||||||
import yeelight
|
from yeelight import BulbException
|
||||||
|
|
||||||
if not self.bulb:
|
if not self.bulb:
|
||||||
return
|
return
|
||||||
@ -275,7 +269,7 @@ class YeelightDevice:
|
|||||||
try:
|
try:
|
||||||
self.bulb.get_properties(UPDATE_REQUEST_PROPERTIES)
|
self.bulb.get_properties(UPDATE_REQUEST_PROPERTIES)
|
||||||
self._available = True
|
self._available = True
|
||||||
except yeelight.BulbException as ex:
|
except BulbException as ex:
|
||||||
if self._available: # just inform once
|
if self._available: # just inform once
|
||||||
_LOGGER.error("Unable to update bulb status: %s", ex)
|
_LOGGER.error("Unable to update bulb status: %s", ex)
|
||||||
self._available = False
|
self._available = False
|
||||||
|
@ -189,6 +189,8 @@ class YeelightLight(Light):
|
|||||||
|
|
||||||
def __init__(self, device, custom_effects=None):
|
def __init__(self, device, custom_effects=None):
|
||||||
"""Initialize the Yeelight light."""
|
"""Initialize the Yeelight light."""
|
||||||
|
from yeelight.enums import LightType
|
||||||
|
|
||||||
self.config = device.config
|
self.config = device.config
|
||||||
self._device = device
|
self._device = device
|
||||||
|
|
||||||
@ -202,6 +204,8 @@ class YeelightLight(Light):
|
|||||||
self._min_mireds = None
|
self._min_mireds = None
|
||||||
self._max_mireds = None
|
self._max_mireds = None
|
||||||
|
|
||||||
|
self._light_type = LightType.Main
|
||||||
|
|
||||||
if custom_effects:
|
if custom_effects:
|
||||||
self._custom_effects = custom_effects
|
self._custom_effects = custom_effects
|
||||||
else:
|
else:
|
||||||
@ -281,8 +285,7 @@ class YeelightLight(Light):
|
|||||||
@property
|
@property
|
||||||
def light_type(self):
|
def light_type(self):
|
||||||
"""Return light type."""
|
"""Return light type."""
|
||||||
import yeelight
|
return self._light_type
|
||||||
return yeelight.enums.LightType.Main
|
|
||||||
|
|
||||||
def _get_hs_from_properties(self):
|
def _get_hs_from_properties(self):
|
||||||
rgb = self._get_property('rgb')
|
rgb = self._get_property('rgb')
|
||||||
@ -589,21 +592,19 @@ class YeelightAmbientLight(YeelightLight):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Initialize the Yeelight Ambient light."""
|
"""Initialize the Yeelight Ambient light."""
|
||||||
|
from yeelight.enums import LightType
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self._min_mireds = kelvin_to_mired(6500)
|
self._min_mireds = kelvin_to_mired(6500)
|
||||||
self._max_mireds = kelvin_to_mired(1700)
|
self._max_mireds = kelvin_to_mired(1700)
|
||||||
|
|
||||||
|
self._light_type = LightType.Ambient
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return the name of the device if any."""
|
"""Return the name of the device if any."""
|
||||||
return "{} ambilight".format(self.device.name)
|
return "{} ambilight".format(self.device.name)
|
||||||
|
|
||||||
@property
|
|
||||||
def light_type(self):
|
|
||||||
"""Return light type."""
|
|
||||||
import yeelight
|
|
||||||
return yeelight.enums.LightType.Ambient
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _is_nightlight_enabled(self):
|
def _is_nightlight_enabled(self):
|
||||||
return False
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user