diff --git a/Cargo.lock b/Cargo.lock index feed7b7..0ac98e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -424,6 +424,15 @@ dependencies = [ "wyz", ] +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "block2" version = "0.5.1" @@ -761,6 +770,15 @@ version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7704b5fdd17b18ae31c4c1da5a2e0305a2bf17b5249300a9ee9ed7b72114c636" +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + [[package]] name = "crc32fast" version = "1.5.0" @@ -816,6 +834,16 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "ctor" version = "0.10.1" @@ -874,11 +902,19 @@ dependencies = [ "embedded-graphics-core", "evdev", "framebuffer", + "hass-rs", "linfb", "slint", "slint-build", + "tokio", ] +[[package]] +name = "data-encoding" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4583a4551df46e2792f82ceeac45e850d2e2d5debba0b91f102385cda5b11f06" + [[package]] name = "data-url" version = "0.3.2" @@ -944,6 +980,16 @@ dependencies = [ "syn 3.0.3", ] +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + [[package]] name = "dispatch" version = "0.2.0" @@ -1510,6 +1556,16 @@ dependencies = [ "slab", ] +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "gethostname" version = "1.1.0" @@ -1711,6 +1767,22 @@ dependencies = [ "foldhash", ] +[[package]] +name = "hass-rs" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c4fe79e692fd6cdf1385f7cc84e6a59e1fc2f6c21aea05ba47fe6d0f90be336" +dependencies = [ + "futures-util", + "log", + "parking_lot", + "serde", + "serde_json", + "thiserror 2.0.19", + "tokio", + "tokio-tungstenite", +] + [[package]] name = "heck" version = "0.5.0" @@ -1741,6 +1813,22 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48ce8546b993eaf241d69ded33b1be6d205dd9857ec879d9d18bd05d3676e144" +[[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + [[package]] name = "i-slint-backend-linuxkms" version = "1.17.1" @@ -2583,6 +2671,15 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + [[package]] name = "log" version = "0.4.33" @@ -2705,6 +2802,17 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "mio" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30d65c71f1ce40ab09135ce117d742b9f8a19ff91a41a8b57ed50bc2de59c427" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + [[package]] name = "moxcms" version = "0.8.1" @@ -3341,6 +3449,29 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if 1.0.4", + "libc", + "redox_syscall 0.5.18", + "smallvec", + "windows-link", +] + [[package]] name = "parlance" version = "0.1.0" @@ -4110,6 +4241,17 @@ dependencies = [ "serde_core", ] +[[package]] +name = "sha1" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8" +dependencies = [ + "cfg-if 1.0.4", + "cpufeatures", + "digest", +] + [[package]] name = "shlex" version = "1.3.0" @@ -4333,6 +4475,16 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + [[package]] name = "softbuffer" version = "0.4.8" @@ -4656,6 +4808,46 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" +[[package]] +name = "tokio" +version = "1.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" +dependencies = [ + "proc-macro2 1.0.107", + "quote 1.0.47", + "syn 2.0.119", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f72a05e828585856dacd553fba484c242c46e391fb0e58917c942ee9202915c" +dependencies = [ + "futures-util", + "log", + "tokio", + "tungstenite", +] + [[package]] name = "toml" version = "1.1.4+spec-1.1.0" @@ -4749,6 +4941,22 @@ dependencies = [ "core_maths", ] +[[package]] +name = "tungstenite" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c01152af293afb9c7c2a57e4b559c5620b421f6d133261c60dd2d0cdb38e6b8" +dependencies = [ + "bytes", + "data-encoding", + "http", + "httparse", + "log", + "rand", + "sha1", + "thiserror 2.0.19", +] + [[package]] name = "typed-index-collections" version = "3.5.0" @@ -4759,6 +4967,12 @@ dependencies = [ "serde", ] +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + [[package]] name = "udev" version = "0.9.3" @@ -4979,6 +5193,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + [[package]] name = "wasip2" version = "1.0.4+wasi-0.2.12" diff --git a/Cargo.toml b/Cargo.toml index 0354590..0312a97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,10 @@ embedded-graphics = "0.8.2" embedded-graphics-core = "0.4.1" evdev = "0.13.2" framebuffer = "0.3.1" +hass-rs = "0.5.0" linfb = { version = "0.2.1", default-features = false } slint = { version = "1.17.1", default-features = false, features = ["std", "compat-1-2", "libm", "renderer-software", "unsafe-single-threaded"] } +tokio = { version = "1.53.1", features = ["full"] } [features] dev = ["slint/backend-winit-x11"] diff --git a/src/main.rs b/src/main.rs index 1683240..ae8cf22 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::{thread::sleep, time::Duration}; +use slint::{ModelRc, VecModel}; mod rgba; #[cfg(not(feature = "dev"))] @@ -6,21 +6,31 @@ mod trekstor; slint::include_modules!(); -fn main() -> Result<(), slint::PlatformError> { +#[tokio::main] +async fn main() -> Result<(), slint::PlatformError> { #[cfg(not(feature = "dev"))] slint::platform::set_platform(Box::new(crate::trekstor::Trekstor::new())) .expect("set platform"); let main_window = MainWindow::new()?; - let weak_window = main_window.as_weak(); - slint::spawn_local(async move { - sleep(Duration::from_secs(5)); - weak_window.upgrade_in_event_loop(move |ui| { - ui.set_text("GoodBye!".into()); - }) - }) - .unwrap(); + let lights = vec![LightData { + available: true, + entity_id: "light.living_room".into(), + name: "Living Room Lights".into(), + on: false, + }]; + + main_window.set_lights(ModelRc::new(VecModel::from(lights))); + + // let weak_window = main_window.as_weak(); + // slint::spawn_local(async move { + // sleep(Duration::from_secs(5)); + // weak_window.upgrade_in_event_loop(move |ui| { + // ui.set_text("GoodBye!".into()); + // }) + // }) + // .unwrap(); main_window.run() } diff --git a/ui/main.slint b/ui/main.slint index d40f582..7f93d44 100644 --- a/ui/main.slint +++ b/ui/main.slint @@ -9,22 +9,32 @@ import { Horizontal, Vertical, Switch } from "./material.slint"; import "./fonts/Roboto-VariableFont.ttf"; import { FilledIcons, OutlinedIcons } from "./icons.slint"; +export struct LightData { + name: string, + entity_id: string, + on: bool, + available: bool, +} + component LightSwitch inherits Horizontal { - in property text: ""; - in_out property checked; - in property enabled: true; + in property light; + callback toggled(string); + + TouchArea { + clicked => { if root.light.available { root.toggled(root.light.entity_id); } } + } alignment: end; - Text { - text: root.text; + label := Text { + text: root.light.name; vertical-alignment: center; horizontal-alignment: right; - font-size: 18px; - font-weight: root.checked ? 700 : 500; + font-size: 24px; + font-weight: root.light.on ? 700 : 500; } - Switch { - enabled: root.enabled; - checked: root.checked; + switch := Switch { + enabled: root.light.on; + checked: root.light.available; } } @@ -37,8 +47,10 @@ export component MainWindow inherits Window { preferred-height: 600px; default-font-family: "Roboto"; + in property <[LightData]> lights; + callback toggle-light(string); + in-out property current-page: 0; - in property text: "Hello World"; in property next-event-label: "NEXT EVENT"; in property next-event-title: "LOADING CALENDAR"; in property next-event-time: "6:00 pm"; @@ -122,39 +134,9 @@ export component MainWindow inherits Window { Vertical { alignment: start; - LightSwitch { - text: "Armory Light"; - } - - LightSwitch { - text: "Bedroom Light"; - } - - LightSwitch { - text: "Hallway Light"; - } - - LightSwitch { - text: "Kitchen Light"; - } - - LightSwitch { - text: "Living Room Light"; - checked: true; - } - - LightSwitch { - text: "Shower Light"; - } - - LightSwitch { - text: "Utilities Light"; - enabled: false; - checked: false; - } - - LightSwitch { - text: "WC Light"; + for light_data in root.lights: LightSwitch { + light: light_data; + toggled(entity_id) => { root.user-activity(); root.toggle-light(entity_id); } } } }