<commit_before>"""
Support for switching devices via Pilight to on and off.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.pilight/
"""
import logging

import voluptuous as vol

import homeassistant.helpers.config_validation as cv
import homeassistant.components.pilight as pilight
from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA)
from homeassistant.const import (CONF_NAME, CONF_ID, CONF_SWITCHES, CONF_STATE,
                                 CONF_PROTOCOL)

_LOGGER = logging.getLogger(__name__)

CONF_OFF_CODE = 'off_code'
CONF_OFF_CODE_RECIEVE = 'off_code_receive'
CONF_ON_CODE = 'on_code'
CONF_ON_CODE_RECIEVE = 'on_code_receive'
CONF_SYSTEMCODE = 'systemcode'
CONF_UNIT = 'unit'
CONF_UNITCODE = 'unitcode'
CONF_ECHO = 'echo'

DEPENDENCIES = ['pilight']

COMMAND_SCHEMA = vol.Schema({
    vol.Optional(CONF_PROTOCOL): cv.string,
    vol.Optional('on'): cv.positive_int,
    vol.Optional('off'): cv.positive_int,
    vol.Optional(CONF_UNIT): cv.positive_int,
    vol.Optional(CONF_UNITCODE): cv.positive_int,
    vol.Optional(CONF_ID): cv.positive_int,
    vol.Optional(CONF_STATE): cv.string,
    vol.Optional(CONF_SYSTEMCODE): cv.positive_int,
}, extra=vol.ALLOW_EXTRA)

RECEIVE_SCHEMA = COMMAND_SCHEMA.extend({
    vol.Optional(CONF_ECHO): cv.boolean
})

SWITCHES_SCHEMA = vol.Schema({
    vol.Required(CONF_ON_CODE): COMMAND_SCHEMA,
    vol.Required(CONF_OFF_CODE): COMMAND_SCHEMA,
    vol.Optional(CONF_NAME): cv.string,
    vol.Optional(CONF_OFF_CODE_RECIEVE, default=[]): vol.All(cv.ensure_list,
                                                             [COMMAND_SCHEMA]),
    vol.Optional(CONF_ON_CODE_RECIEVE, default=[]): vol.All(cv.ensure_list,
                                                            [COMMAND_SCHEMA])
})

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_SWITCHES):
        vol.Schema({cv.string: SWITCHES_SCHEMA}),
})


def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the Pilight platform."""
    switches = config.get(CONF_SWITCHES)
    devices = []
<commit_msg>Fixes: Pilight Switch rejects alphanumeric IDs #5119 (#5601)<commit_after>"""
Support for switching devices via Pilight to on and off.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.pilight/
"""
import logging

import voluptuous as vol

import homeassistant.helpers.config_validation as cv
import homeassistant.components.pilight as pilight
from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA)
from homeassistant.const import (CONF_NAME, CONF_ID, CONF_SWITCHES, CONF_STATE,
                                 CONF_PROTOCOL)

_LOGGER = logging.getLogger(__name__)

CONF_OFF_CODE = 'off_code'
CONF_OFF_CODE_RECIEVE = 'off_code_receive'
CONF_ON_CODE = 'on_code'
CONF_ON_CODE_RECIEVE = 'on_code_receive'
CONF_SYSTEMCODE = 'systemcode'
CONF_UNIT = 'unit'
CONF_UNITCODE = 'unitcode'
CONF_ECHO = 'echo'

DEPENDENCIES = ['pilight']

COMMAND_SCHEMA = vol.Schema({
    vol.Optional(CONF_PROTOCOL): cv.string,
    vol.Optional('on'): cv.positive_int,
    vol.Optional('off'): cv.positive_int,
    vol.Optional(CONF_UNIT): cv.positive_int,
    vol.Optional(CONF_UNITCODE): cv.positive_int,
    vol.Optional(CONF_ID): vol.Any(cv.positive_int, cv.string),
    vol.Optional(CONF_STATE): cv.string,
    vol.Optional(CONF_SYSTEMCODE): cv.positive_int,
}, extra=vol.ALLOW_EXTRA)

RECEIVE_SCHEMA = COMMAND_SCHEMA.extend({
    vol.Optional(CONF_ECHO): cv.boolean
})

SWITCHES_SCHEMA = vol.Schema({
    vol.Required(CONF_ON_CODE): COMMAND_SCHEMA,
    vol.Required(CONF_OFF_CODE): COMMAND_SCHEMA,
    vol.Optional(CONF_NAME): cv.string,
    vol.Optional(CONF_OFF_CODE_RECIEVE, default=[]): vol.All(cv.ensure_list,
                                                             [COMMAND_SCHEMA]),
    vol.Optional(CONF_ON_CODE_RECIEVE, default=[]): vol.All(cv.ensure_list,
                                                            [COMMAND_SCHEMA])
})

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_SWITCHES):
        vol.Schema({cv.string: SWITCHES_SCHEMA}),
})


def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the Pilight platform."""
    switches = config.get(CONF_SWITCHES)
    devices = []

{'fraction_non_alphanumeric': 0.10884975989023554, 'fraction_numerical': 0.001829407729247656, 'mean_word_length': 3.790799561883899, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1357471', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1457, 'n_words': 264}