Compare commits
6 Commits
e458c69c80
...
0.2.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
f7ec98f8e3
|
|||
|
924a14cdcb
|
|||
|
d5a221e1a3
|
|||
|
b8e05e33a6
|
|||
|
362534384a
|
|||
|
fee9c7a171
|
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -206,7 +206,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "common"
|
||||
version = "0.2.0"
|
||||
version = "0.2.3"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"lighter_lib",
|
||||
@ -576,7 +576,7 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "hemma"
|
||||
version = "0.2.0"
|
||||
version = "0.2.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
@ -600,7 +600,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "hemma_web"
|
||||
version = "0.2.0"
|
||||
version = "0.2.3"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"common",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "hemma"
|
||||
version = "0.2.0"
|
||||
version = "0.2.3"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@ -144,7 +144,7 @@ fn wind_speed_to_beaufort(mps: f64) -> BeaufortScale {
|
||||
let index = beaufort_wind_speeds
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find_map(|(i, range)| range.contains(&mps).then(|| i))
|
||||
.find_map(|(i, range)| range.contains(&mps).then_some(i))
|
||||
.unwrap_or(beaufort_wind_speeds.len());
|
||||
|
||||
BeaufortScale(index as u8)
|
||||
|
||||
@ -53,7 +53,6 @@ pub async fn lights_task(state: &State) {
|
||||
|
||||
loop {
|
||||
let notify = bulb_states.notify_on_change();
|
||||
sleep(tokio::time::Duration::from_millis(1000 / 10)).await; // limit to 10 updates/second
|
||||
select! {
|
||||
_ = notify => {
|
||||
let lights_state = lights_state.get();
|
||||
@ -112,20 +111,19 @@ pub async fn lights_task(state: &State) {
|
||||
};
|
||||
|
||||
if let Some(time) = time {
|
||||
let handle = spawn(wake_task(
|
||||
state.client_message.clone(),
|
||||
cmd.clone(),
|
||||
id.clone(),
|
||||
day,
|
||||
time,
|
||||
));
|
||||
let handle = spawn(wake_task(
|
||||
state.client_message.clone(),
|
||||
cmd.clone(),
|
||||
id.clone(),
|
||||
day,
|
||||
time,
|
||||
));
|
||||
|
||||
if let Some(old_handle) = wake_tasks.insert((id, day), handle) {
|
||||
old_handle.abort();
|
||||
}} else {
|
||||
if let Some(old_handle) = wake_tasks.remove(&(id, day)) {
|
||||
if let Some(old_handle) = wake_tasks.insert((id, day), handle) {
|
||||
old_handle.abort();
|
||||
}
|
||||
} else if let Some(old_handle) = wake_tasks.remove(&(id, day)) {
|
||||
old_handle.abort();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@ -181,7 +179,11 @@ fn next_alarm(now: DateTime<Local>, day: Weekday, time: NaiveTime) -> DateTime<L
|
||||
let day_now = now.weekday().num_days_from_monday() as i64;
|
||||
|
||||
let alarm = now + chrono::Duration::days(day_of_alarm - day_now);
|
||||
let mut alarm = alarm.date().and_time(time).unwrap();
|
||||
let mut alarm = alarm
|
||||
.date_naive()
|
||||
.and_time(time)
|
||||
.and_local_timezone(Local)
|
||||
.unwrap();
|
||||
|
||||
if alarm <= now {
|
||||
alarm += chrono::Duration::weeks(1);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "common"
|
||||
version = "0.2.0"
|
||||
version = "0.2.3"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "hemma_web"
|
||||
version = "0.2.0"
|
||||
version = "0.2.3"
|
||||
authors = ["Joakim Hulthe <joakim@hulthe.net"]
|
||||
edition = "2021"
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ pub struct ColorPicker {
|
||||
#[derive(Default)]
|
||||
enum ColorPickerSetting {
|
||||
#[default]
|
||||
HSB,
|
||||
Hsb,
|
||||
Kelvin,
|
||||
}
|
||||
|
||||
@ -55,14 +55,14 @@ impl ColorPicker {
|
||||
}
|
||||
|
||||
match self.dragging.take() {
|
||||
Some(ColorPickerAttr::HueSat) => self.mode = ColorPickerSetting::HSB,
|
||||
Some(ColorPickerAttr::HueSat) => self.mode = ColorPickerSetting::Hsb,
|
||||
Some(ColorPickerAttr::Brightness) => {}
|
||||
Some(ColorPickerAttr::Temperature) => self.mode = ColorPickerSetting::Kelvin,
|
||||
None => return,
|
||||
}
|
||||
|
||||
let color = match self.mode {
|
||||
ColorPickerSetting::HSB => {
|
||||
ColorPickerSetting::Hsb => {
|
||||
BulbColor::hsb(self.hue, self.saturation, self.brightness)
|
||||
}
|
||||
ColorPickerSetting::Kelvin => {
|
||||
@ -130,10 +130,12 @@ impl ColorPicker {
|
||||
|
||||
let (r, g, b) = hsb_to_rgb(self.hue, 1.0, 1.0);
|
||||
let saturation_gradient = match self.mode {
|
||||
ColorPickerSetting::HSB => {
|
||||
ColorPickerSetting::Hsb => {
|
||||
format!("background: linear-gradient(0deg, #000, rgba({r},{g},{b},1));")
|
||||
}
|
||||
ColorPickerSetting::Kelvin => format!("background: linear-gradient(0deg, #000, #fff);"),
|
||||
ColorPickerSetting::Kelvin => {
|
||||
"background: linear-gradient(0deg, #000, #fff);".to_string()
|
||||
}
|
||||
};
|
||||
|
||||
div![
|
||||
@ -186,7 +188,7 @@ impl ColorPicker {
|
||||
self.hue = h;
|
||||
self.saturation = s;
|
||||
self.brightness = b;
|
||||
self.mode = ColorPickerSetting::HSB;
|
||||
self.mode = ColorPickerSetting::Hsb;
|
||||
}
|
||||
|
||||
pub fn set_kelvin(&mut self, t: f32, b: f32) {
|
||||
|
||||
@ -3,7 +3,7 @@ use crate::css::C;
|
||||
use chrono::{NaiveTime, Weekday};
|
||||
use common::{BulbGroup, BulbGroupShape, BulbMap, ClientMessage, ServerMessage};
|
||||
use lighter_lib::{BulbId, BulbMode};
|
||||
use seed::{attrs, button, div, input, C};
|
||||
use seed::{attrs, button, div, h2, input, table, td, tr, C};
|
||||
use seed::{prelude::*, IF};
|
||||
use seed_router::Page;
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
@ -112,7 +112,7 @@ impl Page for Model {
|
||||
}
|
||||
Msg::ColorPicker(msg) => {
|
||||
self.color_picker
|
||||
.update(msg, &mut orders.proxy(|msg| Msg::ColorPicker(msg)));
|
||||
.update(msg, &mut orders.proxy(Msg::ColorPicker));
|
||||
}
|
||||
Msg::SetBulbPower(power) => {
|
||||
self.groups_interacted = true;
|
||||
@ -125,7 +125,7 @@ impl Page for Model {
|
||||
});
|
||||
}
|
||||
Msg::LightTime(time, day) => {
|
||||
if time == "" {
|
||||
if time.is_empty() {
|
||||
self.for_selected_bulbs(|id, _| {
|
||||
let message = ClientMessage::SetBulbWakeTime {
|
||||
id: id.clone(),
|
||||
@ -235,14 +235,14 @@ impl Page for Model {
|
||||
.and_then(|b| b.wake_schedule.get(&day))
|
||||
.map(|t| t.to_string())
|
||||
.unwrap_or_default();
|
||||
div![
|
||||
tr![
|
||||
C![C.calendar_day],
|
||||
day.to_string(),
|
||||
input![
|
||||
td![day.to_string()],
|
||||
td![input![
|
||||
C![C.calendar_time_input],
|
||||
attrs! {At::Placeholder => time},
|
||||
input_ev(Ev::Input, move |input| Msg::LightTime(input, day))
|
||||
],
|
||||
]],
|
||||
]
|
||||
};
|
||||
|
||||
@ -251,17 +251,15 @@ impl Page for Model {
|
||||
div![
|
||||
C![C.bulb_map],
|
||||
attrs! {
|
||||
At::Style => format!("width: {}rem; height: {}rem;", bulb_map_width, bulb_map_height),
|
||||
At::Style => format!("min-width: {}rem; height: {}rem;", bulb_map_width, bulb_map_height),
|
||||
},
|
||||
ev(Ev::Click, |_| Msg::DeselectGroups),
|
||||
self.bulb_map.groups.iter().enumerate().map(view_bulb_group),
|
||||
],
|
||||
div![
|
||||
C![C.bulb_controls],
|
||||
IF!(selected_bulb.is_none() => C![C.bulb_controls_disable]),
|
||||
self.color_picker
|
||||
.view()
|
||||
.map_msg(|msg| Msg::ColorPicker(msg)),
|
||||
IF!(selected_bulb.is_none() => C![C.cross_out]),
|
||||
self.color_picker.view().map_msg(Msg::ColorPicker),
|
||||
button![
|
||||
if selected_bulb.map(|b| b.mode.power).unwrap_or(false) {
|
||||
C![C.bulb_power_button, C.bulb_power_button_on]
|
||||
@ -281,13 +279,17 @@ impl Page for Model {
|
||||
],
|
||||
div![
|
||||
C![C.calendar_box],
|
||||
calendar_day(Weekday::Mon),
|
||||
calendar_day(Weekday::Tue),
|
||||
calendar_day(Weekday::Wed),
|
||||
calendar_day(Weekday::Thu),
|
||||
calendar_day(Weekday::Fri),
|
||||
calendar_day(Weekday::Sat),
|
||||
calendar_day(Weekday::Sun),
|
||||
IF!(selected_bulb.is_none() => C![C.cross_out]),
|
||||
h2!["Wake Schedule"],
|
||||
table![
|
||||
calendar_day(Weekday::Mon),
|
||||
calendar_day(Weekday::Tue),
|
||||
calendar_day(Weekday::Wed),
|
||||
calendar_day(Weekday::Thu),
|
||||
calendar_day(Weekday::Fri),
|
||||
calendar_day(Weekday::Sat),
|
||||
calendar_day(Weekday::Sun),
|
||||
],
|
||||
],
|
||||
]
|
||||
}
|
||||
|
||||
@ -94,17 +94,12 @@ body {
|
||||
}
|
||||
|
||||
.bulb_box {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
width: fit-content;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.bulb_box > * {
|
||||
margin-bottom: 1em;
|
||||
margin-right: 1em;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.bulb_controls {
|
||||
@ -112,21 +107,20 @@ body {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
padding-right: 0.5em;
|
||||
background: #56636e;
|
||||
border: solid 0.25em #5b3f63;
|
||||
background: #00000000;
|
||||
}
|
||||
|
||||
.bulb_controls_disable {
|
||||
.cross_out {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.bulb_controls_disable:before {
|
||||
.cross_out:before {
|
||||
position: absolute;
|
||||
content: '';
|
||||
display: block;
|
||||
background: #000000;
|
||||
opacity: 0.5;
|
||||
background: #00000000;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
@ -135,7 +129,7 @@ body {
|
||||
z-index: 90;
|
||||
}
|
||||
|
||||
.bulb_controls_disable:after {
|
||||
.cross_out:after {
|
||||
position: absolute;
|
||||
content: '';
|
||||
background: #56636e;
|
||||
@ -151,23 +145,24 @@ body {
|
||||
bottom: 0;
|
||||
margin: auto;
|
||||
z-index: 91;
|
||||
animation: to_full_width .2s ease-out 0s 1 forwards;
|
||||
box-shadow: black 0.5rem 0.6rem 1rem 0.3rem;
|
||||
animation: to_width_90 .2s ease-out 0s 1 forwards;
|
||||
}
|
||||
@keyframes to_full_width { to { width: 100%; } }
|
||||
@keyframes to_width_90 { to { width: 90%; } }
|
||||
|
||||
.bulb_map {
|
||||
background: url(images/blueprint_bg.png);
|
||||
background-size: auto;
|
||||
background-size: 1em;
|
||||
padding: 2rem;
|
||||
border: solid 0.4rem #5b3f63;
|
||||
border: solid 0.1rem;
|
||||
border-radius: 0.2rem;
|
||||
}
|
||||
|
||||
.bulb_map::after {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
content: #0003;
|
||||
}
|
||||
|
||||
.bulb_group {
|
||||
@ -179,6 +174,7 @@ body {
|
||||
font-size: 2em;
|
||||
position: absolute;
|
||||
box-shadow: #0006 0.1em 0.1em 0.1em;
|
||||
user-select: none;
|
||||
transition: 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
@ -326,7 +322,18 @@ body {
|
||||
//margin-bottom: .7em;
|
||||
margin-left: .5em;
|
||||
}
|
||||
|
||||
.calendar_box {
|
||||
with: 10em;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.calendar_box > h2 {
|
||||
writing-mode: sideways-lr;
|
||||
margin-top: auto;
|
||||
margin-bottom: auto;
|
||||
}
|
||||
.calendar_box > * {
|
||||
flex-shrink: 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user