fix: harden widget error feedback

This commit is contained in:
Thomas Camlong committed 2026-08-02 17:34:52 +02:00
1 parent f0d8e97f8d
commit 5010ecf188
5 files changed
+29 -8

No files matched your search

@@ -50,7 +50,9 @@ export default function SmartHomeEntityStateWidget({
const apiUnit = entity?.attributes.unit_of_measurement;
const unit = options.entityUnit || (typeof apiUnit === "string" ? apiUnit : "");
const attribute = unit.length > 0 ? ` ${unit}` : "";
const isActionable = options.clickable && canInteract && entity !== undefined && !isEntityPending && !isPending;
const isActionable =
options.clickable && canInteract && entity !== undefined && !entityError && !isEntityPending && !isPending;
const queryErrorLabel = entityError ? t("widget.smartHome-entityState.error.loadFailed") : undefined;
const handleClick = useCallback(() => {
if (isEditMode) {
@@ -108,7 +110,7 @@ export default function SmartHomeEntityStateWidget({
onClick={handleClick}
disabled={!isActionable}
aria-label={`${displayName}: ${state}${attribute}`}
aria-description={error?.message}
aria-description={queryErrorLabel ?? (error ? t("widget.smartHome-entityState.error.toggleFailed") : undefined)}
w="100%"
h="100%"
styles={{
@@ -127,6 +129,11 @@ export default function SmartHomeEntityStateWidget({
<Text ta="center" c="dimmed" fw={500} size={isTiny ? "xs" : "sm"} lineClamp={2} maw="100%">
{displayName}
</Text>
{queryErrorLabel && (
<Text size="xs" c="orange" ta="center" lineClamp={1} maw="100%" aria-live="polite">
{queryErrorLabel}
</Text>
)}
{displayMode === "advanced" && entity && (
<>
<Group justify="center" gap={4}>
@@ -1,4 +1,4 @@
import { IconBinaryTree } from "@tabler/icons-react";
import { IconBinaryTree, IconServerOff } from "@tabler/icons-react";
import { getIntegrationKindsByCategory } from "@homarr/definitions";
@@ -22,4 +22,10 @@ export const { definition, componentLoader } = createWidgetDefinition("smartHome
}));
},
supportedIntegrations: getIntegrationKindsByCategory("smartHomeServer"),
errors: {
INTERNAL_SERVER_ERROR: {
icon: IconServerOff,
message: (t) => t("widget.smartHome-entityState.error.loadFailed"),
},
},
}).withDynamicImport(() => import("./component"));