v0.12.0-preety_code

This commit is contained in:
Mateusz Gruszczyński committed 2026-09-03 15:33:37 +02:00
1 parent be67932b47
commit 07be4b85d9
87 files changed
+11691 -3172

No files matched your search

-2
View File
@@ -25,7 +25,6 @@ pub struct Schedule {
pub flow_node_id: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct FlowRuntimeNodeState {
#[serde(default)]
@@ -98,4 +97,3 @@ pub struct Automation {
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
-1
View File
@@ -109,4 +109,3 @@ pub struct ControlPlan {
pub zones: Vec<ZoneControlPlan>,
pub rules: Vec<AutomationPlanRule>,
}
+114 -39
View File
@@ -1,39 +1,114 @@
fn default_true() -> bool { true }
fn default_port() -> u16 { 7000 }
fn default_protocol() -> u8 { 0 }
fn default_mode() -> String { "cool".into() }
fn default_fan() -> u8 { 0 }
fn default_target() -> f64 { 24.0 }
fn default_hysteresis() -> f64 { 0.6 }
fn default_external_sensor_weight() -> f64 { 0.4 }
fn default_max_sensor_difference() -> f64 { 3.0 }
fn default_control_temperature_source() -> String { "device".into() }
fn default_min_cycle() -> u64 { 180 }
fn default_compressor_protection_seconds() -> u64 { 180 }
fn default_sensor_stale_after() -> u64 { 300 }
fn default_cooldown() -> u64 { 300 }
fn default_house_mode() -> String { "cool".into() }
fn default_control_strategy() -> String { "setpoint".into() }
fn default_standby_offset() -> f64 { 2.0 }
fn default_min_adjust() -> u64 { 120 }
fn default_schedule_preset() -> String { "custom".into() }
fn default_active_preset() -> String { "comfort".into() }
fn default_cool_comfort() -> f64 { 23.0 }
fn default_cool_sleep() -> f64 { 24.5 }
fn default_cool_away() -> f64 { 27.0 }
fn default_heat_comfort() -> f64 { 21.0 }
fn default_heat_sleep() -> f64 { 19.0 }
fn default_heat_away() -> f64 { 17.0 }
fn default_history_retention_days() -> u32 { 30 }
fn default_event_log_retention_days() -> u32 { 30 }
fn default_influx_version() -> String { "2".into() }
fn default_influx_database() -> String { "gree_controller".into() }
fn default_influx_threshold_days() -> u32 { 30 }
fn default_night_start() -> String { "22:00".into() }
fn default_night_end() -> String { "06:00".into() }
fn default_night_max_fan_speed() -> u8 { 1 }
fn default_group_power_enabled() -> bool { true }
fn default_temporary_tolerance() -> f64 { 0.3 }
fn default_temporary_start_kind() -> String { "now".into() }
fn default_temporary_state() -> String { "scheduled".into() }
fn default_true() -> bool {
true
}
fn default_port() -> u16 {
7000
}
fn default_protocol() -> u8 {
0
}
fn default_mode() -> String {
"cool".into()
}
fn default_fan() -> u8 {
0
}
fn default_target() -> f64 {
24.0
}
fn default_hysteresis() -> f64 {
0.6
}
fn default_external_sensor_weight() -> f64 {
0.4
}
fn default_max_sensor_difference() -> f64 {
3.0
}
fn default_control_temperature_source() -> String {
"device".into()
}
fn default_min_cycle() -> u64 {
180
}
fn default_compressor_protection_seconds() -> u64 {
180
}
fn default_sensor_stale_after() -> u64 {
300
}
fn default_cooldown() -> u64 {
300
}
fn default_house_mode() -> String {
"cool".into()
}
fn default_control_strategy() -> String {
"setpoint".into()
}
fn default_standby_offset() -> f64 {
2.0
}
fn default_min_adjust() -> u64 {
120
}
fn default_schedule_preset() -> String {
"custom".into()
}
fn default_active_preset() -> String {
"comfort".into()
}
fn default_cool_comfort() -> f64 {
23.0
}
fn default_cool_sleep() -> f64 {
24.5
}
fn default_cool_away() -> f64 {
27.0
}
fn default_heat_comfort() -> f64 {
21.0
}
fn default_heat_sleep() -> f64 {
19.0
}
fn default_heat_away() -> f64 {
17.0
}
fn default_history_retention_days() -> u32 {
30
}
fn default_event_log_retention_days() -> u32 {
30
}
fn default_influx_version() -> String {
"2".into()
}
fn default_influx_database() -> String {
"gree_controller".into()
}
fn default_influx_threshold_days() -> u32 {
30
}
fn default_night_start() -> String {
"22:00".into()
}
fn default_night_end() -> String {
"06:00".into()
}
fn default_night_max_fan_speed() -> u8 {
1
}
fn default_group_power_enabled() -> bool {
true
}
fn default_temporary_tolerance() -> f64 {
0.3
}
fn default_temporary_start_kind() -> String {
"now".into()
}
fn default_temporary_state() -> String {
"scheduled".into()
}
+69 -23
View File
@@ -162,21 +162,42 @@ pub struct DeviceCommand {
impl DeviceCommand {
pub fn is_empty(&self) -> bool {
self.power.is_none() && self.mode.is_none() && self.target_temperature.is_none()
&& self.fan_speed.is_none() && self.swing_vertical.is_none() && self.swing_horizontal.is_none()
&& self.quiet.is_none() && self.turbo.is_none() && self.light.is_none()
&& self.air.is_none() && self.xfan.is_none() && self.health.is_none() && self.sleep.is_none()
self.power.is_none()
&& self.mode.is_none()
&& self.target_temperature.is_none()
&& self.fan_speed.is_none()
&& self.swing_vertical.is_none()
&& self.swing_horizontal.is_none()
&& self.quiet.is_none()
&& self.turbo.is_none()
&& self.light.is_none()
&& self.air.is_none()
&& self.xfan.is_none()
&& self.health.is_none()
&& self.sleep.is_none()
}
/// Return only fields that differ from the last known device state.
pub fn changed_from(&self, device: &Device) -> Self {
Self {
power: self.power.filter(|value| *value != device.power),
mode: self.mode.as_ref().filter(|value| value.as_str() != device.mode.as_str()).cloned(),
target_temperature: self.target_temperature.filter(|value| value.clamp(8.0, 30.0).round() != device.target_temperature.clamp(8.0, 30.0).round()),
fan_speed: self.fan_speed.filter(|value| (*value).min(5) != device.fan_speed),
swing_vertical: self.swing_vertical.filter(|value| *value != device.swing_vertical),
swing_horizontal: self.swing_horizontal.filter(|value| *value != device.swing_horizontal),
mode: self
.mode
.as_ref()
.filter(|value| value.as_str() != device.mode.as_str())
.cloned(),
target_temperature: self.target_temperature.filter(|value| {
value.clamp(8.0, 30.0).round() != device.target_temperature.clamp(8.0, 30.0).round()
}),
fan_speed: self
.fan_speed
.filter(|value| (*value).min(5) != device.fan_speed),
swing_vertical: self
.swing_vertical
.filter(|value| *value != device.swing_vertical),
swing_horizontal: self
.swing_horizontal
.filter(|value| *value != device.swing_horizontal),
quiet: self.quiet.filter(|value| *value != device.quiet),
turbo: self.turbo.filter(|value| *value != device.turbo),
light: self.light.filter(|value| *value != device.light),
@@ -188,19 +209,45 @@ impl DeviceCommand {
}
pub fn apply(&self, device: &mut Device) {
if let Some(v) = self.power { device.power = v; }
if let Some(v) = &self.mode { device.mode = v.clone(); }
if let Some(v) = self.target_temperature { device.target_temperature = v.clamp(8.0, 30.0).round(); }
if let Some(v) = self.fan_speed { device.fan_speed = v.min(5); }
if let Some(v) = self.swing_vertical { device.swing_vertical = v; }
if let Some(v) = self.swing_horizontal { device.swing_horizontal = v; }
if let Some(v) = self.quiet { device.quiet = v; }
if let Some(v) = self.turbo { device.turbo = v; }
if let Some(v) = self.light { device.light = v; }
if let Some(v) = self.air { device.air = v; }
if let Some(v) = self.xfan { device.xfan = v; }
if let Some(v) = self.health { device.health = v; }
if let Some(v) = self.sleep { device.sleep = v; }
if let Some(v) = self.power {
device.power = v;
}
if let Some(v) = &self.mode {
device.mode = v.clone();
}
if let Some(v) = self.target_temperature {
device.target_temperature = v.clamp(8.0, 30.0).round();
}
if let Some(v) = self.fan_speed {
device.fan_speed = v.min(5);
}
if let Some(v) = self.swing_vertical {
device.swing_vertical = v;
}
if let Some(v) = self.swing_horizontal {
device.swing_horizontal = v;
}
if let Some(v) = self.quiet {
device.quiet = v;
}
if let Some(v) = self.turbo {
device.turbo = v;
}
if let Some(v) = self.light {
device.light = v;
}
if let Some(v) = self.air {
device.air = v;
}
if let Some(v) = self.xfan {
device.xfan = v;
}
if let Some(v) = self.health {
device.health = v;
}
if let Some(v) = self.sleep {
device.sleep = v;
}
device.updated_at = Utc::now();
}
}
@@ -227,4 +274,3 @@ impl From<&Device> for ManualDeviceBaseline {
}
}
}
-1
View File
@@ -49,4 +49,3 @@ pub struct EventLog {
pub message: String,
pub metadata: Value,
}
+30 -12
View File
@@ -78,7 +78,6 @@ impl Default for InfluxDbSettings {
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NotificationAlertTypes {
/// Home Assistant sensor exceeded the configured freshness window.
@@ -110,8 +109,14 @@ pub struct NotificationAlertTypes {
impl Default for NotificationAlertTypes {
fn default() -> Self {
Self {
stale_sensor: true, sensor_errors: true, communication: true, target_timeout: true,
automation: true, control_errors: true, important_events: true, other: true,
stale_sensor: true,
sensor_errors: true,
communication: true,
target_timeout: true,
automation: true,
control_errors: true,
important_events: true,
other: true,
}
}
}
@@ -145,18 +150,32 @@ pub struct NotificationSettings {
pub alert_types: NotificationAlertTypes,
}
fn default_notification_mode() -> String { "problems".into() }
fn default_notification_provider() -> String { "pushover".into() }
fn default_notification_cooldown() -> u64 { 300 }
fn default_notification_failure_threshold() -> u32 { 3 }
fn default_notification_target_timeout() -> u32 { 60 }
fn default_notification_mode() -> String {
"problems".into()
}
fn default_notification_provider() -> String {
"pushover".into()
}
fn default_notification_cooldown() -> u64 {
300
}
fn default_notification_failure_threshold() -> u32 {
3
}
fn default_notification_target_timeout() -> u32 {
60
}
impl Default for NotificationSettings {
fn default() -> Self {
Self {
enabled: false, mode: default_notification_mode(), provider: default_notification_provider(),
pushover_app_token: String::new(), pushover_user_key: String::new(),
slack_webhook_url: String::new(), discord_webhook_url: String::new(),
enabled: false,
mode: default_notification_mode(),
provider: default_notification_provider(),
pushover_app_token: String::new(),
pushover_user_key: String::new(),
slack_webhook_url: String::new(),
discord_webhook_url: String::new(),
cooldown_seconds: default_notification_cooldown(),
communication_failure_threshold: default_notification_failure_threshold(),
target_timeout_minutes: default_notification_target_timeout(),
@@ -204,4 +223,3 @@ impl Default for NightModeSettings {
}
}
}
-1
View File
@@ -106,4 +106,3 @@ pub struct TemporaryQuickThermostatRequest {
#[serde(default)]
pub max_duration_minutes: Option<u64>,
}
+8 -4
View File
@@ -175,7 +175,11 @@ pub struct Zone {
impl Zone {
pub fn hysteresis_for_mode(&self, mode: &str) -> f64 {
let value = if self.separate_hysteresis {
if mode == "heat" { self.heat_hysteresis } else { self.cool_hysteresis }
if mode == "heat" {
self.heat_hysteresis
} else {
self.cool_hysteresis
}
} else {
self.hysteresis
};
@@ -183,8 +187,9 @@ impl Zone {
}
}
fn default_sensor_source() -> String { "device".into() }
fn default_sensor_source() -> String {
"device".into()
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClimateGroup {
@@ -244,4 +249,3 @@ pub struct ZoneControlPatch {
#[serde(default)]
pub clear_temporary_quick_thermostat: Option<bool>,
}