@@ -0,0 +1,2349 @@
+%22%22%22%0Ahomeassistant.components.binary_sensor.mqtt%0A~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%0AAllows to configure a MQTT binary sensor.%0A%0AFor more details about this platform, please refer to the documentation at%0Ahttps://home-assistant.io/components/binary_sensor.mqtt/%0A%22%22%22%0Aimport logging%0Afrom homeassistant.components.binary_sensor import BinarySensorDevice%0Aimport homeassistant.components.mqtt as mqtt%0A%0A_LOGGER = logging.getLogger(__name__)%0A%0ADEFAULT_NAME = 'MQTT Binary sensor'%0ADEFAULT_QOS = 0%0ADEFAULT_PAYLOAD_ON = 'ON'%0ADEFAULT_PAYLOAD_OFF = 'OFF'%0A%0ADEPENDENCIES = %5B'mqtt'%5D%0A%0A%0A# pylint: disable=unused-argument%0Adef setup_platform(hass, config, add_devices, discovery_info=None):%0A    %22%22%22 Add MQTT binary sensor. %22%22%22%0A%0A    if config.get('state_topic') is None:%0A        _LOGGER.error('Missing required variable: state_topic')%0A        return False%0A%0A    add_devices(%5BMqttBinarySensor(%0A        hass,%0A        config.get('name', DEFAULT_NAME),%0A        config.get('state_topic', None),%0A        config.get('qos', DEFAULT_QOS),%0A        config.get('payload_on', DEFAULT_PAYLOAD_ON),%0A        config.get('payload_off', DEFAULT_PAYLOAD_OFF))%5D)%0A%0A%0A# pylint: disable=too-many-arguments, too-many-instance-attributes%0Aclass MqttBinarySensor(BinarySensorDevice):%0A    %22%22%22 Represents a binary sensor that is updated by MQTT. %22%22%22%0A    def __init__(self, hass, name, state_topic, qos, payload_on, payload_off):%0A        self._hass = hass%0A        self._name = name%0A        self._state = False%0A        self._state_topic = state_topic%0A        self._payload_on = payload_on%0A        self._payload_off = payload_off%0A        self._qos = qos%0A%0A        def message_received(topic, payload, qos):%0A            %22%22%22 A new MQTT message has been received. %22%22%22%0A            if payload == self._payload_on:%0A                self._state = True%0A                self.update_ha_state()%0A            elif payload == self._payload_off:%0A                self._state = False%0A                self.update_ha_state()%0A%0A        mqtt.subscribe(hass, self._state_topic, message_received, self._qos)%0A%0A    @property%0A    def should_poll(self):%0A        %22%22%22 No polling needed. %22%22%22%0A        return False%0A%0A    @property%0A    def name(self):%0A        %22%22%22 The name of the binary sensor. %22%22%22%0A        return self._name%0A%0A    @property%0A    def is_on(self):%0A        %22%22%22 True if the binary sensor is on. %22%22%22%0A        return self._state%0A

Add MQTT binary sensor