mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Deprecate 'beat' display option in Time & Date (#106871)
* Deprecate 'beat' display option in Time & Date * Move deprecation warning * Update homeassistant/components/time_date/const.py Co-authored-by: Sander <developer@golles.nl> --------- Co-authored-by: G Johansson <goran.johansson@shiftit.se> Co-authored-by: Sander <developer@golles.nl>
This commit is contained in:
parent
8f9bd75a36
commit
8f8c0ef13b
6
homeassistant/components/time_date/const.py
Normal file
6
homeassistant/components/time_date/const.py
Normal file
@ -0,0 +1,6 @@
|
||||
"""Constants for the Time & Date integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Final
|
||||
|
||||
DOMAIN: Final = "time_date"
|
@ -12,9 +12,12 @@ from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import async_track_point_in_utc_time
|
||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
TIME_STR_FORMAT = "%H:%M"
|
||||
@ -50,6 +53,23 @@ async def async_setup_platform(
|
||||
_LOGGER.error("Timezone is not set in Home Assistant configuration") # type: ignore[unreachable]
|
||||
return False
|
||||
|
||||
if "beat" in config[CONF_DISPLAY_OPTIONS]:
|
||||
async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
"deprecated_beat",
|
||||
breaks_in_ha_version="2024.7.0",
|
||||
is_fixable=False,
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="deprecated_beat",
|
||||
translation_placeholders={
|
||||
"config_key": "beat",
|
||||
"display_options": "display_options",
|
||||
"integration": DOMAIN,
|
||||
},
|
||||
)
|
||||
_LOGGER.warning("'beat': is deprecated and will be removed in version 2024.7")
|
||||
|
||||
async_add_entities(
|
||||
[TimeDateSensor(hass, variable) for variable in config[CONF_DISPLAY_OPTIONS]]
|
||||
)
|
||||
|
8
homeassistant/components/time_date/strings.json
Normal file
8
homeassistant/components/time_date/strings.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"issues": {
|
||||
"deprecated_beat": {
|
||||
"title": "The `{config_key}` Time & Date sensor is being removed",
|
||||
"description": "Please remove the `{config_key}` key from the `{display_options}` for the {integration} entry in your configuration.yaml file and restart Home Assistant to fix this issue."
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,13 @@
|
||||
"""The tests for time_date sensor platform."""
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.time_date.const import DOMAIN
|
||||
import homeassistant.components.time_date.sensor as time_date
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
|
||||
@ -172,3 +176,39 @@ async def test_icons(hass: HomeAssistant) -> None:
|
||||
assert device.icon == "mdi:calendar-clock"
|
||||
device = time_date.TimeDateSensor(hass, "date_time_iso")
|
||||
assert device.icon == "mdi:calendar-clock"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
(
|
||||
"display_options",
|
||||
"expected_warnings",
|
||||
"expected_issues",
|
||||
),
|
||||
[
|
||||
(["time", "date"], [], []),
|
||||
(["beat"], ["'beat': is deprecated"], ["deprecated_beat"]),
|
||||
(["time", "beat"], ["'beat': is deprecated"], ["deprecated_beat"]),
|
||||
],
|
||||
)
|
||||
async def test_deprecation_warning(
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
display_options: list[str],
|
||||
expected_warnings: list[str],
|
||||
expected_issues: list[str],
|
||||
) -> None:
|
||||
"""Test deprecation warning for swatch beat."""
|
||||
config = {"sensor": {"platform": "time_date", "display_options": display_options}}
|
||||
|
||||
await async_setup_component(hass, "sensor", config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
warnings = [record for record in caplog.records if record.levelname == "WARNING"]
|
||||
assert len(warnings) == len(expected_warnings)
|
||||
for expected_warning in expected_warnings:
|
||||
assert any(expected_warning in warning.message for warning in warnings)
|
||||
|
||||
issue_registry = ir.async_get(hass)
|
||||
assert len(issue_registry.issues) == len(expected_issues)
|
||||
for expected_issue in expected_issues:
|
||||
assert (DOMAIN, expected_issue) in issue_registry.issues
|
||||
|
Loading…
x
Reference in New Issue
Block a user