Remove beat (internet time) from time_date (#119785)
This commit is contained in:
parent
fc3fbc6862
commit
bd37ce6e9a
5 changed files with 7 additions and 124 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue