core/homeassistant/components/lw12wifi/light.py

151 lines
4.6 KiB
Python
Raw Normal View History

"""Support for Lagute LW-12 WiFi LED Controller."""
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
import logging
import lw12
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
import voluptuous as vol
from homeassistant.components.light import (
2019-07-31 19:25:30 +00:00
ATTR_BRIGHTNESS,
ATTR_EFFECT,
ATTR_HS_COLOR,
ATTR_TRANSITION,
PLATFORM_SCHEMA,
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
SUPPORT_EFFECT,
2019-07-31 19:25:30 +00:00
SUPPORT_TRANSITION,
2020-04-26 16:49:41 +00:00
LightEntity,
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
)
2019-07-31 19:25:30 +00:00
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
import homeassistant.helpers.config_validation as cv
import homeassistant.util.color as color_util
_LOGGER = logging.getLogger(__name__)
2019-07-31 19:25:30 +00:00
DEFAULT_NAME = "LW-12 FC"
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
DEFAULT_PORT = 5000
2019-07-31 19:25:30 +00:00
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
}
)
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
def setup_platform(hass, config, add_entities, discovery_info=None):
2018-08-19 20:29:08 +00:00
"""Set up LW-12 WiFi LED Controller platform."""
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
# Assign configuration variables.
name = config.get(CONF_NAME)
host = config.get(CONF_HOST)
port = config.get(CONF_PORT)
# Add devices
lw12_light = lw12.LW12Controller(host, port)
add_entities([LW12WiFi(name, lw12_light)])
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
2020-04-26 16:49:41 +00:00
class LW12WiFi(LightEntity):
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
"""LW-12 WiFi LED Controller."""
def __init__(self, name, lw12_light):
"""Initialise LW-12 WiFi LED Controller.
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
:param name: Friendly name for this platform to use.
:param lw12_light: Instance of the LW12 controller.
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
"""
self._light = lw12_light
self._name = name
self._state = None
self._effect = None
self._rgb_color = [255, 255, 255]
self._brightness = 255
# Setup feature list
2019-07-31 19:25:30 +00:00
self._supported_features = (
SUPPORT_BRIGHTNESS | SUPPORT_EFFECT | SUPPORT_COLOR | SUPPORT_TRANSITION
)
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
@property
def name(self):
"""Return the display name of the controlled light."""
return self._name
@property
def brightness(self):
"""Return the brightness of the light."""
return self._brightness
@property
def hs_color(self):
"""Read back the hue-saturation of the light."""
return color_util.color_RGB_to_hs(*self._rgb_color)
@property
def effect(self):
"""Return current light effect."""
if self._effect is None:
return None
2019-07-31 19:25:30 +00:00
return self._effect.replace("_", " ").title()
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
@property
def is_on(self):
"""Return true if light is on."""
return self._state
@property
def supported_features(self):
"""Return a list of supported features."""
return self._supported_features
@property
def effect_list(self):
"""Return a list of available effects.
Use the Enum element name for display.
"""
2019-07-31 19:25:30 +00:00
return [effect.name.replace("_", " ").title() for effect in lw12.LW12_EFFECT]
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
@property
def assumed_state(self) -> bool:
"""Return True if unable to access real state of the entity."""
return True
@property
def should_poll(self) -> bool:
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
"""Return False to not poll the state of this entity."""
return False
def turn_on(self, **kwargs):
"""Instruct the light to turn on."""
self._light.light_on()
if ATTR_HS_COLOR in kwargs:
2019-07-31 19:25:30 +00:00
self._rgb_color = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
self._light.set_color(*self._rgb_color)
self._effect = None
if ATTR_BRIGHTNESS in kwargs:
self._brightness = kwargs.get(ATTR_BRIGHTNESS)
brightness = int(self._brightness / 255 * 100)
2019-07-31 19:25:30 +00:00
self._light.set_light_option(lw12.LW12_LIGHT.BRIGHTNESS, brightness)
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
if ATTR_EFFECT in kwargs:
2019-07-31 19:25:30 +00:00
self._effect = kwargs[ATTR_EFFECT].replace(" ", "_").upper()
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
# Check if a known and supported effect was selected.
if self._effect in [eff.name for eff in lw12.LW12_EFFECT]:
# Selected effect is supported and will be applied.
self._light.set_effect(lw12.LW12_EFFECT[self._effect])
else:
# Unknown effect was set, recover by disabling the effect
# mode and log an error.
_LOGGER.error("Unknown effect selected: %s", self._effect)
self._effect = None
if ATTR_TRANSITION in kwargs:
transition_speed = int(kwargs[ATTR_TRANSITION])
2019-07-31 19:25:30 +00:00
self._light.set_light_option(lw12.LW12_LIGHT.FLASH, transition_speed)
Lagute LW-12 Wifi LED control (#13307) * Added platform lw12wifi for Lagute LW-12 Wifi Lights Supported features: * RGB colors * Variable brightness * 29 effects * Changing transitions speed for animated effects * Added lw12wifi to the list of omitted files to test * Added lw12 module as new requirement for lw12wifi platform * Added configuration example docstring for platform lw12wifi * Updating code according to review in PR: * Removed unused imports: enum, socket. * Unused and not imported feature SUPPORT_FLASH was removed. * Unused import lw12 in setup_platform method removed. * Fixed indention for valuptuous. * Changed check if effect is None. * Removed personal debug output. * Blocking function are not async anymore. * Further improvements to satisfy PR. * Unused import asyncio removed. * Fixed: Return value and docstring no match up for `assumed_state`. * Check if the set effect is supported, otherwise revert to normal light. * Added describing missing docstrings to all functions. * Adopted code to work with HS color setting. * Syntactical change in comment. * Removed redefinition of DOMAIN. * Refactored lw12 controller setup: removed requirement for host and port in LW12Wifi class. * Rewritten supported feature setup to a more static expression. * Removed unused rgb_color property * Fixed typo in comment for set_light_option * Changed RGB option validation schema * Removed instance properties as config options * Removed optional settings to be more inline with code style. * Removed unused option from config example * Removal of unused import * Added property to disable state polling for this entity. * Raise an exception if an unknown effect was selected. * Fixed an issue with the check for known effects. * As we do not need to set a default, use simple accessing by key. * Log if an unknown effect was selected. * Added link to future documentation.
2018-05-22 07:25:10 +00:00
self._state = True
def turn_off(self, **kwargs):
"""Instruct the light to turn off."""
self._light.light_off()
self._state = False