Skip to content

Commit

Permalink
Remove beat
Browse files Browse the repository at this point in the history
  • Loading branch information
gjohansson-ST committed Dec 11, 2023
1 parent 9bff129 commit 51857f2
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 27 deletions.
2 changes: 2 additions & 0 deletions homeassistant/components/time_date/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ async def validate_input(
hass = async_get_hass()
if hass.config.time_zone is None:
raise SchemaFlowError("timezone_not_exist")
if user_input.get("beat"):
user_input.pop("beat")
return user_input


Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/time_date/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
"date_time_utc",
"date_time_iso",
"time_date",
"beat",
"time_utc",
]
24 changes: 2 additions & 22 deletions homeassistant/components/time_date/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,8 @@ def get_next_interval(self) -> datetime:
tomorrow = dt_util.as_local(now) + 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(now + timedelta(hours=1))
interval = 86.4
else:
timestamp = dt_util.as_timestamp(now)
interval = 60
timestamp = dt_util.as_timestamp(now)
interval = 60

delta = interval - (timestamp % interval)
next_interval = now + timedelta(seconds=delta)
Expand All @@ -166,21 +161,6 @@ def _update_internal_state(self, time_date: datetime) -> None:
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" and (
_datetime := dt_util.parse_datetime(f"{date} {time}")
):
Expand Down
4 changes: 0 additions & 4 deletions homeassistant/components/time_date/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"date_time_utc": "Date & Time (UTC)",
"date_time_iso": "Date & Time (ISO)",
"time_date": "Time & Date",
"beat": "Internet time",
"time_utc": "Time (UTC)"
}
}
Expand All @@ -57,9 +56,6 @@
"time_date": {
"name": "[%key:component::time_date::selector::display_options::options::time_date%]"
},
"beat": {
"name": "[%key:component::time_date::selector::display_options::options::beat%]"
},
"time_utc": {
"name": "[%key:component::time_date::selector::display_options::options::time_utc%]"
}
Expand Down

0 comments on commit 51857f2

Please sign in to comment.