Remove deprecated uptime sensor from qnap_qsw (#134493)

pull/126578/head^2
G Johansson 2025-01-02 22:29:50 +01:00 committed by GitHub
parent a7fb20ab58
commit 13ec0659ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 1 additions and 97 deletions

View File

@ -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)

View File

@ -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."
}
}
}

View File

@ -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,