1786272593
This commit is contained in:
@@ -5,13 +5,29 @@ use std::sync::{Arc, RwLock};
|
|||||||
use dotenvy::var;
|
use dotenvy::var;
|
||||||
use hass_rs::{HassClient, HassEntity};
|
use hass_rs::{HassClient, HassEntity};
|
||||||
use serde_json::{Value, json};
|
use serde_json::{Value, json};
|
||||||
|
use slint::language::ColorScheme;
|
||||||
use slint::{ModelRc, VecModel, Weak};
|
use slint::{ModelRc, VecModel, Weak};
|
||||||
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
|
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
|
||||||
|
|
||||||
slint::include_modules!();
|
slint::include_modules!();
|
||||||
|
|
||||||
fn apply_state(app: &Weak<AppWindow>, state: State) {
|
fn apply_state(app: &Weak<AppWindow>, state: State) {
|
||||||
app.upgrade_in_event_loop(move |app| {
|
app.upgrade_in_event_loop(move |app| {
|
||||||
|
// Light/Dark mode
|
||||||
|
//
|
||||||
|
if let Some(illuminance) = state
|
||||||
|
.get("sensor.living_room_motion_sensor_illuminance")
|
||||||
|
.as_ref()
|
||||||
|
&& let Ok(illuminance) = illuminance.state.parse::<i32>()
|
||||||
|
{
|
||||||
|
let scheme = if illuminance < 100 {
|
||||||
|
ColorScheme::Dark
|
||||||
|
} else {
|
||||||
|
ColorScheme::Light
|
||||||
|
};
|
||||||
|
|
||||||
|
app.set_color_scheme(scheme);
|
||||||
|
}
|
||||||
|
|
||||||
// Lights
|
// Lights
|
||||||
let lights = state
|
let lights = state
|
||||||
.domain("light")
|
.domain("light")
|
||||||
|
|||||||
@@ -44,12 +44,6 @@ export struct DateTimeData {
|
|||||||
component Clock {
|
component Clock {
|
||||||
in property <DateTimeData> date-time;
|
in property <DateTimeData> date-time;
|
||||||
|
|
||||||
TouchArea {
|
|
||||||
clicked => {
|
|
||||||
Palette.color-scheme = Palette.color-scheme == ColorScheme.dark ? ColorScheme.light : ColorScheme.dark;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VerticalLayout {
|
VerticalLayout {
|
||||||
alignment: center;
|
alignment: center;
|
||||||
padding-left: 5px;
|
padding-left: 5px;
|
||||||
@@ -129,8 +123,9 @@ export component AppWindow inherits Window {
|
|||||||
height: 600px;
|
height: 600px;
|
||||||
default-font-size: 16px;
|
default-font-size: 16px;
|
||||||
|
|
||||||
in property <DateTimeData> date-time;
|
in-out property <ColorScheme> color-scheme <=> Palette.color-scheme;
|
||||||
|
|
||||||
|
in property <DateTimeData> date-time;
|
||||||
in property <[ThermostatData]> thermostats;
|
in property <[ThermostatData]> thermostats;
|
||||||
in property <WeatherData> weather;
|
in property <WeatherData> weather;
|
||||||
in property <bool> is-night;
|
in property <bool> is-night;
|
||||||
|
|||||||
Reference in New Issue
Block a user