Fix issue where an MQTT device is removed linked to two config entries (#120430)
* Fix issue where an MQTT device is removed linked to two config entries * Update homeassistant/components/mqtt/discovery.py Co-authored-by: J. Nick Koston <nick@koston.org> * Update homeassistant/components/mqtt/debug_info.py Co-authored-by: J. Nick Koston <nick@koston.org> --------- Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
d3ceaef098
commit
e567f8f3d5
4 changed files with 8 additions and 5 deletions
|
@ -138,7 +138,7 @@ def remove_trigger_discovery_data(
|
|||
hass: HomeAssistant, discovery_hash: tuple[str, str]
|
||||
) -> None:
|
||||
"""Remove discovery data."""
|
||||
del hass.data[DATA_MQTT].debug_info_triggers[discovery_hash]
|
||||
hass.data[DATA_MQTT].debug_info_triggers.pop(discovery_hash, None)
|
||||
|
||||
|
||||
def _info_for_entity(hass: HomeAssistant, entity_id: str) -> dict[str, Any]:
|
||||
|
|
|
@ -73,7 +73,7 @@ class MQTTDiscoveryPayload(dict[str, Any]):
|
|||
|
||||
def clear_discovery_hash(hass: HomeAssistant, discovery_hash: tuple[str, str]) -> None:
|
||||
"""Clear entry from already discovered list."""
|
||||
hass.data[DATA_MQTT].discovery_already_discovered.remove(discovery_hash)
|
||||
hass.data[DATA_MQTT].discovery_already_discovered.discard(discovery_hash)
|
||||
|
||||
|
||||
def set_discovery_hash(hass: HomeAssistant, discovery_hash: tuple[str, str]) -> None:
|
||||
|
|
|
@ -180,5 +180,6 @@ class MQTTTagScanner(MqttDiscoveryDeviceUpdateMixin):
|
|||
self._sub_state = subscription.async_unsubscribe_topics(
|
||||
self.hass, self._sub_state
|
||||
)
|
||||
if self.device_id:
|
||||
del self.hass.data[DATA_MQTT].tags[self.device_id][discovery_id]
|
||||
tags = self.hass.data[DATA_MQTT].tags
|
||||
if self.device_id in tags and discovery_id in tags[self.device_id]:
|
||||
del tags[self.device_id][discovery_id]
|
||||
|
|
|
@ -809,7 +809,7 @@ async def test_duplicate_removal(
|
|||
assert "Component has already been discovered: binary_sensor bla" not in caplog.text
|
||||
|
||||
|
||||
async def test_cleanup_device(
|
||||
async def test_cleanup_device_manual(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
|
@ -1012,6 +1012,7 @@ async def test_cleanup_device_multiple_config_entries(
|
|||
|
||||
async def test_cleanup_device_multiple_config_entries_mqtt(
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
|
@ -1093,6 +1094,7 @@ async def test_cleanup_device_multiple_config_entries_mqtt(
|
|||
|
||||
# Verify retained discovery topics have not been cleared again
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
assert "KeyError:" not in caplog.text
|
||||
|
||||
|
||||
async def test_discovery_expansion(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue