mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
More support for availability reporting on MQTT components (#11336)
* Abstract MQTT availability from individual components - Moved availability topic and payloads to MQTT base schema. - Updated components that already report availability: - Switch - Binary sensor - Cover * Add availability reporting to additional MQTT components - Light - JSON light - Template light - Lock - Fan - HVAC - Sensor - Vacuum - Alarm control panel * Annotate MQTT platform coroutines
This commit is contained in:
committed by
Paulus Schoutsen
parent
541707c3e7
commit
f0bf7b0def
@@ -2,8 +2,8 @@
|
||||
import unittest
|
||||
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.const import (STATE_LOCKED, STATE_UNLOCKED,
|
||||
ATTR_ASSUMED_STATE)
|
||||
from homeassistant.const import (
|
||||
STATE_LOCKED, STATE_UNLOCKED, STATE_UNAVAILABLE, ATTR_ASSUMED_STATE)
|
||||
import homeassistant.components.lock as lock
|
||||
from tests.common import (
|
||||
mock_mqtt_component, fire_mqtt_message, get_test_home_assistant)
|
||||
@@ -111,3 +111,34 @@ class TestLockMQTT(unittest.TestCase):
|
||||
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertEqual(STATE_UNLOCKED, state.state)
|
||||
|
||||
def test_custom_availability_payload(self):
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
self.assertTrue(setup_component(self.hass, lock.DOMAIN, {
|
||||
lock.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'state_topic': 'state-topic',
|
||||
'command_topic': 'command-topic',
|
||||
'payload_lock': 'LOCK',
|
||||
'payload_unlock': 'UNLOCK',
|
||||
'availability_topic': 'availability-topic',
|
||||
'payload_available': 'good',
|
||||
'payload_not_available': 'nogood'
|
||||
}
|
||||
}))
|
||||
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||
|
||||
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
||||
|
||||
fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||
|
||||
Reference in New Issue
Block a user