Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions homeassistant/components/sun/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
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
Expand Down Expand Up @@ -149,10 +154,31 @@ def native_value(self) -> StateType | datetime:
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,
self.entity_description.signal,
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")
6 changes: 6 additions & 0 deletions homeassistant/components/sun/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}."
}
}
}
48 changes: 47 additions & 1 deletion tests/components/sun/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
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(
Expand Down Expand Up @@ -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