Skip to content

Commit

Permalink
Removed unnecessary output configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jinglemansweep committed Jun 4, 2024
1 parent 9e13e9c commit 99c4e92
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 51 deletions.
16 changes: 6 additions & 10 deletions inkyframeweb/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
from datetime import datetime
from dynaconf import Dynaconf
from flask import Flask, jsonify, redirect
from flask import Flask, jsonify, redirect, request
from pathlib import Path
from typing import List
from . import _APP_NAME, _APP_TITLE, _APP_VERSION
Expand Down Expand Up @@ -33,11 +32,8 @@
image_files = glob_images(Path(output.image_path))
output_display = OutputDisplay(
image_files,
(int(output.width), int(output.height)),
output.delay,
output.show_date,
output.show_time,
output.show_watermark,
)
logger.info(f"Output Display: {output_display}")
output_displays.append(output_display)
Expand All @@ -53,18 +49,18 @@ def handle_output(output: str):
global slideshows
if output not in config.outputs:
return "Output not found", 404
width = int(request.args.get("w", config.default.image_width))
height = int(request.args.get("h", config.default.image_height))
image_size = (width, height)
output_idx = int(output)
output_display = output_displays[output_idx]
if output_display.should_advance(int(datetime.now().timestamp())):
logger.info(f"Advancing Display: {output_display}")
output_display.next()
output_display.next()
image_bytes = render_image(
output_display.image_file,
config,
output_display.image_size,
image_size,
output_display.show_date,
output_display.show_time,
output_display.show_watermark,
)
return build_response(image_bytes)

Expand Down
86 changes: 86 additions & 0 deletions inkyframeweb/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from dynaconf import Validator
from pathlib import Path

VALIDATORS = [
# General
Validator("GENERAL__DEBUG", default=False, cast=bool),
Validator("GENERAL__LOG_LEVEL", default="info"), # error, warning, info, debug
Validator("GENERAL__DEMO_MODE", default=False, cast=bool),
# Web
Validator("WEB__HOST", default="0.0.0.0"),
Validator("WEB__PORT", default=5665, cast=int),
# Locale
Validator("LOCALE__DATE_FORMAT", default="%d %B %Y"),
Validator("LOCALE__TIME_FORMAT", default="%H:%M"),
# Defaults
Validator("DEFAULT__IMAGE_WIDTH", default=800, cast=int),
Validator("DEFAULT__IMAGE_HEIGHT", default=480, cast=int),
# Outputs
Validator(
"OUTPUTS__0__IMAGE_PATH",
default="images/samples",
cast=Path,
),
Validator(
"OUTPUTS__0__SHOW_DATE",
default=False,
cast=bool,
),
Validator(
"OUTPUTS__0__SHOW_TIME",
default=False,
cast=bool,
),
# MQTT
Validator(
"MQTT__HOST",
default="homeassistant.local",
cast=str,
),
Validator(
"MQTT__PORT",
default=1883,
cast=int,
),
Validator(
"MQTT__TOPIC_PREFIX__APP",
default="inkyframeweb",
cast=str,
),
Validator(
"MQTT__TOPIC_PREFIX__HOMEASSISTANT__DEFAULT",
default="homeassistant",
cast=str,
),
Validator(
"MQTT__TOPIC_PREFIX__HOMEASSISTANT__STATESTREAM",
default="homeassistant/statestream",
cast=str,
),
Validator(
"MQTT__USER",
default=None,
cast=str,
),
Validator(
"MQTT__PASSWORD",
default=None,
cast=str,
),
Validator(
"MQTT__KEEPALIVE",
default=60,
cast=int,
),
Validator(
"MQTT__LOG_MESSAGES",
default=False,
cast=bool,
),
# PATHS
Validator(
"PATHS__IMAGES",
default="images",
cast=Path,
),
]
11 changes: 5 additions & 6 deletions inkyframeweb/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def overlay_watermark(image: Image.Image, size: tuple[int, int]) -> None:
overlay_text(
image,
_APP_TITLE,
position=(size[0] - 120, size[1] - 18),
font_size=14,
position=(size[0] - 200, size[1] - 28),
font_size=24,
color="yellow",
stroke_color="black",
stroke_width=2,
Expand All @@ -115,9 +115,8 @@ def render_image(
image_file: Path,
config: Dynaconf,
size: tuple[int, int],
show_date: bool = True,
show_time: bool = True,
show_watermark: bool = True,
show_date: bool = False,
show_time: bool = False,
) -> io.BytesIO:
# Load and resize image
image = load_and_resize_image(image_file, size)
Expand All @@ -127,7 +126,7 @@ def render_image(
if show_time:
overlay_time(image, size, config.locale.time_format)
# Overlay watermark
if show_watermark:
if config.general.demo_mode:
overlay_watermark(image, size)
# Return image bytes
return pil_to_bytes(image, "JPEG", False, 50)
Expand Down
24 changes: 0 additions & 24 deletions inkyframeweb/outputs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from datetime import datetime
from pathlib import Path
from typing import List

Expand All @@ -7,32 +6,15 @@ class OutputDisplay:
def __init__(
self,
image_files: List[Path],
image_size: tuple[int, int],
delay: int = 60,
show_date: bool = True,
show_time: bool = True,
show_watermark: bool = False,
) -> None:
self.delay = delay
self.image_files = image_files
self.image_count = len(image_files)
self.image_index = 0
self.image_current = image_files[self.image_index]
self.start_time = int(datetime.now().timestamp())
self.previous_time = self.start_time
self.image_size = image_size
self.show_date = show_date
self.show_time = show_time
self.show_watermark = show_watermark

def should_advance(self, now: int) -> bool:
advance = False
diff = now - self.start_time
if (diff % self.delay) == 0:
if now != self.previous_time:
self.previous_time = now
advance = True
return advance

def next(self) -> None:
self.image_index = (self.image_index + 1) % self.image_count
Expand All @@ -45,15 +27,9 @@ def __repr__(self) -> str:
return (
"<OutputDisplay items="
+ str(len(self.image_files))
+ " size="
+ str(self.image_size)
+ " delay="
+ str(self.delay)
+ " show_date="
+ str(self.show_date)
+ " show_time="
+ str(self.show_time)
+ " show_watermark="
+ str(self.show_watermark)
+ ">"
)
7 changes: 7 additions & 0 deletions micropython/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SSID = "PT-Admin"
PSK = "AmusementUnmasking1Managing"
COUNTRY = "GB"

ENDPOINT_URL = "http://10.1.1.61:5665"
DISPLAY_ID = 0
SLEEP_MINS = 5
16 changes: 5 additions & 11 deletions settings.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[general]
# debug = false
# log_level = "debug" # info, debug
# demo_mode = false

[web]
# host = "0.0.0.0"
Expand All @@ -10,27 +11,20 @@
# date_format = "%d %B %Y"
# time_format = "%H:%M"

[display]
# Inky Frame 7.3: 800w x 480h
# width = 800
# height = 480
[defaults]
# image_width = 800
# image_height = 480

[outputs]
# [outputs.0]
# name = "inkyframe7"
# width = 800
# height = 480
# image_path = "images/samples"
# delay = 600
# show_date = true
# show_date = false
# show_time = false
# show_watermark = false
# [outputs.1]
# ...
# [outputs.2]
# ...


[mqtt]
# host = "hass.local"
# port = 1883
Expand Down

0 comments on commit 99c4e92

Please sign in to comment.