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

Add label support #16626

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 2 additions & 0 deletions demo/src/ha-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class HaDemo extends HomeAssistantAppEl {
has_entity_name: false,
unique_id: "co2_intensity",
options: null,
labels: [],
},
{
config_entry_id: "co2signal",
Expand All @@ -90,6 +91,7 @@ export class HaDemo extends HomeAssistantAppEl {
has_entity_name: false,
unique_id: "grid_fossil_fuel_percentage",
options: null,
labels: [],
},
]);

Expand Down
7 changes: 7 additions & 0 deletions demo/src/stubs/label_registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { LabelRegistryEntry } from "../../../src/data/label_registry";
import type { MockHomeAssistant } from "../../../src/fake_data/provide_hass";

export const mockLabelRegistry = (
hass: MockHomeAssistant,
data: LabelRegistryEntry[] = []
) => hass.mockWS("config/label_registry/list", () => data);
2 changes: 2 additions & 0 deletions gallery/src/pages/automation/editor-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "../../components/demo-black-white-row";
import { mockEntityRegistry } from "../../../../demo/src/stubs/entity_registry";
import { mockDeviceRegistry } from "../../../../demo/src/stubs/device_registry";
import { mockAreaRegistry } from "../../../../demo/src/stubs/area_registry";
import { mockLabelRegistry } from "../../../../demo/src/stubs/label_registry";
import { mockHassioSupervisor } from "../../../../demo/src/stubs/hassio_supervisor";
import "../../../../src/panels/config/automation/action/ha-automation-action";
import { HaChooseAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-choose";
Expand Down Expand Up @@ -59,6 +60,7 @@ class DemoHaAutomationEditorAction extends LitElement {
mockEntityRegistry(hass);
mockDeviceRegistry(hass);
mockAreaRegistry(hass);
mockLabelRegistry(hass);
mockHassioSupervisor(hass);
}

Expand Down
2 changes: 2 additions & 0 deletions gallery/src/pages/automation/editor-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "../../components/demo-black-white-row";
import { mockEntityRegistry } from "../../../../demo/src/stubs/entity_registry";
import { mockDeviceRegistry } from "../../../../demo/src/stubs/device_registry";
import { mockAreaRegistry } from "../../../../demo/src/stubs/area_registry";
import { mockLabelRegistry } from "../../../../demo/src/stubs/label_registry";
import { mockHassioSupervisor } from "../../../../demo/src/stubs/hassio_supervisor";
import type { ConditionWithShorthand } from "../../../../src/data/automation";
import "../../../../src/panels/config/automation/condition/ha-automation-condition";
Expand Down Expand Up @@ -95,6 +96,7 @@ class DemoHaAutomationEditorCondition extends LitElement {
mockEntityRegistry(hass);
mockDeviceRegistry(hass);
mockAreaRegistry(hass);
mockLabelRegistry(hass);
mockHassioSupervisor(hass);
}

Expand Down
2 changes: 2 additions & 0 deletions gallery/src/pages/automation/editor-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "../../components/demo-black-white-row";
import { mockEntityRegistry } from "../../../../demo/src/stubs/entity_registry";
import { mockDeviceRegistry } from "../../../../demo/src/stubs/device_registry";
import { mockAreaRegistry } from "../../../../demo/src/stubs/area_registry";
import { mockLabelRegistry } from "../../../../demo/src/stubs/label_registry";
import { mockHassioSupervisor } from "../../../../demo/src/stubs/hassio_supervisor";
import type { Trigger } from "../../../../src/data/automation";
import { HaGeolocationTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-geo_location";
Expand Down Expand Up @@ -141,6 +142,7 @@ class DemoHaAutomationEditorTrigger extends LitElement {
mockEntityRegistry(hass);
mockDeviceRegistry(hass);
mockAreaRegistry(hass);
mockLabelRegistry(hass);
mockHassioSupervisor(hass);
}

Expand Down
31 changes: 31 additions & 0 deletions gallery/src/pages/components/ha-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { mockAreaRegistry } from "../../../../demo/src/stubs/area_registry";
import { mockConfigEntries } from "../../../../demo/src/stubs/config_entries";
import { mockDeviceRegistry } from "../../../../demo/src/stubs/device_registry";
import { mockEntityRegistry } from "../../../../demo/src/stubs/entity_registry";
import { mockLabelRegistry } from "../../../../demo/src/stubs/label_registry";
import { mockHassioSupervisor } from "../../../../demo/src/stubs/hassio_supervisor";
import { computeInitialHaFormData } from "../../../../src/components/ha-form/compute-initial-ha-form-data";
import "../../../../src/components/ha-form/ha-form";
Expand Down Expand Up @@ -58,6 +59,7 @@ const DEVICES = [
hw_version: null,
via_device_id: null,
serial_number: null,
labels: [],
},
{
area_id: "backyard",
Expand All @@ -76,6 +78,7 @@ const DEVICES = [
hw_version: null,
via_device_id: null,
serial_number: null,
labels: [],
},
{
area_id: null,
Expand All @@ -94,6 +97,7 @@ const DEVICES = [
hw_version: null,
via_device_id: null,
serial_number: null,
labels: [],
},
];

Expand All @@ -118,6 +122,30 @@ const AREAS = [
},
];

const LABELS = [
{
label_id: "romantic",
name: "Romantic",
icon: "mdi:heart",
color: "#ff0000",
description: "Lights that can create a romantic atmosphere",
},
{
label_id: "away",
name: "Away",
icon: "mdi:home-export-outline",
color: "#cccccc",
description: "All that can all be turned off when away from home",
},
{
label_id: "cleaning",
name: "Cleaning",
icon: "mdi:home-export-outline",
color: "#cccccc",
description: "Everything to turn on while cleaning the house",
},
];

const SCHEMAS: {
title: string;
translations?: Record<string, string>;
Expand All @@ -132,6 +160,7 @@ const SCHEMAS: {
entity: "Entity",
device: "Device",
area: "Area",
label: "Label",
target: "Target",
number: "Number",
boolean: "Boolean",
Expand Down Expand Up @@ -163,6 +192,7 @@ const SCHEMAS: {
{ name: "Config entry", selector: { config_entry: {} } },
{ name: "Duration", selector: { duration: {} } },
{ name: "area", selector: { area: {} } },
{ name: "label", selector: { label: {} } },
{ name: "target", selector: { target: {} } },
{ name: "number", selector: { number: { min: 0, max: 10 } } },
{ name: "boolean", selector: { boolean: {} } },
Expand Down Expand Up @@ -444,6 +474,7 @@ class DemoHaForm extends LitElement {
mockDeviceRegistry(hass, DEVICES);
mockConfigEntries(hass);
mockAreaRegistry(hass, AREAS);
mockLabelRegistry(hass, LABELS);
mockHassioSupervisor(hass);
}

Expand Down
32 changes: 31 additions & 1 deletion gallery/src/pages/components/ha-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { mockConfigEntries } from "../../../../demo/src/stubs/config_entries";
import { mockDeviceRegistry } from "../../../../demo/src/stubs/device_registry";
import { mockEntityRegistry } from "../../../../demo/src/stubs/entity_registry";
import { mockHassioSupervisor } from "../../../../demo/src/stubs/hassio_supervisor";
import { mockLabelRegistry } from "../../../../demo/src/stubs/label_registry";
import "../../../../src/components/ha-selector/ha-selector";
import "../../../../src/components/ha-settings-row";
import { BlueprintInput } from "../../../../src/data/blueprint";
Expand Down Expand Up @@ -54,6 +55,7 @@ const DEVICES = [
hw_version: null,
via_device_id: null,
serial_number: null,
labels: [],
},
{
area_id: "backyard",
Expand All @@ -72,6 +74,7 @@ const DEVICES = [
hw_version: null,
via_device_id: null,
serial_number: null,
labels: [],
},
{
area_id: null,
Expand All @@ -90,9 +93,9 @@ const DEVICES = [
hw_version: null,
via_device_id: null,
serial_number: null,
labels: [],
},
];

const AREAS = [
{
area_id: "backyard",
Expand All @@ -114,6 +117,30 @@ const AREAS = [
},
];

const LABELS = [
{
label_id: "romantic",
name: "Romantic",
icon: "mdi:heart",
color: "#ff0000",
description: "Lights that can create a romantic atmosphere",
},
{
label_id: "away",
name: "Away",
icon: "mdi:home-export-outline",
color: "#cccccc",
description: "All that can all be turned off when away from home",
},
{
label_id: "cleaning",
name: "Cleaning",
icon: "mdi:home-export-outline",
color: "#cccccc",
description: "Everything to turn on while cleaning the house",
},
];

const SCHEMAS: {
name: string;
input: Record<string, (BlueprintInput & { required?: boolean }) | null>;
Expand All @@ -138,6 +165,7 @@ const SCHEMAS: {
duration: { name: "Duration", selector: { duration: {} } },
addon: { name: "Addon", selector: { addon: {} } },
area: { name: "Area", selector: { area: {} } },
label: { name: "Label", selector: { label: {} } },
target: { name: "Target", selector: { target: {} } },
number_box: {
name: "Number Box",
Expand Down Expand Up @@ -279,6 +307,7 @@ const SCHEMAS: {
entity: { name: "Entity", selector: { entity: { multiple: true } } },
device: { name: "Device", selector: { device: { multiple: true } } },
area: { name: "Area", selector: { area: { multiple: true } } },
label: { name: "Label", selector: { label: { multiple: true } } },
select: {
name: "Select Multiple",
selector: {
Expand Down Expand Up @@ -335,6 +364,7 @@ class DemoHaSelector extends LitElement implements ProvideHassElement {
mockDeviceRegistry(hass, DEVICES);
mockConfigEntries(hass);
mockAreaRegistry(hass, AREAS);
mockLabelRegistry(hass, LABELS);
mockHassioSupervisor(hass);
hass.mockWS("auth/sign_path", (params) => params);
hass.mockWS("media_player/browse_media", this._browseMedia);
Expand Down
2 changes: 2 additions & 0 deletions gallery/src/pages/misc/integration-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ const createEntityRegistryEntries = (
has_entity_name: false,
unique_id: "updater",
options: null,
labels: [],
},
];

Expand All @@ -221,6 +222,7 @@ const createDeviceRegistryEntries = (
name_by_user: null,
disabled_by: null,
configuration_url: null,
labels: [],
},
];

Expand Down
Loading
Loading