From a9990c130dc613d83a63128375767458e52f4937 Mon Sep 17 00:00:00 2001 From: emontnemery Date: Fri, 30 Nov 2018 13:57:17 +0100 Subject: [PATCH] Revert change to MQTT discovery_hash introduced in #18169 (#18763) --- homeassistant/components/mqtt/discovery.py | 7 ++--- tests/components/binary_sensor/test_mqtt.py | 33 --------------------- 2 files changed, 2 insertions(+), 38 deletions(-) diff --git a/homeassistant/components/mqtt/discovery.py b/homeassistant/components/mqtt/discovery.py index 9ea3151c65c..8d5f28278d9 100644 --- a/homeassistant/components/mqtt/discovery.py +++ b/homeassistant/components/mqtt/discovery.py @@ -202,11 +202,8 @@ async def async_start(hass: HomeAssistantType, discovery_topic, hass_config, if value[-1] == TOPIC_BASE and key.endswith('_topic'): payload[key] = "{}{}".format(value[:-1], base) - # If present, unique_id is used as the discovered object id. Otherwise, - # if present, the node_id will be included in the discovered object id - discovery_id = payload.get( - 'unique_id', ' '.join( - (node_id, object_id)) if node_id else object_id) + # If present, the node_id will be included in the discovered object id + discovery_id = ' '.join((node_id, object_id)) if node_id else object_id discovery_hash = (component, discovery_id) if payload: diff --git a/tests/components/binary_sensor/test_mqtt.py b/tests/components/binary_sensor/test_mqtt.py index 88bd39ebfe2..71d179211a2 100644 --- a/tests/components/binary_sensor/test_mqtt.py +++ b/tests/components/binary_sensor/test_mqtt.py @@ -333,39 +333,6 @@ async def test_discovery_update_binary_sensor(hass, mqtt_mock, caplog): assert state is None -async def test_discovery_unique_id(hass, mqtt_mock, caplog): - """Test unique id option only creates one sensor per unique_id.""" - entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, 'homeassistant', {}, entry) - data1 = ( - '{ "name": "Beer",' - ' "state_topic": "test_topic",' - ' "unique_id": "TOTALLY_UNIQUE" }' - ) - data2 = ( - '{ "name": "Milk",' - ' "state_topic": "test_topic",' - ' "unique_id": "TOTALLY_DIFFERENT" }' - ) - async_fire_mqtt_message(hass, 'homeassistant/binary_sensor/bla/config', - data1) - await hass.async_block_till_done() - state = hass.states.get('binary_sensor.beer') - assert state is not None - assert state.name == 'Beer' - async_fire_mqtt_message(hass, 'homeassistant/binary_sensor/bla/config', - data2) - await hass.async_block_till_done() - await hass.async_block_till_done() - state = hass.states.get('binary_sensor.beer') - assert state is not None - assert state.name == 'Beer' - - state = hass.states.get('binary_sensor.milk') - assert state is not None - assert state.name == 'Milk' - - async def test_entity_device_info_with_identifier(hass, mqtt_mock): """Test MQTT binary sensor device registry integration.""" entry = MockConfigEntry(domain=mqtt.DOMAIN)