Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update selector and ha form #420

Merged
merged 1 commit into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: {};
}