diff --git a/homeassistant/components/mqtt/__init__.py b/homeassistant/components/mqtt/__init__.py index 8852ae76e08..ed2a3cd6c52 100644 --- a/homeassistant/components/mqtt/__init__.py +++ b/homeassistant/components/mqtt/__init__.py @@ -234,7 +234,7 @@ MQTT_JSON_ATTRS_SCHEMA = vol.Schema({ vol.Optional(CONF_JSON_ATTRS_TOPIC): valid_subscribe_topic, }) -MQTT_BASE_PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend(SCHEMA_BASE) +MQTT_BASE_PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA_2.extend(SCHEMA_BASE) # Sensor type platforms subscribe to MQTT events MQTT_RO_PLATFORM_SCHEMA = MQTT_BASE_PLATFORM_SCHEMA.extend({ @@ -985,6 +985,7 @@ class MqttDiscoveryUpdate(Entity): elif self._discovery_update: # Non-empty payload: Notify component _LOGGER.info("Updating component: %s", self.entity_id) + payload.pop(ATTR_DISCOVERY_HASH) self.hass.async_create_task(self._discovery_update(payload)) if self._discovery_hash: diff --git a/homeassistant/components/mqtt/alarm_control_panel.py b/homeassistant/components/mqtt/alarm_control_panel.py index 6bb864f2cdb..b3e4d452b5c 100644 --- a/homeassistant/components/mqtt/alarm_control_panel.py +++ b/homeassistant/components/mqtt/alarm_control_panel.py @@ -40,6 +40,7 @@ DEPENDENCIES = ['mqtt'] PLATFORM_SCHEMA = mqtt.MQTT_BASE_PLATFORM_SCHEMA.extend({ vol.Required(CONF_COMMAND_TOPIC): mqtt.valid_publish_topic, + vol.Optional(CONF_RETAIN, default=mqtt.DEFAULT_RETAIN): cv.boolean, vol.Required(CONF_STATE_TOPIC): mqtt.valid_subscribe_topic, vol.Optional(CONF_CODE): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, @@ -63,7 +64,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async def async_discover(discovery_payload): """Discover and add an MQTT alarm control panel.""" try: - discovery_hash = discovery_payload[ATTR_DISCOVERY_HASH] + discovery_hash = discovery_payload.pop(ATTR_DISCOVERY_HASH) config = PLATFORM_SCHEMA(discovery_payload) await _async_setup_entity(config, async_add_entities, config_entry, discovery_hash) diff --git a/homeassistant/components/mqtt/binary_sensor.py b/homeassistant/components/mqtt/binary_sensor.py index 297d4436c7c..cb93712776c 100644 --- a/homeassistant/components/mqtt/binary_sensor.py +++ b/homeassistant/components/mqtt/binary_sensor.py @@ -63,7 +63,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async def async_discover(discovery_payload): """Discover and add a MQTT binary sensor.""" try: - discovery_hash = discovery_payload[ATTR_DISCOVERY_HASH] + discovery_hash = discovery_payload.pop(ATTR_DISCOVERY_HASH) config = PLATFORM_SCHEMA(discovery_payload) await _async_setup_entity(config, async_add_entities, config_entry, discovery_hash) diff --git a/homeassistant/components/mqtt/cover.py b/homeassistant/components/mqtt/cover.py index 26d10e85a34..75fae0e9c15 100644 --- a/homeassistant/components/mqtt/cover.py +++ b/homeassistant/components/mqtt/cover.py @@ -135,7 +135,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async def async_discover(discovery_payload): """Discover and add an MQTT cover.""" try: - discovery_hash = discovery_payload[ATTR_DISCOVERY_HASH] + discovery_hash = discovery_payload.pop(ATTR_DISCOVERY_HASH) config = PLATFORM_SCHEMA(discovery_payload) await _async_setup_entity(config, async_add_entities, config_entry, discovery_hash) diff --git a/homeassistant/components/mqtt/discovery.py b/homeassistant/components/mqtt/discovery.py index 693a1a4d41d..9a2daf388cb 100644 --- a/homeassistant/components/mqtt/discovery.py +++ b/homeassistant/components/mqtt/discovery.py @@ -216,8 +216,8 @@ async def async_start(hass: HomeAssistantType, discovery_topic, hass_config, key = ABBREVIATIONS.get(key, key) payload[key] = payload.pop(abbreviated_key) - if TOPIC_BASE in payload: - base = payload[TOPIC_BASE] + base = payload.pop(TOPIC_BASE, None) + if base: for key, value in payload.items(): if isinstance(value, str) and value: if value[0] == TOPIC_BASE and key.endswith('_topic'): diff --git a/homeassistant/components/mqtt/fan.py b/homeassistant/components/mqtt/fan.py index 1d1258993de..d15b236038e 100644 --- a/homeassistant/components/mqtt/fan.py +++ b/homeassistant/components/mqtt/fan.py @@ -93,7 +93,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async def async_discover(discovery_payload): """Discover and add a MQTT fan.""" try: - discovery_hash = discovery_payload[ATTR_DISCOVERY_HASH] + discovery_hash = discovery_payload.pop(ATTR_DISCOVERY_HASH) config = PLATFORM_SCHEMA(discovery_payload) await _async_setup_entity(config, async_add_entities, config_entry, discovery_hash) diff --git a/homeassistant/components/mqtt/light/__init__.py b/homeassistant/components/mqtt/light/__init__.py index 908ad1ac989..4ff6efb8643 100644 --- a/homeassistant/components/mqtt/light/__init__.py +++ b/homeassistant/components/mqtt/light/__init__.py @@ -15,10 +15,6 @@ from homeassistant.components.mqtt.discovery import ( from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.typing import HomeAssistantType, ConfigType -from . import schema_basic -from . import schema_json -from . import schema_template - _LOGGER = logging.getLogger(__name__) DEPENDENCIES = ['mqtt'] @@ -28,6 +24,10 @@ CONF_SCHEMA = 'schema' def validate_mqtt_light(value): """Validate MQTT light schema.""" + from . import schema_basic + from . import schema_json + from . import schema_template + schemas = { 'basic': schema_basic.PLATFORM_SCHEMA_BASIC, 'json': schema_json.PLATFORM_SCHEMA_JSON, @@ -36,9 +36,12 @@ def validate_mqtt_light(value): return schemas[value[CONF_SCHEMA]](value) -PLATFORM_SCHEMA = vol.All(vol.Schema({ +MQTT_LIGHT_SCHEMA_SCHEMA = vol.Schema({ vol.Optional(CONF_SCHEMA, default='basic'): vol.All( vol.Lower, vol.Any('basic', 'json', 'template')) +}) + +PLATFORM_SCHEMA = vol.All(MQTT_LIGHT_SCHEMA_SCHEMA.extend({ }, extra=vol.ALLOW_EXTRA), validate_mqtt_light) @@ -53,7 +56,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async def async_discover(discovery_payload): """Discover and add a MQTT light.""" try: - discovery_hash = discovery_payload[ATTR_DISCOVERY_HASH] + discovery_hash = discovery_payload.pop(ATTR_DISCOVERY_HASH) config = PLATFORM_SCHEMA(discovery_payload) await _async_setup_entity(config, async_add_entities, config_entry, discovery_hash) @@ -70,6 +73,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async def _async_setup_entity(config, async_add_entities, config_entry=None, discovery_hash=None): """Set up a MQTT Light.""" + from . import schema_basic + from . import schema_json + from . import schema_template + setup_entity = { 'basic': schema_basic.async_setup_entity_basic, 'json': schema_json.async_setup_entity_json, diff --git a/homeassistant/components/mqtt/light/schema_basic.py b/homeassistant/components/mqtt/light/schema_basic.py index 0ba1db890d7..4aee026a2f6 100644 --- a/homeassistant/components/mqtt/light/schema_basic.py +++ b/homeassistant/components/mqtt/light/schema_basic.py @@ -26,6 +26,8 @@ from homeassistant.helpers.restore_state import RestoreEntity import homeassistant.helpers.config_validation as cv import homeassistant.util.color as color_util +from . import MQTT_LIGHT_SCHEMA_SCHEMA + _LOGGER = logging.getLogger(__name__) DEPENDENCIES = ['mqtt'] @@ -108,7 +110,7 @@ PLATFORM_SCHEMA_BASIC = mqtt.MQTT_RW_PLATFORM_SCHEMA.extend({ vol.In(VALUES_ON_COMMAND_TYPE), vol.Optional(CONF_DEVICE): mqtt.MQTT_ENTITY_DEVICE_INFO_SCHEMA, }).extend(mqtt.MQTT_AVAILABILITY_SCHEMA.schema).extend( - mqtt.MQTT_JSON_ATTRS_SCHEMA.schema) + mqtt.MQTT_JSON_ATTRS_SCHEMA.schema).extend(MQTT_LIGHT_SCHEMA_SCHEMA.schema) async def async_setup_entity_basic(config, async_add_entities, config_entry, diff --git a/homeassistant/components/mqtt/light/schema_json.py b/homeassistant/components/mqtt/light/schema_json.py index 4b1a1cff3ff..4a97eeea520 100644 --- a/homeassistant/components/mqtt/light/schema_json.py +++ b/homeassistant/components/mqtt/light/schema_json.py @@ -28,6 +28,7 @@ from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.typing import ConfigType import homeassistant.util.color as color_util +from . import MQTT_LIGHT_SCHEMA_SCHEMA from .schema_basic import CONF_BRIGHTNESS_SCALE _LOGGER = logging.getLogger(__name__) @@ -81,7 +82,7 @@ PLATFORM_SCHEMA_JSON = mqtt.MQTT_RW_PLATFORM_SCHEMA.extend({ vol.Required(CONF_COMMAND_TOPIC): mqtt.valid_publish_topic, vol.Optional(CONF_DEVICE): mqtt.MQTT_ENTITY_DEVICE_INFO_SCHEMA, }).extend(mqtt.MQTT_AVAILABILITY_SCHEMA.schema).extend( - mqtt.MQTT_JSON_ATTRS_SCHEMA.schema) + mqtt.MQTT_JSON_ATTRS_SCHEMA.schema).extend(MQTT_LIGHT_SCHEMA_SCHEMA.schema) async def async_setup_entity_json(config: ConfigType, async_add_entities, diff --git a/homeassistant/components/mqtt/light/schema_template.py b/homeassistant/components/mqtt/light/schema_template.py index 9b8e57c1d2a..4d086fd73e1 100644 --- a/homeassistant/components/mqtt/light/schema_template.py +++ b/homeassistant/components/mqtt/light/schema_template.py @@ -24,6 +24,8 @@ import homeassistant.helpers.config_validation as cv import homeassistant.util.color as color_util from homeassistant.helpers.restore_state import RestoreEntity +from . import MQTT_LIGHT_SCHEMA_SCHEMA + _LOGGER = logging.getLogger(__name__) DOMAIN = 'mqtt_template' @@ -67,7 +69,7 @@ PLATFORM_SCHEMA_TEMPLATE = mqtt.MQTT_RW_PLATFORM_SCHEMA.extend({ vol.Optional(CONF_UNIQUE_ID): cv.string, vol.Optional(CONF_DEVICE): mqtt.MQTT_ENTITY_DEVICE_INFO_SCHEMA, }).extend(mqtt.MQTT_AVAILABILITY_SCHEMA.schema).extend( - mqtt.MQTT_JSON_ATTRS_SCHEMA.schema) + mqtt.MQTT_JSON_ATTRS_SCHEMA.schema).extend(MQTT_LIGHT_SCHEMA_SCHEMA.schema) async def async_setup_entity_template(config, async_add_entities, config_entry, diff --git a/homeassistant/components/mqtt/lock.py b/homeassistant/components/mqtt/lock.py index da872fda612..82462b8171f 100644 --- a/homeassistant/components/mqtt/lock.py +++ b/homeassistant/components/mqtt/lock.py @@ -58,7 +58,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async def async_discover(discovery_payload): """Discover and add an MQTT lock.""" try: - discovery_hash = discovery_payload[ATTR_DISCOVERY_HASH] + discovery_hash = discovery_payload.pop(ATTR_DISCOVERY_HASH) config = PLATFORM_SCHEMA(discovery_payload) await _async_setup_entity(config, async_add_entities, config_entry, discovery_hash) diff --git a/homeassistant/components/mqtt/sensor.py b/homeassistant/components/mqtt/sensor.py index 9637caa9053..02a4de9cad4 100644 --- a/homeassistant/components/mqtt/sensor.py +++ b/homeassistant/components/mqtt/sensor.py @@ -66,7 +66,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async def async_discover_sensor(discovery_payload): """Discover and add a discovered MQTT sensor.""" try: - discovery_hash = discovery_payload[ATTR_DISCOVERY_HASH] + discovery_hash = discovery_payload.pop(ATTR_DISCOVERY_HASH) config = PLATFORM_SCHEMA(discovery_payload) await _async_setup_entity(config, async_add_entities, config_entry, discovery_hash) diff --git a/homeassistant/components/mqtt/switch.py b/homeassistant/components/mqtt/switch.py index 56fc1a51206..c9f8c880573 100644 --- a/homeassistant/components/mqtt/switch.py +++ b/homeassistant/components/mqtt/switch.py @@ -62,7 +62,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async def async_discover(discovery_payload): """Discover and add a MQTT switch.""" try: - discovery_hash = discovery_payload[ATTR_DISCOVERY_HASH] + discovery_hash = discovery_payload.pop(ATTR_DISCOVERY_HASH) config = PLATFORM_SCHEMA(discovery_payload) await _async_setup_entity(config, async_add_entities, config_entry, discovery_hash) diff --git a/homeassistant/components/mqtt/vacuum.py b/homeassistant/components/mqtt/vacuum.py index 90cca62da38..3d53f32c6f6 100644 --- a/homeassistant/components/mqtt/vacuum.py +++ b/homeassistant/components/mqtt/vacuum.py @@ -162,7 +162,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async def async_discover(discovery_payload): """Discover and add a MQTT vacuum.""" try: - discovery_hash = discovery_payload[ATTR_DISCOVERY_HASH] + discovery_hash = discovery_payload.pop(ATTR_DISCOVERY_HASH) config = PLATFORM_SCHEMA(discovery_payload) await _async_setup_entity(config, async_add_entities, config_entry, discovery_hash) diff --git a/tests/components/mqtt/test_alarm_control_panel.py b/tests/components/mqtt/test_alarm_control_panel.py index 0bcb29ec9c6..572cbdb0e10 100644 --- a/tests/components/mqtt/test_alarm_control_panel.py +++ b/tests/components/mqtt/test_alarm_control_panel.py @@ -379,7 +379,7 @@ async def test_discovery_removal_alarm(hass, mqtt_mock, caplog): data = ( '{ "name": "Beer",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) @@ -409,12 +409,12 @@ async def test_discovery_update_alarm(hass, mqtt_mock, caplog): data1 = ( '{ "name": "Beer",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) data2 = ( '{ "name": "Milk",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) @@ -451,7 +451,7 @@ async def test_discovery_broken(hass, mqtt_mock, caplog): ) data2 = ( '{ "name": "Milk",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) diff --git a/tests/components/mqtt/test_binary_sensor.py b/tests/components/mqtt/test_binary_sensor.py index 2f8a87b8a9b..3e6e36cd050 100644 --- a/tests/components/mqtt/test_binary_sensor.py +++ b/tests/components/mqtt/test_binary_sensor.py @@ -344,12 +344,12 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog): await async_start(hass, 'homeassistant', {}, entry) data1 = ( '{ "name": "Beer",' - ' "command_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "json_attributes_topic": "attr-topic1" }' ) data2 = ( '{ "name": "Beer",' - ' "command_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "json_attributes_topic": "attr-topic2" }' ) async_fire_mqtt_message(hass, 'homeassistant/binary_sensor/bla/config', @@ -540,7 +540,6 @@ async def test_entity_device_info_update(hass, mqtt_mock): 'platform': 'mqtt', 'name': 'Test 1', 'state_topic': 'test-topic', - 'command_topic': 'test-command-topic', 'device': { 'identifiers': ['helloworld'], 'connections': [ diff --git a/tests/components/mqtt/test_light.py b/tests/components/mqtt/test_light.py index f501f97331e..cfb0d75d1c7 100644 --- a/tests/components/mqtt/test_light.py +++ b/tests/components/mqtt/test_light.py @@ -1177,13 +1177,13 @@ async def test_unique_id(hass): light.DOMAIN: [{ 'platform': 'mqtt', 'name': 'Test 1', - 'status_topic': 'test-topic', + 'state_topic': 'test-topic', 'command_topic': 'test_topic', 'unique_id': 'TOTALLY_UNIQUE' }, { 'platform': 'mqtt', 'name': 'Test 2', - 'status_topic': 'test-topic', + 'state_topic': 'test-topic', 'command_topic': 'test_topic', 'unique_id': 'TOTALLY_UNIQUE' }] @@ -1200,7 +1200,7 @@ async def test_discovery_removal_light(hass, mqtt_mock, caplog): data = ( '{ "name": "Beer",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) @@ -1245,12 +1245,12 @@ async def test_discovery_update_light(hass, mqtt_mock, caplog): data1 = ( '{ "name": "Beer",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) data2 = ( '{ "name": "Milk",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) @@ -1284,7 +1284,7 @@ async def test_discovery_broken(hass, mqtt_mock, caplog): ) data2 = ( '{ "name": "Milk",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) diff --git a/tests/components/mqtt/test_light_json.py b/tests/components/mqtt/test_light_json.py index 9533ea5f204..a0ae0ddb2fb 100644 --- a/tests/components/mqtt/test_light_json.py +++ b/tests/components/mqtt/test_light_json.py @@ -649,14 +649,14 @@ async def test_unique_id(hass): 'platform': 'mqtt', 'name': 'Test 1', 'schema': 'json', - 'status_topic': 'test-topic', + 'state_topic': 'test-topic', 'command_topic': 'test_topic', 'unique_id': 'TOTALLY_UNIQUE' }, { 'platform': 'mqtt', 'name': 'Test 2', 'schema': 'json', - 'status_topic': 'test-topic', + 'state_topic': 'test-topic', 'command_topic': 'test_topic', 'unique_id': 'TOTALLY_UNIQUE' }] @@ -714,13 +714,13 @@ async def test_discovery_update_light(hass, mqtt_mock, caplog): data1 = ( '{ "name": "Beer",' ' "schema": "json",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) data2 = ( '{ "name": "Milk",' ' "schema": "json",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) @@ -755,7 +755,7 @@ async def test_discovery_broken(hass, mqtt_mock, caplog): data2 = ( '{ "name": "Milk",' ' "schema": "json",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) diff --git a/tests/components/mqtt/test_light_template.py b/tests/components/mqtt/test_light_template.py index a7147e83b99..2db2bd06aa2 100644 --- a/tests/components/mqtt/test_light_template.py +++ b/tests/components/mqtt/test_light_template.py @@ -265,7 +265,6 @@ async def test_optimistic(hass, mqtt_mock): '{{ blue|d }}', 'command_off_template': 'off', 'effect_list': ['colorloop', 'random'], - 'effect_command_topic': 'test_light_rgb/effect/set', 'qos': 2 } }) @@ -608,7 +607,7 @@ async def test_unique_id(hass): 'platform': 'mqtt', 'name': 'Test 1', 'schema': 'template', - 'status_topic': 'test-topic', + 'state_topic': 'test-topic', 'command_topic': 'test_topic', 'command_on_template': 'on,{{ transition }}', 'command_off_template': 'off,{{ transition|d }}', @@ -617,7 +616,7 @@ async def test_unique_id(hass): 'platform': 'mqtt', 'name': 'Test 2', 'schema': 'template', - 'status_topic': 'test-topic', + 'state_topic': 'test-topic', 'command_topic': 'test_topic', 'unique_id': 'TOTALLY_UNIQUE' }] @@ -679,7 +678,7 @@ async def test_discovery_update_light(hass, mqtt_mock, caplog): data1 = ( '{ "name": "Beer",' ' "schema": "template",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic",' ' "command_on_template": "on",' ' "command_off_template": "off"}' @@ -687,7 +686,7 @@ async def test_discovery_update_light(hass, mqtt_mock, caplog): data2 = ( '{ "name": "Milk",' ' "schema": "template",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic",' ' "command_on_template": "on",' ' "command_off_template": "off"}' @@ -724,7 +723,7 @@ async def test_discovery_broken(hass, mqtt_mock, caplog): data2 = ( '{ "name": "Milk",' ' "schema": "template",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic",' ' "command_on_template": "on",' ' "command_off_template": "off"}' diff --git a/tests/components/mqtt/test_lock.py b/tests/components/mqtt/test_lock.py index c4741445cca..52dd3ecfbdb 100644 --- a/tests/components/mqtt/test_lock.py +++ b/tests/components/mqtt/test_lock.py @@ -246,13 +246,13 @@ async def test_unique_id(hass): lock.DOMAIN: [{ 'platform': 'mqtt', 'name': 'Test 1', - 'status_topic': 'test-topic', + 'state_topic': 'test-topic', 'command_topic': 'test_topic', 'unique_id': 'TOTALLY_UNIQUE' }, { 'platform': 'mqtt', 'name': 'Test 2', - 'status_topic': 'test-topic', + 'state_topic': 'test-topic', 'command_topic': 'test_topic', 'unique_id': 'TOTALLY_UNIQUE' }] diff --git a/tests/components/mqtt/test_sensor.py b/tests/components/mqtt/test_sensor.py index cd637d2aa01..027135e8a7a 100644 --- a/tests/components/mqtt/test_sensor.py +++ b/tests/components/mqtt/test_sensor.py @@ -428,12 +428,12 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog): await async_start(hass, 'homeassistant', {}, entry) data1 = ( '{ "name": "Beer",' - ' "command_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "json_attributes_topic": "attr-topic1" }' ) data2 = ( '{ "name": "Beer",' - ' "command_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "json_attributes_topic": "attr-topic2" }' ) async_fire_mqtt_message(hass, 'homeassistant/sensor/bla/config', @@ -495,7 +495,7 @@ async def test_discovery_removal_sensor(hass, mqtt_mock, caplog): await async_start(hass, 'homeassistant', {}, entry) data = ( '{ "name": "Beer",' - ' "status_topic": "test_topic" }' + ' "state_topic": "test_topic" }' ) async_fire_mqtt_message(hass, 'homeassistant/sensor/bla/config', data) @@ -517,11 +517,11 @@ async def test_discovery_update_sensor(hass, mqtt_mock, caplog): await async_start(hass, 'homeassistant', {}, entry) data1 = ( '{ "name": "Beer",' - ' "status_topic": "test_topic" }' + ' "state_topic": "test_topic" }' ) data2 = ( '{ "name": "Milk",' - ' "status_topic": "test_topic" }' + ' "state_topic": "test_topic" }' ) async_fire_mqtt_message(hass, 'homeassistant/sensor/bla/config', data1) @@ -626,7 +626,6 @@ async def test_entity_device_info_update(hass, mqtt_mock): 'platform': 'mqtt', 'name': 'Test 1', 'state_topic': 'test-topic', - 'command_topic': 'test-command-topic', 'device': { 'identifiers': ['helloworld'], 'connections': [ diff --git a/tests/components/mqtt/test_switch.py b/tests/components/mqtt/test_switch.py index f1956207a55..7917803aa07 100644 --- a/tests/components/mqtt/test_switch.py +++ b/tests/components/mqtt/test_switch.py @@ -392,7 +392,7 @@ async def test_discovery_removal_switch(hass, mqtt_mock, caplog): data = ( '{ "name": "Beer",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) @@ -421,12 +421,12 @@ async def test_discovery_update_switch(hass, mqtt_mock, caplog): data1 = ( '{ "name": "Beer",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) data2 = ( '{ "name": "Milk",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) @@ -460,7 +460,7 @@ async def test_discovery_broken(hass, mqtt_mock, caplog): ) data2 = ( '{ "name": "Milk",' - ' "status_topic": "test_topic",' + ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' )