import switchmate import voluptuous as vol from openpeerpower.components.switch import PLATFORM_SCHEMA, SwitchEntity from openpeerpower.const import CONF_MAC, CONF_NAME import openpeerpower.helpers.config_validation as cv CONF_FLIP_ON_OFF = "flip_on_off" DEFAULT_NAME = "Switchmate" SCAN_INTERVAL = timedelta(minutes=30) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_MAC): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_FLIP_ON_OFF, default=False): cv.boolean, }) def setup_platform(opp, config, add_entities, discovery_info=None) -> None: """Perform the setup for Switchmate devices.""" name = config.get(CONF_NAME) mac_addr = config[CONF_MAC] flip_on_off = config[CONF_FLIP_ON_OFF] add_entities([SwitchmateEntity(mac_addr, name, flip_on_off)], True) class SwitchmateEntity(SwitchEntity): """Representation of a Switchmate."""
CONF_I2CADDR = "i2c_address" CONF_BITS = "bits" DEFAULT_INVERT_LOGIC = False DEFAULT_BITS = 24 DEFAULT_BUS = 1 DEFAULT_ADDR = 0x20 _SWITCHES_SCHEMA = vol.Schema({cv.positive_int: cv.string}) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_PINS): _SWITCHES_SCHEMA, vol.Optional(CONF_I2CBUS, default=DEFAULT_BUS): cv.positive_int, vol.Optional(CONF_I2CADDR, default=DEFAULT_ADDR): cv.positive_int, vol.Optional(CONF_BITS, default=DEFAULT_BITS): cv.positive_int, vol.Optional(CONF_INVERT_LOGIC, default=DEFAULT_INVERT_LOGIC): cv.boolean, }) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the swiches devices.""" pins = config.get(CONF_PINS) switches = [] pi4ioe5v9xxxx.setup( i2c_bus=config[CONF_I2CBUS], i2c_addr=config[CONF_I2CADDR],
ATTR_MEMORY, ATTR_OS, ATTR_REGION, ATTR_SUBSCRIPTION_ID, ATTR_SUBSCRIPTION_NAME, ATTR_VCPUS, CONF_SUBSCRIPTION, DATA_VULTR, ) _LOGGER = logging.getLogger(__name__) DEFAULT_NAME = "Vultr {}" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_SUBSCRIPTION): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, }) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the Vultr subscription switch.""" vultr = opp.data[DATA_VULTR] subscription = config.get(CONF_SUBSCRIPTION) name = config.get(CONF_NAME) if subscription not in vultr.data: _LOGGER.error("Subscription %s not found", subscription) return False
ALLOWED_WATERING_TIME, ATTRIBUTION, CONF_WATERING_TIME, DATA_RAINCLOUD, DEFAULT_WATERING_TIME, SWITCHES, RainCloudEntity, ) _LOGGER = logging.getLogger(__name__) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Optional(CONF_MONITORED_CONDITIONS, default=list(SWITCHES)): vol.All( cv.ensure_list, [vol.In(SWITCHES)] ), vol.Optional(CONF_WATERING_TIME, default=DEFAULT_WATERING_TIME): vol.All( vol.In(ALLOWED_WATERING_TIME) ), } ) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up a sensor for a raincloud device.""" raincloud = opp.data[DATA_RAINCLOUD].data default_watering_timer = config.get(CONF_WATERING_TIME) sensors = [] for sensor_type in config.get(CONF_MONITORED_CONDITIONS): # create a sensor for each zone managed by faucet for zone in raincloud.controller.faucet.zones:
vol.Optional(CONF_COMMAND_OFF): data_packet, vol.Optional(CONF_COMMAND_ON): data_packet, vol.Optional(CONF_FRIENDLY_NAME): cv.string, }) PLATFORM_SCHEMA = vol.All( cv.deprecated(CONF_HOST), cv.deprecated(CONF_SLOTS), cv.deprecated(CONF_TIMEOUT), cv.deprecated(CONF_TYPE), PLATFORM_SCHEMA.extend({ vol.Required(CONF_MAC): mac_address, vol.Optional(CONF_HOST): cv.string, vol.Optional(CONF_SWITCHES, default=[]): vol.Any( cv.schema_with_slug_keys(OLD_SWITCH_SCHEMA), vol.All(cv.ensure_list, [SWITCH_SCHEMA]), ), }), ) async def async_setup_platform(opp, config, async_add_entities, discovery_info=None): """Import the device and set up custom switches. This is for backward compatibility.
"""Support for ADS switch platform.""" import voluptuous as vol from openpeerpower.components.switch import PLATFORM_SCHEMA, SwitchEntity from openpeerpower.const import CONF_NAME import openpeerpower.helpers.config_validation as cv from . import CONF_ADS_VAR, DATA_ADS, STATE_KEY_STATE, AdsEntity DEFAULT_NAME = "ADS Switch" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_ADS_VAR): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, }) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up switch platform for ADS.""" ads_hub = opp.data.get(DATA_ADS) name = config[CONF_NAME] ads_var = config[CONF_ADS_VAR] add_entities([AdsSwitch(ads_hub, name, ads_var)]) class AdsSwitch(AdsEntity, SwitchEntity): """Representation of an ADS switch device."""
SWITCH_SCHEMA = vol.Schema( { vol.Required(CONF_CODE_OFF): vol.All(cv.ensure_list_csv, [cv.positive_int]), vol.Required(CONF_CODE_ON): vol.All(cv.ensure_list_csv, [cv.positive_int]), vol.Optional(CONF_PULSELENGTH): cv.positive_int, vol.Optional( CONF_SIGNAL_REPETITIONS, default=DEFAULT_SIGNAL_REPETITIONS ): cv.positive_int, vol.Optional(CONF_PROTOCOL, default=DEFAULT_PROTOCOL): cv.positive_int, } ) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_GPIO): cv.positive_int, vol.Required(CONF_SWITCHES): vol.Schema({cv.string: SWITCH_SCHEMA}), } ) def setup_platform(opp, config, add_entities, discovery_info=None): """Find and return switches controlled by a generic RF device via GPIO.""" rpi_rf = importlib.import_module("rpi_rf") gpio = config.get(CONF_GPIO) rfdevice = rpi_rf.RFDevice(gpio) rfdevice_lock = RLock() switches = config.get(CONF_SWITCHES) devices = [] for dev_name, properties in switches.items():
_LOGGER = logging.getLogger(__name__) CONF_AUTH_KEY = "auth_key" CONF_COMMUNITY = "community" CONF_PRIV_KEY = "priv_key" DEFAULT_COMMUNITY = "private" DEFAULT_PORT = "161" DEFAULT_USERNAME = "******" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_HOST): cv.string, vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, vol.Optional(CONF_COMMUNITY, default=DEFAULT_COMMUNITY): cv.string, vol.Optional(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string, vol.Optional(CONF_AUTH_KEY): cv.string, vol.Optional(CONF_PRIV_KEY): cv.string, }) async def async_setup_platform(opp, config, async_add_entities, discovery_info=None): """Set up the ATEN PE switch.""" node = config[CONF_HOST] serv = config[CONF_PORT]
from openpeerpower.helpers.entity import ToggleEntity CONF_PINS = "pins" CONF_INITIAL = "initial" CONF_INVERT_LOGIC = "invert_logic" PIN_SCHEMA = vol.Schema( { vol.Required(CONF_NAME): cv.string, vol.Optional(CONF_INITIAL, default=False): cv.boolean, vol.Optional(CONF_INVERT_LOGIC, default=False): cv.boolean, } ) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( {vol.Required(CONF_PINS, default={}): vol.Schema({cv.string: PIN_SCHEMA})} ) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the BeagleBone Black GPIO devices.""" pins = config[CONF_PINS] switches = [] for pin, params in pins.items(): switches.append(BBBGPIOSwitch(pin, params)) add_entities(switches) class BBBGPIOSwitch(ToggleEntity): """Representation of a BeagleBone Black GPIO."""
"""Support for switching devices via Pilight to on and off.""" import voluptuous as vol from openpeerpower.components.switch import PLATFORM_SCHEMA, SwitchEntity from openpeerpower.const import CONF_SWITCHES import openpeerpower.helpers.config_validation as cv from .base_class import SWITCHES_SCHEMA, PilightBaseDevice PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( {vol.Required(CONF_SWITCHES): vol.Schema({cv.string: SWITCHES_SCHEMA})} ) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the Pilight platform.""" switches = config.get(CONF_SWITCHES) devices = [] for dev_name, dev_config in switches.items(): devices.append(PilightSwitch(opp, dev_name, dev_config)) add_entities(devices) class PilightSwitch(PilightBaseDevice, SwitchEntity): """Representation of a Pilight switch."""
import logging import voluptuous as vol from zoneminder.monitor import MonitorState from openpeerpower.components.switch import PLATFORM_SCHEMA, SwitchEntity from openpeerpower.const import CONF_COMMAND_OFF, CONF_COMMAND_ON import openpeerpower.helpers.config_validation as cv from . import DOMAIN as ZONEMINDER_DOMAIN _LOGGER = logging.getLogger(__name__) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_COMMAND_ON): cv.string, vol.Required(CONF_COMMAND_OFF): cv.string, }) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the ZoneMinder switch platform.""" on_state = MonitorState(config.get(CONF_COMMAND_ON)) off_state = MonitorState(config.get(CONF_COMMAND_OFF)) switches = [] for zm_client in opp.data[ZONEMINDER_DOMAIN].values(): monitors = zm_client.get_monitors() if not monitors: _LOGGER.warning("Could not fetch monitors from ZoneMinder")
ATTR_INVERT_LOGIC = "invert_logic" CONF_PORTS = "ports" DEFAULT_INVERT_LOGIC = False PORT_SCHEMA = vol.Schema({ vol.Optional(ATTR_NAME): cv.string, vol.Optional(ATTR_INVERT_LOGIC, default=DEFAULT_INVERT_LOGIC): cv.boolean, }) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_PORTS, default={}): vol.Schema({cv.positive_int: PORT_SCHEMA}) }) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the PiFace Digital Output devices.""" switches = [] ports = config.get(CONF_PORTS) for port, port_entity in ports.items(): name = port_entity.get(ATTR_NAME) invert_logic = port_entity[ATTR_INVERT_LOGIC] switches.append(RPiPFIOSwitch(port, name, invert_logic)) add_entities(switches)
import openpeerpower.helpers.config_validation as cv from openpeerpower.helpers.entity import ToggleEntity MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10) MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(milliseconds=100) MIN_TIME_TO_WAIT = timedelta(seconds=5) MIN_TIME_TO_LOCK_UPDATE = 5 SWITCH_TYPES = { "clean": ["Clean", None, None], "dock": ["Dock", None, None], "find": ["Find", None, None], } PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({vol.Optional(CONF_HOST): cv.string}) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the ThinkingCleaner platform.""" host = config.get(CONF_HOST) if host: devices = [ThinkingCleaner(host, "unknown")] else: discovery = Discovery() devices = discovery.discover() @util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS) def update_devices(): """Update all devices.""" for device_object in devices:
CONF_SWITCHES, ) import openpeerpower.helpers.config_validation as cv _LOGGER = logging.getLogger(__name__) DEFAULT_NAME = "Orvibo S20 Switch" DEFAULT_DISCOVERY = True PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_SWITCHES, default=[]): vol.All( cv.ensure_list, [{ vol.Required(CONF_HOST): cv.string, vol.Optional(CONF_MAC): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, }], ), vol.Optional(CONF_DISCOVERY, default=DEFAULT_DISCOVERY): cv.boolean, }) def setup_platform(opp, config, add_entities_callback, discovery_info=None): """Set up S20 switches.""" switch_data = {} switches = [] switch_conf = config.get(CONF_SWITCHES, [config])
from openpeerpower.helpers.script import Script _LOGGER = logging.getLogger(__name__) CONF_OFF_ACTION = "turn_off" DEFAULT_NAME = "Wake on LAN" DEFAULT_PING_TIMEOUT = 1 PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_MAC): cv.string, vol.Optional(CONF_BROADCAST_ADDRESS): cv.string, vol.Optional(CONF_BROADCAST_PORT): cv.port, vol.Optional(CONF_HOST): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_OFF_ACTION): cv.SCRIPT_SCHEMA, }) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up a wake on lan switch.""" broadcast_address = config.get(CONF_BROADCAST_ADDRESS) broadcast_port = config.get(CONF_BROADCAST_PORT) host = config.get(CONF_HOST) mac_address = config[CONF_MAC] name = config[CONF_NAME]
cv.positive_int, vol.Required(CONF_NAME): cv.string, vol.Optional(CONF_INVERT_LOGIC, default=False): cv.boolean, vol.Optional(CONF_INITIAL_STATE): cv.boolean, }]) _I2C_HATS_SCHEMA = vol.Schema([{ vol.Required(CONF_BOARD): vol.In(I2C_HAT_NAMES), vol.Required(CONF_ADDRESS): vol.Coerce(int), vol.Required(CONF_CHANNELS): _CHANNELS_SCHEMA, }]) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( {vol.Optional(CONF_I2C_HATS): _I2C_HATS_SCHEMA}) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the raspihats switch devices.""" I2CHatSwitch.I2C_HATS_MANAGER = opp.data[I2C_HATS_MANAGER] switches = [] i2c_hat_configs = config.get(CONF_I2C_HATS) for i2c_hat_config in i2c_hat_configs: board = i2c_hat_config[CONF_BOARD] address = i2c_hat_config[CONF_ADDRESS] try: I2CHatSwitch.I2C_HATS_MANAGER.register_board(board, address) for channel_config in i2c_hat_config[CONF_CHANNELS]: switches.append( I2CHatSwitch(
) from openpeerpower.exceptions import PlatformNotReady import openpeerpower.helpers.config_validation as cv from openpeerpower.helpers.entity import ToggleEntity _LOGGER = logging.getLogger(__name__) DEFAULT_NAME = "Deluge Switch" DEFAULT_PORT = 58846 PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_HOST): cv.string, vol.Required(CONF_PASSWORD): cv.string, vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, vol.Required(CONF_USERNAME): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, }) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the Deluge switch.""" name = config[CONF_NAME] host = config[CONF_HOST] username = config[CONF_USERNAME] password = config[CONF_PASSWORD] port = config[CONF_PORT]
from scsgate.messages import ScenarioTriggeredMessage, StateMessage from scsgate.tasks import ToggleStatusTask import voluptuous as vol from openpeerpower.components.switch import PLATFORM_SCHEMA, SwitchEntity 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 ATTR_SCENARIO_ID = "scenario_id" CONF_TRADITIONAL = "traditional" CONF_SCENARIO = "scenario" 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.""" logger = logging.getLogger(__name__) scsgate = opp.data[DOMAIN] _setup_traditional_switches( logger=logger, config=config, scsgate=scsgate, add_entities_callback=add_entities, ) _setup_scenario_switches(logger=logger,
ARM_HUMIDITY = "humidity" ARM_MOTION = "motion" ARM_LIGHT = "light" ARM_MOISTURE = "moisture" # Switch types: Name, tag sensor type SWITCH_TYPES = { ARM_TEMPERATURE: ["Arm Temperature", "temperature"], ARM_HUMIDITY: ["Arm Humidity", "humidity"], ARM_MOTION: ["Arm Motion", "motion"], ARM_LIGHT: ["Arm Light", "light"], ARM_MOISTURE: ["Arm Moisture", "moisture"], } PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_MONITORED_CONDITIONS, default=[]): vol.All(cv.ensure_list, [vol.In(SWITCH_TYPES)]) }) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up switches for a Wireless Sensor Tags.""" platform = opp.data.get(WIRELESSTAG_DOMAIN) switches = [] tags = platform.load_tags() for switch_type in config.get(CONF_MONITORED_CONDITIONS): for tag in tags.values(): if switch_type in tag.allowed_monitoring_types: switches.append(WirelessTagSwitch(platform, tag, switch_type)) add_entities(switches, True)
from openpeerpower.components.switch import PLATFORM_SCHEMA, SwitchEntity from openpeerpower.const import CONF_HOST, DEVICE_DEFAULT_NAME import openpeerpower.helpers.config_validation as cv from . import CONF_INVERT_LOGIC, DEFAULT_INVERT_LOGIC from .. import remote_rpi_gpio CONF_PORTS = "ports" _SENSORS_SCHEMA = vol.Schema({cv.positive_int: cv.string}) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_HOST): cv.string, vol.Required(CONF_PORTS): _SENSORS_SCHEMA, vol.Optional(CONF_INVERT_LOGIC, default=DEFAULT_INVERT_LOGIC): cv.boolean, }) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the Remote Raspberry PI GPIO devices.""" address = config[CONF_HOST] invert_logic = config[CONF_INVERT_LOGIC] ports = config[CONF_PORTS] devices = [] for port, name in ports.items(): try: led = remote_rpi_gpio.setup_output(address, port, invert_logic)
from openpeerpower.helpers.entity import ToggleEntity from openpeerpower.helpers.reload import setup_reload_service from . import DOMAIN, PLATFORMS CONF_PULL_MODE = "pull_mode" CONF_PORTS = "ports" CONF_INVERT_LOGIC = "invert_logic" DEFAULT_INVERT_LOGIC = False _SWITCHES_SCHEMA = vol.Schema({cv.positive_int: cv.string}) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_PORTS): _SWITCHES_SCHEMA, vol.Optional(CONF_INVERT_LOGIC, default=DEFAULT_INVERT_LOGIC): cv.boolean, } ) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the Raspberry PI GPIO devices.""" setup_reload_service(opp, DOMAIN, PLATFORMS) invert_logic = config.get(CONF_INVERT_LOGIC) switches = [] ports = config.get(CONF_PORTS) for port, name in ports.items(): switches.append(RPiGPIOSwitch(name, port, invert_logic)) add_entities(switches)
SWITCH_TYPES = { "lights": "Lights", "filter": "Filter", "filter_low_speed": "Filter Low Speed", "aux_1": "Aux 1", "aux_2": "Aux 2", "aux_3": "Aux 3", "aux_4": "Aux 4", "aux_5": "Aux 5", "aux_6": "Aux 6", "aux_7": "Aux 7", } PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_MONITORED_CONDITIONS, default=list(SWITCH_TYPES)): vol.All(cv.ensure_list, [vol.In(SWITCH_TYPES)]) }) async def async_setup_platform(opp, config, async_add_entities, discovery_info=None): """Set up the switch platform.""" switches = [] processor = opp.data[DOMAIN] for switch_type in config[CONF_MONITORED_CONDITIONS]: switches.append(AquaLogicSwitch(processor, switch_type)) async_add_entities(switches)
CONF_VERIFY_SSL, ) import openpeerpower.helpers.config_validation as cv _LOGGER = logging.getLogger(__name__) DEFAULT_SSL = True DEFAULT_VERIFY_SSL = True SWITCH_MODELS = ["Outlet", "Output 5v", "Output 12v", "Output 24v", "Dimmer Switch"] PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_HOST): cv.string, vol.Required(CONF_USERNAME): cv.string, vol.Required(CONF_PASSWORD): cv.string, vol.Optional(CONF_PORT): cv.port, vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean, vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): cv.boolean, } ) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up mFi sensors.""" host = config.get(CONF_HOST) username = config.get(CONF_USERNAME) password = config.get(CONF_PASSWORD) use_tls = config[CONF_SSL] verify_tls = config.get(CONF_VERIFY_SSL) default_port = 6443 if use_tls else 6080 port = int(config.get(CONF_PORT, default_port))
STRENGTH_075 = "0.75" STRENGTH_100 = "1.0" DEFAULT_INVERT_LOGIC = False DEFAULT_I2C_ADDRESS = 0x20 DEFAULT_I2C_BUS = 1 DEFAULT_STRENGTH = STRENGTH_100 _SWITCHES_SCHEMA = vol.Schema({cv.positive_int: cv.string}) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_PINS): _SWITCHES_SCHEMA, vol.Optional(CONF_INVERT_LOGIC, default=DEFAULT_INVERT_LOGIC): cv.boolean, vol.Optional(CONF_STRENGTH, default=DEFAULT_STRENGTH): vol.In([STRENGTH_025, STRENGTH_050, STRENGTH_075, STRENGTH_100]), vol.Optional(CONF_I2C_ADDRESS, default=DEFAULT_I2C_ADDRESS): vol.Coerce(int), vol.Optional(CONF_I2C_BUS, default=DEFAULT_I2C_BUS): cv.positive_int, }) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the PCAL9535A devices.""" invert_logic = config[CONF_INVERT_LOGIC] i2c_address = config[CONF_I2C_ADDRESS] bus = config[CONF_I2C_BUS] pcal = PCAL9535A(bus, i2c_address)
_LOGGER = logging.getLogger(__name__) DEFAULT_PORT = 80 DEFAULT_PATH = "/cgi-bin/json.cgi" SWITCH_SCHEMA = vol.Schema({ vol.Required(CONF_HOST): cv.string, vol.Optional(CONF_NAME): cv.string, vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, vol.Optional(CONF_PATH, default=DEFAULT_PATH): cv.string, vol.Optional(CONF_USERNAME): cv.string, vol.Optional(CONF_PASSWORD): cv.string, }) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( {vol.Required(CONF_SWITCHES): cv.schema_with_slug_keys(SWITCH_SCHEMA)}) def setup_platform(opp, config, add_entities_callback, discovery_info=None): """Set up Kankun Wifi switches.""" switches = config.get("switches", {}) devices = [] for dev_name, properties in switches.items(): devices.append( KankunSwitch( opp, properties.get(CONF_NAME, dev_name), properties.get(CONF_HOST), properties.get(CONF_PORT, DEFAULT_PORT), properties.get(CONF_PATH, DEFAULT_PATH),
import voluptuous as vol from openpeerpower.components.switch import PLATFORM_SCHEMA from openpeerpower.const import CONF_ID, CONF_NAME import openpeerpower.helpers.config_validation as cv from openpeerpower.helpers.entity import ToggleEntity from .device import EnOceanEntity CONF_CHANNEL = "channel" DEFAULT_NAME = "EnOcean Switch" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_ID): vol.All(cv.ensure_list, [vol.Coerce(int)]), vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_CHANNEL, default=0): cv.positive_int, }) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the EnOcean switch platform.""" channel = config.get(CONF_CHANNEL) dev_id = config.get(CONF_ID) dev_name = config.get(CONF_NAME) add_entities([EnOceanSwitch(dev_id, dev_name, channel)]) class EnOceanSwitch(EnOceanEntity, ToggleEntity):
# pylint: disable=import-error import switchbot import voluptuous as vol from openpeerpower.components.switch import PLATFORM_SCHEMA, SwitchEntity from openpeerpower.const import CONF_MAC, CONF_NAME, CONF_PASSWORD import openpeerpower.helpers.config_validation as cv from openpeerpower.helpers.restore_state import RestoreEntity DEFAULT_NAME = "Switchbot" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_MAC): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_PASSWORD): cv.string, } ) def setup_platform(opp, config, add_entities, discovery_info=None): """Perform the setup for Switchbot devices.""" name = config.get(CONF_NAME) mac_addr = config[CONF_MAC] password = config.get(CONF_PASSWORD) add_entities([SwitchBot(mac_addr, name, password)]) class SwitchBot(SwitchEntity, RestoreEntity): """Representation of a Switchbot."""
) COILS_SCHEMA = vol.Schema( { vol.Required(CONF_COIL): cv.positive_int, vol.Required(CONF_NAME): cv.string, vol.Required(CONF_SLAVE): cv.positive_int, vol.Optional(CONF_HUB, default=DEFAULT_HUB): cv.string, } ) PLATFORM_SCHEMA = vol.All( cv.has_at_least_one_key(CONF_COILS, CONF_REGISTERS), PLATFORM_SCHEMA.extend( { vol.Optional(CONF_COILS): [COILS_SCHEMA], vol.Optional(CONF_REGISTERS): [REGISTERS_SCHEMA], } ), ) def setup_platform(opp, config, add_entities, discovery_info=None): """Read configuration and create Modbus devices.""" switches = [] if CONF_COILS in config: for coil in config[CONF_COILS]: hub_name = coil[CONF_HUB] hub = opp.data[MODBUS_DOMAIN][hub_name] switches.append( ModbusCoilSwitch( hub, coil[CONF_NAME], coil[CONF_SLAVE], coil[CONF_COIL]
DEFAULT_NAME = "aREST switch" PIN_FUNCTION_SCHEMA = vol.Schema( { vol.Optional(CONF_NAME): cv.string, vol.Optional(CONF_INVERT, default=False): cv.boolean, } ) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_RESOURCE): cv.url, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_PINS, default={}): vol.Schema( {cv.string: PIN_FUNCTION_SCHEMA} ), vol.Optional(CONF_FUNCTIONS, default={}): vol.Schema( {cv.string: PIN_FUNCTION_SCHEMA} ), } ) def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the aREST switches.""" resource = config[CONF_RESOURCE] try: response = requests.get(resource, timeout=10) except requests.exceptions.MissingSchema: _LOGGER.error(
CONF_BOARDS = "boards" CONF_BOARD = "board" CONF_ADDR = "addr" CONF_RELAYS = "relays" RELAY_SCHEMA = vol.Schema({ vol.Required(CONF_NAME): cv.string, vol.Required(CONF_ADDR): cv.positive_int, vol.Optional(CONF_BOARD, default=0): cv.positive_int, }) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_HOST): cv.string, vol.Required(CONF_PORT): cv.port, vol.Optional(CONF_BOARDS, default=1): cv.positive_int, vol.Required(CONF_RELAYS): vol.All(cv.ensure_list, [RELAY_SCHEMA]), }) def setup_platform(opp, config, add_entities, discovery_info=None): """Pencom relay platform (pencompy).""" # Assign configuration variables. host = config[CONF_HOST] port = config[CONF_PORT] boards = config[CONF_BOARDS] # Setup connection