Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Dark Mode / Light Mode setting to UI #23

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions weatherman.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,21 @@ button:
entity_category: config
on_press:
- script.execute: update_screen


select:
- platform: template
name: Appearance
id: appearance
options:
- "Dark Mode"
- "Light Mode"
initial_option: "Dark Mode"
restore_value: true
optimistic: true
entity_category: config
on_value:
then:
- script.execute: update_screen

# Global variables for detecting if the display needs to be refreshed. (Thanks @paviro!)
globals:
Expand Down Expand Up @@ -410,22 +424,6 @@ text_sensor:
then:
- lambda: 'id(data_updated) = true;'


# Define colors
# This design is white on black so this is necessary.
color:
- id: color_bg
red: 0%
green: 0%
blue: 0%
white: 0%
- id: color_text
red: 0%
green: 0%
blue: 0%
white: 100%


# Pins for Waveshare ePaper ESP Board
spi:
clk_pin: GPIO13
Expand Down Expand Up @@ -480,8 +478,23 @@ display:
{"windy-variant", "\U000F059E"},
};

auto color_text = Color::WHITE;
auto color_bg = Color::BLACK;

auto index = id(appearance).active_index();

if (index.has_value()) {
if (index.value() == 1) {
ESP_LOGD("custom", "Light Mode is selected - using black text on a white background.");
color_text = Color::BLACK;
color_bg = Color::WHITE;
} else {
ESP_LOGD("custom", "Dark Mode is selected - using white text on a black background.");
}
}

// Fill background.
// it.fill(color_bg);
it.fill(color_bg);

// Show loading screen before data is received.
if (id(initial_data_received) == false) {
Expand Down