From 143019f5b7d93757b35433785eb367ee7027ac68 Mon Sep 17 00:00:00 2001 From: Pierre-Gilles Leymarie Date: Mon, 11 Sep 2023 11:42:47 +0200 Subject: [PATCH] Dashboard: Should display a warning when device state is too old (#1875) --- .../sensor-value/NoRecentValueBadge.jsx | 9 ++ .../sensor-value/SensorDeviceFeature.jsx | 6 ++ front/src/config/i18n/en.json | 4 + front/src/config/i18n/fr.json | 4 + .../settings-system/SettingsSystemPage.jsx | 25 ++++++ .../routes/settings/settings-system/index.js | 52 +++++++++++- server/lib/device/device.get.js | 30 ++++++- server/test/lib/device/device.get.test.js | 82 +++++++------------ server/utils/constants.js | 1 + server/utils/device.js | 11 +++ 10 files changed, 169 insertions(+), 55 deletions(-) create mode 100644 front/src/components/boxs/device-in-room/device-features/sensor-value/NoRecentValueBadge.jsx diff --git a/front/src/components/boxs/device-in-room/device-features/sensor-value/NoRecentValueBadge.jsx b/front/src/components/boxs/device-in-room/device-features/sensor-value/NoRecentValueBadge.jsx new file mode 100644 index 0000000000..299c645f61 --- /dev/null +++ b/front/src/components/boxs/device-in-room/device-features/sensor-value/NoRecentValueBadge.jsx @@ -0,0 +1,9 @@ +import { Text } from 'preact-i18n'; + +const NoRecentValueBadge = () => ( + + + +); + +export default NoRecentValueBadge; diff --git a/front/src/components/boxs/device-in-room/device-features/sensor-value/SensorDeviceFeature.jsx b/front/src/components/boxs/device-in-room/device-features/sensor-value/SensorDeviceFeature.jsx index b5fa18aa49..197daef96a 100644 --- a/front/src/components/boxs/device-in-room/device-features/sensor-value/SensorDeviceFeature.jsx +++ b/front/src/components/boxs/device-in-room/device-features/sensor-value/SensorDeviceFeature.jsx @@ -11,6 +11,7 @@ import IconBinaryDeviceValue from './IconBinaryDeviceValue'; import SignalQualityDeviceValue from './SignalQualityDeviceValue'; import ButtonClickDeviceValue from './ButtonClickDeviceValue'; import TextDeviceValue from './TextDeviceValue'; +import NoRecentValueBadge from './NoRecentValueBadge'; const DISPLAY_BY_FEATURE_CATEGORY = { [DEVICE_FEATURE_CATEGORIES.MOTION_SENSOR]: LastSeenDeviceValue, @@ -39,6 +40,11 @@ const SensorDeviceType = ({ children, ...props }) => { elementType = BadgeNumberDeviceValue; } + // If the device feature has no recent value, we display a message to the user + if (feature.last_value_is_too_old) { + elementType = NoRecentValueBadge; + } + return ( diff --git a/front/src/config/i18n/en.json b/front/src/config/i18n/en.json index 7acfef402c..21e388e72c 100644 --- a/front/src/config/i18n/en.json +++ b/front/src/config/i18n/en.json @@ -240,6 +240,7 @@ "editRoomLabel": "Select the room you want to display here.", "editDeviceFeaturesLabel": "Select the devices you want to display. Only lights / sensors are showed here.", "noValue": "No value recorded", + "noRecentValue": "No recent value", "deviceTitle": "{{name}} - {{type}}", "addButton": "+", "substractButton": "-" @@ -1828,6 +1829,9 @@ "timezoneText": "The timezone is used in scheduled scene.", "deviceStateRetentionTime": "Keep Device State History", "deviceStateRetentionTimeDescription": "How long Gladys will keep your device states in database.", + "numberOfHoursBeforeStateIsOutdated": "Time to expiry of a state", + "numberOfHoursBeforeStateIsOutdatedDescription": "This delay corresponds to the number of hours before a sensor status is considered \"expired\" and therefore no longer displayed on the dashboard.", + "hours": "hours", "vacuumDatabaseTitle": "Database cleaning", "vacuumDatabaseDescription": "By clicking on this button, Gladys will start cleaning the database to free up space. This does not delete any data, it just physically remove old deleted data. Be careful, this task can take some time to run, and during that time Gladys will not be available.", "vacuumDatabaseButton": "Start database cleaning", diff --git a/front/src/config/i18n/fr.json b/front/src/config/i18n/fr.json index d105199780..5ad42629b3 100644 --- a/front/src/config/i18n/fr.json +++ b/front/src/config/i18n/fr.json @@ -240,6 +240,7 @@ "editRoomLabel": "Sélectionnez la pièce que vous souhaitez afficher ici.", "editDeviceFeaturesLabel": "Sélectionnez les appareils que vous voulez afficher ici. Seuls les capteurs / et interrupteurs on/off sont supportés.", "noValue": "Aucune valeur enregistrée.", + "noRecentValue": "Pas de valeur récente", "deviceTitle": "{{name}} - {{type}}", "addButton": "+", "substractButton": "-" @@ -1829,6 +1830,9 @@ "timezoneText": "Le fuseau horaire est utilisé dans les scènes programmées.", "deviceStateRetentionTime": "Conserver l'historique des états des appareils", "deviceStateRetentionTimeDescription": "La période pendant laquelle Gladys gardera en base de données les états des appareils.", + "numberOfHoursBeforeStateIsOutdated": "Délai avant expiration d'un état", + "numberOfHoursBeforeStateIsOutdatedDescription": "Ce délai correspond au nombre d'heures avant qu'un état de capteur soit considéré comme \"périmé\" et ainsi plus affiché sur le tableau de bord.", + "hours": "heures", "vacuumDatabaseTitle": "Nettoyer la base de donnée", "vacuumDatabaseDescription": "En cliquant sur ce bouton, Gladys lancera un nettoyage de la base de donnée, ce qui libère de l'espace disque. Cette tâche ne supprime pas de données, elle re-arrange juste la donnée existante sur le disque et vide des vieilles lignes qui ne sont plus utilisées. Attention, cette opération peut prendre un certain temps sur les grosses bases de données, et pendant ce temps Gladys sera indisponible. Ne lancez pas cette commande si vous avez besoin de Gladys dans la prochaine heure.", "vacuumDatabaseButton": "Lancer le nettoyage", diff --git a/front/src/routes/settings/settings-system/SettingsSystemPage.jsx b/front/src/routes/settings/settings-system/SettingsSystemPage.jsx index 08051246b0..beab584b57 100644 --- a/front/src/routes/settings/settings-system/SettingsSystemPage.jsx +++ b/front/src/routes/settings/settings-system/SettingsSystemPage.jsx @@ -200,6 +200,31 @@ const SystemPage = ({ children, ...props }) => ( +
+ +

+ + + +

+
+ +
+ + + +
+
+