Compare commits

...
6 changed files with 71 additions and 0 deletions

No files matched your search

@@ -632,6 +632,10 @@ const SCHEMAS: {
},
language: { name: "Language", selector: { language: {} } },
navigation: { name: "Navigation", selector: { navigation: {} } },
ui_condition: {
name: "Dashboard conditions",
selector: { ui_condition: {} },
},
numeric_threshold: {
name: "Numeric threshold",
selector: { numeric_threshold: {} },
@@ -83,6 +83,7 @@ const SELECTOR_FALLBACK_VALUES = {
ui_action: undefined,
ui_clock_date_format: undefined,
ui_color: undefined,
ui_condition: undefined,
ui_state_content: undefined,
ui_time_format: undefined,
unit_of_measurement: undefined,
@@ -118,6 +118,7 @@ const SELECTOR_INITIAL_VALUES = {
ui_action: undefined,
ui_clock_date_format: undefined,
ui_color: undefined,
ui_condition: () => [],
ui_state_content: undefined,
ui_time_format: undefined,
unit_of_measurement: undefined,
@@ -0,0 +1,58 @@
import { css, html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import type { UiConditionSelector } from "../../data/selector";
import "../../panels/lovelace/editor/conditions/ha-card-conditions-editor";
import type { VisibilityCondition } from "../../panels/lovelace/common/validate-condition";
import type { HomeAssistant } from "../../types";
@customElement("ha-selector-ui_condition")
export class HaUiConditionSelector extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false })
public selector!: UiConditionSelector;
@property({ attribute: false }) public value?: VisibilityCondition[];
@property() public label?: string;
@property({ type: Boolean, reflect: true }) public disabled = false;
protected firstUpdated() {
// The editor's labels come from the dashboard translations, which only
// load with a dashboard; this selector can show anywhere.
this.hass.loadFragmentTranslation("lovelace");
}
// The editor fires `value-changed` with the new list, which bubbles out
// as this selector's own change. It has no disabled state of its own, so
// `inert` keeps it from being focused or changed in a disabled form.
protected render() {
return html`
${this.label ? html`<label>${this.label}</label>` : nothing}
<ha-card-conditions-editor
.hass=${this.hass}
.conditions=${this.value ?? []}
?inert=${this.disabled}
></ha-card-conditions-editor>
`;
}
static styles = css`
label {
display: block;
margin-bottom: var(--ha-space-1);
font-weight: var(--ha-font-weight-medium);
color: var(--secondary-text-color);
}
:host([disabled]) ha-card-conditions-editor {
opacity: var(--light-disabled-opacity);
}
`;
}
declare global {
interface HTMLElementTagNameMap {
"ha-selector-ui_condition": HaUiConditionSelector;
}
}
@@ -69,6 +69,7 @@ const LOAD_ELEMENTS = {
ui_action: () => import("./ha-selector-ui-action"),
ui_clock_date_format: () => import("./ha-selector-ui-clock-date-format"),
ui_color: () => import("./ha-selector-ui-color"),
ui_condition: () => import("./ha-selector-ui-condition"),
ui_state_content: () => import("./ha-selector-ui-state-content"),
ui_time_format: () => import("./ha-selector-ui-time-format"),
unit_of_measurement: () => import("./ha-selector-unit-of-measurement"),
+6
View File
@@ -89,6 +89,7 @@ export type Selector =
| UiActionSelector
| UiClockDateFormatSelector
| UiColorSelector
| UiConditionSelector
| UiStateContentSelector
| UiTimeFormatSelector
| UnitOfMeasurementSelector
@@ -203,6 +204,11 @@ export interface ConditionSelector {
} | null;
}
/** Dashboard conditions, edited like a card's visibility tab. */
export interface UiConditionSelector {
ui_condition: {} | null;
}
export interface ConversationAgentSelector {
conversation_agent: { language?: string } | null;
}