ATTR_BRIGHTNESS, ATTR_HS_COLOR, PLATFORM_SCHEMA, SUPPORT_BRIGHTNESS, SUPPORT_COLOR, LightEntity, ) from openpeerpower.const import CONF_NAME import openpeerpower.helpers.config_validation as cv import openpeerpower.util.color as color_util SUPPORT_BLINKT = SUPPORT_BRIGHTNESS | SUPPORT_COLOR DEFAULT_NAME = "blinkt" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( {vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string}) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the Blinkt Light platform.""" blinkt = importlib.import_module("blinkt") # ensure that the lights are off when exiting blinkt.set_clear_on_exit() name = config[CONF_NAME] add_entities([ BlinktLight(blinkt, name, index) for index in range(blinkt.NUM_PIXELS) ])
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Optional(CONF_DEVICE_DEFAULTS, default=DEVICE_DEFAULTS_SCHEMA({})): DEVICE_DEFAULTS_SCHEMA, vol.Optional(CONF_AUTOMATIC_ADD, default=True): cv.boolean, vol.Optional(CONF_DEVICES, default={}): { cv.string: vol.Schema({ vol.Optional(CONF_NAME): cv.string, vol.Optional(CONF_TYPE): vol.Any(TYPE_DIMMABLE, TYPE_SWITCHABLE, TYPE_HYBRID, TYPE_TOGGLE), vol.Optional(CONF_ALIASES, default=[]): vol.All(cv.ensure_list, [cv.string]), vol.Optional(CONF_GROUP_ALIASES, default=[]): vol.All(cv.ensure_list, [cv.string]), vol.Optional(CONF_NOGROUP_ALIASES, default=[]): vol.All(cv.ensure_list, [cv.string]), vol.Optional(CONF_FIRE_EVENT): cv.boolean, vol.Optional(CONF_SIGNAL_REPETITIONS): vol.Coerce(int), vol.Optional(CONF_GROUP, default=True): cv.boolean, }) }, }, extra=vol.ALLOW_EXTRA, )
SUPPORT_EFFECT, LightEntity, ) from openpeerpower.const import CONF_HOSTS from openpeerpower.exceptions import PlatformNotReady from openpeerpower.helpers.aiohttp_client import async_get_clientsession import openpeerpower.helpers.config_validation as cv import openpeerpower.util.color as color_util _LOGGER = logging.getLogger(__name__) SUPPORT_EVERLIGHTS = SUPPORT_EFFECT | SUPPORT_BRIGHTNESS | SUPPORT_COLOR SCAN_INTERVAL = timedelta(minutes=1) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( {vol.Required(CONF_HOSTS): vol.All(cv.ensure_list, [cv.string])}) def color_rgb_to_int(red: int, green: int, blue: int) -> int: """Return a RGB color as an integer.""" return red * 256 * 256 + green * 256 + blue def color_int_to_rgb(value: int) -> tuple[int, int, int]: """Return an RGB tuple from an integer.""" return (value >> 16, (value >> 8) & 0xFF, value & 0xFF) async def async_setup_platform(opp, config, async_add_entities,
STATE_ON, STATE_UNAVAILABLE, ) from openpeerpower.core import OpenPeerPower, State, callback import openpeerpower.helpers.config_validation as cv from openpeerpower.helpers.entity_platform import AddEntitiesCallback from openpeerpower.helpers.event import async_track_state_change_event from openpeerpower.helpers.typing import ConfigType, DiscoveryInfoType # mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs DEFAULT_NAME = "Light Switch" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Required(CONF_ENTITY_ID): cv.entity_domain(switch.DOMAIN), }) async def async_setup_platform( opp: OpenPeerPower, config: ConfigType, async_add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Initialize Light Switch platform.""" registry = await opp.helpers.entity_registry.async_get_registry() wrapped_switch = registry.async_get(config[CONF_ENTITY_ID]) unique_id = wrapped_switch.unique_id if wrapped_switch else None
) from openpeerpower.const import CONF_ADDRESS, CONF_DEVICES, CONF_NAME, CONF_PLATFORM from openpeerpower.helpers import config_validation as cv from . import CONF_COMM_TYPE, DOMAIN, REQ_LOCK _LOGGER = logging.getLogger(__name__) CONF_BRIGHTNESS_LEVELS = "brightness_levels" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_PLATFORM): DOMAIN, CONF_DEVICES: [{ vol.Optional(CONF_NAME): cv.string, vol.Required(CONF_ADDRESS): cv.x10_address, vol.Optional(CONF_COMM_TYPE): cv.string, vol.Optional(CONF_BRIGHTNESS_LEVELS, default=32): vol.All(vol.Coerce(int), vol.In([32, 64, 256])), }], }) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up X10 dimmers over a mochad controller.""" mochad_controller = opp.data[DOMAIN] devs = config.get(CONF_DEVICES) add_entities( [MochadLight(opp, mochad_controller.ctrl, dev) for dev in devs]) return True
import openpeerpower.helpers.config_validation as cv SUPPORT_AVION_LED = SUPPORT_BRIGHTNESS DEVICE_SCHEMA = vol.Schema( { vol.Required(CONF_API_KEY): cv.string, vol.Optional(CONF_ID): cv.positive_int, vol.Optional(CONF_NAME): cv.string, } ) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Optional(CONF_DEVICES, default={}): {cv.string: DEVICE_SCHEMA}, vol.Optional(CONF_USERNAME): cv.string, vol.Optional(CONF_PASSWORD): cv.string, } ) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up an Avion switch.""" avion = importlib.import_module("avion") lights = [] if CONF_USERNAME in config and CONF_PASSWORD in config: devices = avion.get_devices(config[CONF_USERNAME], config[CONF_PASSWORD]) for device in devices: lights.append(AvionLight(device))
PLATFORM_SCHEMA, SUPPORT_BRIGHTNESS, LightEntity, ) from openpeerpower.const import CONF_DEVICES, CONF_ID, CONF_NAME import openpeerpower.helpers.config_validation as cv _LOGGER = logging.getLogger(__name__) SUPPORT_X10 = SUPPORT_BRIGHTNESS PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_DEVICES): vol.All( cv.ensure_list, [{ vol.Required(CONF_ID): cv.string, vol.Required(CONF_NAME): cv.string }], ) }) def x10_command(command): """Execute X10 command and check output.""" return check_output(["heyu"] + command.split(" "), stderr=STDOUT) def get_unit_status(code): """Get on/off status for given unit.""" output = check_output(["heyu", "onstate", code]) return int(output.decode("utf-8")[0])
"""Support for SCSGate lights.""" import logging from scsgate.tasks import ToggleStatusTask import voluptuous as vol from openpeerpower.components.light import PLATFORM_SCHEMA, LightEntity from openpeerpower.const import ATTR_ENTITY_ID, ATTR_STATE, CONF_DEVICES, CONF_NAME import openpeerpower.helpers.config_validation as cv from . import CONF_SCS_ID, DOMAIN, SCSGATE_SCHEMA PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( {vol.Required(CONF_DEVICES): cv.schema_with_slug_keys(SCSGATE_SCHEMA)} ) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the SCSGate switches.""" devices = config.get(CONF_DEVICES) lights = [] logger = logging.getLogger(__name__) scsgate = opp.data[DOMAIN] if devices: for entity_info in devices.values(): if entity_info[CONF_SCS_ID] in scsgate.devices: continue name = entity_info[CONF_NAME] scs_id = entity_info[CONF_SCS_ID]
import openpeerpower.helpers.config_validation as cv from . import ( CONF_ADS_VAR, CONF_ADS_VAR_BRIGHTNESS, DATA_ADS, STATE_KEY_BRIGHTNESS, STATE_KEY_STATE, AdsEntity, ) DEFAULT_NAME = "ADS Light" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_ADS_VAR): cv.string, vol.Optional(CONF_ADS_VAR_BRIGHTNESS): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, }) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the light platform for ADS.""" ads_hub = opp.data.get(DATA_ADS) ads_var_enable = config[CONF_ADS_VAR] ads_var_brightness = config.get(CONF_ADS_VAR_BRIGHTNESS) name = config[CONF_NAME] add_entities([AdsLight(ads_hub, ads_var_enable, ads_var_brightness, name)])
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_BRIDGES): vol.All( cv.ensure_list, [ { vol.Required(CONF_HOST): cv.string, vol.Optional( CONF_VERSION, default=DEFAULT_VERSION ): cv.positive_int, vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, vol.Required(CONF_GROUPS): vol.All( cv.ensure_list, [ { vol.Required(CONF_NAME): cv.string, vol.Optional( CONF_TYPE, default=DEFAULT_LED_TYPE ): vol.In(LED_TYPE), vol.Required(CONF_NUMBER): cv.positive_int, vol.Optional( CONF_FADE, default=DEFAULT_FADE ): cv.boolean, } ], ), } ], ) } )
CONF_DRIVER = "driver" CONF_DRIVER_FNIP6X10AD = "FNIP6x10ad" CONF_DRIVER_FNIP8X10A = "FNIP8x10a" CONF_DRIVER_TYPES = [CONF_DRIVER_FNIP6X10AD, CONF_DRIVER_FNIP8X10A] DEVICE_SCHEMA = vol.Schema({ vol.Required(CONF_NAME): cv.string, vol.Optional("dimmable", default=False): cv.boolean, }) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_DRIVER): vol.In(CONF_DRIVER_TYPES), vol.Required(CONF_HOST): cv.string, vol.Required(CONF_PORT): cv.port, vol.Required(CONF_DEVICES): { cv.string: DEVICE_SCHEMA }, }) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the light platform for each FutureNow unit.""" lights = [] for channel, device_config in config[CONF_DEVICES].items(): device = {} device["name"] = device_config[CONF_NAME] device["dimmable"] = device_config["dimmable"] device["channel"] = channel
DEVICE_SCHEMA = vol.Schema({ vol.Optional(CONF_NAME): cv.string, vol.Optional(ATTR_MODE, default=MODE_RGBW): vol.All(cv.string, vol.In([MODE_RGBW, MODE_RGB, MODE_WHITE])), vol.Optional(CONF_PROTOCOL): vol.All(cv.string, vol.In(["ledenet"])), vol.Optional(CONF_CUSTOM_EFFECT): CUSTOM_EFFECT_SCHEMA, }) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_DEVICES, default={}): { cv.string: DEVICE_SCHEMA }, vol.Optional(CONF_AUTOMATIC_ADD, default=False): cv.boolean, }) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the Flux lights.""" lights = [] light_ips = [] for ipaddr, device_config in config.get(CONF_DEVICES, {}).items(): device = {} device["name"] = device_config[CONF_NAME] device["ipaddr"] = ipaddr device[CONF_PROTOCOL] = device_config.get(CONF_PROTOCOL)
from openpeerpower.core import CALLBACK_TYPE, State, callback import openpeerpower.helpers.config_validation as cv from openpeerpower.helpers.event import async_track_state_change from openpeerpower.helpers.typing import ConfigType, OpenPeerPowerType from openpeerpower.util import color as color_util # mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs # mypy: no-check-untyped-defs _LOGGER = logging.getLogger(__name__) DEFAULT_NAME = "Light Group" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Required(CONF_ENTITIES): cv.entities_domain(light.DOMAIN), } ) SUPPORT_GROUP_LIGHT = ( SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_EFFECT | SUPPORT_FLASH | SUPPORT_COLOR | SUPPORT_TRANSITION | SUPPORT_WHITE_VALUE ) async def async_setup_platform(
ATTR_BRIGHTNESS, ATTR_HS_COLOR, PLATFORM_SCHEMA, SUPPORT_BRIGHTNESS, SUPPORT_COLOR, LightEntity, ) from openpeerpower.const import CONF_HOST import openpeerpower.helpers.config_validation as cv import openpeerpower.util.color as color_util _LOGGER = logging.getLogger(__name__) SUPPORT_YEELIGHT_SUNFLOWER = SUPPORT_BRIGHTNESS | SUPPORT_COLOR PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({vol.Required(CONF_HOST): cv.string}) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the Yeelight Sunflower Light platform.""" host = config.get(CONF_HOST) hub = yeelightsunflower.Hub(host) if not hub.available: _LOGGER.error("Could not connect to Yeelight Sunflower hub") return False add_entities(SunflowerBulb(light) for light in hub.get_lights()) class SunflowerBulb(LightEntity):
LightEntity, ) from openpeerpower.const import CONF_LIGHTS import openpeerpower.helpers.config_validation as cv from .base_class import SWITCHES_SCHEMA, PilightBaseDevice from .const import CONF_DIMLEVEL_MAX, CONF_DIMLEVEL_MIN LIGHTS_SCHEMA = SWITCHES_SCHEMA.extend({ vol.Optional(CONF_DIMLEVEL_MIN, default=0): cv.positive_int, vol.Optional(CONF_DIMLEVEL_MAX, default=15): cv.positive_int, }) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( {vol.Required(CONF_LIGHTS): vol.Schema({cv.string: LIGHTS_SCHEMA})}) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the Pilight platform.""" switches = config.get(CONF_LIGHTS) devices = [] for dev_name, dev_config in switches.items(): devices.append(PilightLight(opp, dev_name, dev_config)) add_entities(devices) class PilightLight(PilightBaseDevice, LightEntity): """Representation of a Pilight switch."""
DEFAULT_ALLOW_LIGHTIFY_SWITCHES = True DEFAULT_INTERVAL_LIGHTIFY_STATUS = 5 DEFAULT_INTERVAL_LIGHTIFY_CONF = 3600 PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_HOST): cv.string, vol.Optional( CONF_ALLOW_LIGHTIFY_NODES, default=DEFAULT_ALLOW_LIGHTIFY_NODES ): cv.boolean, vol.Optional( CONF_ALLOW_LIGHTIFY_GROUPS, default=DEFAULT_ALLOW_LIGHTIFY_GROUPS ): cv.boolean, vol.Optional( CONF_ALLOW_LIGHTIFY_SENSORS, default=DEFAULT_ALLOW_LIGHTIFY_SENSORS ): cv.boolean, vol.Optional( CONF_ALLOW_LIGHTIFY_SWITCHES, default=DEFAULT_ALLOW_LIGHTIFY_SWITCHES ): cv.boolean, vol.Optional( CONF_INTERVAL_LIGHTIFY_STATUS, default=DEFAULT_INTERVAL_LIGHTIFY_STATUS ): cv.positive_int, vol.Optional( CONF_INTERVAL_LIGHTIFY_CONF, default=DEFAULT_INTERVAL_LIGHTIFY_CONF ): cv.positive_int, } ) DEFAULT_BRIGHTNESS = 2 DEFAULT_KELVIN = 2700
from openpeerpower.components.light import ( ATTR_BRIGHTNESS, ATTR_TRANSITION, PLATFORM_SCHEMA, SUPPORT_BRIGHTNESS, SUPPORT_TRANSITION, LightEntity, ) from openpeerpower.const import CONF_PASSWORD, CONF_USERNAME, EVENT_OPENPEERPOWER_STOP import openpeerpower.helpers.config_validation as cv _LOGGER = logging.getLogger(__name__) # Validation of the user's configuration PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_USERNAME): cv.string, vol.Required(CONF_PASSWORD): cv.string }) NOTIFICATION_ID = "leviton_notification" NOTIFICATION_TITLE = "myLeviton Decora Setup" def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the Decora WiFi platform.""" email = config[CONF_USERNAME] password = config[CONF_PASSWORD] session = DecoraWiFiSession() try: success = session.login(email, password)
DATA_NANOLEAF = "nanoleaf" CONFIG_FILE = ".nanoleaf.conf" ICON = "mdi:triangle-outline" SUPPORT_NANOLEAF = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_EFFECT | SUPPORT_COLOR | SUPPORT_TRANSITION) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_HOST): cv.string, vol.Required(CONF_TOKEN): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, }) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the Nanoleaf light.""" if DATA_NANOLEAF not in opp.data: opp.data[DATA_NANOLEAF] = {} token = "" if discovery_info is not None: host = discovery_info["host"] name = None
SERVICE_SET_DELAYED_TURN_OFF, SERVICE_SET_SCENE, ) from .device import XiaomiMiioEntity from .gateway import XiaomiGatewayDevice _LOGGER = logging.getLogger(__name__) DEFAULT_NAME = "Xiaomi Philips Light" DATA_KEY = "light.xiaomi_miio" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_HOST): cv.string, vol.Required(CONF_TOKEN): vol.All(cv.string, vol.Length(min=32, max=32)), vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_MODEL): vol.In(MODELS_LIGHT), }) # The light does not accept cct values < 1 CCT_MIN = 1 CCT_MAX = 100 DELAYED_TURN_OFF_MAX_DEVIATION_SECONDS = 4 DELAYED_TURN_OFF_MAX_DEVIATION_MINUTES = 1 SUCCESS = ["ok"] ATTR_SCENE = "scene" ATTR_DELAYED_TURN_OFF = "delayed_turn_off"
LightEntity, ) from openpeerpower.const import CONF_DEVICES, CONF_NAME, CONF_PASSWORD import openpeerpower.helpers.config_validation as cv import openpeerpower.util.color as color_util _LOGGER = logging.getLogger(__name__) SUPPORT_TIKTECK_LED = SUPPORT_BRIGHTNESS | SUPPORT_COLOR DEVICE_SCHEMA = vol.Schema( {vol.Optional(CONF_NAME): cv.string, vol.Required(CONF_PASSWORD): cv.string} ) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( {vol.Optional(CONF_DEVICES, default={}): {cv.string: DEVICE_SCHEMA}} ) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the Tikteck platform.""" lights = [] for address, device_config in config[CONF_DEVICES].items(): device = {} device["name"] = device_config[CONF_NAME] device["password"] = device_config[CONF_PASSWORD] device["address"] = address light = TikteckLight(device) if light.is_valid: lights.append(light)
LightEntity, ) from openpeerpower.const import CONF_ID, CONF_NAME import openpeerpower.helpers.config_validation as cv from .device import EnOceanEntity CONF_SENDER_ID = "sender_id" DEFAULT_NAME = "EnOcean Light" SUPPORT_ENOCEAN = SUPPORT_BRIGHTNESS PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_ID, default=[]): vol.All(cv.ensure_list, [vol.Coerce(int)]), vol.Required(CONF_SENDER_ID): vol.All(cv.ensure_list, [vol.Coerce(int)]), vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, }) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the EnOcean light platform.""" sender_id = config.get(CONF_SENDER_ID) dev_name = config.get(CONF_NAME) dev_id = config.get(CONF_ID) add_entities([EnOceanLight(sender_id, dev_id, dev_name)]) class EnOceanLight(EnOceanEntity, LightEntity):