Fix change of entity_id for discovered MQTT entities (#33444)
parent
531207e005
commit
9508c51403
|
@ -56,7 +56,7 @@ from .const import (
|
|||
DEFAULT_QOS,
|
||||
PROTOCOL_311,
|
||||
)
|
||||
from .discovery import MQTT_DISCOVERY_UPDATED, clear_discovery_hash
|
||||
from .discovery import MQTT_DISCOVERY_UPDATED, clear_discovery_hash, set_discovery_hash
|
||||
from .models import Message, MessageCallbackType, PublishPayloadType
|
||||
from .subscription import async_subscribe_topics, async_unsubscribe_topics
|
||||
|
||||
|
@ -1181,10 +1181,12 @@ class MqttDiscoveryUpdate(Entity):
|
|||
self._discovery_data = discovery_data
|
||||
self._discovery_update = discovery_update
|
||||
self._remove_signal = None
|
||||
self._removed_from_hass = False
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Subscribe to discovery updates."""
|
||||
await super().async_added_to_hass()
|
||||
self._removed_from_hass = False
|
||||
discovery_hash = (
|
||||
self._discovery_data[ATTR_DISCOVERY_HASH] if self._discovery_data else None
|
||||
)
|
||||
|
@ -1217,6 +1219,8 @@ class MqttDiscoveryUpdate(Entity):
|
|||
await self._discovery_update(payload)
|
||||
|
||||
if discovery_hash:
|
||||
# Set in case the entity has been removed and is re-added
|
||||
set_discovery_hash(self.hass, discovery_hash)
|
||||
self._remove_signal = async_dispatcher_connect(
|
||||
self.hass,
|
||||
MQTT_DISCOVERY_UPDATED.format(discovery_hash),
|
||||
|
@ -1225,7 +1229,7 @@ class MqttDiscoveryUpdate(Entity):
|
|||
|
||||
async def async_removed_from_registry(self) -> None:
|
||||
"""Clear retained discovery topic in broker."""
|
||||
if self._discovery_data:
|
||||
if not self._removed_from_hass:
|
||||
discovery_topic = self._discovery_data[ATTR_DISCOVERY_TOPIC]
|
||||
publish(
|
||||
self.hass, discovery_topic, "", retain=True,
|
||||
|
@ -1237,9 +1241,9 @@ class MqttDiscoveryUpdate(Entity):
|
|||
|
||||
def _cleanup_on_remove(self) -> None:
|
||||
"""Stop listening to signal and cleanup discovery data."""
|
||||
if self._discovery_data:
|
||||
if self._discovery_data and not self._removed_from_hass:
|
||||
clear_discovery_hash(self.hass, self._discovery_data[ATTR_DISCOVERY_HASH])
|
||||
self._discovery_data = None
|
||||
self._removed_from_hass = True
|
||||
|
||||
if self._remove_signal:
|
||||
self._remove_signal()
|
||||
|
|
|
@ -64,6 +64,11 @@ def clear_discovery_hash(hass, discovery_hash):
|
|||
del hass.data[ALREADY_DISCOVERED][discovery_hash]
|
||||
|
||||
|
||||
def set_discovery_hash(hass, discovery_hash):
|
||||
"""Clear entry in ALREADY_DISCOVERED list."""
|
||||
hass.data[ALREADY_DISCOVERED][discovery_hash] = {}
|
||||
|
||||
|
||||
class MQTTConfig(dict):
|
||||
"""Dummy class to allow adding attributes."""
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ from homeassistant.const import (
|
|||
STATE_UNKNOWN,
|
||||
)
|
||||
|
||||
from .common import (
|
||||
from .test_common import (
|
||||
help_test_availability_without_topic,
|
||||
help_test_custom_availability_payload,
|
||||
help_test_default_availability_payload,
|
||||
|
@ -25,7 +25,8 @@ from .common import (
|
|||
help_test_entity_device_info_update,
|
||||
help_test_entity_device_info_with_connection,
|
||||
help_test_entity_device_info_with_identifier,
|
||||
help_test_entity_id_update,
|
||||
help_test_entity_id_update_discovery_update,
|
||||
help_test_entity_id_update_subscriptions,
|
||||
help_test_setting_attribute_via_mqtt_json_message,
|
||||
help_test_setting_attribute_with_template,
|
||||
help_test_unique_id,
|
||||
|
@ -481,8 +482,15 @@ async def test_entity_device_info_remove(hass, mqtt_mock):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update(hass, mqtt_mock):
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock):
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update(
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock, alarm_control_panel.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock, alarm_control_panel.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
|
|
@ -15,7 +15,7 @@ import homeassistant.core as ha
|
|||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from .common import (
|
||||
from .test_common import (
|
||||
help_test_availability_without_topic,
|
||||
help_test_custom_availability_payload,
|
||||
help_test_default_availability_payload,
|
||||
|
@ -27,7 +27,8 @@ from .common import (
|
|||
help_test_entity_device_info_update,
|
||||
help_test_entity_device_info_with_connection,
|
||||
help_test_entity_device_info_with_identifier,
|
||||
help_test_entity_id_update,
|
||||
help_test_entity_id_update_discovery_update,
|
||||
help_test_entity_id_update_subscriptions,
|
||||
help_test_setting_attribute_via_mqtt_json_message,
|
||||
help_test_setting_attribute_with_template,
|
||||
help_test_unique_id,
|
||||
|
@ -495,8 +496,15 @@ async def test_entity_device_info_remove(hass, mqtt_mock):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update(hass, mqtt_mock):
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock):
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update(
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
|
|
@ -5,7 +5,7 @@ from homeassistant.components import camera, mqtt
|
|||
from homeassistant.components.mqtt.discovery import async_start
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import (
|
||||
from .test_common import (
|
||||
help_test_availability_without_topic,
|
||||
help_test_custom_availability_payload,
|
||||
help_test_default_availability_payload,
|
||||
|
@ -17,7 +17,8 @@ from .common import (
|
|||
help_test_entity_device_info_update,
|
||||
help_test_entity_device_info_with_connection,
|
||||
help_test_entity_device_info_with_identifier,
|
||||
help_test_entity_id_update,
|
||||
help_test_entity_id_update_discovery_update,
|
||||
help_test_entity_id_update_subscriptions,
|
||||
help_test_setting_attribute_via_mqtt_json_message,
|
||||
help_test_setting_attribute_with_template,
|
||||
help_test_unique_id,
|
||||
|
@ -194,8 +195,15 @@ async def test_entity_device_info_remove(hass, mqtt_mock):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update(hass, mqtt_mock):
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock):
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update(
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock, camera.DOMAIN, DEFAULT_CONFIG, ["test_topic"]
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock, camera.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
|
|
@ -25,7 +25,7 @@ from homeassistant.components.climate.const import (
|
|||
)
|
||||
from homeassistant.const import STATE_OFF
|
||||
|
||||
from .common import (
|
||||
from .test_common import (
|
||||
help_test_availability_without_topic,
|
||||
help_test_custom_availability_payload,
|
||||
help_test_default_availability_payload,
|
||||
|
@ -37,7 +37,8 @@ from .common import (
|
|||
help_test_entity_device_info_update,
|
||||
help_test_entity_device_info_with_connection,
|
||||
help_test_entity_device_info_with_identifier,
|
||||
help_test_entity_id_update,
|
||||
help_test_entity_id_update_discovery_update,
|
||||
help_test_entity_id_update_subscriptions,
|
||||
help_test_setting_attribute_via_mqtt_json_message,
|
||||
help_test_setting_attribute_with_template,
|
||||
help_test_unique_id,
|
||||
|
@ -885,7 +886,7 @@ async def test_entity_device_info_remove(hass, mqtt_mock):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update(hass, mqtt_mock):
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock):
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
config = {
|
||||
CLIMATE_DOMAIN: {
|
||||
|
@ -895,11 +896,18 @@ async def test_entity_id_update(hass, mqtt_mock):
|
|||
"availability_topic": "avty-topic",
|
||||
}
|
||||
}
|
||||
await help_test_entity_id_update(
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock, CLIMATE_DOMAIN, config, ["test-topic", "avty-topic"]
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_precision_default(hass, mqtt_mock):
|
||||
"""Test that setting precision to tenths works as intended."""
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
||||
|
|
|
@ -440,7 +440,9 @@ async def help_test_entity_device_info_update(hass, mqtt_mock, domain, config):
|
|||
assert device.name == "Milk"
|
||||
|
||||
|
||||
async def help_test_entity_id_update(hass, mqtt_mock, domain, config, topics=None):
|
||||
async def help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock, domain, config, topics=None
|
||||
):
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
# Add unique_id to config
|
||||
config = copy.deepcopy(config)
|
||||
|
@ -473,3 +475,47 @@ async def help_test_entity_id_update(hass, mqtt_mock, domain, config, topics=Non
|
|||
assert state is not None
|
||||
for topic in topics:
|
||||
mock_mqtt.async_subscribe.assert_any_call(topic, ANY, ANY, ANY)
|
||||
|
||||
|
||||
async def help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock, domain, config, topic=None
|
||||
):
|
||||
"""Test MQTT discovery update after entity_id is updated."""
|
||||
# Add unique_id to config
|
||||
config = copy.deepcopy(config)
|
||||
config[domain]["unique_id"] = "TOTALLY_UNIQUE"
|
||||
|
||||
if topic is None:
|
||||
# Add default topic to config
|
||||
config[domain]["availability_topic"] = "avty-topic"
|
||||
topic = "avty-topic"
|
||||
|
||||
entry = MockConfigEntry(domain=mqtt.DOMAIN)
|
||||
entry.add_to_hass(hass)
|
||||
await async_start(hass, "homeassistant", {}, entry)
|
||||
ent_registry = mock_registry(hass, {})
|
||||
|
||||
data = json.dumps(config[domain])
|
||||
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
async_fire_mqtt_message(hass, topic, "online")
|
||||
state = hass.states.get(f"{domain}.test")
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, topic, "offline")
|
||||
state = hass.states.get(f"{domain}.test")
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
ent_registry.async_update_entity(f"{domain}.test", new_entity_id=f"{domain}.milk")
|
||||
await hass.async_block_till_done()
|
||||
|
||||
config[domain]["availability_topic"] = f"{topic}_2"
|
||||
data = json.dumps(config[domain])
|
||||
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data)
|
||||
await hass.async_block_till_done()
|
||||
assert len(hass.states.async_entity_ids(domain)) == 1
|
||||
|
||||
async_fire_mqtt_message(hass, f"{topic}_2", "online")
|
||||
state = hass.states.get(f"{domain}.milk")
|
||||
assert state.state != STATE_UNAVAILABLE
|
|
@ -22,7 +22,7 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import (
|
||||
from .test_common import (
|
||||
help_test_availability_without_topic,
|
||||
help_test_custom_availability_payload,
|
||||
help_test_default_availability_payload,
|
||||
|
@ -34,7 +34,8 @@ from .common import (
|
|||
help_test_entity_device_info_update,
|
||||
help_test_entity_device_info_with_connection,
|
||||
help_test_entity_device_info_with_identifier,
|
||||
help_test_entity_id_update,
|
||||
help_test_entity_id_update_discovery_update,
|
||||
help_test_entity_id_update_subscriptions,
|
||||
help_test_setting_attribute_via_mqtt_json_message,
|
||||
help_test_setting_attribute_with_template,
|
||||
help_test_unique_id,
|
||||
|
@ -1749,6 +1750,15 @@ async def test_entity_device_info_remove(hass, mqtt_mock):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update(hass, mqtt_mock):
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock):
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update(hass, mqtt_mock, cover.DOMAIN, DEFAULT_CONFIG)
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock, cover.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock, cover.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
|
|
@ -3,7 +3,7 @@ from homeassistant.components import fan
|
|||
from homeassistant.const import ATTR_ASSUMED_STATE, STATE_OFF, STATE_ON
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import (
|
||||
from .test_common import (
|
||||
help_test_availability_without_topic,
|
||||
help_test_custom_availability_payload,
|
||||
help_test_default_availability_payload,
|
||||
|
@ -15,7 +15,8 @@ from .common import (
|
|||
help_test_entity_device_info_update,
|
||||
help_test_entity_device_info_with_connection,
|
||||
help_test_entity_device_info_with_identifier,
|
||||
help_test_entity_id_update,
|
||||
help_test_entity_id_update_discovery_update,
|
||||
help_test_entity_id_update_subscriptions,
|
||||
help_test_setting_attribute_via_mqtt_json_message,
|
||||
help_test_setting_attribute_with_template,
|
||||
help_test_unique_id,
|
||||
|
@ -496,6 +497,15 @@ async def test_entity_device_info_remove(hass, mqtt_mock):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update(hass, mqtt_mock):
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock):
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update(hass, mqtt_mock, fan.DOMAIN, DEFAULT_CONFIG)
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock, fan.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock, fan.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
|
|
@ -19,7 +19,7 @@ from homeassistant.components.vacuum import (
|
|||
from homeassistant.const import CONF_NAME, CONF_PLATFORM, STATE_OFF, STATE_ON
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import (
|
||||
from .test_common import (
|
||||
help_test_availability_without_topic,
|
||||
help_test_custom_availability_payload,
|
||||
help_test_default_availability_payload,
|
||||
|
@ -31,7 +31,8 @@ from .common import (
|
|||
help_test_entity_device_info_update,
|
||||
help_test_entity_device_info_with_connection,
|
||||
help_test_entity_device_info_with_identifier,
|
||||
help_test_entity_id_update,
|
||||
help_test_entity_id_update_discovery_update,
|
||||
help_test_entity_id_update_subscriptions,
|
||||
help_test_setting_attribute_via_mqtt_json_message,
|
||||
help_test_setting_attribute_with_template,
|
||||
help_test_unique_id,
|
||||
|
@ -606,7 +607,7 @@ async def test_entity_device_info_remove(hass, mqtt_mock):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update(hass, mqtt_mock):
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock):
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
config = {
|
||||
vacuum.DOMAIN: {
|
||||
|
@ -618,6 +619,13 @@ async def test_entity_id_update(hass, mqtt_mock):
|
|||
"availability_topic": "avty-topic",
|
||||
}
|
||||
}
|
||||
await help_test_entity_id_update(
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock, vacuum.DOMAIN, config, ["test-topic", "avty-topic"]
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
|
|
@ -162,7 +162,7 @@ from homeassistant.const import ATTR_ASSUMED_STATE, STATE_OFF, STATE_ON
|
|||
import homeassistant.core as ha
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import (
|
||||
from .test_common import (
|
||||
help_test_availability_without_topic,
|
||||
help_test_custom_availability_payload,
|
||||
help_test_default_availability_payload,
|
||||
|
@ -174,7 +174,8 @@ from .common import (
|
|||
help_test_entity_device_info_update,
|
||||
help_test_entity_device_info_with_connection,
|
||||
help_test_entity_device_info_with_identifier,
|
||||
help_test_entity_id_update,
|
||||
help_test_entity_id_update_discovery_update,
|
||||
help_test_entity_id_update_subscriptions,
|
||||
help_test_setting_attribute_via_mqtt_json_message,
|
||||
help_test_setting_attribute_with_template,
|
||||
help_test_unique_id,
|
||||
|
@ -1345,6 +1346,15 @@ async def test_entity_device_info_remove(hass, mqtt_mock):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update(hass, mqtt_mock):
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock):
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update(hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG)
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
|
|
@ -101,7 +101,7 @@ from homeassistant.const import (
|
|||
import homeassistant.core as ha
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import (
|
||||
from .test_common import (
|
||||
help_test_availability_without_topic,
|
||||
help_test_custom_availability_payload,
|
||||
help_test_default_availability_payload,
|
||||
|
@ -113,7 +113,8 @@ from .common import (
|
|||
help_test_entity_device_info_update,
|
||||
help_test_entity_device_info_with_connection,
|
||||
help_test_entity_device_info_with_identifier,
|
||||
help_test_entity_id_update,
|
||||
help_test_entity_id_update_discovery_update,
|
||||
help_test_entity_id_update_subscriptions,
|
||||
help_test_setting_attribute_via_mqtt_json_message,
|
||||
help_test_setting_attribute_with_template,
|
||||
help_test_unique_id,
|
||||
|
@ -1121,6 +1122,15 @@ async def test_entity_device_info_remove(hass, mqtt_mock):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update(hass, mqtt_mock):
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock):
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update(hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG)
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
|
|
@ -38,7 +38,7 @@ from homeassistant.const import (
|
|||
import homeassistant.core as ha
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import (
|
||||
from .test_common import (
|
||||
help_test_availability_without_topic,
|
||||
help_test_custom_availability_payload,
|
||||
help_test_default_availability_payload,
|
||||
|
@ -50,7 +50,8 @@ from .common import (
|
|||
help_test_entity_device_info_update,
|
||||
help_test_entity_device_info_with_connection,
|
||||
help_test_entity_device_info_with_identifier,
|
||||
help_test_entity_id_update,
|
||||
help_test_entity_id_update_discovery_update,
|
||||
help_test_entity_id_update_subscriptions,
|
||||
help_test_setting_attribute_via_mqtt_json_message,
|
||||
help_test_setting_attribute_with_template,
|
||||
help_test_unique_id,
|
||||
|
@ -944,6 +945,15 @@ async def test_entity_device_info_remove(hass, mqtt_mock):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update(hass, mqtt_mock):
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock):
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update(hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG)
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
|
|
@ -3,7 +3,7 @@ from homeassistant.components import lock
|
|||
from homeassistant.const import ATTR_ASSUMED_STATE, STATE_LOCKED, STATE_UNLOCKED
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import (
|
||||
from .test_common import (
|
||||
help_test_availability_without_topic,
|
||||
help_test_custom_availability_payload,
|
||||
help_test_default_availability_payload,
|
||||
|
@ -15,7 +15,8 @@ from .common import (
|
|||
help_test_entity_device_info_update,
|
||||
help_test_entity_device_info_with_connection,
|
||||
help_test_entity_device_info_with_identifier,
|
||||
help_test_entity_id_update,
|
||||
help_test_entity_id_update_discovery_update,
|
||||
help_test_entity_id_update_subscriptions,
|
||||
help_test_setting_attribute_via_mqtt_json_message,
|
||||
help_test_setting_attribute_with_template,
|
||||
help_test_unique_id,
|
||||
|
@ -386,6 +387,15 @@ async def test_entity_device_info_remove(hass, mqtt_mock):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update(hass, mqtt_mock):
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock):
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update(hass, mqtt_mock, lock.DOMAIN, DEFAULT_CONFIG)
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock, lock.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock, lock.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
|
|
@ -11,7 +11,7 @@ import homeassistant.core as ha
|
|||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from .common import (
|
||||
from .test_common import (
|
||||
help_test_availability_without_topic,
|
||||
help_test_custom_availability_payload,
|
||||
help_test_default_availability_payload,
|
||||
|
@ -23,7 +23,8 @@ from .common import (
|
|||
help_test_entity_device_info_update,
|
||||
help_test_entity_device_info_with_connection,
|
||||
help_test_entity_device_info_with_identifier,
|
||||
help_test_entity_id_update,
|
||||
help_test_entity_id_update_discovery_update,
|
||||
help_test_entity_id_update_subscriptions,
|
||||
help_test_setting_attribute_via_mqtt_json_message,
|
||||
help_test_setting_attribute_with_template,
|
||||
help_test_unique_id,
|
||||
|
@ -392,9 +393,18 @@ async def test_entity_device_info_remove(hass, mqtt_mock):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update(hass, mqtt_mock):
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock):
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update(hass, mqtt_mock, sensor.DOMAIN, DEFAULT_CONFIG)
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_hub(hass, mqtt_mock):
|
||||
|
|
|
@ -30,7 +30,7 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import (
|
||||
from .test_common import (
|
||||
help_test_availability_without_topic,
|
||||
help_test_custom_availability_payload,
|
||||
help_test_default_availability_payload,
|
||||
|
@ -42,7 +42,8 @@ from .common import (
|
|||
help_test_entity_device_info_update,
|
||||
help_test_entity_device_info_with_connection,
|
||||
help_test_entity_device_info_with_identifier,
|
||||
help_test_entity_id_update,
|
||||
help_test_entity_id_update_discovery_update,
|
||||
help_test_entity_id_update_subscriptions,
|
||||
help_test_setting_attribute_via_mqtt_json_message,
|
||||
help_test_setting_attribute_with_template,
|
||||
help_test_unique_id,
|
||||
|
@ -441,6 +442,15 @@ async def test_entity_device_info_remove(hass, mqtt_mock):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update(hass, mqtt_mock):
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock):
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update(hass, mqtt_mock, vacuum.DOMAIN, DEFAULT_CONFIG_2)
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
|
|
@ -7,7 +7,7 @@ from homeassistant.const import ATTR_ASSUMED_STATE, STATE_OFF, STATE_ON
|
|||
import homeassistant.core as ha
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import (
|
||||
from .test_common import (
|
||||
help_test_availability_without_topic,
|
||||
help_test_custom_availability_payload,
|
||||
help_test_default_availability_payload,
|
||||
|
@ -19,7 +19,8 @@ from .common import (
|
|||
help_test_entity_device_info_update,
|
||||
help_test_entity_device_info_with_connection,
|
||||
help_test_entity_device_info_with_identifier,
|
||||
help_test_entity_id_update,
|
||||
help_test_entity_id_update_discovery_update,
|
||||
help_test_entity_id_update_subscriptions,
|
||||
help_test_setting_attribute_via_mqtt_json_message,
|
||||
help_test_setting_attribute_with_template,
|
||||
help_test_unique_id,
|
||||
|
@ -353,6 +354,15 @@ async def test_entity_device_info_remove(hass, mqtt_mock):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update(hass, mqtt_mock):
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock):
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update(hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG)
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue