From 247f73f0db7510e9e85d1215dd7b3e45b8a04a00 Mon Sep 17 00:00:00 2001
From: RoboMagus <68224306+RoboMagus@users.noreply.github.com>
Date: Mon, 11 Mar 2024 15:06:27 +0100
Subject: [PATCH] Fix: Add alternative 'offline' status to EspHome widget
(#3107)
---
docs/widgets/services/esphome.md | 5 ++++-
public/locales/en/common.json | 1 +
src/widgets/esphome/component.jsx | 3 +++
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/docs/widgets/services/esphome.md b/docs/widgets/services/esphome.md
index 6038cb61..e14431fd 100644
--- a/docs/widgets/services/esphome.md
+++ b/docs/widgets/services/esphome.md
@@ -7,7 +7,10 @@ Learn more about [ESPHome](https://esphome.io/).
Show the number of ESPHome devices based on their state.
-Allowed fields: `["total", "online", "offline", "unknown"]`.
+Allowed fields: `["total", "online", "offline", "offline_alt", "unknown"]` (maximum of 4).
+
+By default ESPHome will only mark devices as `offline` if their address cannot be pinged. If it has an invalid config or its name cannot be resolved (by DNS) its status will be marked as `unknown`.
+To group both `offline` and `unknown` devices together, users should use the `offline_alt` field instead. This sums all devices that are _not_ online together.
```yaml
widget:
diff --git a/public/locales/en/common.json b/public/locales/en/common.json
index 9f4c4b13..c7339c0b 100644
--- a/public/locales/en/common.json
+++ b/public/locales/en/common.json
@@ -109,6 +109,7 @@
},
"esphome": {
"offline": "Offline",
+ "offline_alt": "Offline",
"online": "Online",
"total": "Total",
"unknown": "Unknown"
diff --git a/src/widgets/esphome/component.jsx b/src/widgets/esphome/component.jsx
index c44352fa..ea2e5db3 100644
--- a/src/widgets/esphome/component.jsx
+++ b/src/widgets/esphome/component.jsx
@@ -19,6 +19,7 @@ export default function Component({ service }) {
+
@@ -27,6 +28,7 @@ export default function Component({ service }) {
const total = Object.keys(resultData).length;
const online = Object.entries(resultData).filter(([, v]) => v === true).length;
+ const notOnline = Object.entries(resultData).filter(([, v]) => v !== true).length;
const offline = Object.entries(resultData).filter(([, v]) => v === false).length;
const unknown = Object.entries(resultData).filter(([, v]) => v === null).length;
@@ -34,6 +36,7 @@ export default function Component({ service }) {
+