Remove deprecated uptime sensor from qnap_qsw (#134493)
parent
a7fb20ab58
commit
13ec0659ff
|
@ -27,12 +27,9 @@ from aioqsw.const import (
|
||||||
QSD_TEMP_MAX,
|
QSD_TEMP_MAX,
|
||||||
QSD_TX_OCTETS,
|
QSD_TX_OCTETS,
|
||||||
QSD_TX_SPEED,
|
QSD_TX_SPEED,
|
||||||
QSD_UPTIME_SECONDS,
|
|
||||||
QSD_UPTIME_TIMESTAMP,
|
QSD_UPTIME_TIMESTAMP,
|
||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.components.automation import automations_with_entity
|
|
||||||
from homeassistant.components.script import scripts_with_entity
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
|
@ -45,10 +42,8 @@ from homeassistant.const import (
|
||||||
UnitOfDataRate,
|
UnitOfDataRate,
|
||||||
UnitOfInformation,
|
UnitOfInformation,
|
||||||
UnitOfTemperature,
|
UnitOfTemperature,
|
||||||
UnitOfTime,
|
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
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.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import UNDEFINED, StateType
|
from homeassistant.helpers.typing import UNDEFINED, StateType
|
||||||
from homeassistant.util import dt as dt_util
|
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
|
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, ...]] = (
|
SENSOR_TYPES: Final[tuple[QswSensorEntityDescription, ...]] = (
|
||||||
QswSensorEntityDescription(
|
QswSensorEntityDescription(
|
||||||
translation_key="fan_1_speed",
|
translation_key="fan_1_speed",
|
||||||
|
@ -355,46 +340,6 @@ async def async_setup_entry(
|
||||||
)
|
)
|
||||||
entities.append(QswSensor(coordinator, _desc, entry, port_id))
|
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)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -57,11 +57,5 @@
|
||||||
"name": "Uptime timestamp"
|
"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."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
"""The sensor tests for the QNAP QSW platform."""
|
"""The sensor tests for the QNAP QSW platform."""
|
||||||
|
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.qnap_qsw.const import ATTR_MAX, DOMAIN
|
from homeassistant.components.qnap_qsw.const import ATTR_MAX, DOMAIN
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
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
|
from .util import async_init_integration, init_config_entry
|
||||||
|
|
||||||
|
@ -383,39 +381,6 @@ async def test_qnap_qsw_create_sensors(
|
||||||
assert state.state == "0"
|
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(
|
async def test_cleanup_deprecated_uptime_seconds(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
|
|
Loading…
Reference in New Issue