From 79b2ad12d8a607618b0c92708829a4b1dc7a9c8d Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 15 Sep 2024 22:06:24 +0200 Subject: [PATCH] Add missing device information synchronization --- central_backend/src/devices/devices_list.rs | 17 +++++++++++++++++ central_backend/src/energy/energy_actor.rs | 1 + .../src/dialogs/EditDeviceRelaysDialog.tsx | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/central_backend/src/devices/devices_list.rs b/central_backend/src/devices/devices_list.rs index 4c418a0..1c6bbd1 100644 --- a/central_backend/src/devices/devices_list.rs +++ b/central_backend/src/devices/devices_list.rs @@ -143,6 +143,23 @@ impl DevicesList { Ok(()) } + /// Update a device general information + pub fn synchronise_dev_info( + &mut self, + id: &DeviceId, + general_info: DeviceInfo, + ) -> anyhow::Result<()> { + let dev = self + .0 + .get_mut(id) + .ok_or(DevicesListError::UpdateDeviceFailedDeviceNotFound)?; + + dev.info = general_info; + self.persist_dev_config(id)?; + + Ok(()) + } + /// Update a device general information pub fn update_general_info( &mut self, diff --git a/central_backend/src/energy/energy_actor.rs b/central_backend/src/energy/energy_actor.rs index 896aadb..4b9acca 100644 --- a/central_backend/src/energy/energy_actor.rs +++ b/central_backend/src/energy/energy_actor.rs @@ -260,6 +260,7 @@ impl Handler for EnergyActor { type Result = anyhow::Result>; fn handle(&mut self, msg: SynchronizeDevice, _ctx: &mut Context) -> Self::Result { + self.devices.synchronise_dev_info(&msg.0, msg.1.clone())?; self.engine.device_state(&msg.0).record_ping(); // TODO : implement real code diff --git a/central_frontend/src/dialogs/EditDeviceRelaysDialog.tsx b/central_frontend/src/dialogs/EditDeviceRelaysDialog.tsx index e9d6479..b2a2f7b 100644 --- a/central_frontend/src/dialogs/EditDeviceRelaysDialog.tsx +++ b/central_frontend/src/dialogs/EditDeviceRelaysDialog.tsx @@ -36,7 +36,7 @@ export function EditDeviceRelaysDialog(p: { p.relay ?? { id: "", name: "relay", - enabled: false, + enabled: true, priority: 1, consumption: 500, minimal_downtime: 60 * 5,