1786192210
This commit is contained in:
@@ -111,6 +111,8 @@ impl From<&HassEntity> for WeatherData {
|
|||||||
}
|
}
|
||||||
.to_shared_string();
|
.to_shared_string();
|
||||||
|
|
||||||
|
let label = pretty_label(&kind).to_shared_string();
|
||||||
|
|
||||||
let attribution = value
|
let attribution = value
|
||||||
.attributes
|
.attributes
|
||||||
.get("attribution")
|
.get("attribution")
|
||||||
@@ -216,6 +218,7 @@ impl From<&HassEntity> for WeatherData {
|
|||||||
|
|
||||||
Self {
|
Self {
|
||||||
kind,
|
kind,
|
||||||
|
label,
|
||||||
attribution,
|
attribution,
|
||||||
cloud_coverage,
|
cloud_coverage,
|
||||||
dew_point,
|
dew_point,
|
||||||
@@ -235,3 +238,22 @@ impl From<&HassEntity> for WeatherData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn pretty_label(value: &str) -> String {
|
||||||
|
let value = match value {
|
||||||
|
"partlycloudy" => "partly cloudy",
|
||||||
|
other => other,
|
||||||
|
};
|
||||||
|
value
|
||||||
|
.split(['_', '-', ' '])
|
||||||
|
.filter(|word| !word.is_empty())
|
||||||
|
.map(|word| {
|
||||||
|
let mut chars = word.chars();
|
||||||
|
match chars.next() {
|
||||||
|
Some(first) => first.to_uppercase().collect::<String>() + chars.as_str(),
|
||||||
|
None => String::new(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" ")
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ in property <string> : "cloud";
|
|||||||
import { Palette } from "std-widgets.slint";
|
import { Palette } from "std-widgets.slint";
|
||||||
export struct WeatherData {
|
export struct WeatherData {
|
||||||
kind: string,
|
kind: string,
|
||||||
|
label: string,
|
||||||
temperature: float,
|
temperature: float,
|
||||||
dew_point: float,
|
dew_point: float,
|
||||||
temperature_unit: string,
|
temperature_unit: string,
|
||||||
@@ -37,6 +38,13 @@ export component Climate inherits Rectangle {
|
|||||||
vertical-alignment: center;
|
vertical-alignment: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
text: weather.label;
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: 500;
|
||||||
|
vertical-alignment: center;
|
||||||
|
}
|
||||||
|
|
||||||
// Text {
|
// Text {
|
||||||
// width: 150px;
|
// width: 150px;
|
||||||
// height: 32px;
|
// height: 32px;
|
||||||
|
|||||||
Reference in New Issue
Block a user