device editor working with special caps

This commit is contained in:
ari committed 2022-06-18 23:23:08 -04:00
1 parent debe48f2b4
commit 1496bc66ad
7 files changed
+233 -34

No files matched your search

+11 -7
View File
@@ -31,12 +31,16 @@ export const useHAEntities = () => {
}
let state: Set<string> = new Set();
entityIds.forEach((entityId) => {
if (!attribute) {
state.add(entities.collection.state[entityId].state);
} else {
const val = entities.collection.state[entityId].attributes[attribute];
if (val) {
state.add(val);
if (entities.collection.state[entityId]) {
if (!attribute) {
state.add(entities.collection.state[entityId].state);
} else {
const val = (entities.collection.state[entityId]?.attributes ?? {})[
attribute
];
if (val) {
state.add(val);
}
}
}
});
@@ -55,7 +59,7 @@ export const useHAEntities = () => {
let attributes: Set<string> = new Set();
entityIds.forEach((entityId) => {
const thisAttrs = new Set(
Object.keys(entities.collection.state[entityId].attributes)
Object.keys(entities.collection.state[entityId]?.attributes ?? {})
);
if (attributes.size === 0) {
attributes = thisAttrs;
+67 -5
View File
@@ -39,9 +39,71 @@ export type DeviceConditionType = DeviceBaseType & {
condition: "device";
};
export type DeviceTypeCapability = {
extra_fields: Array<{
name: string;
required?: true;
type: string;
}>;
extra_fields: Array<HaFormSchema>;
};
export type HaFormSchema =
| HaFormConstantSchema
| HaFormStringSchema
| HaFormIntegerSchema
| HaFormFloatSchema
| HaFormBooleanSchema
| HaFormSelectSchema
| HaFormMultiSelectSchema
| HaFormTimeSchema
| HaFormGridSchema;
export interface HaFormBaseSchema {
name: string;
default?: any;
required?: boolean;
description?: {
suffix?: string;
suggested_value?: any;
};
}
export interface HaFormGridSchema extends HaFormBaseSchema {
type: "grid";
name: "";
column_min_width?: string;
schema: HaFormSchema[];
}
export interface HaFormConstantSchema extends HaFormBaseSchema {
type: "constant";
value?: string;
}
export interface HaFormIntegerSchema extends HaFormBaseSchema {
type: "integer";
valueMin?: number;
valueMax?: number;
}
export interface HaFormSelectSchema extends HaFormBaseSchema {
type: "select";
options: Array<[string, string]>;
}
export interface HaFormMultiSelectSchema extends HaFormBaseSchema {
type: "multi_select";
options: Record<string, string> | string[] | Array<[string, string]>;
}
export interface HaFormFloatSchema extends HaFormBaseSchema {
type: "float";
}
export interface HaFormStringSchema extends HaFormBaseSchema {
type: "string";
format?: string;
}
export interface HaFormBooleanSchema extends HaFormBaseSchema {
type: "boolean";
}
export interface HaFormTimeSchema extends HaFormBaseSchema {
type: "positive_time_period_dict";
}