From c884be6a4cb173b72f827ac220f084f64b11034c Mon Sep 17 00:00:00 2001 From: J-Lindvig <54498188+J-Lindvig@users.noreply.github.com> Date: Sun, 16 Jan 2022 12:32:40 +0100 Subject: [PATCH] Improved name of the current part of day --- custom_components/time_date_dk/manifest.json | 4 ++-- custom_components/time_date_dk/sensor.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/custom_components/time_date_dk/manifest.json b/custom_components/time_date_dk/manifest.json index e290f95..7c0d995 100644 --- a/custom_components/time_date_dk/manifest.json +++ b/custom_components/time_date_dk/manifest.json @@ -1,10 +1,10 @@ { "domain": "time_date_dk", "name": "Time Date DK", - "documentation": "Date and time in many formats", + "documentation": "Date, time and a other attributes in many shape, sizes and formats", "dependencies": [], "codeowners": ["J-Lindvig"], "requirements": [], "iot_class": "local_push", - "version": "1.2" + "version": "1.3" } diff --git a/custom_components/time_date_dk/sensor.py b/custom_components/time_date_dk/sensor.py index 967e0be..524c1ca 100644 --- a/custom_components/time_date_dk/sensor.py +++ b/custom_components/time_date_dk/sensor.py @@ -94,7 +94,7 @@ def _getTime_TTS(self, time = None): timeNames = {0: "natten", 6: "morgenen", 9: "formiddagen", 12: "middagen", 14: "eftermiddagen", 18: "aftenen" } if time is None: - H24 = self._getTime('%-H') + H24 = int(self._getTime('%-H')) H12 = int(self._getTime('%-I')) M = int(self._getTime('%-M')) else: @@ -103,7 +103,13 @@ def _getTime_TTS(self, time = None): H12 = H24 - 12 if H24 > 12 else H24 M = int(timeList[1]) if int(timeList[1][0]) > 0 else int(timeList[1][1]) - timeName = timeNames[min(timeNames, key=lambda x:abs(x-int(H24)))] + timeName = '' + for hour, name in timeNames.items(): + if H24 >= hour: + timeName = name + else: + break + if M == 0: return f'{ H12 } om { timeName }' elif M == 15: