Skip to content
This repository was archived by the owner on Jun 4, 2025. It is now read-only.

Commit fbfabe3

Browse files
committed
Add labeled time component
1 parent e51e97c commit fbfabe3

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

component/labeledtime.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from data import DataResolver
2+
from draw import TextNode, CarouselPanel
3+
from PIL import ImageColor
4+
import time
5+
import pytz
6+
from datetime import datetime
7+
8+
class LabeledTimeComponent(TextNode, CarouselPanel):
9+
def __init__(self, font_path: str, current_time: DataResolver[float], display_tz: pytz.BaseTzInfo, label: str) -> None:
10+
assert font_path is not None
11+
assert current_time is not None
12+
super().__init__(
13+
font_path=font_path,
14+
font="6x10",
15+
)
16+
self.current_time = current_time
17+
self.display_tz = display_tz
18+
self.label = label
19+
20+
def get_background_color(self) -> tuple[int, int, int, int] | tuple[int, int, int]:
21+
return (16, 0, 16)
22+
23+
def get_text_color(self) -> tuple[int, int, int, int] | tuple[int, int, int]:
24+
return (0, 128, 0)
25+
26+
def get_text(self) -> str:
27+
now = self.current_time.data
28+
assert now is not None
29+
dt = datetime.fromtimestamp(now, pytz.utc).astimezone(self.display_tz)
30+
timestr = dt.strftime("%-I:%M%p").lower()
31+
# if int(now % 2) == 0:
32+
# timestr = timestr.replace(":", " ")
33+
return f"{self.label}: {timestr}"

di.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from component.dayofweek import DayOfWeekComponent
77
from component.distance import DistanceComponent
88
from component.door import DoorComponent
9+
from component.labeledtime import LabeledTimeComponent
910
from component.media_player import MediaPlayerComponent
1011
from component.oven import OvenOnComponent
1112
from component.time import TimeComponent
@@ -128,6 +129,12 @@ def create_clock(config: AppConfig) -> Clock:
128129
font_path=config.font_path,
129130
current_time=current_time,
130131
)
132+
home_time_component = LabeledTimeComponent(
133+
font_path=config.font_path,
134+
current_time=current_time,
135+
display_tz=pytz.timezone("America/Edmonton"),
136+
label="Home",
137+
)
131138

132139
# aqi_component = providers.Singleton(
133140
# AqiComponent,
@@ -292,6 +299,7 @@ def create_clock(config: AppConfig) -> Clock:
292299
bottom.add_panel(oven_component)
293300
bottom.add_panel(paris_component)
294301
bottom.add_panel(timer_component)
302+
bottom.add_panel(home_time_component)
295303

296304
root = ContainerNode(
297305
size=(100*PCT, 100*PCT),

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
'component/dayofweek',
1515
'component/distance',
1616
'component/door',
17+
'component/labeledtime',
1718
'component/media_player',
1819
'component/oven',
1920
'component/sunforecast',

0 commit comments

Comments
 (0)