From 6711ad919e7bd0a5ca030675f2003cfbfae2c73d Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Mon, 12 Oct 2026 09:52:37 +0200 Subject: [PATCH] Remove deprecated MQTT via_hub device option (#185917) --- homeassistant/components/mqtt/schemas.py | 3 +- tests/components/mqtt/test_discovery.py | 3 +- tests/components/mqtt/test_sensor.py | 38 ++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/mqtt/schemas.py b/homeassistant/components/mqtt/schemas.py index 3d3743fad9f3..5734c6674cb6 100644 --- a/homeassistant/components/mqtt/schemas.py +++ b/homeassistant/components/mqtt/schemas.py @@ -131,7 +131,8 @@ def validate_device_has_at_least_one_identifier(value: ConfigType) -> ConfigType MQTT_ENTITY_DEVICE_INFO_SCHEMA = probatio.All( - cv.deprecated(CONF_DEPRECATED_VIA_HUB, CONF_VIA_DEVICE), + # Remove in HA Core 2027.4, together with CONF_DEPRECATED_VIA_HUB + cv.removed(CONF_DEPRECATED_VIA_HUB, raise_if_present=False), probatio.Schema( { probatio.Optional(CONF_IDENTIFIERS, default=list): probatio.All( diff --git a/tests/components/mqtt/test_discovery.py b/tests/components/mqtt/test_discovery.py index 68e1dbd5aed7..af563e92785b 100644 --- a/tests/components/mqtt/test_discovery.py +++ b/tests/components/mqtt/test_discovery.py @@ -2574,8 +2574,6 @@ ABBREVIATIONS_WHITE_LIST = [ # MQTT client/server/trigger settings # Integration info "CONF_SUPPORT_URL", - # Undocumented device configuration - "CONF_DEPRECATED_VIA_HUB", "CONF_VIA_DEVICE", # Already short "CONF_FAN_MODE_LIST", @@ -2587,6 +2585,7 @@ ABBREVIATIONS_WHITE_LIST = [ "CONF_SCHEMA", "CONF_TEMP_STEP", # Removed + "CONF_DEPRECATED_VIA_HUB", "CONF_WHITE_VALUE", # Config entry only settings "CONF_BROKER", diff --git a/tests/components/mqtt/test_sensor.py b/tests/components/mqtt/test_sensor.py index 17fdd0498b73..36d114b89511 100644 --- a/tests/components/mqtt/test_sensor.py +++ b/tests/components/mqtt/test_sensor.py @@ -1577,6 +1577,44 @@ async def test_entity_device_info_with_identifier( ) +async def test_discovery_with_removed_via_hub_option( + hass: HomeAssistant, + mqtt_mock_entry: MqttMockHAClientGenerator, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + caplog: pytest.LogCaptureFixture, +) -> None: + """Test discovery of a sensor with the removed via_hub device option.""" + await mqtt_mock_entry() + data = json.dumps( + { + "name": "test", + "state_topic": "test-topic", + "unique_id": "veryunique", + "device": { + "identifiers": ["helloworld"], + "name": "Hello World", + "via_hub": "hub-id", + }, + } + ) + async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data) + await hass.async_block_till_done() + + assert entity_registry.async_get_entity_id(sensor.DOMAIN, DOMAIN, "veryunique") + entry_id = hass.config_entries.async_entries(DOMAIN)[0].entry_id + device = device_registry.async_get_device_by_identifier( + (DOMAIN, "helloworld"), entry_id + ) + assert device is not None + assert device.via_device_id is None + assert ( + device_registry.async_get_device_by_identifier((DOMAIN, "hub-id"), entry_id) + is None + ) + assert "The 'via_hub' option has been removed" in caplog.text + + async def test_entity_device_info_update( hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: