Skip to content

Commit

Permalink
More tinting options
Browse files Browse the repository at this point in the history
  • Loading branch information
jinglemansweep committed Jan 25, 2024
1 parent 8b12288 commit c3e30a6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
6 changes: 4 additions & 2 deletions wideboy/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ class AppState:
hass_state: dict = field(default_factory=dict)
master_power: bool = True
master_brightness: int = 128
background_tint: tuple = (255, 255, 255)
slideshow_interval: int = 60
tint_enabled: bool = False
tint_brightness: int = 128
tint_color: tuple = (255, 0, 64)
slideshow_interval: int = 30
slideshow_index: int = 0
clock_24_hour: bool = True
screenshot: bool = False
Expand Down
22 changes: 13 additions & 9 deletions wideboy/systems/scene/hass_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ class BackgroundTintLight(LightEntity):
name: str = "background_tint"
description: str = "Background Tint"
initial_state: Dict[str, Any] = {
"state": "ON",
"state": "OFF",
"brightness": 255,
"color": {"r": 255, "g": 255, "b": 255},
}
options: Dict[str, Any] = {
"brightness": False,
"brightness": True,
"supported_color_modes": ["rgb"],
"color_mode": True,
}
Expand All @@ -123,25 +123,29 @@ def callback(
payload: str,
) -> None:
payload_dict = json.loads(payload)
app_state.tint_enabled = payload_dict["state"] == "ON"
if "brightness" in payload_dict:
app_state.tint_brightness = int(payload_dict["brightness"])
if "color" in payload_dict:
app_state.background_tint = (
app_state.tint_color = (
int(payload_dict["color"]["r"]),
int(payload_dict["color"]["g"]),
int(payload_dict["color"]["b"]),
)
logger.debug(
f"sys.hass.entities.light.background_tint: color={app_state.background_tint}"
f"sys.hass.entities.light.background_tint: enabled={app_state.tint_enabled} color={app_state.tint_color} brightness={app_state.tint_brightness}"
)
client.publish(
state_topic,
json.dumps(
{
"state": to_hass_bool(True),
"state": to_hass_bool(app_state.tint_enabled),
"brightness": app_state.tint_brightness,
"color_mode": "rgb",
"color": {
"r": app_state.background_tint[0],
"g": app_state.background_tint[1],
"b": app_state.background_tint[2],
"r": app_state.tint_color[0],
"g": app_state.tint_color[1],
"b": app_state.tint_color[2],
},
}
),
Expand All @@ -152,7 +156,7 @@ def callback(
class BackgroundIntervalNumber(NumberEntity):
name: str = "slideshow_interval"
description: str = "Slideshow Interval"
initial_state: int = 60
initial_state: int = 10
options: Dict[str, Any] = {
"device_class": "duration",
"step": 1,
Expand Down
11 changes: 10 additions & 1 deletion wideboy/systems/scene/stages/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ def _glob_backgrounds(self, randomize: bool = False) -> None:
self.slideshow_images = images

def _load_and_process_image(self, filename: str) -> Surface:
tint_enabled = self.app_state.tint_enabled
color = self.app_state.tint_color
brightness = self.app_state.tint_brightness
color = Color(
color[0] * brightness / 255,
color[1] * brightness / 255,
color[2] * brightness / 255,
)
surface = load_image(filename)
surface = recolor_image(surface, Color(*self.app_state.background_tint))
if tint_enabled:
surface = recolor_image(surface, color)
return surface

0 comments on commit c3e30a6

Please sign in to comment.