From 13ec0659ffa23b29ae72e9af7eb190eb27c1ba5d Mon Sep 17 00:00:00 2001 From: G Johansson Date: Thu, 2 Jan 2025 22:29:50 +0100 Subject: [PATCH] Remove deprecated uptime sensor from qnap_qsw (#134493) --- homeassistant/components/qnap_qsw/sensor.py | 55 ------------------- .../components/qnap_qsw/strings.json | 6 -- tests/components/qnap_qsw/test_sensor.py | 37 +------------ 3 files changed, 1 insertion(+), 97 deletions(-) diff --git a/homeassistant/components/qnap_qsw/sensor.py b/homeassistant/components/qnap_qsw/sensor.py index 45ec1828b9d..e7f2c18638f 100644 --- a/homeassistant/components/qnap_qsw/sensor.py +++ b/homeassistant/components/qnap_qsw/sensor.py @@ -27,12 +27,9 @@ from aioqsw.const import ( QSD_TEMP_MAX, QSD_TX_OCTETS, QSD_TX_SPEED, - QSD_UPTIME_SECONDS, QSD_UPTIME_TIMESTAMP, ) -from homeassistant.components.automation import automations_with_entity -from homeassistant.components.script import scripts_with_entity from homeassistant.components.sensor import ( SensorDeviceClass, SensorEntity, @@ -45,10 +42,8 @@ from homeassistant.const import ( UnitOfDataRate, UnitOfInformation, UnitOfTemperature, - UnitOfTime, ) from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers import entity_registry as er, issue_registry as ir from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import UNDEFINED, StateType from homeassistant.util import dt as dt_util @@ -68,16 +63,6 @@ class QswSensorEntityDescription(SensorEntityDescription, QswEntityDescription): value_fn: Callable[[str], datetime | StateType] = lambda value: value -DEPRECATED_UPTIME_SECONDS = QswSensorEntityDescription( - translation_key="uptime", - key=QSD_SYSTEM_TIME, - entity_category=EntityCategory.DIAGNOSTIC, - native_unit_of_measurement=UnitOfTime.SECONDS, - state_class=SensorStateClass.TOTAL_INCREASING, - subkey=QSD_UPTIME_SECONDS, -) - - SENSOR_TYPES: Final[tuple[QswSensorEntityDescription, ...]] = ( QswSensorEntityDescription( translation_key="fan_1_speed", @@ -355,46 +340,6 @@ async def async_setup_entry( ) entities.append(QswSensor(coordinator, _desc, entry, port_id)) - # Can be removed in HA 2025.5.0 - entity_reg = er.async_get(hass) - reg_entities = er.async_entries_for_config_entry(entity_reg, entry.entry_id) - for entity in reg_entities: - if entity.domain == "sensor" and entity.unique_id.endswith( - ("_uptime", "_uptime_seconds") - ): - entity_id = entity.entity_id - - if entity.disabled: - entity_reg.async_remove(entity_id) - continue - - if ( - DEPRECATED_UPTIME_SECONDS.key in coordinator.data - and DEPRECATED_UPTIME_SECONDS.subkey - in coordinator.data[DEPRECATED_UPTIME_SECONDS.key] - ): - entities.append( - QswSensor(coordinator, DEPRECATED_UPTIME_SECONDS, entry) - ) - - entity_automations = automations_with_entity(hass, entity_id) - entity_scripts = scripts_with_entity(hass, entity_id) - - for item in entity_automations + entity_scripts: - ir.async_create_issue( - hass, - DOMAIN, - f"uptime_seconds_deprecated_{entity_id}_{item}", - breaks_in_ha_version="2025.5.0", - is_fixable=False, - severity=ir.IssueSeverity.WARNING, - translation_key="uptime_seconds_deprecated", - translation_placeholders={ - "entity": entity_id, - "info": item, - }, - ) - async_add_entities(entities) diff --git a/homeassistant/components/qnap_qsw/strings.json b/homeassistant/components/qnap_qsw/strings.json index 462e66a25c3..e946bc4257d 100644 --- a/homeassistant/components/qnap_qsw/strings.json +++ b/homeassistant/components/qnap_qsw/strings.json @@ -57,11 +57,5 @@ "name": "Uptime timestamp" } } - }, - "issues": { - "uptime_seconds_deprecated": { - "title": "QNAP QSW uptime seconds sensor deprecated", - "description": "The QNAP QSW uptime seconds sensor entity is deprecated and will be removed in HA 2025.2.0.\nHome Assistant detected that entity `{entity}` is being used in `{info}`\n\nYou should remove the uptime seconds entity from `{info}` then click submit to fix this issue." - } } } diff --git a/tests/components/qnap_qsw/test_sensor.py b/tests/components/qnap_qsw/test_sensor.py index 16335e878fd..1f56efded16 100644 --- a/tests/components/qnap_qsw/test_sensor.py +++ b/tests/components/qnap_qsw/test_sensor.py @@ -1,14 +1,12 @@ """The sensor tests for the QNAP QSW platform.""" -from unittest.mock import patch - from freezegun.api import FrozenDateTimeFactory import pytest from homeassistant.components.qnap_qsw.const import ATTR_MAX, DOMAIN from homeassistant.const import Platform from homeassistant.core import HomeAssistant -from homeassistant.helpers import entity_registry as er, issue_registry as ir +from homeassistant.helpers import entity_registry as er from .util import async_init_integration, init_config_entry @@ -383,39 +381,6 @@ async def test_qnap_qsw_create_sensors( assert state.state == "0" -@pytest.mark.usefixtures("entity_registry_enabled_by_default") -async def test_deprecated_uptime_seconds( - hass: HomeAssistant, - entity_registry: er.EntityRegistry, - issue_registry: ir.IssueRegistry, -) -> None: - """Test deprecation warning of the Uptime seconds sensor entity.""" - original_id = "sensor.qsw_m408_4c_uptime" - domain = Platform.SENSOR - - config_entry = init_config_entry(hass) - - entity = entity_registry.async_get_or_create( - domain=domain, - platform=DOMAIN, - unique_id=original_id, - config_entry=config_entry, - suggested_object_id=original_id, - disabled_by=None, - ) - - assert entity_registry.async_get_entity_id(domain, DOMAIN, original_id) - - with patch( - "homeassistant.components.qnap_qsw.sensor.automations_with_entity", - return_value=["item"], - ): - await async_init_integration(hass, config_entry=config_entry) - assert issue_registry.async_get_issue( - DOMAIN, f"uptime_seconds_deprecated_{entity.entity_id}_item" - ) - - async def test_cleanup_deprecated_uptime_seconds( hass: HomeAssistant, entity_registry: er.EntityRegistry,