From bd37ce6e9a3ef7321f9be2c0094b70d42b7184e7 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Mon, 17 Jun 2024 05:36:06 +0200 Subject: [PATCH] Remove beat (internet time) from time_date (#119785) --- .../components/time_date/config_flow.py | 2 +- homeassistant/components/time_date/const.py | 1 - homeassistant/components/time_date/sensor.py | 47 ++----------- .../components/time_date/strings.json | 13 ---- tests/components/time_date/test_sensor.py | 68 +------------------ 5 files changed, 7 insertions(+), 124 deletions(-) diff --git a/homeassistant/components/time_date/config_flow.py b/homeassistant/components/time_date/config_flow.py index f65978144c6..9ae98992acb 100644 --- a/homeassistant/components/time_date/config_flow.py +++ b/homeassistant/components/time_date/config_flow.py @@ -35,7 +35,7 @@ USER_SCHEMA = vol.Schema( { vol.Required(CONF_DISPLAY_OPTIONS): SelectSelector( SelectSelectorConfig( - options=[option for option in OPTION_TYPES if option != "beat"], + options=OPTION_TYPES, mode=SelectSelectorMode.DROPDOWN, translation_key="display_options", ) diff --git a/homeassistant/components/time_date/const.py b/homeassistant/components/time_date/const.py index 5d13ec0203c..53656bae181 100644 --- a/homeassistant/components/time_date/const.py +++ b/homeassistant/components/time_date/const.py @@ -18,6 +18,5 @@ OPTION_TYPES = [ "date_time_utc", "date_time_iso", "time_date", - "beat", "time_utc", ] diff --git a/homeassistant/components/time_date/sensor.py b/homeassistant/components/time_date/sensor.py index 57bb87e6ea5..ed999e5a0b2 100644 --- a/homeassistant/components/time_date/sensor.py +++ b/homeassistant/components/time_date/sensor.py @@ -20,11 +20,10 @@ from homeassistant.core import CALLBACK_TYPE, Event, 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, OPTION_TYPES +from .const import OPTION_TYPES _LOGGER = logging.getLogger(__name__) @@ -51,23 +50,6 @@ 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(variable) for variable in config[CONF_DISPLAY_OPTIONS]] ) @@ -95,8 +77,7 @@ class TimeDateSensor(SensorEntity): """Initialize the sensor.""" self._attr_translation_key = option_type self.type = option_type - object_id = "internet_time" if option_type == "beat" else option_type - self.entity_id = ENTITY_ID_FORMAT.format(object_id) + self.entity_id = ENTITY_ID_FORMAT.format(option_type) self._attr_unique_id = option_type if entry_id else None self._update_internal_state(dt_util.utcnow()) @@ -169,13 +150,8 @@ class TimeDateSensor(SensorEntity): tomorrow = dt_util.as_local(time_date) + timedelta(days=1) return dt_util.start_of_local_day(tomorrow) - if self.type == "beat": - # Add 1 hour because @0 beats is at 23:00:00 UTC. - timestamp = dt_util.as_timestamp(time_date + timedelta(hours=1)) - interval = 86.4 - else: - timestamp = dt_util.as_timestamp(time_date) - interval = 60 + timestamp = dt_util.as_timestamp(time_date) + interval = 60 delta = interval - (timestamp % interval) next_interval = time_date + timedelta(seconds=delta) @@ -201,21 +177,6 @@ class TimeDateSensor(SensorEntity): self._state = f"{time}, {date}" elif self.type == "time_utc": self._state = time_utc - elif self.type == "beat": - # Calculate Swatch Internet Time. - time_bmt = time_date + timedelta(hours=1) - delta = timedelta( - hours=time_bmt.hour, - minutes=time_bmt.minute, - seconds=time_bmt.second, - microseconds=time_bmt.microsecond, - ) - - # Use integers to better handle rounding. For example, - # int(63763.2/86.4) = 737 but 637632//864 = 738. - beat = int(delta.total_seconds() * 10) // 864 - - self._state = f"@{beat:03d}" elif self.type == "date_time_iso": self._state = dt_util.parse_datetime( f"{date} {time}", raise_on_error=True diff --git a/homeassistant/components/time_date/strings.json b/homeassistant/components/time_date/strings.json index e9efe949b9b..adf37253f90 100644 --- a/homeassistant/components/time_date/strings.json +++ b/homeassistant/components/time_date/strings.json @@ -66,18 +66,5 @@ "name": "[%key:component::time_date::selector::display_options::options::time_utc%]" } } - }, - "issues": { - "deprecated_beat": { - "title": "The `{config_key}` Time & Date sensor is being removed", - "fix_flow": { - "step": { - "confirm": { - "title": "[%key:component::time_date::issues::deprecated_beat::title%]", - "description": "Please remove the `{config_key}` key from the {integration} config entry options and click submit to fix this issue." - } - } - } - } } } diff --git a/tests/components/time_date/test_sensor.py b/tests/components/time_date/test_sensor.py index cbbf9a25d5c..ddeec48b3d2 100644 --- a/tests/components/time_date/test_sensor.py +++ b/tests/components/time_date/test_sensor.py @@ -5,10 +5,9 @@ from unittest.mock import ANY, Mock, patch from freezegun.api import FrozenDateTimeFactory import pytest -from homeassistant.components.time_date.const import DOMAIN, OPTION_TYPES +from homeassistant.components.time_date.const import OPTION_TYPES from homeassistant.core import HomeAssistant -from homeassistant.helpers import event, issue_registry as ir -from homeassistant.setup import async_setup_component +from homeassistant.helpers import event import homeassistant.util.dt as dt_util from . import load_int @@ -25,11 +24,6 @@ from tests.common import async_fire_time_changed dt_util.utc_from_timestamp(45.5), dt_util.utc_from_timestamp(60), ), - ( - "beat", - dt_util.parse_datetime("2020-11-13 00:00:29+01:00"), - dt_util.parse_datetime("2020-11-13 00:01:26.4+01:00"), - ), ( "date_time", dt_util.utc_from_timestamp(1495068899), @@ -83,9 +77,6 @@ async def test_states(hass: HomeAssistant, freezer: FrozenDateTimeFactory) -> No state = hass.states.get("sensor.date_time_utc") assert state.state == "2017-05-18, 00:54" - state = hass.states.get("sensor.internet_time") - assert state.state == "@079" - state = hass.states.get("sensor.date_time_iso") assert state.state == "2017-05-18T00:54:00" @@ -110,9 +101,6 @@ async def test_states(hass: HomeAssistant, freezer: FrozenDateTimeFactory) -> No state = hass.states.get("sensor.date_time_utc") assert state.state == "2020-10-17, 16:42" - state = hass.states.get("sensor.internet_time") - assert state.state == "@738" - state = hass.states.get("sensor.date_time_iso") assert state.state == "2020-10-17T16:42:00" @@ -143,9 +131,6 @@ async def test_states_non_default_timezone( state = hass.states.get("sensor.date_time_utc") assert state.state == "2017-05-18, 00:54" - state = hass.states.get("sensor.internet_time") - assert state.state == "@079" - state = hass.states.get("sensor.date_time_iso") assert state.state == "2017-05-17T20:54:00" @@ -170,9 +155,6 @@ async def test_states_non_default_timezone( state = hass.states.get("sensor.date_time_utc") assert state.state == "2020-10-17, 16:42" - state = hass.states.get("sensor.internet_time") - assert state.state == "@738" - state = hass.states.get("sensor.date_time_iso") assert state.state == "2020-10-17T12:42:00" @@ -195,9 +177,6 @@ async def test_states_non_default_timezone( state = hass.states.get("sensor.date_time_utc") assert state.state == "2020-10-17, 16:42" - state = hass.states.get("sensor.internet_time") - assert state.state == "@738" - state = hass.states.get("sensor.date_time_iso") assert state.state == "2020-10-17T18:42:00" @@ -280,48 +259,5 @@ async def test_icons(hass: HomeAssistant) -> None: assert state.attributes["icon"] == "mdi:calendar-clock" state = hass.states.get("sensor.date_time_utc") assert state.attributes["icon"] == "mdi:calendar-clock" - state = hass.states.get("sensor.internet_time") - assert state.attributes["icon"] == "mdi:clock" state = hass.states.get("sensor.date_time_iso") assert state.attributes["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], - issue_registry: ir.IssueRegistry, -) -> None: - """Test deprecation warning for swatch beat.""" - config = { - "sensor": { - "platform": "time_date", - "display_options": display_options, - } - } - - assert 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) - - assert len(issue_registry.issues) == len(expected_issues) - for expected_issue in expected_issues: - assert (DOMAIN, expected_issue) in issue_registry.issues