Skip to content

Commit

Permalink
chore: update selector and ha form (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored Apr 30, 2022
1 parent 31a4016 commit 398749d
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 109 deletions.
10 changes: 2 additions & 8 deletions src/utils/form/ha-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export type HaFormSchema =
| HaFormBooleanSchema
| HaFormSelectSchema
| HaFormMultiSelectSchema
| HaFormTemplateSchema
| HaFormTimeSchema
| HaFormSelector
| HaFormGridSchema;
Expand All @@ -31,6 +30,7 @@ export interface HaFormBaseSchema {
// This value will be set initially when form is loaded
suggested_value?: HaFormData;
};
context?: Record<string, string>;
}

export interface HaFormGridSchema extends HaFormBaseSchema {
Expand All @@ -47,7 +47,7 @@ export interface HaFormSelector extends HaFormBaseSchema {

export interface HaFormConstantSchema extends HaFormBaseSchema {
type: "constant";
value: string;
value?: string;
}

export interface HaFormIntegerSchema extends HaFormBaseSchema {
Expand Down Expand Up @@ -80,10 +80,6 @@ export interface HaFormBooleanSchema extends HaFormBaseSchema {
type: "boolean";
}

export interface HaFormTemplateSchema extends HaFormBaseSchema {
type: "template";
}

export interface HaFormTimeSchema extends HaFormBaseSchema {
type: "positive_time_period_dict";
}
Expand All @@ -99,7 +95,6 @@ export type HaFormData =
| HaFormBooleanData
| HaFormSelectData
| HaFormMultiSelectData
| HaFormTemplateData
| HaFormTimeData;

export type HaFormStringData = string;
Expand All @@ -108,7 +103,6 @@ export type HaFormFloatData = number;
export type HaFormBooleanData = boolean;
export type HaFormSelectData = string;
export type HaFormMultiSelectData = string[];
export type HaFormTemplateData = string;
export type HaFormTimeData = HaDurationData;

export interface HaFormElement extends LitElement {
Expand Down
247 changes: 146 additions & 101 deletions src/utils/form/ha-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,42 @@ import { MushInfoSelector } from "./custom/ha-selector-mushroom-info";
import { MushLayoutSelector } from "./custom/ha-selector-mushroom-layout";
import { MushAlignementSelector } from "./custom/ha-selector-mushroom-alignment";

type MushSelector =
| MushColorSelector
| MushLayoutSelector
| MushInfoSelector
| MushActionSelector
| MushAlignementSelector;

export type Selector =
| ActionSelector
| AddonSelector
| AreaSelector
| AttributeSelector
| EntitySelector
| BooleanSelector
| ColorRGBSelector
| ColorTempSelector
| DateSelector
| DateTimeSelector
| DeviceSelector
| DurationSelector
| AreaSelector
| TargetSelector
| EntitySelector
| IconSelector
| LocationSelector
| MediaSelector
| NumberSelector
| BooleanSelector
| TemplateSelector
| TimeSelector
| ActionSelector
| StringSelector
| ObjectSelector
| SelectSelector
| IconSelector
| MediaSelector
| StringSelector
| TargetSelector
| TemplateSelector
| ThemeSelector
| MushColorSelector
| MushLayoutSelector
| MushInfoSelector
| MushActionSelector
| MushAlignementSelector;

export interface EntitySelector {
entity: {
integration?: string;
domain?: string | string[];
device_class?: string;
};
}

export interface AttributeSelector {
attribute: {
entity_id: string;
};
}

export interface DeviceSelector {
device: {
integration?: string;
manufacturer?: string;
model?: string;
entity?: {
domain?: EntitySelector["entity"]["domain"];
device_class?: EntitySelector["entity"]["device_class"];
};
};
}
| TimeSelector
| MushSelector;

export interface DurationSelector {
export interface ActionSelector {
// eslint-disable-next-line @typescript-eslint/ban-types
duration: {};
action: {};
}

export interface AddonSelector {
Expand All @@ -79,21 +61,105 @@ export interface AreaSelector {
manufacturer?: DeviceSelector["device"]["manufacturer"];
model?: DeviceSelector["device"]["model"];
};
multiple?: boolean;
};
}

export interface TargetSelector {
target: {
export interface AttributeSelector {
attribute: {
entity_id?: string;
};
}

export interface BooleanSelector {
// eslint-disable-next-line @typescript-eslint/ban-types
boolean: {};
}

export interface ColorRGBSelector {
// eslint-disable-next-line @typescript-eslint/ban-types
color_rgb: {};
}

export interface ColorTempSelector {
color_temp: {
min_mireds?: number;
max_mireds?: number;
};
}

export interface DateSelector {
// eslint-disable-next-line @typescript-eslint/ban-types
date: {};
}

export interface DateTimeSelector {
// eslint-disable-next-line @typescript-eslint/ban-types
datetime: {};
}

export interface DeviceSelector {
device: {
integration?: string;
manufacturer?: string;
model?: string;
entity?: {
integration?: EntitySelector["entity"]["integration"];
domain?: EntitySelector["entity"]["domain"];
device_class?: EntitySelector["entity"]["device_class"];
};
device?: {
integration?: DeviceSelector["device"]["integration"];
manufacturer?: DeviceSelector["device"]["manufacturer"];
model?: DeviceSelector["device"]["model"];
};
multiple?: boolean;
};
}

export interface DurationSelector {
duration: {
enable_day?: boolean;
};
}

export interface EntitySelector {
entity: {
integration?: string;
domain?: string | string[];
device_class?: string;
multiple?: boolean;
include_entities?: string[];
exclude_entities?: string[];
};
}

export interface IconSelector {
icon: {
placeholder?: string;
fallbackPath?: string;
};
}

export interface LocationSelector {
location: { radius?: boolean; icon?: string };
}

export interface LocationSelectorValue {
latitude: number;
longitude: number;
radius?: number;
}

export interface MediaSelector {
// eslint-disable-next-line @typescript-eslint/ban-types
media: {};
}

export interface MediaSelectorValue {
entity_id?: string;
media_content_id?: string;
media_content_type?: string;
metadata?: {
title?: string;
thumbnail?: string | null;
media_class?: string;
children_media_class?: string | null;
navigateIds?: { media_content_type: string; media_content_id: string }[];
};
}

Expand All @@ -107,24 +173,23 @@ export interface NumberSelector {
};
}

export interface BooleanSelector {
// eslint-disable-next-line @typescript-eslint/ban-types
boolean: {};
}

export interface TemplateSelector {
export interface ObjectSelector {
// eslint-disable-next-line @typescript-eslint/ban-types
template: {};
object: {};
}

export interface TimeSelector {
// eslint-disable-next-line @typescript-eslint/ban-types
time: {};
export interface SelectOption {
value: string;
label: string;
}

export interface ActionSelector {
// eslint-disable-next-line @typescript-eslint/ban-types
action: {};
export interface SelectSelector {
select: {
multiple?: boolean;
custom_value?: boolean;
mode?: "list" | "dropdown";
options: string[] | SelectOption[];
};
}

export interface StringSelector {
Expand All @@ -148,51 +213,31 @@ export interface StringSelector {
};
}

export interface ObjectSelector {
// eslint-disable-next-line @typescript-eslint/ban-types
object: {};
}

export interface SelectOption {
value: string;
label: string;
}

export interface SelectSelector {
select: {
multiple?: boolean;
custom_value?: boolean;
mode?: "list" | "dropdown";
options: string[] | SelectOption[];
export interface TargetSelector {
target: {
entity?: {
integration?: EntitySelector["entity"]["integration"];
domain?: EntitySelector["entity"]["domain"];
device_class?: EntitySelector["entity"]["device_class"];
};
device?: {
integration?: DeviceSelector["device"]["integration"];
manufacturer?: DeviceSelector["device"]["manufacturer"];
model?: DeviceSelector["device"]["model"];
};
};
}

export interface IconSelector {
icon: {
placeholder?: string;
fallbackPath?: string;
};
export interface TemplateSelector {
// eslint-disable-next-line @typescript-eslint/ban-types
template: {};
}

export interface ThemeSelector {
// eslint-disable-next-line @typescript-eslint/ban-types
theme: {};
}

export interface MediaSelector {
export interface TimeSelector {
// eslint-disable-next-line @typescript-eslint/ban-types
media: {};
}

export interface MediaSelectorValue {
entity_id?: string;
media_content_id?: string;
media_content_type?: string;
metadata?: {
title?: string;
thumbnail?: string | null;
media_class?: string;
children_media_class?: string | null;
navigateIds?: { media_content_type: string; media_content_id: string }[];
};
time: {};
}

0 comments on commit 398749d

Please sign in to comment.