feat: modernize dashboard widgets
This commit is contained in:
1 parent
1a5e083fd0
commit
6f2cd7fc2b
270 files changed
+10189
-3544
No files matched your search
@@ -1,10 +1,29 @@
|
||||
import type { IntegrationKindByCategory } from "@homarr/definitions";
|
||||
import { createIntegrationAsync } from "@homarr/integrations";
|
||||
import type { EntityState } from "@homarr/integrations";
|
||||
|
||||
import { createIntegrationRequestHandler } from "./lib/integration-request-handler";
|
||||
|
||||
const safeAttributeKeys = ["friendly_name", "unit_of_measurement", "device_class", "icon"] as const;
|
||||
|
||||
export const toSafeEntityDetails = (entity: EntityState) => {
|
||||
const attributes: Partial<Record<(typeof safeAttributeKeys)[number], string>> = {};
|
||||
for (const key of safeAttributeKeys) {
|
||||
const value = entity.attributes[key];
|
||||
if (typeof value === "string") attributes[key] = value;
|
||||
}
|
||||
|
||||
return {
|
||||
attributes,
|
||||
entity_id: entity.entity_id,
|
||||
last_changed: entity.last_changed,
|
||||
last_updated: entity.last_updated,
|
||||
state: entity.state,
|
||||
};
|
||||
};
|
||||
|
||||
export const smartHomeEntityStateRequestHandler = createIntegrationRequestHandler<
|
||||
string,
|
||||
EntityState,
|
||||
IntegrationKindByCategory<"smartHomeServer">,
|
||||
{ entityId: string }
|
||||
>({
|
||||
@@ -16,6 +35,6 @@ export const smartHomeEntityStateRequestHandler = createIntegrationRequestHandle
|
||||
throw new Error(`Unable to fetch data from Home Assistant error='${result.error as string}'`);
|
||||
}
|
||||
|
||||
return result.data.state;
|
||||
return result.data;
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user