2016-03-09 10:25:50 +01:00
|
|
|
"""The tests for the MQTT lock platform."""
|
2020-03-09 17:40:00 +01:00
|
|
|
from homeassistant.components import lock
|
2019-01-27 18:54:52 +01:00
|
|
|
from homeassistant.const import (
|
2019-07-31 12:25:30 -07:00
|
|
|
ATTR_ASSUMED_STATE,
|
|
|
|
STATE_LOCKED,
|
|
|
|
STATE_UNAVAILABLE,
|
|
|
|
STATE_UNLOCKED,
|
|
|
|
)
|
2019-01-27 18:54:52 +01:00
|
|
|
from homeassistant.setup import async_setup_component
|
2018-09-26 18:02:05 +02:00
|
|
|
|
2020-03-09 17:40:00 +01:00
|
|
|
from .common import (
|
|
|
|
help_test_discovery_broken,
|
|
|
|
help_test_discovery_removal,
|
|
|
|
help_test_discovery_update,
|
|
|
|
help_test_discovery_update_attr,
|
2020-03-12 02:00:47 +01:00
|
|
|
help_test_entity_device_info_remove,
|
2020-03-09 17:40:00 +01:00
|
|
|
help_test_entity_device_info_update,
|
|
|
|
help_test_entity_device_info_with_identifier,
|
|
|
|
help_test_entity_id_update,
|
|
|
|
help_test_setting_attribute_via_mqtt_json_message,
|
|
|
|
help_test_unique_id,
|
|
|
|
help_test_update_with_json_attrs_bad_JSON,
|
|
|
|
help_test_update_with_json_attrs_not_dict,
|
2019-07-31 12:25:30 -07:00
|
|
|
)
|
2020-03-09 17:40:00 +01:00
|
|
|
|
|
|
|
from tests.common import async_fire_mqtt_message
|
2019-04-10 22:56:34 +02:00
|
|
|
from tests.components.lock import common
|
2018-10-24 22:20:25 +02:00
|
|
|
|
2020-03-11 17:34:19 +01:00
|
|
|
DEFAULT_CONFIG_ATTR = {
|
|
|
|
lock.DOMAIN: {
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "test",
|
|
|
|
"command_topic": "test-topic",
|
|
|
|
"json_attributes_topic": "attr-topic",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFAULT_CONFIG_DEVICE_INFO = {
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "Test 1",
|
|
|
|
"state_topic": "test-topic",
|
|
|
|
"command_topic": "test-command-topic",
|
|
|
|
"device": {
|
|
|
|
"identifiers": ["helloworld"],
|
|
|
|
"connections": [["mac", "02:5b:26:a8:dc:12"]],
|
|
|
|
"manufacturer": "Whatever",
|
|
|
|
"name": "Beer",
|
|
|
|
"model": "Glass",
|
|
|
|
"sw_version": "0.1-beta",
|
|
|
|
},
|
|
|
|
"unique_id": "veryunique",
|
|
|
|
}
|
|
|
|
|
2018-10-24 22:20:25 +02:00
|
|
|
|
|
|
|
async def test_controlling_state_via_topic(hass, mqtt_mock):
|
|
|
|
"""Test the controlling state via topic."""
|
2019-07-31 12:25:30 -07:00
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
lock.DOMAIN,
|
|
|
|
{
|
|
|
|
lock.DOMAIN: {
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "test",
|
|
|
|
"state_topic": "state-topic",
|
|
|
|
"command_topic": "command-topic",
|
|
|
|
"payload_lock": "LOCK",
|
|
|
|
"payload_unlock": "UNLOCK",
|
2019-12-31 15:24:09 +01:00
|
|
|
"state_locked": "LOCKED",
|
|
|
|
"state_unlocked": "UNLOCKED",
|
2019-07-31 12:25:30 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2018-10-24 22:20:25 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2018-10-24 22:20:25 +02:00
|
|
|
assert state.state is STATE_UNLOCKED
|
|
|
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
|
|
|
|
2019-12-31 15:24:09 +01:00
|
|
|
async_fire_mqtt_message(hass, "state-topic", "LOCKED")
|
2018-10-24 22:20:25 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2018-10-24 22:20:25 +02:00
|
|
|
assert state.state is STATE_LOCKED
|
|
|
|
|
2019-12-31 15:24:09 +01:00
|
|
|
async_fire_mqtt_message(hass, "state-topic", "UNLOCKED")
|
|
|
|
|
|
|
|
state = hass.states.get("lock.test")
|
|
|
|
assert state.state is STATE_UNLOCKED
|
|
|
|
|
|
|
|
|
|
|
|
async def test_controlling_non_default_state_via_topic(hass, mqtt_mock):
|
|
|
|
"""Test the controlling state via topic."""
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
lock.DOMAIN,
|
|
|
|
{
|
|
|
|
lock.DOMAIN: {
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "test",
|
|
|
|
"state_topic": "state-topic",
|
|
|
|
"command_topic": "command-topic",
|
|
|
|
"payload_lock": "LOCK",
|
|
|
|
"payload_unlock": "UNLOCK",
|
|
|
|
"state_locked": "closed",
|
|
|
|
"state_unlocked": "open",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
state = hass.states.get("lock.test")
|
|
|
|
assert state.state is STATE_UNLOCKED
|
|
|
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "state-topic", "closed")
|
|
|
|
|
|
|
|
state = hass.states.get("lock.test")
|
|
|
|
assert state.state is STATE_LOCKED
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "state-topic", "open")
|
2018-10-24 22:20:25 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2018-10-24 22:20:25 +02:00
|
|
|
assert state.state is STATE_UNLOCKED
|
|
|
|
|
|
|
|
|
|
|
|
async def test_controlling_state_via_topic_and_json_message(hass, mqtt_mock):
|
|
|
|
"""Test the controlling state via topic and JSON message."""
|
2019-07-31 12:25:30 -07:00
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
lock.DOMAIN,
|
|
|
|
{
|
|
|
|
lock.DOMAIN: {
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "test",
|
|
|
|
"state_topic": "state-topic",
|
|
|
|
"command_topic": "command-topic",
|
|
|
|
"payload_lock": "LOCK",
|
|
|
|
"payload_unlock": "UNLOCK",
|
2019-12-31 15:24:09 +01:00
|
|
|
"state_locked": "LOCKED",
|
|
|
|
"state_unlocked": "UNLOCKED",
|
|
|
|
"value_template": "{{ value_json.val }}",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
state = hass.states.get("lock.test")
|
|
|
|
assert state.state is STATE_UNLOCKED
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "state-topic", '{"val":"LOCKED"}')
|
|
|
|
|
|
|
|
state = hass.states.get("lock.test")
|
|
|
|
assert state.state is STATE_LOCKED
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "state-topic", '{"val":"UNLOCKED"}')
|
|
|
|
|
|
|
|
state = hass.states.get("lock.test")
|
|
|
|
assert state.state is STATE_UNLOCKED
|
|
|
|
|
|
|
|
|
|
|
|
async def test_controlling_non_default_state_via_topic_and_json_message(
|
|
|
|
hass, mqtt_mock
|
|
|
|
):
|
|
|
|
"""Test the controlling state via topic and JSON message."""
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
lock.DOMAIN,
|
|
|
|
{
|
|
|
|
lock.DOMAIN: {
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "test",
|
|
|
|
"state_topic": "state-topic",
|
|
|
|
"command_topic": "command-topic",
|
|
|
|
"payload_lock": "LOCK",
|
|
|
|
"payload_unlock": "UNLOCK",
|
|
|
|
"state_locked": "closed",
|
|
|
|
"state_unlocked": "open",
|
2019-07-31 12:25:30 -07:00
|
|
|
"value_template": "{{ value_json.val }}",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2018-10-24 22:20:25 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2018-10-24 22:20:25 +02:00
|
|
|
assert state.state is STATE_UNLOCKED
|
|
|
|
|
2019-12-31 15:24:09 +01:00
|
|
|
async_fire_mqtt_message(hass, "state-topic", '{"val":"closed"}')
|
2018-10-24 22:20:25 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2018-10-24 22:20:25 +02:00
|
|
|
assert state.state is STATE_LOCKED
|
|
|
|
|
2019-12-31 15:24:09 +01:00
|
|
|
async_fire_mqtt_message(hass, "state-topic", '{"val":"open"}')
|
2018-10-24 22:20:25 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2018-10-24 22:20:25 +02:00
|
|
|
assert state.state is STATE_UNLOCKED
|
|
|
|
|
|
|
|
|
2019-04-10 22:56:34 +02:00
|
|
|
async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
|
|
|
"""Test optimistic mode without state topic."""
|
2019-07-31 12:25:30 -07:00
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
lock.DOMAIN,
|
|
|
|
{
|
|
|
|
lock.DOMAIN: {
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "test",
|
|
|
|
"command_topic": "command-topic",
|
|
|
|
"payload_lock": "LOCK",
|
|
|
|
"payload_unlock": "UNLOCK",
|
2019-12-31 15:24:09 +01:00
|
|
|
"state_locked": "LOCKED",
|
|
|
|
"state_unlocked": "UNLOCKED",
|
2019-07-31 12:25:30 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2019-04-10 22:56:34 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2019-04-10 22:56:34 +02:00
|
|
|
assert state.state is STATE_UNLOCKED
|
|
|
|
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
await common.async_lock(hass, "lock.test")
|
2019-04-10 22:56:34 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
mqtt_mock.async_publish.assert_called_once_with("command-topic", "LOCK", 0, False)
|
2019-04-10 22:56:34 +02:00
|
|
|
mqtt_mock.async_publish.reset_mock()
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2019-04-10 22:56:34 +02:00
|
|
|
assert state.state is STATE_LOCKED
|
|
|
|
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
await common.async_unlock(hass, "lock.test")
|
2019-04-10 22:56:34 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
mqtt_mock.async_publish.assert_called_once_with("command-topic", "UNLOCK", 0, False)
|
2019-04-10 22:56:34 +02:00
|
|
|
mqtt_mock.async_publish.reset_mock()
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2019-04-10 22:56:34 +02:00
|
|
|
assert state.state is STATE_UNLOCKED
|
|
|
|
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
|
|
|
|
|
|
|
|
|
|
|
async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock):
|
|
|
|
"""Test optimistic mode without state topic."""
|
2019-07-31 12:25:30 -07:00
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
lock.DOMAIN,
|
|
|
|
{
|
|
|
|
lock.DOMAIN: {
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "test",
|
|
|
|
"state_topic": "state-topic",
|
|
|
|
"command_topic": "command-topic",
|
|
|
|
"payload_lock": "LOCK",
|
|
|
|
"payload_unlock": "UNLOCK",
|
2019-12-31 15:24:09 +01:00
|
|
|
"state_locked": "LOCKED",
|
|
|
|
"state_unlocked": "UNLOCKED",
|
2019-07-31 12:25:30 -07:00
|
|
|
"optimistic": True,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2019-04-10 22:56:34 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2019-04-10 22:56:34 +02:00
|
|
|
assert state.state is STATE_UNLOCKED
|
|
|
|
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
await common.async_lock(hass, "lock.test")
|
2019-04-10 22:56:34 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
mqtt_mock.async_publish.assert_called_once_with("command-topic", "LOCK", 0, False)
|
2019-04-10 22:56:34 +02:00
|
|
|
mqtt_mock.async_publish.reset_mock()
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2019-04-10 22:56:34 +02:00
|
|
|
assert state.state is STATE_LOCKED
|
|
|
|
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
await common.async_unlock(hass, "lock.test")
|
2019-04-10 22:56:34 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
mqtt_mock.async_publish.assert_called_once_with("command-topic", "UNLOCK", 0, False)
|
2019-04-10 22:56:34 +02:00
|
|
|
mqtt_mock.async_publish.reset_mock()
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2019-04-10 22:56:34 +02:00
|
|
|
assert state.state is STATE_UNLOCKED
|
|
|
|
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
|
|
|
|
|
|
|
|
2018-10-24 22:20:25 +02:00
|
|
|
async def test_default_availability_payload(hass, mqtt_mock):
|
|
|
|
"""Test availability by default payload with defined topic."""
|
2019-07-31 12:25:30 -07:00
|
|
|
assert await async_setup_component(
|
|
|
|
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",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2018-10-24 22:20:25 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2018-10-24 22:20:25 +02:00
|
|
|
assert state.state is STATE_UNAVAILABLE
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
async_fire_mqtt_message(hass, "availability-topic", "online")
|
2018-10-24 22:20:25 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2018-10-24 22:20:25 +02:00
|
|
|
assert state.state is not STATE_UNAVAILABLE
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
async_fire_mqtt_message(hass, "availability-topic", "offline")
|
2018-10-24 22:20:25 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2018-10-24 22:20:25 +02:00
|
|
|
assert state.state is STATE_UNAVAILABLE
|
|
|
|
|
|
|
|
|
|
|
|
async def test_custom_availability_payload(hass, mqtt_mock):
|
|
|
|
"""Test availability by custom payload with defined topic."""
|
2019-07-31 12:25:30 -07:00
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
lock.DOMAIN,
|
|
|
|
{
|
|
|
|
lock.DOMAIN: {
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "test",
|
|
|
|
"state_topic": "state-topic",
|
|
|
|
"command_topic": "command-topic",
|
|
|
|
"payload_lock": "LOCK",
|
|
|
|
"payload_unlock": "UNLOCK",
|
2019-12-31 15:24:09 +01:00
|
|
|
"state_locked": "LOCKED",
|
|
|
|
"state_unlocked": "UNLOCKED",
|
2019-07-31 12:25:30 -07:00
|
|
|
"availability_topic": "availability-topic",
|
|
|
|
"payload_available": "good",
|
|
|
|
"payload_not_available": "nogood",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2018-10-24 22:20:25 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2018-10-24 22:20:25 +02:00
|
|
|
assert state.state is STATE_UNAVAILABLE
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
async_fire_mqtt_message(hass, "availability-topic", "good")
|
2018-10-24 22:20:25 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2018-10-24 22:20:25 +02:00
|
|
|
assert state.state is not STATE_UNAVAILABLE
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
async_fire_mqtt_message(hass, "availability-topic", "nogood")
|
2018-10-24 22:20:25 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("lock.test")
|
2018-10-24 22:20:25 +02:00
|
|
|
assert state.state is STATE_UNAVAILABLE
|
2018-09-25 19:32:25 +02:00
|
|
|
|
|
|
|
|
2019-01-21 01:41:50 +01:00
|
|
|
async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
|
|
|
"""Test the setting of attribute via MQTT with JSON payload."""
|
2020-03-09 17:40:00 +01:00
|
|
|
await help_test_setting_attribute_via_mqtt_json_message(
|
2020-03-11 17:34:19 +01:00
|
|
|
hass, mqtt_mock, lock.DOMAIN, DEFAULT_CONFIG_ATTR
|
2019-07-31 12:25:30 -07:00
|
|
|
)
|
2019-01-21 01:41:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
|
|
|
"""Test attributes get extracted from a JSON result."""
|
2020-03-09 17:40:00 +01:00
|
|
|
await help_test_update_with_json_attrs_not_dict(
|
2020-03-11 17:34:19 +01:00
|
|
|
hass, mqtt_mock, caplog, lock.DOMAIN, DEFAULT_CONFIG_ATTR
|
2019-07-31 12:25:30 -07:00
|
|
|
)
|
2019-01-21 01:41:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def test_update_with_json_attrs_bad_JSON(hass, mqtt_mock, caplog):
|
|
|
|
"""Test attributes get extracted from a JSON result."""
|
2020-03-09 17:40:00 +01:00
|
|
|
await help_test_update_with_json_attrs_bad_JSON(
|
2020-03-11 17:34:19 +01:00
|
|
|
hass, mqtt_mock, caplog, lock.DOMAIN, DEFAULT_CONFIG_ATTR
|
2019-07-31 12:25:30 -07:00
|
|
|
)
|
2019-01-21 01:41:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
|
|
|
"""Test update of discovered MQTTAttributes."""
|
|
|
|
data1 = (
|
2020-03-11 17:34:19 +01:00
|
|
|
'{ "name": "test",'
|
2019-01-21 01:41:50 +01:00
|
|
|
' "command_topic": "test_topic",'
|
|
|
|
' "json_attributes_topic": "attr-topic1" }'
|
|
|
|
)
|
|
|
|
data2 = (
|
2020-03-11 17:34:19 +01:00
|
|
|
'{ "name": "test",'
|
2019-01-21 01:41:50 +01:00
|
|
|
' "command_topic": "test_topic",'
|
|
|
|
' "json_attributes_topic": "attr-topic2" }'
|
|
|
|
)
|
2020-03-09 17:40:00 +01:00
|
|
|
await help_test_discovery_update_attr(
|
|
|
|
hass, mqtt_mock, caplog, lock.DOMAIN, data1, data2
|
|
|
|
)
|
2019-01-21 01:41:50 +01:00
|
|
|
|
|
|
|
|
2018-12-19 19:26:07 +01:00
|
|
|
async def test_unique_id(hass):
|
2020-03-09 17:40:00 +01:00
|
|
|
"""Test unique id option only creates one lock per unique_id."""
|
|
|
|
config = {
|
|
|
|
lock.DOMAIN: [
|
|
|
|
{
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "Test 1",
|
|
|
|
"state_topic": "test-topic",
|
|
|
|
"command_topic": "test_topic",
|
|
|
|
"unique_id": "TOTALLY_UNIQUE",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "Test 2",
|
|
|
|
"state_topic": "test-topic",
|
|
|
|
"command_topic": "test_topic",
|
|
|
|
"unique_id": "TOTALLY_UNIQUE",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
await help_test_unique_id(hass, lock.DOMAIN, config)
|
2018-12-19 19:26:07 +01:00
|
|
|
|
|
|
|
|
2018-09-25 19:32:25 +02:00
|
|
|
async def test_discovery_removal_lock(hass, mqtt_mock, caplog):
|
|
|
|
"""Test removal of discovered lock."""
|
2020-03-11 17:34:19 +01:00
|
|
|
data = '{ "name": "test",' ' "command_topic": "test_topic" }'
|
2020-03-09 17:40:00 +01:00
|
|
|
await help_test_discovery_removal(hass, mqtt_mock, caplog, lock.DOMAIN, data)
|
2019-01-08 16:45:38 +01:00
|
|
|
|
|
|
|
|
2019-01-14 21:01:42 +01:00
|
|
|
async def test_discovery_update_lock(hass, mqtt_mock, caplog):
|
|
|
|
"""Test update of discovered lock."""
|
|
|
|
data1 = (
|
|
|
|
'{ "name": "Beer",'
|
|
|
|
' "state_topic": "test_topic",'
|
|
|
|
' "command_topic": "command_topic",'
|
|
|
|
' "availability_topic": "availability_topic1" }'
|
|
|
|
)
|
|
|
|
data2 = (
|
|
|
|
'{ "name": "Milk",'
|
|
|
|
' "state_topic": "test_topic2",'
|
|
|
|
' "command_topic": "command_topic",'
|
|
|
|
' "availability_topic": "availability_topic2" }'
|
|
|
|
)
|
2020-03-09 17:40:00 +01:00
|
|
|
await help_test_discovery_update(hass, mqtt_mock, caplog, lock.DOMAIN, data1, data2)
|
2019-01-14 21:01:42 +01:00
|
|
|
|
2020-03-09 17:40:00 +01:00
|
|
|
|
|
|
|
async def test_discovery_broken(hass, mqtt_mock, caplog):
|
|
|
|
"""Test handling of bad discovery message."""
|
|
|
|
data1 = '{ "name": "Beer" }'
|
|
|
|
data2 = '{ "name": "Milk",' ' "command_topic": "test_topic" }'
|
|
|
|
await help_test_discovery_broken(hass, mqtt_mock, caplog, lock.DOMAIN, data1, data2)
|
2019-01-14 21:01:42 +01:00
|
|
|
|
|
|
|
|
2018-12-19 19:26:07 +01:00
|
|
|
async def test_entity_device_info_with_identifier(hass, mqtt_mock):
|
|
|
|
"""Test MQTT lock device registry integration."""
|
2020-03-09 17:40:00 +01:00
|
|
|
await help_test_entity_device_info_with_identifier(
|
2020-03-11 17:34:19 +01:00
|
|
|
hass, mqtt_mock, lock.DOMAIN, DEFAULT_CONFIG_DEVICE_INFO
|
2020-03-09 17:40:00 +01:00
|
|
|
)
|
2019-01-14 21:01:42 +01:00
|
|
|
|
|
|
|
|
2019-01-27 17:42:45 +01:00
|
|
|
async def test_entity_device_info_update(hass, mqtt_mock):
|
|
|
|
"""Test device registry update."""
|
2020-03-11 17:34:19 +01:00
|
|
|
await help_test_entity_device_info_update(
|
|
|
|
hass, mqtt_mock, lock.DOMAIN, DEFAULT_CONFIG_DEVICE_INFO
|
|
|
|
)
|
2019-01-27 17:42:45 +01:00
|
|
|
|
|
|
|
|
2020-03-12 02:00:47 +01:00
|
|
|
async def test_entity_device_info_remove(hass, mqtt_mock):
|
|
|
|
"""Test device registry remove."""
|
|
|
|
config = {
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "Test 1",
|
|
|
|
"state_topic": "test-topic",
|
|
|
|
"command_topic": "test-command-topic",
|
|
|
|
"device": {"identifiers": ["helloworld"]},
|
|
|
|
"unique_id": "veryunique",
|
|
|
|
}
|
|
|
|
await help_test_entity_device_info_remove(hass, mqtt_mock, lock.DOMAIN, config)
|
|
|
|
|
|
|
|
|
2019-01-14 21:01:42 +01:00
|
|
|
async def test_entity_id_update(hass, mqtt_mock):
|
|
|
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
2020-03-09 17:40:00 +01:00
|
|
|
config = {
|
|
|
|
lock.DOMAIN: [
|
|
|
|
{
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "beer",
|
|
|
|
"state_topic": "test-topic",
|
|
|
|
"command_topic": "command-topic",
|
|
|
|
"availability_topic": "avty-topic",
|
|
|
|
"unique_id": "TOTALLY_UNIQUE",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
await help_test_entity_id_update(hass, mqtt_mock, lock.DOMAIN, config)
|