mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 10:16:46 +00:00
Add selector demo to gallery (#10213)
This commit is contained in:
parent
4358b7f924
commit
6f6fc759cc
@ -210,6 +210,9 @@ module.exports.config = {
|
|||||||
publicPath: publicPath(latestBuild),
|
publicPath: publicPath(latestBuild),
|
||||||
isProdBuild,
|
isProdBuild,
|
||||||
latestBuild,
|
latestBuild,
|
||||||
|
defineOverlay: {
|
||||||
|
__DEMO__: true,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -173,6 +173,7 @@ gulp.task("webpack-dev-server-gallery", () =>
|
|||||||
compiler: webpack(bothBuilds(createGalleryConfig, { isProdBuild: false })),
|
compiler: webpack(bothBuilds(createGalleryConfig, { isProdBuild: false })),
|
||||||
contentBase: paths.gallery_output_root,
|
contentBase: paths.gallery_output_root,
|
||||||
port: 8100,
|
port: 8100,
|
||||||
|
listenHost: "0.0.0.0",
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
7
demo/src/stubs/area_registry.ts
Normal file
7
demo/src/stubs/area_registry.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { AreaRegistryEntry } from "../../../src/data/area_registry";
|
||||||
|
import type { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
||||||
|
|
||||||
|
export const mockAreaRegistry = (
|
||||||
|
hass: MockHomeAssistant,
|
||||||
|
data: AreaRegistryEntry[] = []
|
||||||
|
) => hass.mockWS("config/area_registry/list", () => data);
|
7
demo/src/stubs/device_registry.ts
Normal file
7
demo/src/stubs/device_registry.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { DeviceRegistryEntry } from "../../../src/data/device_registry";
|
||||||
|
import type { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
||||||
|
|
||||||
|
export const mockDeviceRegistry = (
|
||||||
|
hass: MockHomeAssistant,
|
||||||
|
data: DeviceRegistryEntry[] = []
|
||||||
|
) => hass.mockWS("config/device_registry/list", () => data);
|
7
demo/src/stubs/entity_registry.ts
Normal file
7
demo/src/stubs/entity_registry.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { EntityRegistryEntry } from "../../../src/data/entity_registry";
|
||||||
|
import type { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
||||||
|
|
||||||
|
export const mockEntityRegistry = (
|
||||||
|
hass: MockHomeAssistant,
|
||||||
|
data: EntityRegistryEntry[] = []
|
||||||
|
) => hass.mockWS("config/entity_registry/list", () => data);
|
59
demo/src/stubs/hassio_supervisor.ts
Normal file
59
demo/src/stubs/hassio_supervisor.ts
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import { HassioSupervisorInfo } from "../../../src/data/hassio/supervisor";
|
||||||
|
import type { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
||||||
|
|
||||||
|
export const mockHassioSupervisor = (hass: MockHomeAssistant) => {
|
||||||
|
hass.config.components.push("hassio");
|
||||||
|
hass.mockWS("supervisor/api", (msg) => {
|
||||||
|
if (msg.endpoint === "/supervisor/info") {
|
||||||
|
const data: HassioSupervisorInfo = {
|
||||||
|
version: "2021.10.dev0805",
|
||||||
|
version_latest: "2021.10.dev0806",
|
||||||
|
update_available: true,
|
||||||
|
channel: "dev",
|
||||||
|
arch: "aarch64",
|
||||||
|
supported: true,
|
||||||
|
healthy: true,
|
||||||
|
ip_address: "172.30.32.2",
|
||||||
|
wait_boot: 5,
|
||||||
|
timezone: "America/Los_Angeles",
|
||||||
|
logging: "info",
|
||||||
|
debug: false,
|
||||||
|
debug_block: false,
|
||||||
|
diagnostics: true,
|
||||||
|
addons: [
|
||||||
|
{
|
||||||
|
name: "Visual Studio Code",
|
||||||
|
slug: "a0d7b954_vscode",
|
||||||
|
description:
|
||||||
|
"Fully featured VSCode experience, to edit your HA config in the browser, including auto-completion!",
|
||||||
|
state: "started",
|
||||||
|
version: "3.6.2",
|
||||||
|
version_latest: "3.6.2",
|
||||||
|
update_available: false,
|
||||||
|
repository: "a0d7b954",
|
||||||
|
icon: true,
|
||||||
|
logo: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Z-Wave JS",
|
||||||
|
slug: "core_zwave_js",
|
||||||
|
description:
|
||||||
|
"Control a ZWave network with Home Assistant Z-Wave JS",
|
||||||
|
state: "started",
|
||||||
|
version: "0.1.45",
|
||||||
|
version_latest: "0.1.45",
|
||||||
|
update_available: false,
|
||||||
|
repository: "core",
|
||||||
|
icon: true,
|
||||||
|
logo: true,
|
||||||
|
},
|
||||||
|
] as any,
|
||||||
|
addons_repositories: [
|
||||||
|
"https://github.com/hassio-addons/repository",
|
||||||
|
] as any,
|
||||||
|
};
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
return Promise.reject(`${msg.method} ${msg.endpoint} is not implemented`);
|
||||||
|
});
|
||||||
|
};
|
131
gallery/src/demos/demo-ha-selector.ts
Normal file
131
gallery/src/demos/demo-ha-selector.ts
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
/* eslint-disable lit/no-template-arrow */
|
||||||
|
import "@material/mwc-button";
|
||||||
|
import { LitElement, TemplateResult, css, html } from "lit";
|
||||||
|
import { customElement, state } from "lit/decorators";
|
||||||
|
import "../../../src/components/ha-selector/ha-selector";
|
||||||
|
import "../../../src/components/ha-settings-row";
|
||||||
|
import { provideHass } from "../../../src/fake_data/provide_hass";
|
||||||
|
import type { HomeAssistant } from "../../../src/types";
|
||||||
|
import "../components/demo-black-white-row";
|
||||||
|
import { BlueprintInput } from "../../../src/data/blueprint";
|
||||||
|
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 { mockHassioSupervisor } from "../../../demo/src/stubs/hassio_supervisor";
|
||||||
|
|
||||||
|
const SCHEMAS: {
|
||||||
|
name: string;
|
||||||
|
input: Record<string, BlueprintInput | null>;
|
||||||
|
}[] = [
|
||||||
|
{
|
||||||
|
name: "One of each",
|
||||||
|
input: {
|
||||||
|
entity: { name: "Entity", selector: { entity: {} } },
|
||||||
|
device: { name: "Device", selector: { device: {} } },
|
||||||
|
addon: { name: "Addon", selector: { addon: {} } },
|
||||||
|
area: { name: "Area", selector: { area: {} } },
|
||||||
|
target: { name: "Target", selector: { target: {} } },
|
||||||
|
number_box: {
|
||||||
|
name: "Number Box",
|
||||||
|
selector: {
|
||||||
|
number: {
|
||||||
|
min: 0,
|
||||||
|
max: 10,
|
||||||
|
mode: "box",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
number_slider: {
|
||||||
|
name: "Number Slider",
|
||||||
|
selector: {
|
||||||
|
number: {
|
||||||
|
min: 0,
|
||||||
|
max: 10,
|
||||||
|
mode: "slider",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
boolean: { name: "Boolean", selector: { boolean: {} } },
|
||||||
|
time: { name: "Time", selector: { time: {} } },
|
||||||
|
action: { name: "Action", selector: { action: {} } },
|
||||||
|
text: { name: "Text", selector: { text: { multiline: false } } },
|
||||||
|
text_multiline: {
|
||||||
|
name: "Text multiline",
|
||||||
|
selector: { text: { multiline: true } },
|
||||||
|
},
|
||||||
|
object: { name: "Object", selector: { object: {} } },
|
||||||
|
select: {
|
||||||
|
name: "Select",
|
||||||
|
selector: { select: { options: ["Option 1", "Option 2"] } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
@customElement("demo-ha-selector")
|
||||||
|
class DemoHaSelector extends LitElement {
|
||||||
|
@state() private hass!: HomeAssistant;
|
||||||
|
|
||||||
|
private data = SCHEMAS.map(() => ({}));
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
const hass = provideHass(this);
|
||||||
|
hass.updateTranslations(null, "en");
|
||||||
|
hass.updateTranslations("config", "en");
|
||||||
|
mockEntityRegistry(hass);
|
||||||
|
mockDeviceRegistry(hass);
|
||||||
|
mockAreaRegistry(hass);
|
||||||
|
mockHassioSupervisor(hass);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render(): TemplateResult {
|
||||||
|
return html`
|
||||||
|
${SCHEMAS.map((info, idx) => {
|
||||||
|
const data = this.data[idx];
|
||||||
|
const valueChanged = (ev) => {
|
||||||
|
this.data[idx] = {
|
||||||
|
...data,
|
||||||
|
[ev.target.key]: ev.detail.value,
|
||||||
|
};
|
||||||
|
this.requestUpdate();
|
||||||
|
};
|
||||||
|
return html`
|
||||||
|
<demo-black-white-row .title=${info.name} .value=${this.data[idx]}>
|
||||||
|
${["light", "dark"].map((slot) =>
|
||||||
|
Object.entries(info.input).map(
|
||||||
|
([key, value]) =>
|
||||||
|
html`
|
||||||
|
<ha-settings-row narrow slot=${slot}>
|
||||||
|
<span slot="heading">${value?.name || key}</span>
|
||||||
|
<span slot="description">${value?.description}</span>
|
||||||
|
<ha-selector
|
||||||
|
.hass=${this.hass}
|
||||||
|
.selector=${value!.selector}
|
||||||
|
.key=${key}
|
||||||
|
.value=${data[key] ?? value!.default}
|
||||||
|
@value-changed=${valueChanged}
|
||||||
|
></ha-selector>
|
||||||
|
</ha-settings-row>
|
||||||
|
`
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</demo-black-white-row>
|
||||||
|
`;
|
||||||
|
})}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static styles = css`
|
||||||
|
paper-input,
|
||||||
|
ha-selector {
|
||||||
|
width: 60;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"demo-ha-selector": DemoHaSelector;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,10 @@ export const atLeastVersion = (
|
|||||||
minor: number,
|
minor: number,
|
||||||
patch?: number
|
patch?: number
|
||||||
): boolean => {
|
): boolean => {
|
||||||
|
if (__DEMO__) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
const [haMajor, haMinor, haPatch] = version.split(".", 3);
|
const [haMajor, haMinor, haPatch] = version.split(".", 3);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user