Skip to content

Commit

Permalink
Improved name of the current part of day
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Lindvig authored Jan 16, 2022
1 parent f2be121 commit c884be6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions custom_components/time_date_dk/manifest.json
Original file line number Diff line number Diff line change
@@ -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"
}
10 changes: 8 additions & 2 deletions custom_components/time_date_dk/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit c884be6

Please sign in to comment.