device action builder
This commit is contained in:
1 parent
6be6005531
commit
029df7932e
16 files changed
+725
-434
No files matched your search
@@ -1,47 +1,53 @@
|
||||
import { HAEntitiesState, HAServicesState } from 'haService';
|
||||
import { FC } from 'react';
|
||||
import { AutomationAction } from 'types/automations/actions';
|
||||
import { AutomationCondition } from 'types/automations/conditions';
|
||||
import { HAEntitiesState, HAService } from "haService";
|
||||
import { FC } from "react";
|
||||
import { AutomationAction } from "types/automations/actions";
|
||||
import { AutomationCondition } from "types/automations/conditions";
|
||||
export type OptionManager<T> = {
|
||||
defaultState(): T;
|
||||
isReady(s: T): boolean;
|
||||
} & ({
|
||||
renderOptionList(s: T, set: (s: T) => void, entities: HAEntitiesState): JSX.Element;
|
||||
} | {
|
||||
Component: FC<{
|
||||
state: T,
|
||||
setState: (s: T) => void,
|
||||
entities: HAEntitiesState,
|
||||
services: HAServicesState,
|
||||
}>
|
||||
})
|
||||
} & (
|
||||
| {
|
||||
renderOptionList(
|
||||
s: T,
|
||||
set: (s: T) => void,
|
||||
entities: HAEntitiesState
|
||||
): JSX.Element;
|
||||
}
|
||||
| {
|
||||
Component: FC<{
|
||||
state: T;
|
||||
setState: (s: T) => void;
|
||||
ha: HAService;
|
||||
}>;
|
||||
}
|
||||
);
|
||||
|
||||
export const cleanUpUndefined = (data: Record<string, any>): any => {
|
||||
const clean: any = {};
|
||||
Object.keys(data).forEach(k => {
|
||||
if ((data[k] !== undefined) && (data[k] !== null)) {
|
||||
clean[k] = data[k]
|
||||
Object.keys(data).forEach((k) => {
|
||||
if (data[k] !== undefined && data[k] !== null) {
|
||||
clean[k] = data[k];
|
||||
}
|
||||
})
|
||||
});
|
||||
return clean;
|
||||
}
|
||||
};
|
||||
|
||||
export const updateConditionData = <T extends AutomationCondition>(
|
||||
setState: (s: T) => void
|
||||
) => (
|
||||
state: T,
|
||||
data: Partial<T>,
|
||||
) => setState(cleanUpUndefined({
|
||||
...state,
|
||||
...data,
|
||||
}))
|
||||
export const updateConditionData =
|
||||
<T extends AutomationCondition>(setState: (s: T) => void) =>
|
||||
(state: T, data: Partial<T>) =>
|
||||
setState(
|
||||
cleanUpUndefined({
|
||||
...state,
|
||||
...data,
|
||||
})
|
||||
);
|
||||
|
||||
export const updateActionData = <T extends AutomationAction>(
|
||||
state: T,
|
||||
setState: (s: T) => void
|
||||
) => (
|
||||
data: Partial<T>,
|
||||
) => setState(cleanUpUndefined({
|
||||
...state,
|
||||
...data,
|
||||
}))
|
||||
export const updateActionData =
|
||||
<T extends AutomationAction>(state: T, setState: (s: T) => void) =>
|
||||
(data: Partial<T>) =>
|
||||
setState(
|
||||
cleanUpUndefined({
|
||||
...state,
|
||||
...data,
|
||||
})
|
||||
);
|
||||
Reference in new issue
Block a user