Create a deprecation/repair for sensor.sun_solar_rising (#146462)

* Create a deprecation/repair for `sensor.sun_solar_rising`

* test

* Update homeassistant/components/sun/strings.json
This commit is contained in:
karwosts 2025-06-11 02:02:14 -07:00 committed by GitHub
parent 8deec55204
commit 5b4c309170
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 79 additions and 1 deletions

View File

@ -18,6 +18,11 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.issue_registry import (
IssueSeverity,
async_create_issue,
async_delete_issue,
)
from homeassistant.helpers.typing import StateType
from .const import DOMAIN, SIGNAL_EVENTS_CHANGED, SIGNAL_POSITION_CHANGED
@ -149,6 +154,21 @@ class SunSensor(SensorEntity):
async def async_added_to_hass(self) -> None:
"""Register signal listener when added to hass."""
await super().async_added_to_hass()
if self.entity_description.key == "solar_rising":
async_create_issue(
self.hass,
DOMAIN,
"deprecated_sun_solar_rising",
breaks_in_ha_version="2026.1.0",
is_fixable=False,
severity=IssueSeverity.WARNING,
translation_key="deprecated_sun_solar_rising",
translation_placeholders={
"entity": self.entity_id,
},
)
self.async_on_remove(
async_dispatcher_connect(
self.hass,
@ -156,3 +176,9 @@ class SunSensor(SensorEntity):
self.async_write_ha_state,
)
)
async def async_will_remove_from_hass(self) -> None:
"""Call when entity will be removed from hass."""
await super().async_will_remove_from_hass()
if self.entity_description.key == "solar_rising":
async_delete_issue(self.hass, DOMAIN, "deprecated_sun_solar_rising")

View File

@ -37,5 +37,11 @@
}
}
}
},
"issues": {
"deprecated_sun_solar_rising": {
"title": "Deprecated 'Solar rising' sensor",
"description": "The 'Solar rising' sensor of the Sun integration is being deprecated; an equivalent 'Solar rising' binary sensor has been made available as a replacement. To resolve this issue, disable {entity}."
}
}
}

View File

@ -8,12 +8,15 @@ from freezegun.api import FrozenDateTimeFactory
import pytest
from homeassistant.components import sun
from homeassistant.config_entries import RELOAD_AFTER_UPDATE_DELAY
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers import entity_registry as er, issue_registry as ir
from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util
from tests.common import async_fire_time_changed
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_setting_rising(
@ -179,3 +182,46 @@ async def test_setting_rising(
assert entity
assert entity.entity_category is EntityCategory.DIAGNOSTIC
assert entity.unique_id == f"{entry_ids[0].entry_id}-solar_rising"
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_deprecation(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
issue_registry: ir.IssueRegistry,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test sensor.sun_solar_rising deprecation."""
utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC)
freezer.move_to(utc_now)
await async_setup_component(hass, sun.DOMAIN, {sun.DOMAIN: {}})
await hass.async_block_till_done()
assert issue_registry.async_get_issue(
domain="sun",
issue_id="deprecated_sun_solar_rising",
)
assert len(issue_registry.issues) == 1
entity_registry.async_update_entity(
"sensor.sun_solar_rising", disabled_by=er.RegistryEntryDisabler.USER
)
await hass.async_block_till_done()
assert not issue_registry.async_get_issue(
domain="sun",
issue_id="deprecated_sun_solar_rising",
)
assert len(issue_registry.issues) == 0
entity_registry.async_update_entity("sensor.sun_solar_rising", disabled_by=None)
await hass.async_block_till_done()
freezer.tick(delta=RELOAD_AFTER_UPDATE_DELAY)
async_fire_time_changed(hass)
await hass.async_block_till_done()
assert issue_registry.async_get_issue(
domain="sun",
issue_id="deprecated_sun_solar_rising",
)
assert len(issue_registry.issues) == 1