mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Use constants (#5390)
This commit is contained in:
parent
cfc936761b
commit
bfc0a6a17c
@ -5,8 +5,11 @@ For more details about this platform, please refer to the documentation at
|
|||||||
https://home-assistant.io/components/light.qwikswitch/
|
https://home-assistant.io/components/light.qwikswitch/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import homeassistant.components.qwikswitch as qwikswitch
|
import homeassistant.components.qwikswitch as qwikswitch
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEPENDENCIES = ['qwikswitch']
|
DEPENDENCIES = ['qwikswitch']
|
||||||
|
|
||||||
|
|
||||||
@ -14,7 +17,7 @@ DEPENDENCIES = ['qwikswitch']
|
|||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Add lights from the main Qwikswitch component."""
|
"""Add lights from the main Qwikswitch component."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
logging.getLogger(__name__).error('Configure Qwikswitch Component.')
|
_LOGGER.error("Configure Qwikswitch component")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
add_devices(qwikswitch.QSUSB['light'])
|
add_devices(qwikswitch.QSUSB['light'])
|
||||||
|
@ -5,26 +5,32 @@ For more details about this component, please refer to the documentation at
|
|||||||
https://home-assistant.io/components/qwikswitch/
|
https://home-assistant.io/components/qwikswitch/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (EVENT_HOMEASSISTANT_START,
|
from homeassistant.const import (
|
||||||
EVENT_HOMEASSISTANT_STOP)
|
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, CONF_URL)
|
||||||
from homeassistant.helpers.discovery import load_platform
|
from homeassistant.helpers.discovery import load_platform
|
||||||
from homeassistant.components.light import (ATTR_BRIGHTNESS,
|
from homeassistant.components.light import (
|
||||||
SUPPORT_BRIGHTNESS, Light)
|
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
|
||||||
from homeassistant.components.switch import SwitchDevice
|
from homeassistant.components.switch import SwitchDevice
|
||||||
|
|
||||||
DOMAIN = 'qwikswitch'
|
|
||||||
REQUIREMENTS = ['pyqwikswitch==0.4']
|
REQUIREMENTS = ['pyqwikswitch==0.4']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DOMAIN = 'qwikswitch'
|
||||||
|
|
||||||
|
CONF_DIMMER_ADJUST = 'dimmer_adjust'
|
||||||
|
CONF_BUTTON_EVENTS = 'button_events'
|
||||||
CV_DIM_VALUE = vol.All(vol.Coerce(float), vol.Range(min=1, max=3))
|
CV_DIM_VALUE = vol.All(vol.Coerce(float), vol.Range(min=1, max=3))
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
DOMAIN: vol.Schema({
|
DOMAIN: vol.Schema({
|
||||||
vol.Required('url', default='http://127.0.0.1:2020'): vol.Coerce(str),
|
vol.Required(CONF_URL, default='http://127.0.0.1:2020'):
|
||||||
vol.Optional('dimmer_adjust', default=1): CV_DIM_VALUE,
|
vol.Coerce(str),
|
||||||
vol.Optional('button_events'): vol.Coerce(str)
|
vol.Optional(CONF_DIMMER_ADJUST, default=1): CV_DIM_VALUE,
|
||||||
|
vol.Optional(CONF_BUTTON_EVENTS): vol.Coerce(str)
|
||||||
})}, extra=vol.ALLOW_EXTRA)
|
})}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
QSUSB = {}
|
QSUSB = {}
|
||||||
@ -118,16 +124,17 @@ class QSLight(QSToggleEntity, Light):
|
|||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
"""Setup the QSUSB component."""
|
"""Setup the QSUSB component."""
|
||||||
from pyqwikswitch import (QSUsb, CMD_BUTTONS, QS_NAME, QS_ID, QS_CMD,
|
from pyqwikswitch import (
|
||||||
PQS_VALUE, PQS_TYPE, QSType)
|
QSUsb, CMD_BUTTONS, QS_NAME, QS_ID, QS_CMD, PQS_VALUE, PQS_TYPE,
|
||||||
|
QSType)
|
||||||
|
|
||||||
# Override which cmd's in /&listen packets will fire events
|
# Override which cmd's in /&listen packets will fire events
|
||||||
# By default only buttons of type [TOGGLE,SCENE EXE,LEVEL]
|
# By default only buttons of type [TOGGLE,SCENE EXE,LEVEL]
|
||||||
cmd_buttons = config[DOMAIN].get('button_events', ','.join(CMD_BUTTONS))
|
cmd_buttons = config[DOMAIN].get(CONF_BUTTON_EVENTS, ','.join(CMD_BUTTONS))
|
||||||
cmd_buttons = cmd_buttons.split(',')
|
cmd_buttons = cmd_buttons.split(',')
|
||||||
|
|
||||||
url = config[DOMAIN]['url']
|
url = config[DOMAIN][CONF_URL]
|
||||||
dimmer_adjust = config[DOMAIN]['dimmer_adjust']
|
dimmer_adjust = config[DOMAIN][CONF_DIMMER_ADJUST]
|
||||||
|
|
||||||
qsusb = QSUsb(url, _LOGGER, dimmer_adjust)
|
qsusb = QSUsb(url, _LOGGER, dimmer_adjust)
|
||||||
|
|
||||||
|
@ -5,8 +5,11 @@ For more details about this platform, please refer to the documentation at
|
|||||||
https://home-assistant.io/components/switch.qwikswitch/
|
https://home-assistant.io/components/switch.qwikswitch/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import homeassistant.components.qwikswitch as qwikswitch
|
import homeassistant.components.qwikswitch as qwikswitch
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEPENDENCIES = ['qwikswitch']
|
DEPENDENCIES = ['qwikswitch']
|
||||||
|
|
||||||
|
|
||||||
@ -14,8 +17,7 @@ DEPENDENCIES = ['qwikswitch']
|
|||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Add switched from the main Qwikswitch component."""
|
"""Add switched from the main Qwikswitch component."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
logging.getLogger(__name__).error(
|
_LOGGER.error("Configure Qwikswitch component")
|
||||||
'Configure main Qwikswitch component')
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
add_devices(qwikswitch.QSUSB['switch'])
|
add_devices(qwikswitch.QSUSB['switch'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user