parent
fb0232429e
commit
ee6c83f569
|
@ -8,25 +8,26 @@ import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.components.mqtt as mqtt
|
|
||||||
from homeassistant.components.lock import LockDevice
|
from homeassistant.components.lock import LockDevice
|
||||||
from homeassistant.const import CONF_NAME, CONF_OPTIMISTIC, CONF_VALUE_TEMPLATE
|
|
||||||
from homeassistant.components.mqtt import (
|
from homeassistant.components.mqtt import (
|
||||||
CONF_STATE_TOPIC, CONF_COMMAND_TOPIC, CONF_QOS, CONF_RETAIN)
|
CONF_STATE_TOPIC, CONF_COMMAND_TOPIC, CONF_QOS, CONF_RETAIN)
|
||||||
|
from homeassistant.const import (
|
||||||
|
CONF_NAME, CONF_OPTIMISTIC, CONF_VALUE_TEMPLATE)
|
||||||
from homeassistant.helpers import template
|
from homeassistant.helpers import template
|
||||||
|
import homeassistant.components.mqtt as mqtt
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEPENDENCIES = ['mqtt']
|
|
||||||
|
|
||||||
CONF_PAYLOAD_LOCK = 'payload_lock'
|
CONF_PAYLOAD_LOCK = 'payload_lock'
|
||||||
CONF_PAYLOAD_UNLOCK = 'payload_unlock'
|
CONF_PAYLOAD_UNLOCK = 'payload_unlock'
|
||||||
|
|
||||||
DEFAULT_NAME = 'MQTT Lock'
|
DEFAULT_NAME = 'MQTT Lock'
|
||||||
|
DEFAULT_OPTIMISTIC = False
|
||||||
DEFAULT_PAYLOAD_LOCK = 'LOCK'
|
DEFAULT_PAYLOAD_LOCK = 'LOCK'
|
||||||
DEFAULT_PAYLOAD_UNLOCK = 'UNLOCK'
|
DEFAULT_PAYLOAD_UNLOCK = 'UNLOCK'
|
||||||
DEFAULT_OPTIMISTIC = False
|
DEPENDENCIES = ['mqtt']
|
||||||
|
|
||||||
PLATFORM_SCHEMA = mqtt.MQTT_RW_PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = mqtt.MQTT_RW_PLATFORM_SCHEMA.extend({
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
|
@ -43,15 +44,16 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the MQTT lock."""
|
"""Setup the MQTT lock."""
|
||||||
add_devices([MqttLock(
|
add_devices([MqttLock(
|
||||||
hass,
|
hass,
|
||||||
config[CONF_NAME],
|
config.get(CONF_NAME),
|
||||||
config.get(CONF_STATE_TOPIC),
|
config.get(CONF_STATE_TOPIC),
|
||||||
config[CONF_COMMAND_TOPIC],
|
config.get(CONF_COMMAND_TOPIC),
|
||||||
config[CONF_QOS],
|
config.get(CONF_QOS),
|
||||||
config[CONF_RETAIN],
|
config.get(CONF_RETAIN),
|
||||||
config[CONF_PAYLOAD_LOCK],
|
config.get(CONF_PAYLOAD_LOCK),
|
||||||
config[CONF_PAYLOAD_UNLOCK],
|
config.get(CONF_PAYLOAD_UNLOCK),
|
||||||
config[CONF_OPTIMISTIC],
|
config.get(CONF_OPTIMISTIC),
|
||||||
config.get(CONF_VALUE_TEMPLATE))])
|
config.get(CONF_VALUE_TEMPLATE)
|
||||||
|
)])
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
||||||
|
@ -88,8 +90,8 @@ class MqttLock(LockDevice):
|
||||||
# Force into optimistic mode.
|
# Force into optimistic mode.
|
||||||
self._optimistic = True
|
self._optimistic = True
|
||||||
else:
|
else:
|
||||||
mqtt.subscribe(hass, self._state_topic, message_received,
|
mqtt.subscribe(
|
||||||
self._qos)
|
hass, self._state_topic, message_received, self._qos)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
|
|
|
@ -8,24 +8,23 @@ import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.components.mqtt as mqtt
|
|
||||||
from homeassistant.components.switch import SwitchDevice
|
|
||||||
from homeassistant.const import CONF_NAME, CONF_OPTIMISTIC, CONF_VALUE_TEMPLATE
|
|
||||||
from homeassistant.components.mqtt import (
|
from homeassistant.components.mqtt import (
|
||||||
CONF_STATE_TOPIC, CONF_COMMAND_TOPIC, CONF_QOS, CONF_RETAIN)
|
CONF_STATE_TOPIC, CONF_COMMAND_TOPIC, CONF_QOS, CONF_RETAIN)
|
||||||
import homeassistant.helpers.config_validation as cv
|
from homeassistant.components.switch import SwitchDevice
|
||||||
|
from homeassistant.const import (
|
||||||
|
CONF_NAME, CONF_OPTIMISTIC, CONF_VALUE_TEMPLATE, CONF_PAYLOAD_OFF,
|
||||||
|
CONF_PAYLOAD_ON)
|
||||||
from homeassistant.helpers import template
|
from homeassistant.helpers import template
|
||||||
|
import homeassistant.components.mqtt as mqtt
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEPENDENCIES = ['mqtt']
|
DEPENDENCIES = ['mqtt']
|
||||||
|
|
||||||
CONF_PAYLOAD_ON = 'payload_on'
|
DEFAULT_NAME = 'MQTT Switch'
|
||||||
CONF_PAYLOAD_OFF = 'payload_off'
|
DEFAULT_PAYLOAD_ON = 'ON'
|
||||||
|
DEFAULT_PAYLOAD_OFF = 'OFF'
|
||||||
DEFAULT_NAME = "MQTT Switch"
|
|
||||||
DEFAULT_PAYLOAD_ON = "ON"
|
|
||||||
DEFAULT_PAYLOAD_OFF = "OFF"
|
|
||||||
DEFAULT_OPTIMISTIC = False
|
DEFAULT_OPTIMISTIC = False
|
||||||
|
|
||||||
PLATFORM_SCHEMA = mqtt.MQTT_RW_PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = mqtt.MQTT_RW_PLATFORM_SCHEMA.extend({
|
||||||
|
@ -37,19 +36,20 @@ PLATFORM_SCHEMA = mqtt.MQTT_RW_PLATFORM_SCHEMA.extend({
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Add MQTT switch."""
|
"""Setup the MQTT switch."""
|
||||||
add_devices_callback([MqttSwitch(
|
add_devices([MqttSwitch(
|
||||||
hass,
|
hass,
|
||||||
config[CONF_NAME],
|
config.get(CONF_NAME),
|
||||||
config.get(CONF_STATE_TOPIC),
|
config.get(CONF_STATE_TOPIC),
|
||||||
config[CONF_COMMAND_TOPIC],
|
config.get(CONF_COMMAND_TOPIC),
|
||||||
config[CONF_QOS],
|
config.get(CONF_QOS),
|
||||||
config[CONF_RETAIN],
|
config.get(CONF_RETAIN),
|
||||||
config[CONF_PAYLOAD_ON],
|
config.get(CONF_PAYLOAD_ON),
|
||||||
config[CONF_PAYLOAD_OFF],
|
config.get(CONF_PAYLOAD_OFF),
|
||||||
config[CONF_OPTIMISTIC],
|
config.get(CONF_OPTIMISTIC),
|
||||||
config.get(CONF_VALUE_TEMPLATE))])
|
config.get(CONF_VALUE_TEMPLATE)
|
||||||
|
)])
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
||||||
|
@ -86,8 +86,8 @@ class MqttSwitch(SwitchDevice):
|
||||||
# Force into optimistic mode.
|
# Force into optimistic mode.
|
||||||
self._optimistic = True
|
self._optimistic = True
|
||||||
else:
|
else:
|
||||||
mqtt.subscribe(hass, self._state_topic, message_received,
|
mqtt.subscribe(
|
||||||
self._qos)
|
hass, self._state_topic, message_received, self._qos)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
|
|
Loading…
Reference in New Issue