mirror of
https://github.com/home-assistant/frontend.git
synced 2025-09-04 02:45:02 +00:00
Compare commits
1 Commits
20221002.0
...
fix-entity
Author | SHA1 | Date | |
---|---|---|---|
![]() |
be6fef1824 |
4
.github/workflows/demo.yaml
vendored
4
.github/workflows/demo.yaml
vendored
@@ -27,7 +27,9 @@ jobs:
|
|||||||
- name: Build Demo
|
- name: Build Demo
|
||||||
run: ./node_modules/.bin/gulp build-demo
|
run: ./node_modules/.bin/gulp build-demo
|
||||||
- name: Deploy to Netlify
|
- name: Deploy to Netlify
|
||||||
run: npx netlify-cli deploy --dir=demo/dist --prod
|
uses: netlify/actions/cli@master
|
||||||
env:
|
env:
|
||||||
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
||||||
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEMO_DEV_SITE_ID }}
|
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEMO_DEV_SITE_ID }}
|
||||||
|
with:
|
||||||
|
args: deploy --dir=demo/dist --prod
|
||||||
|
2
.github/workflows/stale.yml
vendored
2
.github/workflows/stale.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: 90 days stale policy
|
- name: 90 days stale policy
|
||||||
uses: actions/stale@v6.0.0
|
uses: actions/stale@v5.1.1
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
days-before-stale: 90
|
days-before-stale: 90
|
||||||
|
@@ -61,14 +61,12 @@ class HaDemo extends HomeAssistantAppEl {
|
|||||||
area_id: null,
|
area_id: null,
|
||||||
disabled_by: null,
|
disabled_by: null,
|
||||||
entity_id: "sensor.co2_intensity",
|
entity_id: "sensor.co2_intensity",
|
||||||
id: "sensor.co2_intensity",
|
|
||||||
name: null,
|
name: null,
|
||||||
icon: null,
|
icon: null,
|
||||||
platform: "co2signal",
|
platform: "co2signal",
|
||||||
hidden_by: null,
|
hidden_by: null,
|
||||||
entity_category: null,
|
entity_category: null,
|
||||||
has_entity_name: false,
|
has_entity_name: false,
|
||||||
unique_id: "co2_intensity",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
config_entry_id: "co2signal",
|
config_entry_id: "co2signal",
|
||||||
@@ -76,14 +74,12 @@ class HaDemo extends HomeAssistantAppEl {
|
|||||||
area_id: null,
|
area_id: null,
|
||||||
disabled_by: null,
|
disabled_by: null,
|
||||||
entity_id: "sensor.grid_fossil_fuel_percentage",
|
entity_id: "sensor.grid_fossil_fuel_percentage",
|
||||||
id: "sensor.co2_intensity",
|
|
||||||
name: null,
|
name: null,
|
||||||
icon: null,
|
icon: null,
|
||||||
platform: "co2signal",
|
platform: "co2signal",
|
||||||
hidden_by: null,
|
hidden_by: null,
|
||||||
entity_category: null,
|
entity_category: null,
|
||||||
has_entity_name: false,
|
has_entity_name: false,
|
||||||
unique_id: "grid_fossil_fuel_percentage",
|
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@@ -11,12 +11,14 @@ export const mockEnergy = (hass: MockHomeAssistant) => {
|
|||||||
{
|
{
|
||||||
stat_energy_from: "sensor.energy_consumption_tarif_1",
|
stat_energy_from: "sensor.energy_consumption_tarif_1",
|
||||||
stat_cost: "sensor.energy_consumption_tarif_1_cost",
|
stat_cost: "sensor.energy_consumption_tarif_1_cost",
|
||||||
|
entity_energy_from: "sensor.energy_consumption_tarif_1",
|
||||||
entity_energy_price: null,
|
entity_energy_price: null,
|
||||||
number_energy_price: null,
|
number_energy_price: null,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
stat_energy_from: "sensor.energy_consumption_tarif_2",
|
stat_energy_from: "sensor.energy_consumption_tarif_2",
|
||||||
stat_cost: "sensor.energy_consumption_tarif_2_cost",
|
stat_cost: "sensor.energy_consumption_tarif_2_cost",
|
||||||
|
entity_energy_from: "sensor.energy_consumption_tarif_2",
|
||||||
entity_energy_price: null,
|
entity_energy_price: null,
|
||||||
number_energy_price: null,
|
number_energy_price: null,
|
||||||
},
|
},
|
||||||
@@ -25,12 +27,14 @@ export const mockEnergy = (hass: MockHomeAssistant) => {
|
|||||||
{
|
{
|
||||||
stat_energy_to: "sensor.energy_production_tarif_1",
|
stat_energy_to: "sensor.energy_production_tarif_1",
|
||||||
stat_compensation: "sensor.energy_production_tarif_1_compensation",
|
stat_compensation: "sensor.energy_production_tarif_1_compensation",
|
||||||
|
entity_energy_to: "sensor.energy_production_tarif_1",
|
||||||
entity_energy_price: null,
|
entity_energy_price: null,
|
||||||
number_energy_price: null,
|
number_energy_price: null,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
stat_energy_to: "sensor.energy_production_tarif_2",
|
stat_energy_to: "sensor.energy_production_tarif_2",
|
||||||
stat_compensation: "sensor.energy_production_tarif_2_compensation",
|
stat_compensation: "sensor.energy_production_tarif_2_compensation",
|
||||||
|
entity_energy_to: "sensor.energy_production_tarif_2",
|
||||||
entity_energy_price: null,
|
entity_energy_price: null,
|
||||||
number_energy_price: null,
|
number_energy_price: null,
|
||||||
},
|
},
|
||||||
@@ -51,6 +55,7 @@ export const mockEnergy = (hass: MockHomeAssistant) => {
|
|||||||
type: "gas",
|
type: "gas",
|
||||||
stat_energy_from: "sensor.energy_gas",
|
stat_energy_from: "sensor.energy_gas",
|
||||||
stat_cost: "sensor.energy_gas_cost",
|
stat_cost: "sensor.energy_gas_cost",
|
||||||
|
entity_energy_from: "sensor.energy_gas",
|
||||||
entity_energy_price: null,
|
entity_energy_price: null,
|
||||||
number_energy_price: null,
|
number_energy_price: null,
|
||||||
},
|
},
|
||||||
|
@@ -6,7 +6,7 @@ import {
|
|||||||
endOfDay,
|
endOfDay,
|
||||||
} from "date-fns/esm";
|
} from "date-fns/esm";
|
||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { StatisticValue } from "../../../src/data/recorder";
|
import { StatisticValue } from "../../../src/data/history";
|
||||||
import { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
import { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
||||||
|
|
||||||
interface HistoryQueryParams {
|
interface HistoryQueryParams {
|
||||||
|
@@ -1,56 +0,0 @@
|
|||||||
---
|
|
||||||
title: When to use remove, delete, add and create
|
|
||||||
subtitle: The difference between remove/delete and add/create.
|
|
||||||
---
|
|
||||||
|
|
||||||
# Remove vs Delete
|
|
||||||
Remove and Delete are quite similar, but can be frustrating if used inconsistently.
|
|
||||||
|
|
||||||
## Remove
|
|
||||||
Take away and set aside, but kept in existence.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
* Removing a user's permission
|
|
||||||
* Removing a user from a group
|
|
||||||
* Removing links between items
|
|
||||||
* Removing a widget
|
|
||||||
* Removing a link
|
|
||||||
* Removing an item from a cart
|
|
||||||
|
|
||||||
## Delete
|
|
||||||
Erase, rendered nonexistent or nonrecoverable.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
* Deleting a field
|
|
||||||
* Deleting a value in a field
|
|
||||||
* Deleting a task
|
|
||||||
* Deleting a group
|
|
||||||
* Deleting a permission
|
|
||||||
* Deleting a calendar event
|
|
||||||
|
|
||||||
# Add vs Create
|
|
||||||
In most cases, Create can be paired with Delete, and Add can be paired with Remove.
|
|
||||||
|
|
||||||
## Add
|
|
||||||
An already-exisiting item.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
* Adding a permission to a user
|
|
||||||
* Adding a user to a group
|
|
||||||
* Adding links between items
|
|
||||||
* Adding a widget
|
|
||||||
* Adding a link
|
|
||||||
* Adding an item to a cart
|
|
||||||
|
|
||||||
## Create
|
|
||||||
Something made from scratch.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
* Creating a new field
|
|
||||||
* Creating a new value in a field
|
|
||||||
* Creating a new task
|
|
||||||
* Creating a new group
|
|
||||||
* Creating a new permission
|
|
||||||
* Creating a new calendar event
|
|
||||||
|
|
||||||
Based on this is [UX magazine article](https://uxmag.com/articles/ui-copy-remove-vs-delete2-banner).
|
|
@@ -36,7 +36,6 @@ const conditions = [
|
|||||||
{ condition: "sun", after: "sunset" },
|
{ condition: "sun", after: "sunset" },
|
||||||
{ condition: "sun", after: "sunrise", offset: "-01:00" },
|
{ condition: "sun", after: "sunrise", offset: "-01:00" },
|
||||||
{ condition: "zone", entity_id: "device_tracker.person", zone: "zone.home" },
|
{ condition: "zone", entity_id: "device_tracker.person", zone: "zone.home" },
|
||||||
{ condition: "trigger", id: "motion" },
|
|
||||||
{ condition: "time" },
|
{ condition: "time" },
|
||||||
{ condition: "template" },
|
{ condition: "template" },
|
||||||
];
|
];
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable lit/no-template-arrow */
|
/* eslint-disable lit/no-template-arrow */
|
||||||
import { LitElement, TemplateResult, html, css } from "lit";
|
import { LitElement, TemplateResult, html } from "lit";
|
||||||
import { customElement, state } from "lit/decorators";
|
import { customElement, state } from "lit/decorators";
|
||||||
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
||||||
import type { HomeAssistant } from "../../../../src/types";
|
import type { HomeAssistant } from "../../../../src/types";
|
||||||
@@ -47,8 +47,6 @@ const SCHEMAS: { name: string; actions: Action[] }[] = [
|
|||||||
class DemoHaAutomationEditorAction extends LitElement {
|
class DemoHaAutomationEditorAction extends LitElement {
|
||||||
@state() private hass!: HomeAssistant;
|
@state() private hass!: HomeAssistant;
|
||||||
|
|
||||||
@state() private _disabled = false;
|
|
||||||
|
|
||||||
private data: any = SCHEMAS.map((info) => info.actions);
|
private data: any = SCHEMAS.map((info) => info.actions);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -69,15 +67,6 @@ class DemoHaAutomationEditorAction extends LitElement {
|
|||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
};
|
};
|
||||||
return html`
|
return html`
|
||||||
<div class="options">
|
|
||||||
<ha-formfield label="Disabled">
|
|
||||||
<ha-switch
|
|
||||||
.name=${"disabled"}
|
|
||||||
.checked=${this._disabled}
|
|
||||||
@change=${this._handleOptionChange}
|
|
||||||
></ha-switch>
|
|
||||||
</ha-formfield>
|
|
||||||
</div>
|
|
||||||
${SCHEMAS.map(
|
${SCHEMAS.map(
|
||||||
(info, sampleIdx) => html`
|
(info, sampleIdx) => html`
|
||||||
<demo-black-white-row
|
<demo-black-white-row
|
||||||
@@ -92,7 +81,6 @@ class DemoHaAutomationEditorAction extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.actions=${this.data[sampleIdx]}
|
.actions=${this.data[sampleIdx]}
|
||||||
.sampleIdx=${sampleIdx}
|
.sampleIdx=${sampleIdx}
|
||||||
.disabled=${this._disabled}
|
|
||||||
@value-changed=${valueChanged}
|
@value-changed=${valueChanged}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
`
|
`
|
||||||
@@ -102,20 +90,6 @@ class DemoHaAutomationEditorAction extends LitElement {
|
|||||||
)}
|
)}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleOptionChange(ev) {
|
|
||||||
this[`_${ev.target.name}`] = ev.target.checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
static styles = css`
|
|
||||||
.options {
|
|
||||||
max-width: 800px;
|
|
||||||
margin: 16px auto;
|
|
||||||
}
|
|
||||||
.options ha-formfield {
|
|
||||||
margin-right: 16px;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable lit/no-template-arrow */
|
/* eslint-disable lit/no-template-arrow */
|
||||||
import { LitElement, TemplateResult, html, css } from "lit";
|
import { LitElement, TemplateResult, html } from "lit";
|
||||||
import { customElement, state } from "lit/decorators";
|
import { customElement, state } from "lit/decorators";
|
||||||
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
||||||
import type { HomeAssistant } from "../../../../src/types";
|
import type { HomeAssistant } from "../../../../src/types";
|
||||||
@@ -83,8 +83,6 @@ const SCHEMAS: { name: string; conditions: ConditionWithShorthand[] }[] = [
|
|||||||
class DemoHaAutomationEditorCondition extends LitElement {
|
class DemoHaAutomationEditorCondition extends LitElement {
|
||||||
@state() private hass!: HomeAssistant;
|
@state() private hass!: HomeAssistant;
|
||||||
|
|
||||||
@state() private _disabled = false;
|
|
||||||
|
|
||||||
private data: any = SCHEMAS.map((info) => info.conditions);
|
private data: any = SCHEMAS.map((info) => info.conditions);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -105,15 +103,6 @@ class DemoHaAutomationEditorCondition extends LitElement {
|
|||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
};
|
};
|
||||||
return html`
|
return html`
|
||||||
<div class="options">
|
|
||||||
<ha-formfield label="Disabled">
|
|
||||||
<ha-switch
|
|
||||||
.name=${"disabled"}
|
|
||||||
.checked=${this._disabled}
|
|
||||||
@change=${this._handleOptionChange}
|
|
||||||
></ha-switch>
|
|
||||||
</ha-formfield>
|
|
||||||
</div>
|
|
||||||
${SCHEMAS.map(
|
${SCHEMAS.map(
|
||||||
(info, sampleIdx) => html`
|
(info, sampleIdx) => html`
|
||||||
<demo-black-white-row
|
<demo-black-white-row
|
||||||
@@ -128,7 +117,6 @@ class DemoHaAutomationEditorCondition extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.conditions=${this.data[sampleIdx]}
|
.conditions=${this.data[sampleIdx]}
|
||||||
.sampleIdx=${sampleIdx}
|
.sampleIdx=${sampleIdx}
|
||||||
.disabled=${this._disabled}
|
|
||||||
@value-changed=${valueChanged}
|
@value-changed=${valueChanged}
|
||||||
></ha-automation-condition>
|
></ha-automation-condition>
|
||||||
`
|
`
|
||||||
@@ -138,20 +126,6 @@ class DemoHaAutomationEditorCondition extends LitElement {
|
|||||||
)}
|
)}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleOptionChange(ev) {
|
|
||||||
this[`_${ev.target.name}`] = ev.target.checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
static styles = css`
|
|
||||||
.options {
|
|
||||||
max-width: 800px;
|
|
||||||
margin: 16px auto;
|
|
||||||
}
|
|
||||||
.options ha-formfield {
|
|
||||||
margin-right: 16px;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable lit/no-template-arrow */
|
/* eslint-disable lit/no-template-arrow */
|
||||||
import { LitElement, TemplateResult, html, css } from "lit";
|
import { LitElement, TemplateResult, html } from "lit";
|
||||||
import { customElement, state } from "lit/decorators";
|
import { customElement, state } from "lit/decorators";
|
||||||
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
||||||
import type { HomeAssistant } from "../../../../src/types";
|
import type { HomeAssistant } from "../../../../src/types";
|
||||||
@@ -107,8 +107,6 @@ const SCHEMAS: { name: string; triggers: Trigger[] }[] = [
|
|||||||
class DemoHaAutomationEditorTrigger extends LitElement {
|
class DemoHaAutomationEditorTrigger extends LitElement {
|
||||||
@state() private hass!: HomeAssistant;
|
@state() private hass!: HomeAssistant;
|
||||||
|
|
||||||
@state() private _disabled = false;
|
|
||||||
|
|
||||||
private data: any = SCHEMAS.map((info) => info.triggers);
|
private data: any = SCHEMAS.map((info) => info.triggers);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -129,15 +127,6 @@ class DemoHaAutomationEditorTrigger extends LitElement {
|
|||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
};
|
};
|
||||||
return html`
|
return html`
|
||||||
<div class="options">
|
|
||||||
<ha-formfield label="Disabled">
|
|
||||||
<ha-switch
|
|
||||||
.name=${"disabled"}
|
|
||||||
.checked=${this._disabled}
|
|
||||||
@change=${this._handleOptionChange}
|
|
||||||
></ha-switch>
|
|
||||||
</ha-formfield>
|
|
||||||
</div>
|
|
||||||
${SCHEMAS.map(
|
${SCHEMAS.map(
|
||||||
(info, sampleIdx) => html`
|
(info, sampleIdx) => html`
|
||||||
<demo-black-white-row
|
<demo-black-white-row
|
||||||
@@ -152,7 +141,6 @@ class DemoHaAutomationEditorTrigger extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.triggers=${this.data[sampleIdx]}
|
.triggers=${this.data[sampleIdx]}
|
||||||
.sampleIdx=${sampleIdx}
|
.sampleIdx=${sampleIdx}
|
||||||
.disabled=${this._disabled}
|
|
||||||
@value-changed=${valueChanged}
|
@value-changed=${valueChanged}
|
||||||
></ha-automation-trigger>
|
></ha-automation-trigger>
|
||||||
`
|
`
|
||||||
@@ -162,20 +150,6 @@ class DemoHaAutomationEditorTrigger extends LitElement {
|
|||||||
)}
|
)}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleOptionChange(ev) {
|
|
||||||
this[`_${ev.target.name}`] = ev.target.checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
static styles = css`
|
|
||||||
.options {
|
|
||||||
max-width: 800px;
|
|
||||||
margin: 16px auto;
|
|
||||||
}
|
|
||||||
.options ha-formfield {
|
|
||||||
margin-right: 16px;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
---
|
---
|
||||||
title: Dialogs
|
title: Dialgos
|
||||||
subtitle: Dialogs provide important prompts in a user flow.
|
subtitle: Dialogs provide important prompts in a user flow.
|
||||||
---
|
---
|
||||||
|
|
||||||
# Material Design 3
|
# Material Desing 3
|
||||||
|
|
||||||
Our dialogs are based on the latest version of Material Design. Specs and guidelines can be found on it's [website](https://m3.material.io/components/dialogs/overview).
|
Our dialogs are based on the latest version of Material Design. Specs and guidelines can be found on it's [website](https://m3.material.io/components/dialogs/overview).
|
||||||
|
|
||||||
|
@@ -195,48 +195,6 @@ const SCHEMAS: {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
select_disabled_list: {
|
|
||||||
name: "Select disabled option",
|
|
||||||
selector: {
|
|
||||||
select: {
|
|
||||||
options: [
|
|
||||||
{ label: "Option 1", value: "Option 1" },
|
|
||||||
{ label: "Option 2", value: "Option 2" },
|
|
||||||
{ label: "Option 3", value: "Option 3", disabled: true },
|
|
||||||
],
|
|
||||||
mode: "list",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
select_disabled_multiple: {
|
|
||||||
name: "Select disabled option",
|
|
||||||
selector: {
|
|
||||||
select: {
|
|
||||||
multiple: true,
|
|
||||||
options: [
|
|
||||||
{ label: "Option 1", value: "Option 1" },
|
|
||||||
{ label: "Option 2", value: "Option 2" },
|
|
||||||
{ label: "Option 3", value: "Option 3", disabled: true },
|
|
||||||
],
|
|
||||||
mode: "list",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
select_disabled: {
|
|
||||||
name: "Select disabled option",
|
|
||||||
selector: {
|
|
||||||
select: {
|
|
||||||
options: [
|
|
||||||
{ label: "Option 1", value: "Option 1" },
|
|
||||||
{ label: "Option 2", value: "Option 2" },
|
|
||||||
{ label: "Option 3", value: "Option 3", disabled: true },
|
|
||||||
{ label: "Option 4", value: "Option 4", disabled: true },
|
|
||||||
{ label: "Option 5", value: "Option 5", disabled: true },
|
|
||||||
{ label: "Option 6", value: "Option 6" },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
select_custom: {
|
select_custom: {
|
||||||
name: "Select (Custom)",
|
name: "Select (Custom)",
|
||||||
selector: {
|
selector: {
|
||||||
|
@@ -191,12 +191,10 @@ const createEntityRegistryEntries = (
|
|||||||
hidden_by: null,
|
hidden_by: null,
|
||||||
entity_category: null,
|
entity_category: null,
|
||||||
entity_id: "binary_sensor.updater",
|
entity_id: "binary_sensor.updater",
|
||||||
id: "binary_sensor.updater",
|
|
||||||
name: null,
|
name: null,
|
||||||
icon: null,
|
icon: null,
|
||||||
platform: "updater",
|
platform: "updater",
|
||||||
has_entity_name: false,
|
has_entity_name: false,
|
||||||
unique_id: "updater",
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@@ -1,7 +1,16 @@
|
|||||||
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
||||||
import { customElement, property, query } from "lit/decorators";
|
import { customElement, property, query } from "lit/decorators";
|
||||||
import "../../../../src/components/ha-card";
|
import "../../../../src/components/ha-card";
|
||||||
import { CoverEntityFeature } from "../../../../src/data/cover";
|
import {
|
||||||
|
SUPPORT_OPEN,
|
||||||
|
SUPPORT_STOP,
|
||||||
|
SUPPORT_CLOSE,
|
||||||
|
SUPPORT_SET_POSITION,
|
||||||
|
SUPPORT_OPEN_TILT,
|
||||||
|
SUPPORT_STOP_TILT,
|
||||||
|
SUPPORT_CLOSE_TILT,
|
||||||
|
SUPPORT_SET_TILT_POSITION,
|
||||||
|
} from "../../../../src/data/cover";
|
||||||
import "../../../../src/dialogs/more-info/more-info-content";
|
import "../../../../src/dialogs/more-info/more-info-content";
|
||||||
import { getEntity } from "../../../../src/fake_data/entity";
|
import { getEntity } from "../../../../src/fake_data/entity";
|
||||||
import {
|
import {
|
||||||
@@ -13,127 +22,113 @@ import "../../components/demo-more-infos";
|
|||||||
const ENTITIES = [
|
const ENTITIES = [
|
||||||
getEntity("cover", "position_buttons", "on", {
|
getEntity("cover", "position_buttons", "on", {
|
||||||
friendly_name: "Position Buttons",
|
friendly_name: "Position Buttons",
|
||||||
supported_features:
|
supported_features: SUPPORT_OPEN + SUPPORT_STOP + SUPPORT_CLOSE,
|
||||||
CoverEntityFeature.OPEN +
|
|
||||||
CoverEntityFeature.STOP +
|
|
||||||
CoverEntityFeature.CLOSE,
|
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "position_slider_half", "on", {
|
getEntity("cover", "position_slider_half", "on", {
|
||||||
friendly_name: "Position Half-Open",
|
friendly_name: "Position Half-Open",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN +
|
SUPPORT_OPEN + SUPPORT_STOP + SUPPORT_CLOSE + SUPPORT_SET_POSITION,
|
||||||
CoverEntityFeature.STOP +
|
|
||||||
CoverEntityFeature.CLOSE +
|
|
||||||
CoverEntityFeature.SET_POSITION,
|
|
||||||
current_position: 50,
|
current_position: 50,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "position_slider_open", "on", {
|
getEntity("cover", "position_slider_open", "on", {
|
||||||
friendly_name: "Position Open",
|
friendly_name: "Position Open",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN +
|
SUPPORT_OPEN + SUPPORT_STOP + SUPPORT_CLOSE + SUPPORT_SET_POSITION,
|
||||||
CoverEntityFeature.STOP +
|
|
||||||
CoverEntityFeature.CLOSE +
|
|
||||||
CoverEntityFeature.SET_POSITION,
|
|
||||||
current_position: 100,
|
current_position: 100,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "position_slider_closed", "on", {
|
getEntity("cover", "position_slider_closed", "on", {
|
||||||
friendly_name: "Position Closed",
|
friendly_name: "Position Closed",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN +
|
SUPPORT_OPEN + SUPPORT_STOP + SUPPORT_CLOSE + SUPPORT_SET_POSITION,
|
||||||
CoverEntityFeature.STOP +
|
|
||||||
CoverEntityFeature.CLOSE +
|
|
||||||
CoverEntityFeature.SET_POSITION,
|
|
||||||
current_position: 0,
|
current_position: 0,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "tilt_buttons", "on", {
|
getEntity("cover", "tilt_buttons", "on", {
|
||||||
friendly_name: "Tilt Buttons",
|
friendly_name: "Tilt Buttons",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT + SUPPORT_STOP_TILT + SUPPORT_CLOSE_TILT,
|
||||||
CoverEntityFeature.STOP_TILT +
|
|
||||||
CoverEntityFeature.CLOSE_TILT,
|
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "tilt_slider_half", "on", {
|
getEntity("cover", "tilt_slider_half", "on", {
|
||||||
friendly_name: "Tilt Half-Open",
|
friendly_name: "Tilt Half-Open",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT +
|
||||||
CoverEntityFeature.STOP_TILT +
|
SUPPORT_STOP_TILT +
|
||||||
CoverEntityFeature.CLOSE_TILT +
|
SUPPORT_CLOSE_TILT +
|
||||||
CoverEntityFeature.SET_TILT_POSITION,
|
SUPPORT_SET_TILT_POSITION,
|
||||||
current_tilt_position: 50,
|
current_tilt_position: 50,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "tilt_slider_open", "on", {
|
getEntity("cover", "tilt_slider_open", "on", {
|
||||||
friendly_name: "Tilt Open",
|
friendly_name: "Tilt Open",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT +
|
||||||
CoverEntityFeature.STOP_TILT +
|
SUPPORT_STOP_TILT +
|
||||||
CoverEntityFeature.CLOSE_TILT +
|
SUPPORT_CLOSE_TILT +
|
||||||
CoverEntityFeature.SET_TILT_POSITION,
|
SUPPORT_SET_TILT_POSITION,
|
||||||
current_tilt_position: 100,
|
current_tilt_position: 100,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "tilt_slider_closed", "on", {
|
getEntity("cover", "tilt_slider_closed", "on", {
|
||||||
friendly_name: "Tilt Closed",
|
friendly_name: "Tilt Closed",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT +
|
||||||
CoverEntityFeature.STOP_TILT +
|
SUPPORT_STOP_TILT +
|
||||||
CoverEntityFeature.CLOSE_TILT +
|
SUPPORT_CLOSE_TILT +
|
||||||
CoverEntityFeature.SET_TILT_POSITION,
|
SUPPORT_SET_TILT_POSITION,
|
||||||
current_tilt_position: 0,
|
current_tilt_position: 0,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "position_slider_tilt_slider", "on", {
|
getEntity("cover", "position_slider_tilt_slider", "on", {
|
||||||
friendly_name: "Both Sliders",
|
friendly_name: "Both Sliders",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN +
|
SUPPORT_OPEN +
|
||||||
CoverEntityFeature.STOP +
|
SUPPORT_STOP +
|
||||||
CoverEntityFeature.CLOSE +
|
SUPPORT_CLOSE +
|
||||||
CoverEntityFeature.SET_POSITION +
|
SUPPORT_SET_POSITION +
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT +
|
||||||
CoverEntityFeature.STOP_TILT +
|
SUPPORT_STOP_TILT +
|
||||||
CoverEntityFeature.CLOSE_TILT +
|
SUPPORT_CLOSE_TILT +
|
||||||
CoverEntityFeature.SET_TILT_POSITION,
|
SUPPORT_SET_TILT_POSITION,
|
||||||
current_position: 30,
|
current_position: 30,
|
||||||
current_tilt_position: 70,
|
current_tilt_position: 70,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "position_tilt_slider", "on", {
|
getEntity("cover", "position_tilt_slider", "on", {
|
||||||
friendly_name: "Position & Tilt Slider",
|
friendly_name: "Position & Tilt Slider",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN +
|
SUPPORT_OPEN +
|
||||||
CoverEntityFeature.STOP +
|
SUPPORT_STOP +
|
||||||
CoverEntityFeature.CLOSE +
|
SUPPORT_CLOSE +
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT +
|
||||||
CoverEntityFeature.STOP_TILT +
|
SUPPORT_STOP_TILT +
|
||||||
CoverEntityFeature.CLOSE_TILT +
|
SUPPORT_CLOSE_TILT +
|
||||||
CoverEntityFeature.SET_TILT_POSITION,
|
SUPPORT_SET_TILT_POSITION,
|
||||||
current_tilt_position: 70,
|
current_tilt_position: 70,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "position_slider_tilt", "on", {
|
getEntity("cover", "position_slider_tilt", "on", {
|
||||||
friendly_name: "Position Slider & Tilt",
|
friendly_name: "Position Slider & Tilt",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.OPEN +
|
SUPPORT_OPEN +
|
||||||
CoverEntityFeature.STOP +
|
SUPPORT_STOP +
|
||||||
CoverEntityFeature.CLOSE +
|
SUPPORT_CLOSE +
|
||||||
CoverEntityFeature.SET_POSITION +
|
SUPPORT_SET_POSITION +
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT +
|
||||||
CoverEntityFeature.STOP_TILT +
|
SUPPORT_STOP_TILT +
|
||||||
CoverEntityFeature.CLOSE_TILT,
|
SUPPORT_CLOSE_TILT,
|
||||||
current_position: 30,
|
current_position: 30,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "position_slider_only_tilt_slider", "on", {
|
getEntity("cover", "position_slider_only_tilt_slider", "on", {
|
||||||
friendly_name: "Position Slider Only & Tilt Buttons",
|
friendly_name: "Position Slider Only & Tilt Buttons",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.SET_POSITION +
|
SUPPORT_SET_POSITION +
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT +
|
||||||
CoverEntityFeature.STOP_TILT +
|
SUPPORT_STOP_TILT +
|
||||||
CoverEntityFeature.CLOSE_TILT,
|
SUPPORT_CLOSE_TILT,
|
||||||
current_position: 30,
|
current_position: 30,
|
||||||
}),
|
}),
|
||||||
getEntity("cover", "position_slider_only_tilt", "on", {
|
getEntity("cover", "position_slider_only_tilt", "on", {
|
||||||
friendly_name: "Position Slider Only & Tilt",
|
friendly_name: "Position Slider Only & Tilt",
|
||||||
supported_features:
|
supported_features:
|
||||||
CoverEntityFeature.SET_POSITION +
|
SUPPORT_SET_POSITION +
|
||||||
CoverEntityFeature.OPEN_TILT +
|
SUPPORT_OPEN_TILT +
|
||||||
CoverEntityFeature.STOP_TILT +
|
SUPPORT_STOP_TILT +
|
||||||
CoverEntityFeature.CLOSE_TILT +
|
SUPPORT_CLOSE_TILT +
|
||||||
CoverEntityFeature.SET_TILT_POSITION,
|
SUPPORT_SET_TILT_POSITION,
|
||||||
current_position: 30,
|
current_position: 30,
|
||||||
current_tilt_position: 70,
|
current_tilt_position: 70,
|
||||||
}),
|
}),
|
||||||
|
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
title: Input Number
|
|
||||||
---
|
|
@@ -1,60 +0,0 @@
|
|||||||
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
|
||||||
import { customElement, property, query } from "lit/decorators";
|
|
||||||
import "../../../../src/components/ha-card";
|
|
||||||
import "../../../../src/dialogs/more-info/more-info-content";
|
|
||||||
import { getEntity } from "../../../../src/fake_data/entity";
|
|
||||||
import {
|
|
||||||
MockHomeAssistant,
|
|
||||||
provideHass,
|
|
||||||
} from "../../../../src/fake_data/provide_hass";
|
|
||||||
import "../../components/demo-more-infos";
|
|
||||||
|
|
||||||
const ENTITIES = [
|
|
||||||
getEntity("input_number", "box1", 0, {
|
|
||||||
friendly_name: "Box1",
|
|
||||||
min: 0,
|
|
||||||
max: 100,
|
|
||||||
step: 1,
|
|
||||||
initial: 0,
|
|
||||||
mode: "box",
|
|
||||||
unit_of_measurement: "items",
|
|
||||||
}),
|
|
||||||
getEntity("input_number", "slider1", 0, {
|
|
||||||
friendly_name: "Slider1",
|
|
||||||
min: 0,
|
|
||||||
max: 100,
|
|
||||||
step: 1,
|
|
||||||
initial: 0,
|
|
||||||
mode: "slider",
|
|
||||||
unit_of_measurement: "items",
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
|
|
||||||
@customElement("demo-more-info-input-number")
|
|
||||||
class DemoMoreInfoInputNumber extends LitElement {
|
|
||||||
@property() public hass!: MockHomeAssistant;
|
|
||||||
|
|
||||||
@query("demo-more-infos") private _demoRoot!: HTMLElement;
|
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
|
||||||
return html`
|
|
||||||
<demo-more-infos
|
|
||||||
.hass=${this.hass}
|
|
||||||
.entities=${ENTITIES.map((ent) => ent.entityId)}
|
|
||||||
></demo-more-infos>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected firstUpdated(changedProperties: PropertyValues) {
|
|
||||||
super.firstUpdated(changedProperties);
|
|
||||||
const hass = provideHass(this._demoRoot);
|
|
||||||
hass.updateTranslations(null, "en");
|
|
||||||
hass.addEntities(ENTITIES);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface HTMLElementTagNameMap {
|
|
||||||
"demo-more-info-input-number": DemoMoreInfoInputNumber;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,7 +1,12 @@
|
|||||||
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
||||||
import { customElement, property, query } from "lit/decorators";
|
import { customElement, property, query } from "lit/decorators";
|
||||||
import "../../../../src/components/ha-card";
|
import "../../../../src/components/ha-card";
|
||||||
import { LightColorMode, LightEntityFeature } from "../../../../src/data/light";
|
import {
|
||||||
|
LightColorModes,
|
||||||
|
SUPPORT_EFFECT,
|
||||||
|
SUPPORT_FLASH,
|
||||||
|
SUPPORT_TRANSITION,
|
||||||
|
} from "../../../../src/data/light";
|
||||||
import "../../../../src/dialogs/more-info/more-info-content";
|
import "../../../../src/dialogs/more-info/more-info-content";
|
||||||
import { getEntity } from "../../../../src/fake_data/entity";
|
import { getEntity } from "../../../../src/fake_data/entity";
|
||||||
import {
|
import {
|
||||||
@@ -17,8 +22,8 @@ const ENTITIES = [
|
|||||||
getEntity("light", "kitchen_light", "on", {
|
getEntity("light", "kitchen_light", "on", {
|
||||||
friendly_name: "Brightness Light",
|
friendly_name: "Brightness Light",
|
||||||
brightness: 200,
|
brightness: 200,
|
||||||
supported_color_modes: [LightColorMode.BRIGHTNESS],
|
supported_color_modes: [LightColorModes.BRIGHTNESS],
|
||||||
color_mode: LightColorMode.BRIGHTNESS,
|
color_mode: LightColorModes.BRIGHTNESS,
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_temperature_light", "on", {
|
getEntity("light", "color_temperature_light", "on", {
|
||||||
friendly_name: "White Color Temperature Light",
|
friendly_name: "White Color Temperature Light",
|
||||||
@@ -27,10 +32,10 @@ const ENTITIES = [
|
|||||||
min_mireds: 30,
|
min_mireds: 30,
|
||||||
max_mireds: 150,
|
max_mireds: 150,
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorMode.BRIGHTNESS,
|
LightColorModes.BRIGHTNESS,
|
||||||
LightColorMode.COLOR_TEMP,
|
LightColorModes.COLOR_TEMP,
|
||||||
],
|
],
|
||||||
color_mode: LightColorMode.COLOR_TEMP,
|
color_mode: LightColorModes.COLOR_TEMP,
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_hs_light", "on", {
|
getEntity("light", "color_hs_light", "on", {
|
||||||
friendly_name: "Color HS Light",
|
friendly_name: "Color HS Light",
|
||||||
@@ -39,16 +44,13 @@ const ENTITIES = [
|
|||||||
rgb_color: [30, 100, 255],
|
rgb_color: [30, 100, 255],
|
||||||
min_mireds: 30,
|
min_mireds: 30,
|
||||||
max_mireds: 150,
|
max_mireds: 150,
|
||||||
supported_features:
|
supported_features: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
||||||
LightEntityFeature.EFFECT +
|
|
||||||
LightEntityFeature.FLASH +
|
|
||||||
LightEntityFeature.TRANSITION,
|
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorMode.BRIGHTNESS,
|
LightColorModes.BRIGHTNESS,
|
||||||
LightColorMode.COLOR_TEMP,
|
LightColorModes.COLOR_TEMP,
|
||||||
LightColorMode.HS,
|
LightColorModes.HS,
|
||||||
],
|
],
|
||||||
color_mode: LightColorMode.HS,
|
color_mode: LightColorModes.HS,
|
||||||
effect_list: ["random", "colorloop"],
|
effect_list: ["random", "colorloop"],
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_rgb_ct_light", "on", {
|
getEntity("light", "color_rgb_ct_light", "on", {
|
||||||
@@ -57,28 +59,22 @@ const ENTITIES = [
|
|||||||
color_temp: 75,
|
color_temp: 75,
|
||||||
min_mireds: 30,
|
min_mireds: 30,
|
||||||
max_mireds: 150,
|
max_mireds: 150,
|
||||||
supported_features:
|
supported_features: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
||||||
LightEntityFeature.EFFECT +
|
|
||||||
LightEntityFeature.FLASH +
|
|
||||||
LightEntityFeature.TRANSITION,
|
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorMode.BRIGHTNESS,
|
LightColorModes.BRIGHTNESS,
|
||||||
LightColorMode.COLOR_TEMP,
|
LightColorModes.COLOR_TEMP,
|
||||||
LightColorMode.RGB,
|
LightColorModes.RGB,
|
||||||
],
|
],
|
||||||
color_mode: LightColorMode.COLOR_TEMP,
|
color_mode: LightColorModes.COLOR_TEMP,
|
||||||
effect_list: ["random", "colorloop"],
|
effect_list: ["random", "colorloop"],
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_RGB_light", "on", {
|
getEntity("light", "color_RGB_light", "on", {
|
||||||
friendly_name: "Color Effects Light",
|
friendly_name: "Color Effects Light",
|
||||||
brightness: 255,
|
brightness: 255,
|
||||||
rgb_color: [30, 100, 255],
|
rgb_color: [30, 100, 255],
|
||||||
supported_features:
|
supported_features: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
||||||
LightEntityFeature.EFFECT +
|
supported_color_modes: [LightColorModes.BRIGHTNESS, LightColorModes.RGB],
|
||||||
LightEntityFeature.FLASH +
|
color_mode: LightColorModes.RGB,
|
||||||
LightEntityFeature.TRANSITION,
|
|
||||||
supported_color_modes: [LightColorMode.BRIGHTNESS, LightColorMode.RGB],
|
|
||||||
color_mode: LightColorMode.RGB,
|
|
||||||
effect_list: ["random", "colorloop"],
|
effect_list: ["random", "colorloop"],
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_rgbw_light", "on", {
|
getEntity("light", "color_rgbw_light", "on", {
|
||||||
@@ -87,16 +83,13 @@ const ENTITIES = [
|
|||||||
rgbw_color: [30, 100, 255, 125],
|
rgbw_color: [30, 100, 255, 125],
|
||||||
min_mireds: 30,
|
min_mireds: 30,
|
||||||
max_mireds: 150,
|
max_mireds: 150,
|
||||||
supported_features:
|
supported_features: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
||||||
LightEntityFeature.EFFECT +
|
|
||||||
LightEntityFeature.FLASH +
|
|
||||||
LightEntityFeature.TRANSITION,
|
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorMode.BRIGHTNESS,
|
LightColorModes.BRIGHTNESS,
|
||||||
LightColorMode.COLOR_TEMP,
|
LightColorModes.COLOR_TEMP,
|
||||||
LightColorMode.RGBW,
|
LightColorModes.RGBW,
|
||||||
],
|
],
|
||||||
color_mode: LightColorMode.RGBW,
|
color_mode: LightColorModes.RGBW,
|
||||||
effect_list: ["random", "colorloop"],
|
effect_list: ["random", "colorloop"],
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_rgbww_light", "on", {
|
getEntity("light", "color_rgbww_light", "on", {
|
||||||
@@ -105,16 +98,13 @@ const ENTITIES = [
|
|||||||
rgbww_color: [30, 100, 255, 125, 10],
|
rgbww_color: [30, 100, 255, 125, 10],
|
||||||
min_mireds: 30,
|
min_mireds: 30,
|
||||||
max_mireds: 150,
|
max_mireds: 150,
|
||||||
supported_features:
|
supported_features: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
||||||
LightEntityFeature.EFFECT +
|
|
||||||
LightEntityFeature.FLASH +
|
|
||||||
LightEntityFeature.TRANSITION,
|
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorMode.BRIGHTNESS,
|
LightColorModes.BRIGHTNESS,
|
||||||
LightColorMode.COLOR_TEMP,
|
LightColorModes.COLOR_TEMP,
|
||||||
LightColorMode.RGBWW,
|
LightColorModes.RGBWW,
|
||||||
],
|
],
|
||||||
color_mode: LightColorMode.RGBWW,
|
color_mode: LightColorModes.RGBWW,
|
||||||
effect_list: ["random", "colorloop"],
|
effect_list: ["random", "colorloop"],
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_xy_light", "on", {
|
getEntity("light", "color_xy_light", "on", {
|
||||||
@@ -124,16 +114,13 @@ const ENTITIES = [
|
|||||||
rgb_color: [30, 100, 255],
|
rgb_color: [30, 100, 255],
|
||||||
min_mireds: 30,
|
min_mireds: 30,
|
||||||
max_mireds: 150,
|
max_mireds: 150,
|
||||||
supported_features:
|
supported_features: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
||||||
LightEntityFeature.EFFECT +
|
|
||||||
LightEntityFeature.FLASH +
|
|
||||||
LightEntityFeature.TRANSITION,
|
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorMode.BRIGHTNESS,
|
LightColorModes.BRIGHTNESS,
|
||||||
LightColorMode.COLOR_TEMP,
|
LightColorModes.COLOR_TEMP,
|
||||||
LightColorMode.XY,
|
LightColorModes.XY,
|
||||||
],
|
],
|
||||||
color_mode: LightColorMode.XY,
|
color_mode: LightColorModes.XY,
|
||||||
effect_list: ["random", "colorloop"],
|
effect_list: ["random", "colorloop"],
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
@@ -1024,13 +1024,10 @@ class HassioAddonInfo extends LitElement {
|
|||||||
button.progress = true;
|
button.progress = true;
|
||||||
|
|
||||||
const confirmed = await showConfirmationDialog(this, {
|
const confirmed = await showConfirmationDialog(this, {
|
||||||
title: this.supervisor.localize("dialog.uninstall_addon.title", {
|
title: this.addon.name,
|
||||||
name: this.addon.name,
|
text: "Are you sure you want to uninstall this add-on?",
|
||||||
}),
|
confirmText: "uninstall add-on",
|
||||||
text: this.supervisor.localize("dialog.uninstall_addon.text"),
|
dismissText: "no",
|
||||||
confirmText: this.supervisor.localize("dialog.uninstall_addon.uninstall"),
|
|
||||||
dismissText: this.supervisor.localize("common.cancel"),
|
|
||||||
destructive: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!confirmed) {
|
if (!confirmed) {
|
||||||
|
@@ -18,11 +18,9 @@ export const suggestAddonRestart = async (
|
|||||||
addon: HassioAddonDetails
|
addon: HassioAddonDetails
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const confirmed = await showConfirmationDialog(element, {
|
const confirmed = await showConfirmationDialog(element, {
|
||||||
title: supervisor.localize("dialog.restart_addon.title", {
|
title: supervisor.localize("common.restart_name", "name", addon.name),
|
||||||
name: addon.name,
|
|
||||||
}),
|
|
||||||
text: supervisor.localize("dialog.restart_addon.text"),
|
text: supervisor.localize("dialog.restart_addon.text"),
|
||||||
confirmText: supervisor.localize("dialog.restart_addon.restart"),
|
confirmText: supervisor.localize("dialog.restart_addon.confirm_text"),
|
||||||
dismissText: supervisor.localize("common.cancel"),
|
dismissText: supervisor.localize("common.cancel"),
|
||||||
});
|
});
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
@@ -30,9 +28,11 @@ export const suggestAddonRestart = async (
|
|||||||
await restartHassioAddon(hass, addon.slug);
|
await restartHassioAddon(hass, addon.slug);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
showAlertDialog(element, {
|
showAlertDialog(element, {
|
||||||
title: supervisor.localize("common.failed_to_restart_name", {
|
title: supervisor.localize(
|
||||||
name: addon.name,
|
"common.failed_to_restart_name",
|
||||||
}),
|
"name",
|
||||||
|
addon.name
|
||||||
|
),
|
||||||
text: extractApiErrorMessage(err),
|
text: extractApiErrorMessage(err),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,6 @@ import {
|
|||||||
showAlertDialog,
|
showAlertDialog,
|
||||||
showConfirmationDialog,
|
showConfirmationDialog,
|
||||||
} from "../../../src/dialogs/generic/show-dialog-box";
|
} from "../../../src/dialogs/generic/show-dialog-box";
|
||||||
import { showJoinBetaDialog } from "../../../src/panels/config/core/updates/show-dialog-join-beta";
|
|
||||||
import {
|
import {
|
||||||
UNHEALTHY_REASON_URL,
|
UNHEALTHY_REASON_URL,
|
||||||
UNSUPPORTED_REASON_URL,
|
UNSUPPORTED_REASON_URL,
|
||||||
@@ -231,27 +230,36 @@ class HassioSupervisorInfo extends LitElement {
|
|||||||
button.progress = true;
|
button.progress = true;
|
||||||
|
|
||||||
if (this.supervisor.supervisor.channel === "stable") {
|
if (this.supervisor.supervisor.channel === "stable") {
|
||||||
showJoinBetaDialog(this, {
|
const confirmed = await showConfirmationDialog(this, {
|
||||||
join: async () => {
|
title: this.supervisor.localize("system.supervisor.warning"),
|
||||||
await this._setChannel("beta");
|
text: html`${this.supervisor.localize("system.supervisor.beta_warning")}
|
||||||
button.progress = false;
|
<br />
|
||||||
},
|
<b> ${this.supervisor.localize("system.supervisor.beta_backup")} </b>
|
||||||
cancel: () => {
|
<br /><br />
|
||||||
button.progress = false;
|
${this.supervisor.localize("system.supervisor.beta_release_items")}
|
||||||
},
|
<ul>
|
||||||
|
<li>Home Assistant Core</li>
|
||||||
|
<li>Home Assistant Supervisor</li>
|
||||||
|
<li>Home Assistant Operating System</li>
|
||||||
|
</ul>
|
||||||
|
<br />
|
||||||
|
${this.supervisor.localize("system.supervisor.beta_join_confirm")}`,
|
||||||
|
confirmText: this.supervisor.localize(
|
||||||
|
"system.supervisor.join_beta_action"
|
||||||
|
),
|
||||||
|
dismissText: this.supervisor.localize("common.cancel"),
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
await this._setChannel("stable");
|
|
||||||
button.progress = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _setChannel(
|
if (!confirmed) {
|
||||||
channel: SupervisorOptions["channel"]
|
button.progress = false;
|
||||||
): Promise<void> {
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data: Partial<SupervisorOptions> = {
|
const data: Partial<SupervisorOptions> = {
|
||||||
channel,
|
channel:
|
||||||
|
this.supervisor.supervisor.channel === "stable" ? "beta" : "stable",
|
||||||
};
|
};
|
||||||
await setSupervisorOption(this.hass, data);
|
await setSupervisorOption(this.hass, data);
|
||||||
await this._reloadSupervisor();
|
await this._reloadSupervisor();
|
||||||
@@ -262,6 +270,8 @@ class HassioSupervisorInfo extends LitElement {
|
|||||||
),
|
),
|
||||||
text: extractApiErrorMessage(err),
|
text: extractApiErrorMessage(err),
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
button.progress = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -93,8 +93,8 @@
|
|||||||
"@polymer/paper-tooltip": "^3.0.1",
|
"@polymer/paper-tooltip": "^3.0.1",
|
||||||
"@polymer/polymer": "3.4.1",
|
"@polymer/polymer": "3.4.1",
|
||||||
"@thomasloven/round-slider": "0.5.4",
|
"@thomasloven/round-slider": "0.5.4",
|
||||||
"@vaadin/combo-box": "^23.2.0",
|
"@vaadin/combo-box": "^23.1.5",
|
||||||
"@vaadin/vaadin-themable-mixin": "^23.2.0",
|
"@vaadin/vaadin-themable-mixin": "^23.1.5",
|
||||||
"@vibrant/color": "^3.2.1-alpha.1",
|
"@vibrant/color": "^3.2.1-alpha.1",
|
||||||
"@vibrant/core": "^3.2.1-alpha.1",
|
"@vibrant/core": "^3.2.1-alpha.1",
|
||||||
"@vibrant/quantizer-mmcq": "^3.2.1-alpha.1",
|
"@vibrant/quantizer-mmcq": "^3.2.1-alpha.1",
|
||||||
@@ -111,7 +111,7 @@
|
|||||||
"deep-freeze": "^0.0.1",
|
"deep-freeze": "^0.0.1",
|
||||||
"fuse.js": "^6.0.0",
|
"fuse.js": "^6.0.0",
|
||||||
"google-timezones-json": "^1.0.2",
|
"google-timezones-json": "^1.0.2",
|
||||||
"hls.js": "^1.2.3",
|
"hls.js": "^1.2.1",
|
||||||
"home-assistant-js-websocket": "^8.0.0",
|
"home-assistant-js-websocket": "^8.0.0",
|
||||||
"idb-keyval": "^5.1.3",
|
"idb-keyval": "^5.1.3",
|
||||||
"intl-messageformat": "^9.9.1",
|
"intl-messageformat": "^9.9.1",
|
||||||
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "home-assistant-frontend"
|
name = "home-assistant-frontend"
|
||||||
version = "20221002.0"
|
version = "20220816.0"
|
||||||
license = {text = "Apache-2.0"}
|
license = {text = "Apache-2.0"}
|
||||||
description = "The Home Assistant frontend"
|
description = "The Home Assistant frontend"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@@ -46,14 +46,6 @@ frontend:
|
|||||||
# development_repo: ${WD}" >> "${WD}/config/configuration.yaml"
|
# development_repo: ${WD}" >> "${WD}/config/configuration.yaml"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -z "${CODESPACES}" ]; then
|
|
||||||
echo "
|
|
||||||
http:
|
|
||||||
use_x_forwarded_for: true
|
|
||||||
trusted_proxies:
|
|
||||||
- 127.0.0.1
|
|
||||||
" >> "${WD}/config/configuration.yaml"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
hass -c "${WD}/config"
|
hass -c "${WD}/config"
|
||||||
|
@@ -6,7 +6,6 @@ import {
|
|||||||
mdiAlert,
|
mdiAlert,
|
||||||
mdiAngleAcute,
|
mdiAngleAcute,
|
||||||
mdiAppleSafari,
|
mdiAppleSafari,
|
||||||
mdiArrowLeftRight,
|
|
||||||
mdiBell,
|
mdiBell,
|
||||||
mdiBookmark,
|
mdiBookmark,
|
||||||
mdiBrightness5,
|
mdiBrightness5,
|
||||||
@@ -26,6 +25,7 @@ import {
|
|||||||
mdiFlower,
|
mdiFlower,
|
||||||
mdiFormatListBulleted,
|
mdiFormatListBulleted,
|
||||||
mdiFormTextbox,
|
mdiFormTextbox,
|
||||||
|
mdiGasCylinder,
|
||||||
mdiGauge,
|
mdiGauge,
|
||||||
mdiGestureTapButton,
|
mdiGestureTapButton,
|
||||||
mdiGoogleAssistant,
|
mdiGoogleAssistant,
|
||||||
@@ -37,8 +37,6 @@ import {
|
|||||||
mdiLightningBolt,
|
mdiLightningBolt,
|
||||||
mdiMailbox,
|
mdiMailbox,
|
||||||
mdiMapMarkerRadius,
|
mdiMapMarkerRadius,
|
||||||
mdiMeterGas,
|
|
||||||
mdiMicrophoneMessage,
|
|
||||||
mdiMolecule,
|
mdiMolecule,
|
||||||
mdiMoleculeCo,
|
mdiMoleculeCo,
|
||||||
mdiMoleculeCo2,
|
mdiMoleculeCo2,
|
||||||
@@ -49,14 +47,13 @@ import {
|
|||||||
mdiRobotVacuum,
|
mdiRobotVacuum,
|
||||||
mdiScriptText,
|
mdiScriptText,
|
||||||
mdiSineWave,
|
mdiSineWave,
|
||||||
mdiSpeedometer,
|
mdiMicrophoneMessage,
|
||||||
mdiThermometer,
|
mdiThermometer,
|
||||||
mdiThermostat,
|
mdiThermostat,
|
||||||
mdiTimerOutline,
|
mdiTimerOutline,
|
||||||
mdiVideo,
|
mdiVideo,
|
||||||
mdiWaterPercent,
|
mdiWaterPercent,
|
||||||
mdiWeatherCloudy,
|
mdiWeatherCloudy,
|
||||||
mdiWeight,
|
|
||||||
mdiWhiteBalanceSunny,
|
mdiWhiteBalanceSunny,
|
||||||
mdiWifi,
|
mdiWifi,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
@@ -124,13 +121,11 @@ export const FIXED_DEVICE_CLASS_ICONS = {
|
|||||||
carbon_monoxide: mdiMoleculeCo,
|
carbon_monoxide: mdiMoleculeCo,
|
||||||
current: mdiCurrentAc,
|
current: mdiCurrentAc,
|
||||||
date: mdiCalendar,
|
date: mdiCalendar,
|
||||||
distance: mdiArrowLeftRight,
|
|
||||||
energy: mdiLightningBolt,
|
energy: mdiLightningBolt,
|
||||||
frequency: mdiSineWave,
|
frequency: mdiSineWave,
|
||||||
gas: mdiMeterGas,
|
gas: mdiGasCylinder,
|
||||||
humidity: mdiWaterPercent,
|
humidity: mdiWaterPercent,
|
||||||
illuminance: mdiBrightness5,
|
illuminance: mdiBrightness5,
|
||||||
moisture: mdiWaterPercent,
|
|
||||||
monetary: mdiCash,
|
monetary: mdiCash,
|
||||||
nitrogen_dioxide: mdiMolecule,
|
nitrogen_dioxide: mdiMolecule,
|
||||||
nitrogen_monoxide: mdiMolecule,
|
nitrogen_monoxide: mdiMolecule,
|
||||||
@@ -144,14 +139,11 @@ export const FIXED_DEVICE_CLASS_ICONS = {
|
|||||||
pressure: mdiGauge,
|
pressure: mdiGauge,
|
||||||
reactive_power: mdiFlash,
|
reactive_power: mdiFlash,
|
||||||
signal_strength: mdiWifi,
|
signal_strength: mdiWifi,
|
||||||
speed: mdiSpeedometer,
|
|
||||||
sulphur_dioxide: mdiMolecule,
|
sulphur_dioxide: mdiMolecule,
|
||||||
temperature: mdiThermometer,
|
temperature: mdiThermometer,
|
||||||
timestamp: mdiClock,
|
timestamp: mdiClock,
|
||||||
volatile_organic_compounds: mdiMolecule,
|
volatile_organic_compounds: mdiMolecule,
|
||||||
voltage: mdiSineWave,
|
voltage: mdiSineWave,
|
||||||
// volume: TBD, => no well matching icon found
|
|
||||||
weight: mdiWeight,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Domains that have a state card. */
|
/** Domains that have a state card. */
|
||||||
|
@@ -1,28 +0,0 @@
|
|||||||
import { HaDurationData } from "../../components/ha-duration-input";
|
|
||||||
|
|
||||||
const leftPad = (num: number) => (num < 10 ? `0${num}` : num);
|
|
||||||
|
|
||||||
export const formatDuration = (duration: HaDurationData) => {
|
|
||||||
const d = duration.days || 0;
|
|
||||||
const h = duration.hours || 0;
|
|
||||||
const m = duration.minutes || 0;
|
|
||||||
const s = duration.seconds || 0;
|
|
||||||
const ms = duration.milliseconds || 0;
|
|
||||||
|
|
||||||
if (d > 0) {
|
|
||||||
return `${d} days ${h}:${leftPad(m)}:${leftPad(s)}`;
|
|
||||||
}
|
|
||||||
if (h > 0) {
|
|
||||||
return `${h}:${leftPad(m)}:${leftPad(s)}`;
|
|
||||||
}
|
|
||||||
if (m > 0) {
|
|
||||||
return `${m}:${leftPad(s)}`;
|
|
||||||
}
|
|
||||||
if (s > 0) {
|
|
||||||
return `${s} seconds`;
|
|
||||||
}
|
|
||||||
if (ms > 0) {
|
|
||||||
return `${ms} milliseconds`;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
@@ -2,18 +2,17 @@ import { HassEntity } from "home-assistant-js-websocket";
|
|||||||
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
||||||
import { FrontendLocaleData } from "../../data/translation";
|
import { FrontendLocaleData } from "../../data/translation";
|
||||||
import {
|
import {
|
||||||
updateIsInstallingFromAttributes,
|
|
||||||
UPDATE_SUPPORT_PROGRESS,
|
UPDATE_SUPPORT_PROGRESS,
|
||||||
|
updateIsInstallingFromAttributes,
|
||||||
} from "../../data/update";
|
} from "../../data/update";
|
||||||
import { formatDuration, UNIT_TO_SECOND_CONVERT } from "../datetime/duration";
|
|
||||||
import { formatDate } from "../datetime/format_date";
|
import { formatDate } from "../datetime/format_date";
|
||||||
import { formatDateTime } from "../datetime/format_date_time";
|
import { formatDateTime } from "../datetime/format_date_time";
|
||||||
import { formatTime } from "../datetime/format_time";
|
import { formatTime } from "../datetime/format_time";
|
||||||
import { formatNumber, isNumericFromAttributes } from "../number/format_number";
|
import { formatNumber, isNumericFromAttributes } from "../number/format_number";
|
||||||
import { blankBeforePercent } from "../translations/blank_before_percent";
|
|
||||||
import { LocalizeFunc } from "../translations/localize";
|
import { LocalizeFunc } from "../translations/localize";
|
||||||
import { computeDomain } from "./compute_domain";
|
|
||||||
import { supportsFeatureFromAttributes } from "./supports-feature";
|
import { supportsFeatureFromAttributes } from "./supports-feature";
|
||||||
|
import { formatDuration, UNIT_TO_SECOND_CONVERT } from "../datetime/duration";
|
||||||
|
import { computeDomain } from "./compute_domain";
|
||||||
|
|
||||||
export const computeStateDisplay = (
|
export const computeStateDisplay = (
|
||||||
localize: LocalizeFunc,
|
localize: LocalizeFunc,
|
||||||
@@ -68,7 +67,7 @@ export const computeStateDisplayFromEntityAttributes = (
|
|||||||
const unit = !attributes.unit_of_measurement
|
const unit = !attributes.unit_of_measurement
|
||||||
? ""
|
? ""
|
||||||
: attributes.unit_of_measurement === "%"
|
: attributes.unit_of_measurement === "%"
|
||||||
? blankBeforePercent(locale) + "%"
|
? "%"
|
||||||
: ` ${attributes.unit_of_measurement}`;
|
: ` ${attributes.unit_of_measurement}`;
|
||||||
return `${formatNumber(state, locale)}${unit}`;
|
return `${formatNumber(state, locale)}${unit}`;
|
||||||
}
|
}
|
||||||
|
@@ -1,14 +1,10 @@
|
|||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { supportsFeature } from "./supports-feature";
|
import { supportsFeature } from "./supports-feature";
|
||||||
|
|
||||||
export type FeatureClassNames<T extends number = number> = Partial<
|
|
||||||
Record<T, string>
|
|
||||||
>;
|
|
||||||
|
|
||||||
// Expects classNames to be an object mapping feature-bit -> className
|
// Expects classNames to be an object mapping feature-bit -> className
|
||||||
export const featureClassNames = (
|
export const featureClassNames = (
|
||||||
stateObj: HassEntity,
|
stateObj: HassEntity,
|
||||||
classNames: FeatureClassNames
|
classNames: { [feature: number]: string }
|
||||||
) => {
|
) => {
|
||||||
if (!stateObj || !stateObj.attributes.supported_features) {
|
if (!stateObj || !stateObj.attributes.supported_features) {
|
||||||
return "";
|
return "";
|
||||||
|
@@ -37,7 +37,6 @@ const FIXED_DOMAIN_STATES = {
|
|||||||
siren: ["on", "off"],
|
siren: ["on", "off"],
|
||||||
sun: ["above_horizon", "below_horizon"],
|
sun: ["above_horizon", "below_horizon"],
|
||||||
switch: ["on", "off"],
|
switch: ["on", "off"],
|
||||||
timer: ["active", "idle", "paused"],
|
|
||||||
update: ["on", "off"],
|
update: ["on", "off"],
|
||||||
vacuum: ["cleaning", "docked", "error", "idle", "paused", "returning"],
|
vacuum: ["cleaning", "docked", "error", "idle", "paused", "returning"],
|
||||||
weather: [
|
weather: [
|
||||||
@@ -240,13 +239,10 @@ export const getStates = (
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "light":
|
case "light":
|
||||||
if (attribute === "effect" && state.attributes.effect_list) {
|
if (attribute === "effect") {
|
||||||
result.push(...state.attributes.effect_list);
|
result.push(...state.attributes.effect_list);
|
||||||
} else if (
|
} else if (attribute === "color_mode") {
|
||||||
attribute === "color_mode" &&
|
result.push(...state.attributes.color_modes);
|
||||||
state.attributes.supported_color_modes
|
|
||||||
) {
|
|
||||||
result.push(...state.attributes.supported_color_modes);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "media_player":
|
case "media_player":
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
import { html } from "lit";
|
import { html } from "lit";
|
||||||
import { getConfigEntries } from "../../data/config_entries";
|
import { getConfigEntries } from "../../data/config_entries";
|
||||||
import { showConfigFlowDialog } from "../../dialogs/config-flow/show-dialog-config-flow";
|
|
||||||
import { showConfirmationDialog } from "../../dialogs/generic/show-dialog-box";
|
import { showConfirmationDialog } from "../../dialogs/generic/show-dialog-box";
|
||||||
import { showZWaveJSAddNodeDialog } from "../../panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-add-node";
|
import { showZWaveJSAddNodeDialog } from "../../panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-add-node";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import { documentationUrl } from "../../util/documentation-url";
|
import { documentationUrl } from "../../util/documentation-url";
|
||||||
import { isComponentLoaded } from "../config/is_component_loaded";
|
import { isComponentLoaded } from "../config/is_component_loaded";
|
||||||
|
import { fireEvent } from "../dom/fire_event";
|
||||||
import { navigate } from "../navigate";
|
import { navigate } from "../navigate";
|
||||||
|
|
||||||
export const protocolIntegrationPicked = async (
|
export const protocolIntegrationPicked = async (
|
||||||
@@ -18,7 +18,7 @@ export const protocolIntegrationPicked = async (
|
|||||||
domain: "zwave_js",
|
domain: "zwave_js",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isComponentLoaded(hass, "zwave_js") || !entries.length) {
|
if (!entries.length) {
|
||||||
// If the component isn't loaded, ask them to load the integration first
|
// If the component isn't loaded, ask them to load the integration first
|
||||||
showConfirmationDialog(element, {
|
showConfirmationDialog(element, {
|
||||||
text: hass.localize(
|
text: hass.localize(
|
||||||
@@ -39,8 +39,8 @@ export const protocolIntegrationPicked = async (
|
|||||||
"ui.panel.config.integrations.config_flow.proceed"
|
"ui.panel.config.integrations.config_flow.proceed"
|
||||||
),
|
),
|
||||||
confirm: () => {
|
confirm: () => {
|
||||||
showConfigFlowDialog(element, {
|
fireEvent(element, "handler-picked", {
|
||||||
startFlowHandler: "zwave_js",
|
handler: "zwave_js",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -75,8 +75,8 @@ export const protocolIntegrationPicked = async (
|
|||||||
"ui.panel.config.integrations.config_flow.proceed"
|
"ui.panel.config.integrations.config_flow.proceed"
|
||||||
),
|
),
|
||||||
confirm: () => {
|
confirm: () => {
|
||||||
showConfigFlowDialog(element, {
|
fireEvent(element, "handler-picked", {
|
||||||
startFlowHandler: "zha",
|
handler: "zha",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@@ -1,4 +0,0 @@
|
|||||||
export const titleCase = (s) =>
|
|
||||||
s.replace(/^_*(.)|_+(.)/g, (_s, c, d) =>
|
|
||||||
c ? c.toUpperCase() : " " + d.toUpperCase()
|
|
||||||
);
|
|
@@ -1,18 +0,0 @@
|
|||||||
import { FrontendLocaleData } from "../../data/translation";
|
|
||||||
|
|
||||||
// Logic based on https://en.wikipedia.org/wiki/Percent_sign#Form_and_spacing
|
|
||||||
export const blankBeforePercent = (
|
|
||||||
localeOptions: FrontendLocaleData
|
|
||||||
): string => {
|
|
||||||
switch (localeOptions.language) {
|
|
||||||
case "cz":
|
|
||||||
case "de":
|
|
||||||
case "fi":
|
|
||||||
case "fr":
|
|
||||||
case "sk":
|
|
||||||
case "sv":
|
|
||||||
return " ";
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
};
|
|
@@ -13,7 +13,6 @@ import {
|
|||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
|
||||||
import { getGraphColorByIndex } from "../../common/color/colors";
|
import { getGraphColorByIndex } from "../../common/color/colors";
|
||||||
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
||||||
import {
|
import {
|
||||||
@@ -21,38 +20,31 @@ import {
|
|||||||
numberFormatToLocale,
|
numberFormatToLocale,
|
||||||
} from "../../common/number/format_number";
|
} from "../../common/number/format_number";
|
||||||
import {
|
import {
|
||||||
getDisplayUnit,
|
getStatisticIds,
|
||||||
getStatisticLabel,
|
getStatisticLabel,
|
||||||
getStatisticMetadata,
|
|
||||||
Statistics,
|
Statistics,
|
||||||
statisticsHaveType,
|
statisticsHaveType,
|
||||||
|
StatisticsMetaData,
|
||||||
StatisticType,
|
StatisticType,
|
||||||
} from "../../data/recorder";
|
} from "../../data/history";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import "./ha-chart-base";
|
import "./ha-chart-base";
|
||||||
|
|
||||||
export type ExtendedStatisticType = StatisticType | "state";
|
|
||||||
|
|
||||||
export const statTypeMap: Record<ExtendedStatisticType, StatisticType> = {
|
|
||||||
mean: "mean",
|
|
||||||
min: "min",
|
|
||||||
max: "max",
|
|
||||||
sum: "sum",
|
|
||||||
state: "sum",
|
|
||||||
};
|
|
||||||
@customElement("statistics-chart")
|
@customElement("statistics-chart")
|
||||||
class StatisticsChart extends LitElement {
|
class StatisticsChart extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property({ attribute: false }) public statisticsData!: Statistics;
|
@property({ attribute: false }) public statisticsData!: Statistics;
|
||||||
|
|
||||||
|
@property({ type: Array }) public statisticIds?: StatisticsMetaData[];
|
||||||
|
|
||||||
@property() public names: boolean | Record<string, string> = false;
|
@property() public names: boolean | Record<string, string> = false;
|
||||||
|
|
||||||
@property() public unit?: string;
|
@property() public unit?: string;
|
||||||
|
|
||||||
@property({ attribute: false }) public endTime?: Date;
|
@property({ attribute: false }) public endTime?: Date;
|
||||||
|
|
||||||
@property({ type: Array }) public statTypes: Array<ExtendedStatisticType> = [
|
@property({ type: Array }) public statTypes: Array<StatisticType> = [
|
||||||
"sum",
|
"sum",
|
||||||
"min",
|
"min",
|
||||||
"mean",
|
"mean",
|
||||||
@@ -199,28 +191,18 @@ class StatisticsChart extends LitElement {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getStatisticsMetaData = memoizeOne(
|
private async _getStatisticIds() {
|
||||||
async (statisticIds: string[] | undefined) => {
|
this.statisticIds = await getStatisticIds(this.hass);
|
||||||
const statsMetadataArray = await getStatisticMetadata(
|
}
|
||||||
this.hass,
|
|
||||||
statisticIds
|
|
||||||
);
|
|
||||||
const statisticsMetaData = {};
|
|
||||||
statsMetadataArray.forEach((x) => {
|
|
||||||
statisticsMetaData[x.statistic_id] = x;
|
|
||||||
});
|
|
||||||
return statisticsMetaData;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
private async _generateData() {
|
private async _generateData() {
|
||||||
if (!this.statisticsData) {
|
if (!this.statisticsData) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const statisticsMetaData = await this._getStatisticsMetaData(
|
if (!this.statisticIds) {
|
||||||
Object.keys(this.statisticsData)
|
await this._getStatisticIds();
|
||||||
);
|
}
|
||||||
|
|
||||||
let colorIndex = 0;
|
let colorIndex = 0;
|
||||||
const statisticsData = Object.values(this.statisticsData);
|
const statisticsData = Object.values(this.statisticsData);
|
||||||
@@ -251,7 +233,9 @@ class StatisticsChart extends LitElement {
|
|||||||
const names = this.names || {};
|
const names = this.names || {};
|
||||||
statisticsData.forEach((stats) => {
|
statisticsData.forEach((stats) => {
|
||||||
const firstStat = stats[0];
|
const firstStat = stats[0];
|
||||||
const meta = statisticsMetaData?.[firstStat.statistic_id];
|
const meta = this.statisticIds!.find(
|
||||||
|
(stat) => stat.statistic_id === firstStat.statistic_id
|
||||||
|
);
|
||||||
let name = names[firstStat.statistic_id];
|
let name = names[firstStat.statistic_id];
|
||||||
if (!name) {
|
if (!name) {
|
||||||
name = getStatisticLabel(this.hass, firstStat.statistic_id, meta);
|
name = getStatisticLabel(this.hass, firstStat.statistic_id, meta);
|
||||||
@@ -259,11 +243,8 @@ class StatisticsChart extends LitElement {
|
|||||||
|
|
||||||
if (!this.unit) {
|
if (!this.unit) {
|
||||||
if (unit === undefined) {
|
if (unit === undefined) {
|
||||||
unit = getDisplayUnit(this.hass, firstStat.statistic_id, meta);
|
unit = meta?.display_unit_of_measurement;
|
||||||
} else if (
|
} else if (unit !== meta?.display_unit_of_measurement) {
|
||||||
unit !== getDisplayUnit(this.hass, firstStat.statistic_id, meta)
|
|
||||||
) {
|
|
||||||
// Clear unit if not all statistics have same unit
|
|
||||||
unit = null;
|
unit = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -320,7 +301,7 @@ class StatisticsChart extends LitElement {
|
|||||||
: this.statTypes;
|
: this.statTypes;
|
||||||
|
|
||||||
sortedTypes.forEach((type) => {
|
sortedTypes.forEach((type) => {
|
||||||
if (statisticsHaveType(stats, statTypeMap[type])) {
|
if (statisticsHaveType(stats, type)) {
|
||||||
const band = drawBands && (type === "min" || type === "max");
|
const band = drawBands && (type === "min" || type === "max");
|
||||||
statTypes.push(type);
|
statTypes.push(type);
|
||||||
statDataSets.push({
|
statDataSets.push({
|
||||||
@@ -348,6 +329,7 @@ class StatisticsChart extends LitElement {
|
|||||||
|
|
||||||
let prevDate: Date | null = null;
|
let prevDate: Date | null = null;
|
||||||
// Process chart data.
|
// Process chart data.
|
||||||
|
let initVal: number | null = null;
|
||||||
let prevSum: number | null = null;
|
let prevSum: number | null = null;
|
||||||
stats.forEach((stat) => {
|
stats.forEach((stat) => {
|
||||||
const date = new Date(stat.start);
|
const date = new Date(stat.start);
|
||||||
@@ -359,11 +341,11 @@ class StatisticsChart extends LitElement {
|
|||||||
statTypes.forEach((type) => {
|
statTypes.forEach((type) => {
|
||||||
let val: number | null;
|
let val: number | null;
|
||||||
if (type === "sum") {
|
if (type === "sum") {
|
||||||
if (prevSum === null) {
|
if (initVal === null) {
|
||||||
val = 0;
|
initVal = val = stat.state || 0;
|
||||||
prevSum = stat.sum;
|
prevSum = stat.sum;
|
||||||
} else {
|
} else {
|
||||||
val = (stat.sum || 0) - prevSum;
|
val = initVal + ((stat.sum || 0) - prevSum!);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val = stat[type];
|
val = stat[type];
|
||||||
|
@@ -312,7 +312,6 @@ export class HaEntityPicker extends LitElement {
|
|||||||
.filteredItems=${this._states}
|
.filteredItems=${this._states}
|
||||||
.renderer=${rowRenderer}
|
.renderer=${rowRenderer}
|
||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
.disabled=${this.disabled}
|
|
||||||
@opened-changed=${this._openedChanged}
|
@opened-changed=${this._openedChanged}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
@filter-changed=${this._filterChanged}
|
@filter-changed=${this._filterChanged}
|
||||||
|
@@ -7,8 +7,6 @@ import { getStates } from "../../common/entity/get_states";
|
|||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import "../ha-combo-box";
|
import "../ha-combo-box";
|
||||||
import type { HaComboBox } from "../ha-combo-box";
|
import type { HaComboBox } from "../ha-combo-box";
|
||||||
import { formatAttributeValue } from "../../data/entity_attributes";
|
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
|
||||||
|
|
||||||
export type HaEntityPickerEntityFilterFunc = (entityId: HassEntity) => boolean;
|
export type HaEntityPickerEntityFilterFunc = (entityId: HassEntity) => boolean;
|
||||||
|
|
||||||
@@ -57,7 +55,7 @@ class HaEntityStatePicker extends LitElement {
|
|||||||
this.hass.locale,
|
this.hass.locale,
|
||||||
key
|
key
|
||||||
)
|
)
|
||||||
: formatAttributeValue(this.hass, key),
|
: key,
|
||||||
}))
|
}))
|
||||||
: [];
|
: [];
|
||||||
}
|
}
|
||||||
@@ -71,7 +69,16 @@ class HaEntityStatePicker extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
<ha-combo-box
|
<ha-combo-box
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.value=${this._value}
|
.value=${this.value
|
||||||
|
? this.entityId && this.hass.states[this.entityId]
|
||||||
|
? computeStateDisplay(
|
||||||
|
this.hass.localize,
|
||||||
|
this.hass.states[this.entityId],
|
||||||
|
this.hass.locale,
|
||||||
|
this.value
|
||||||
|
)
|
||||||
|
: this.value
|
||||||
|
: ""}
|
||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
.label=${this.label ??
|
.label=${this.label ??
|
||||||
this.hass.localize("ui.components.entity.entity-state-picker.state")}
|
this.hass.localize("ui.components.entity.entity-state-picker.state")}
|
||||||
@@ -88,28 +95,12 @@ class HaEntityStatePicker extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private get _value() {
|
|
||||||
return this.value || "";
|
|
||||||
}
|
|
||||||
|
|
||||||
private _openedChanged(ev: PolymerChangedEvent<boolean>) {
|
private _openedChanged(ev: PolymerChangedEvent<boolean>) {
|
||||||
this._opened = ev.detail.value;
|
this._opened = ev.detail.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _valueChanged(ev: PolymerChangedEvent<string>) {
|
private _valueChanged(ev: PolymerChangedEvent<string>) {
|
||||||
ev.stopPropagation();
|
this.value = ev.detail.value;
|
||||||
const newValue = ev.detail.value;
|
|
||||||
if (newValue !== this._value) {
|
|
||||||
this._setValue(newValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private _setValue(value: string) {
|
|
||||||
this.value = value;
|
|
||||||
setTimeout(() => {
|
|
||||||
fireEvent(this, "value-changed", { value });
|
|
||||||
fireEvent(this, "change");
|
|
||||||
}, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,14 +3,10 @@ import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
|||||||
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { ensureArray } from "../../common/ensure-array";
|
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||||
import { stringCompare } from "../../common/string/compare";
|
import { stringCompare } from "../../common/string/compare";
|
||||||
import {
|
import { getStatisticIds, StatisticsMetaData } from "../../data/history";
|
||||||
getStatisticIds,
|
|
||||||
getStatisticLabel,
|
|
||||||
StatisticsMetaData,
|
|
||||||
} from "../../data/recorder";
|
|
||||||
import { PolymerChangedEvent } from "../../polymer-types";
|
import { PolymerChangedEvent } from "../../polymer-types";
|
||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import { documentationUrl } from "../../util/documentation-url";
|
import { documentationUrl } from "../../util/documentation-url";
|
||||||
@@ -43,14 +39,23 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
type: Array,
|
type: Array,
|
||||||
attribute: "include-statistics-unit-of-measurement",
|
attribute: "include-statistics-unit-of-measurement",
|
||||||
})
|
})
|
||||||
public includeStatisticsUnitOfMeasurement?: string | string[];
|
public includeStatisticsUnitOfMeasurement?: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show only statistics with these unit classes.
|
* Show only statistics displayed with these units of measurements.
|
||||||
* @attr include-unit-class
|
* @type {Array}
|
||||||
|
* @attr include-display-unit-of-measurement
|
||||||
*/
|
*/
|
||||||
@property({ attribute: "include-unit-class" })
|
@property({ type: Array, attribute: "include-display-unit-of-measurement" })
|
||||||
public includeUnitClass?: string | string[];
|
public includeDisplayUnitOfMeasurement?: string[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show only statistics with these device classes.
|
||||||
|
* @type {Array}
|
||||||
|
* @attr include-device-classes
|
||||||
|
*/
|
||||||
|
@property({ type: Array, attribute: "include-device-classes" })
|
||||||
|
public includeDeviceClasses?: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show only statistics on entities.
|
* Show only statistics on entities.
|
||||||
@@ -92,8 +97,9 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
private _getStatistics = memoizeOne(
|
private _getStatistics = memoizeOne(
|
||||||
(
|
(
|
||||||
statisticIds: StatisticsMetaData[],
|
statisticIds: StatisticsMetaData[],
|
||||||
includeStatisticsUnitOfMeasurement?: string | string[],
|
includeStatisticsUnitOfMeasurement?: string[],
|
||||||
includeUnitClass?: string | string[],
|
includeDisplayUnitOfMeasurement?: string[],
|
||||||
|
includeDeviceClasses?: string[],
|
||||||
entitiesOnly?: boolean
|
entitiesOnly?: boolean
|
||||||
): Array<{ id: string; name: string; state?: HassEntity }> => {
|
): Array<{ id: string; name: string; state?: HassEntity }> => {
|
||||||
if (!statisticIds.length) {
|
if (!statisticIds.length) {
|
||||||
@@ -108,18 +114,17 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (includeStatisticsUnitOfMeasurement) {
|
if (includeStatisticsUnitOfMeasurement) {
|
||||||
const includeUnits: (string | null)[] = ensureArray(
|
|
||||||
includeStatisticsUnitOfMeasurement
|
|
||||||
);
|
|
||||||
statisticIds = statisticIds.filter((meta) =>
|
statisticIds = statisticIds.filter((meta) =>
|
||||||
includeUnits.includes(meta.statistics_unit_of_measurement)
|
includeStatisticsUnitOfMeasurement.includes(
|
||||||
|
meta.statistics_unit_of_measurement
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (includeUnitClass) {
|
if (includeDisplayUnitOfMeasurement) {
|
||||||
const includeUnitClasses: (string | null)[] =
|
|
||||||
ensureArray(includeUnitClass);
|
|
||||||
statisticIds = statisticIds.filter((meta) =>
|
statisticIds = statisticIds.filter((meta) =>
|
||||||
includeUnitClasses.includes(meta.unit_class)
|
includeDisplayUnitOfMeasurement.includes(
|
||||||
|
meta.display_unit_of_measurement
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,16 +139,23 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
if (!entitiesOnly) {
|
if (!entitiesOnly) {
|
||||||
output.push({
|
output.push({
|
||||||
id: meta.statistic_id,
|
id: meta.statistic_id,
|
||||||
name: getStatisticLabel(this.hass, meta.statistic_id, meta),
|
name: meta.name || meta.statistic_id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
output.push({
|
if (
|
||||||
id: meta.statistic_id,
|
!includeDeviceClasses ||
|
||||||
name: getStatisticLabel(this.hass, meta.statistic_id, meta),
|
includeDeviceClasses.includes(
|
||||||
state: entityState,
|
entityState!.attributes.device_class || ""
|
||||||
});
|
)
|
||||||
|
) {
|
||||||
|
output.push({
|
||||||
|
id: meta.statistic_id,
|
||||||
|
name: computeStateName(entityState),
|
||||||
|
state: entityState,
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!output.length) {
|
if (!output.length) {
|
||||||
@@ -194,7 +206,8 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
(this.comboBox as any).items = this._getStatistics(
|
(this.comboBox as any).items = this._getStatistics(
|
||||||
this.statisticIds!,
|
this.statisticIds!,
|
||||||
this.includeStatisticsUnitOfMeasurement,
|
this.includeStatisticsUnitOfMeasurement,
|
||||||
this.includeUnitClass,
|
this.includeDisplayUnitOfMeasurement,
|
||||||
|
this.includeDeviceClasses,
|
||||||
this.entitiesOnly
|
this.entitiesOnly
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@@ -202,7 +215,8 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
(this.comboBox as any).items = this._getStatistics(
|
(this.comboBox as any).items = this._getStatistics(
|
||||||
this.statisticIds!,
|
this.statisticIds!,
|
||||||
this.includeStatisticsUnitOfMeasurement,
|
this.includeStatisticsUnitOfMeasurement,
|
||||||
this.includeUnitClass,
|
this.includeDisplayUnitOfMeasurement,
|
||||||
|
this.includeDeviceClasses,
|
||||||
this.entitiesOnly
|
this.entitiesOnly
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@@ -22,52 +22,11 @@ class HaStatisticsPicker extends LitElement {
|
|||||||
@property({ attribute: "pick-statistic-label" })
|
@property({ attribute: "pick-statistic-label" })
|
||||||
public pickStatisticLabel?: string;
|
public pickStatisticLabel?: string;
|
||||||
|
|
||||||
/**
|
|
||||||
* Show only statistics natively stored with these units of measurements.
|
|
||||||
* @attr include-statistics-unit-of-measurement
|
|
||||||
*/
|
|
||||||
@property({
|
|
||||||
attribute: "include-statistics-unit-of-measurement",
|
|
||||||
})
|
|
||||||
public includeStatisticsUnitOfMeasurement?: string[] | string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show only statistics with these unit classes.
|
|
||||||
* @attr include-unit-class
|
|
||||||
*/
|
|
||||||
@property({ attribute: "include-unit-class" })
|
|
||||||
public includeUnitClass?: string | string[];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ignore filtering of statistics type and units when only a single statistic is selected.
|
|
||||||
* @type {boolean}
|
|
||||||
* @attr ignore-restrictions-on-first-statistic
|
|
||||||
*/
|
|
||||||
@property({
|
|
||||||
type: Boolean,
|
|
||||||
attribute: "ignore-restrictions-on-first-statistic",
|
|
||||||
})
|
|
||||||
public ignoreRestrictionsOnFirstStatistic = false;
|
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (!this.hass) {
|
if (!this.hass) {
|
||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ignoreRestriction =
|
|
||||||
this.ignoreRestrictionsOnFirstStatistic &&
|
|
||||||
this._currentStatistics.length <= 1;
|
|
||||||
|
|
||||||
const includeStatisticsUnitCurrent = ignoreRestriction
|
|
||||||
? undefined
|
|
||||||
: this.includeStatisticsUnitOfMeasurement;
|
|
||||||
const includeUnitClassCurrent = ignoreRestriction
|
|
||||||
? undefined
|
|
||||||
: this.includeUnitClass;
|
|
||||||
const includeStatisticTypesCurrent = ignoreRestriction
|
|
||||||
? undefined
|
|
||||||
: this.statisticTypes;
|
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
${this._currentStatistics.map(
|
${this._currentStatistics.map(
|
||||||
(statisticId) => html`
|
(statisticId) => html`
|
||||||
@@ -75,10 +34,8 @@ class HaStatisticsPicker extends LitElement {
|
|||||||
<ha-statistic-picker
|
<ha-statistic-picker
|
||||||
.curValue=${statisticId}
|
.curValue=${statisticId}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.includeStatisticsUnitOfMeasurement=${includeStatisticsUnitCurrent}
|
|
||||||
.includeUnitClass=${includeUnitClassCurrent}
|
|
||||||
.value=${statisticId}
|
.value=${statisticId}
|
||||||
.statisticTypes=${includeStatisticTypesCurrent}
|
.statisticTypes=${this.statisticTypes}
|
||||||
.statisticIds=${this.statisticIds}
|
.statisticIds=${this.statisticIds}
|
||||||
.label=${this.pickedStatisticLabel}
|
.label=${this.pickedStatisticLabel}
|
||||||
@value-changed=${this._statisticChanged}
|
@value-changed=${this._statisticChanged}
|
||||||
@@ -89,9 +46,6 @@ class HaStatisticsPicker extends LitElement {
|
|||||||
<div>
|
<div>
|
||||||
<ha-statistic-picker
|
<ha-statistic-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.includeStatisticsUnitOfMeasurement=${this
|
|
||||||
.includeStatisticsUnitOfMeasurement}
|
|
||||||
.includeUnitClass=${this.includeUnitClass}
|
|
||||||
.statisticTypes=${this.statisticTypes}
|
.statisticTypes=${this.statisticTypes}
|
||||||
.statisticIds=${this.statisticIds}
|
.statisticIds=${this.statisticIds}
|
||||||
.label=${this.pickStatisticLabel}
|
.label=${this.pickStatisticLabel}
|
||||||
|
@@ -8,14 +8,7 @@ import type {
|
|||||||
ComboBoxLightValueChangedEvent,
|
ComboBoxLightValueChangedEvent,
|
||||||
} from "@vaadin/combo-box/vaadin-combo-box-light";
|
} from "@vaadin/combo-box/vaadin-combo-box-light";
|
||||||
import { registerStyles } from "@vaadin/vaadin-themable-mixin/register-styles";
|
import { registerStyles } from "@vaadin/vaadin-themable-mixin/register-styles";
|
||||||
import {
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
css,
|
|
||||||
CSSResultGroup,
|
|
||||||
html,
|
|
||||||
LitElement,
|
|
||||||
PropertyValues,
|
|
||||||
TemplateResult,
|
|
||||||
} from "lit";
|
|
||||||
import { ComboBoxLitRenderer, comboBoxRenderer } from "@vaadin/combo-box/lit";
|
import { ComboBoxLitRenderer, comboBoxRenderer } from "@vaadin/combo-box/lit";
|
||||||
import { customElement, property, query } from "lit/decorators";
|
import { customElement, property, query } from "lit/decorators";
|
||||||
import { ifDefined } from "lit/directives/if-defined";
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
@@ -232,13 +225,11 @@ export class HaComboBox extends LitElement {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
fireEvent(this, ev.type, ev.detail);
|
fireEvent(this, ev.type, ev.detail);
|
||||||
|
|
||||||
if (opened) {
|
if (
|
||||||
this.removeInertOnOverlay();
|
opened &&
|
||||||
}
|
"MutationObserver" in window &&
|
||||||
}
|
!this._overlayMutationObserver
|
||||||
|
) {
|
||||||
private removeInertOnOverlay() {
|
|
||||||
if ("MutationObserver" in window && !this._overlayMutationObserver) {
|
|
||||||
const overlay = document.querySelector<HTMLElement>(
|
const overlay = document.querySelector<HTMLElement>(
|
||||||
"vaadin-combo-box-overlay"
|
"vaadin-combo-box-overlay"
|
||||||
);
|
);
|
||||||
@@ -277,16 +268,6 @@ export class HaComboBox extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updated(changedProps: PropertyValues) {
|
|
||||||
super.updated(changedProps);
|
|
||||||
if (
|
|
||||||
changedProps.has("filteredItems") ||
|
|
||||||
(changedProps.has("items") && this.opened)
|
|
||||||
) {
|
|
||||||
this.removeInertOnOverlay();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private _filterChanged(ev: ComboBoxLightFilterChangedEvent) {
|
private _filterChanged(ev: ComboBoxLightFilterChangedEvent) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
fireEvent(this, ev.type, ev.detail, { composed: false });
|
fireEvent(this, ev.type, ev.detail, { composed: false });
|
||||||
@@ -309,7 +290,6 @@ export class HaComboBox extends LitElement {
|
|||||||
}
|
}
|
||||||
vaadin-combo-box-light {
|
vaadin-combo-box-light {
|
||||||
position: relative;
|
position: relative;
|
||||||
--vaadin-combo-box-overlay-max-height: calc(45vh);
|
|
||||||
}
|
}
|
||||||
ha-textfield {
|
ha-textfield {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
@@ -3,14 +3,15 @@ import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
|||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
import { computeCloseIcon, computeOpenIcon } from "../common/entity/cover_icon";
|
import { computeCloseIcon, computeOpenIcon } from "../common/entity/cover_icon";
|
||||||
import { supportsFeature } from "../common/entity/supports-feature";
|
|
||||||
import {
|
import {
|
||||||
CoverEntity,
|
CoverEntity,
|
||||||
CoverEntityFeature,
|
|
||||||
isClosing,
|
isClosing,
|
||||||
isFullyClosed,
|
isFullyClosed,
|
||||||
isFullyOpen,
|
isFullyOpen,
|
||||||
isOpening,
|
isOpening,
|
||||||
|
supportsClose,
|
||||||
|
supportsOpen,
|
||||||
|
supportsStop,
|
||||||
} from "../data/cover";
|
} from "../data/cover";
|
||||||
import { UNAVAILABLE } from "../data/entity";
|
import { UNAVAILABLE } from "../data/entity";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
@@ -31,7 +32,7 @@ class HaCoverControls extends LitElement {
|
|||||||
<div class="state">
|
<div class="state">
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
hidden: !supportsFeature(this.stateObj, CoverEntityFeature.OPEN),
|
hidden: !supportsOpen(this.stateObj),
|
||||||
})}
|
})}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.dialogs.more_info_control.cover.open_cover"
|
"ui.dialogs.more_info_control.cover.open_cover"
|
||||||
@@ -43,7 +44,7 @@ class HaCoverControls extends LitElement {
|
|||||||
</ha-icon-button>
|
</ha-icon-button>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
hidden: !supportsFeature(this.stateObj, CoverEntityFeature.STOP),
|
hidden: !supportsStop(this.stateObj),
|
||||||
})}
|
})}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.dialogs.more_info_control.cover.stop_cover"
|
"ui.dialogs.more_info_control.cover.stop_cover"
|
||||||
@@ -54,7 +55,7 @@ class HaCoverControls extends LitElement {
|
|||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
hidden: !supportsFeature(this.stateObj, CoverEntityFeature.CLOSE),
|
hidden: !supportsClose(this.stateObj),
|
||||||
})}
|
})}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.dialogs.more_info_control.cover.close_cover"
|
"ui.dialogs.more_info_control.cover.close_cover"
|
||||||
|
@@ -2,12 +2,13 @@ import { mdiArrowBottomLeft, mdiArrowTopRight, mdiStop } from "@mdi/js";
|
|||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
import { supportsFeature } from "../common/entity/supports-feature";
|
|
||||||
import {
|
import {
|
||||||
CoverEntity,
|
CoverEntity,
|
||||||
CoverEntityFeature,
|
|
||||||
isFullyClosedTilt,
|
isFullyClosedTilt,
|
||||||
isFullyOpenTilt,
|
isFullyOpenTilt,
|
||||||
|
supportsCloseTilt,
|
||||||
|
supportsOpenTilt,
|
||||||
|
supportsStopTilt,
|
||||||
} from "../data/cover";
|
} from "../data/cover";
|
||||||
import { UNAVAILABLE } from "../data/entity";
|
import { UNAVAILABLE } from "../data/entity";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
@@ -26,10 +27,7 @@ class HaCoverTiltControls extends LitElement {
|
|||||||
|
|
||||||
return html` <ha-icon-button
|
return html` <ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
invisible: !supportsFeature(
|
invisible: !supportsOpenTilt(this.stateObj),
|
||||||
this.stateObj,
|
|
||||||
CoverEntityFeature.OPEN_TILT
|
|
||||||
),
|
|
||||||
})}
|
})}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.dialogs.more_info_control.cover.open_tilt_cover"
|
"ui.dialogs.more_info_control.cover.open_tilt_cover"
|
||||||
@@ -40,10 +38,7 @@ class HaCoverTiltControls extends LitElement {
|
|||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
invisible: !supportsFeature(
|
invisible: !supportsStopTilt(this.stateObj),
|
||||||
this.stateObj,
|
|
||||||
CoverEntityFeature.STOP_TILT
|
|
||||||
),
|
|
||||||
})}
|
})}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.dialogs.more_info_control.cover.stop_cover"
|
"ui.dialogs.more_info_control.cover.stop_cover"
|
||||||
@@ -54,10 +49,7 @@ class HaCoverTiltControls extends LitElement {
|
|||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
invisible: !supportsFeature(
|
invisible: !supportsCloseTilt(this.stateObj),
|
||||||
this.stateObj,
|
|
||||||
CoverEntityFeature.CLOSE_TILT
|
|
||||||
),
|
|
||||||
})}
|
})}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.dialogs.more_info_control.cover.close_tilt_cover"
|
"ui.dialogs.more_info_control.cover.close_tilt_cover"
|
||||||
|
@@ -91,7 +91,7 @@ export class HaDialog extends DialogBase {
|
|||||||
.header_button {
|
.header_button {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 16px;
|
right: 16px;
|
||||||
top: 14px;
|
top: 10px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
@@ -13,9 +13,6 @@ export class HaFormfield extends FormfieldBase {
|
|||||||
switch (input.tagName) {
|
switch (input.tagName) {
|
||||||
case "HA-CHECKBOX":
|
case "HA-CHECKBOX":
|
||||||
case "HA-RADIO":
|
case "HA-RADIO":
|
||||||
if ((input as any).disabled) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
(input as any).checked = !(input as any).checked;
|
(input as any).checked = !(input as any).checked;
|
||||||
fireEvent(input, "change");
|
fireEvent(input, "change");
|
||||||
break;
|
break;
|
||||||
|
@@ -2,7 +2,6 @@ import { css, LitElement, PropertyValues, svg, TemplateResult } from "lit";
|
|||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { styleMap } from "lit/directives/style-map";
|
import { styleMap } from "lit/directives/style-map";
|
||||||
import { formatNumber } from "../common/number/format_number";
|
import { formatNumber } from "../common/number/format_number";
|
||||||
import { blankBeforePercent } from "../common/translations/blank_before_percent";
|
|
||||||
import { afterNextRender } from "../common/util/render-status";
|
import { afterNextRender } from "../common/util/render-status";
|
||||||
import { FrontendLocaleData } from "../data/translation";
|
import { FrontendLocaleData } from "../data/translation";
|
||||||
import { getValueInPercentage, normalize } from "../util/calculate";
|
import { getValueInPercentage, normalize } from "../util/calculate";
|
||||||
@@ -134,11 +133,7 @@ export class Gauge extends LitElement {
|
|||||||
? this._segment_label
|
? this._segment_label
|
||||||
: this.valueText || formatNumber(this.value, this.locale)
|
: this.valueText || formatNumber(this.value, this.locale)
|
||||||
}${
|
}${
|
||||||
this._segment_label
|
this._segment_label ? "" : this.label === "%" ? "%" : ` ${this.label}`
|
||||||
? ""
|
|
||||||
: this.label === "%"
|
|
||||||
? blankBeforePercent(this.locale) + "%"
|
|
||||||
: ` ${this.label}`
|
|
||||||
}
|
}
|
||||||
</text>
|
</text>
|
||||||
</svg>`;
|
</svg>`;
|
||||||
|
@@ -165,7 +165,7 @@ class HaHLSPlayer extends LitElement {
|
|||||||
window.addEventListener("resize", this._resizeExoPlayer);
|
window.addEventListener("resize", this._resizeExoPlayer);
|
||||||
this.updateComplete.then(() => nextRender()).then(this._resizeExoPlayer);
|
this.updateComplete.then(() => nextRender()).then(this._resizeExoPlayer);
|
||||||
this._videoEl.style.visibility = "hidden";
|
this._videoEl.style.visibility = "hidden";
|
||||||
await this.hass!.auth.external!.fireMessage({
|
await this.hass!.auth.external!.sendMessage({
|
||||||
type: "exoplayer/play_hls",
|
type: "exoplayer/play_hls",
|
||||||
payload: {
|
payload: {
|
||||||
url: new URL(url, window.location.href).toString(),
|
url: new URL(url, window.location.href).toString(),
|
||||||
|
@@ -3,8 +3,6 @@ import { mdiDotsVertical } from "@mdi/js";
|
|||||||
import "@polymer/paper-tooltip/paper-tooltip";
|
import "@polymer/paper-tooltip/paper-tooltip";
|
||||||
import { css, html, LitElement, TemplateResult } from "lit";
|
import { css, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
|
||||||
import { haStyle } from "../resources/styles";
|
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
import "./ha-button-menu";
|
import "./ha-button-menu";
|
||||||
import "./ha-icon-button";
|
import "./ha-icon-button";
|
||||||
@@ -17,9 +15,7 @@ export interface IconOverflowMenuItem {
|
|||||||
narrowOnly?: boolean;
|
narrowOnly?: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
tooltip?: string;
|
tooltip?: string;
|
||||||
action: () => any;
|
onClick: CallableFunction;
|
||||||
warning?: boolean;
|
|
||||||
divider?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@customElement("ha-icon-overflow-menu")
|
@customElement("ha-icon-overflow-menu")
|
||||||
@@ -47,23 +43,19 @@ export class HaIconOverflowMenu extends LitElement {
|
|||||||
slot="trigger"
|
slot="trigger"
|
||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
|
|
||||||
${this.items.map((item) =>
|
${this.items.map(
|
||||||
item.divider
|
(item) => html`
|
||||||
? html`<li divider role="separator"></li>`
|
<mwc-list-item
|
||||||
: html`<mwc-list-item
|
graphic="icon"
|
||||||
graphic="icon"
|
.disabled=${item.disabled}
|
||||||
?disabled=${item.disabled}
|
@click=${item.action}
|
||||||
@click=${item.action}
|
>
|
||||||
class=${classMap({ warning: Boolean(item.warning) })}
|
<div slot="graphic">
|
||||||
>
|
<ha-svg-icon .path=${item.path}></ha-svg-icon>
|
||||||
<div slot="graphic">
|
</div>
|
||||||
<ha-svg-icon
|
${item.label}
|
||||||
class=${classMap({ warning: Boolean(item.warning) })}
|
</mwc-list-item>
|
||||||
.path=${item.path}
|
`
|
||||||
></ha-svg-icon>
|
|
||||||
</div>
|
|
||||||
${item.label}
|
|
||||||
</mwc-list-item> `
|
|
||||||
)}
|
)}
|
||||||
</ha-button-menu>`
|
</ha-button-menu>`
|
||||||
: html`
|
: html`
|
||||||
@@ -71,8 +63,6 @@ export class HaIconOverflowMenu extends LitElement {
|
|||||||
${this.items.map((item) =>
|
${this.items.map((item) =>
|
||||||
item.narrowOnly
|
item.narrowOnly
|
||||||
? ""
|
? ""
|
||||||
: item.divider
|
|
||||||
? html`<div role="separator"></div>`
|
|
||||||
: html`<div>
|
: html`<div>
|
||||||
${item.tooltip
|
${item.tooltip
|
||||||
? html`<paper-tooltip animation-delay="0" position="left">
|
? html`<paper-tooltip animation-delay="0" position="left">
|
||||||
@@ -83,7 +73,7 @@ export class HaIconOverflowMenu extends LitElement {
|
|||||||
@click=${item.action}
|
@click=${item.action}
|
||||||
.label=${item.label}
|
.label=${item.label}
|
||||||
.path=${item.path}
|
.path=${item.path}
|
||||||
?disabled=${item.disabled}
|
.disabled=${item.disabled}
|
||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
</div> `
|
</div> `
|
||||||
)}
|
)}
|
||||||
@@ -91,8 +81,7 @@ export class HaIconOverflowMenu extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _handleIconOverflowMenuOpened(e) {
|
protected _handleIconOverflowMenuOpened() {
|
||||||
e.stopPropagation();
|
|
||||||
// If this component is used inside a data table, the z-index of the row
|
// If this component is used inside a data table, the z-index of the row
|
||||||
// needs to be increased. Otherwise the ha-button-menu would be displayed
|
// needs to be increased. Otherwise the ha-button-menu would be displayed
|
||||||
// underneath the next row in the table.
|
// underneath the next row in the table.
|
||||||
@@ -110,22 +99,12 @@ export class HaIconOverflowMenu extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static get styles() {
|
static get styles() {
|
||||||
return [
|
return css`
|
||||||
haStyle,
|
:host {
|
||||||
css`
|
display: flex;
|
||||||
:host {
|
justify-content: flex-end;
|
||||||
display: flex;
|
}
|
||||||
justify-content: flex-end;
|
`;
|
||||||
}
|
|
||||||
li[role="separator"] {
|
|
||||||
border-bottom-color: var(--divider-color);
|
|
||||||
}
|
|
||||||
div[role="separator"] {
|
|
||||||
border-right: 1px solid var(--divider-color);
|
|
||||||
width: 1px;
|
|
||||||
}
|
|
||||||
`,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { css, html, LitElement, PropertyValues, TemplateResult } from "lit";
|
import { css, html, LitElement, TemplateResult } from "lit";
|
||||||
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
@@ -14,7 +14,6 @@ type IconItem = {
|
|||||||
keywords: string[];
|
keywords: string[];
|
||||||
};
|
};
|
||||||
let iconItems: IconItem[] = [];
|
let iconItems: IconItem[] = [];
|
||||||
let iconLoaded = false;
|
|
||||||
|
|
||||||
// eslint-disable-next-line lit/prefer-static-styles
|
// eslint-disable-next-line lit/prefer-static-styles
|
||||||
const rowRenderer: ComboBoxLitRenderer<IconItem> = (item) => html`<mwc-list-item
|
const rowRenderer: ComboBoxLitRenderer<IconItem> = (item) => html`<mwc-list-item
|
||||||
@@ -89,16 +88,15 @@ export class HaIconPicker extends LitElement {
|
|||||||
|
|
||||||
private async _openedChanged(ev: PolymerChangedEvent<boolean>) {
|
private async _openedChanged(ev: PolymerChangedEvent<boolean>) {
|
||||||
this._opened = ev.detail.value;
|
this._opened = ev.detail.value;
|
||||||
if (this._opened && !iconLoaded) {
|
if (this._opened && !iconItems.length) {
|
||||||
const iconList = await import("../../build/mdi/iconList.json");
|
const iconList = await import("../../build/mdi/iconList.json");
|
||||||
|
|
||||||
iconItems = iconList.default.map((icon) => ({
|
iconItems = iconList.default.map((icon) => ({
|
||||||
icon: `mdi:${icon.name}`,
|
icon: `mdi:${icon.name}`,
|
||||||
keywords: icon.keywords,
|
keywords: icon.keywords,
|
||||||
}));
|
}));
|
||||||
iconLoaded = true;
|
|
||||||
|
|
||||||
this.comboBox.filteredItems = iconItems;
|
(this.comboBox as any).filteredItems = iconItems;
|
||||||
|
|
||||||
Object.keys(customIcons).forEach((iconSet) => {
|
Object.keys(customIcons).forEach((iconSet) => {
|
||||||
this._loadCustomIconItems(iconSet);
|
this._loadCustomIconItems(iconSet);
|
||||||
@@ -118,17 +116,13 @@ export class HaIconPicker extends LitElement {
|
|||||||
keywords: icon.keywords ?? [],
|
keywords: icon.keywords ?? [],
|
||||||
}));
|
}));
|
||||||
iconItems.push(...customIconItems);
|
iconItems.push(...customIconItems);
|
||||||
this.comboBox.filteredItems = iconItems;
|
(this.comboBox as any).filteredItems = iconItems;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.warn(`Unable to load icon list for ${iconsetPrefix} iconset`);
|
console.warn(`Unable to load icon list for ${iconsetPrefix} iconset`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected shouldUpdate(changedProps: PropertyValues) {
|
|
||||||
return !this._opened || changedProps.has("_opened");
|
|
||||||
}
|
|
||||||
|
|
||||||
private _valueChanged(ev: PolymerChangedEvent<string>) {
|
private _valueChanged(ev: PolymerChangedEvent<string>) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
this._setValue(ev.detail.value);
|
this._setValue(ev.detail.value);
|
||||||
@@ -167,12 +161,14 @@ export class HaIconPicker extends LitElement {
|
|||||||
filteredItems.push(...filteredItemsByKeywords);
|
filteredItems.push(...filteredItemsByKeywords);
|
||||||
|
|
||||||
if (filteredItems.length > 0) {
|
if (filteredItems.length > 0) {
|
||||||
this.comboBox.filteredItems = filteredItems;
|
(this.comboBox as any).filteredItems = filteredItems;
|
||||||
} else {
|
} else {
|
||||||
this.comboBox.filteredItems = [{ icon: filterString, keywords: [] }];
|
(this.comboBox as any).filteredItems = [
|
||||||
|
{ icon: filterString, keywords: [] },
|
||||||
|
];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.comboBox.filteredItems = iconItems;
|
(this.comboBox as any).filteredItems = iconItems;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,221 +0,0 @@
|
|||||||
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
|
||||||
import { css, html, LitElement, PropertyValues, TemplateResult } from "lit";
|
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
|
||||||
import { titleCase } from "../common/string/title-case";
|
|
||||||
import {
|
|
||||||
fetchConfig,
|
|
||||||
LovelaceConfig,
|
|
||||||
LovelaceViewConfig,
|
|
||||||
} from "../data/lovelace";
|
|
||||||
import { PolymerChangedEvent } from "../polymer-types";
|
|
||||||
import { HomeAssistant, PanelInfo } from "../types";
|
|
||||||
import "./ha-combo-box";
|
|
||||||
import type { HaComboBox } from "./ha-combo-box";
|
|
||||||
import "./ha-icon";
|
|
||||||
|
|
||||||
type NavigationItem = {
|
|
||||||
path: string;
|
|
||||||
icon: string;
|
|
||||||
title: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const DEFAULT_ITEMS: NavigationItem[] = [];
|
|
||||||
|
|
||||||
// eslint-disable-next-line lit/prefer-static-styles
|
|
||||||
const rowRenderer: ComboBoxLitRenderer<NavigationItem> = (item) => html`
|
|
||||||
<mwc-list-item graphic="icon" .twoline=${!!item.title}>
|
|
||||||
<ha-icon .icon=${item.icon} slot="graphic"></ha-icon>
|
|
||||||
<span>${item.title || item.path}</span>
|
|
||||||
<span slot="secondary">${item.path}</span>
|
|
||||||
</mwc-list-item>
|
|
||||||
`;
|
|
||||||
|
|
||||||
const createViewNavigationItem = (
|
|
||||||
prefix: string,
|
|
||||||
view: LovelaceViewConfig,
|
|
||||||
index: number
|
|
||||||
) => ({
|
|
||||||
path: `/${prefix}/${view.path ?? index}`,
|
|
||||||
icon: view.icon ?? "mdi:view-compact",
|
|
||||||
title: view.title ?? (view.path ? titleCase(view.path) : `${index}`),
|
|
||||||
});
|
|
||||||
|
|
||||||
const createPanelNavigationItem = (hass: HomeAssistant, panel: PanelInfo) => ({
|
|
||||||
path: `/${panel.url_path}`,
|
|
||||||
icon: panel.icon ?? "mdi:view-dashboard",
|
|
||||||
title:
|
|
||||||
panel.url_path === hass.defaultPanel
|
|
||||||
? hass.localize("panel.states")
|
|
||||||
: hass.localize(`panel.${panel.title}`) ||
|
|
||||||
panel.title ||
|
|
||||||
(panel.url_path ? titleCase(panel.url_path) : ""),
|
|
||||||
});
|
|
||||||
|
|
||||||
@customElement("ha-navigation-picker")
|
|
||||||
export class HaNavigationPicker extends LitElement {
|
|
||||||
@property() public hass?: HomeAssistant;
|
|
||||||
|
|
||||||
@property() public label?: string;
|
|
||||||
|
|
||||||
@property() public value?: string;
|
|
||||||
|
|
||||||
@property() public helper?: string;
|
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
|
||||||
|
|
||||||
@property({ type: Boolean }) public required = false;
|
|
||||||
|
|
||||||
@state() private _opened = false;
|
|
||||||
|
|
||||||
private navigationItemsLoaded = false;
|
|
||||||
|
|
||||||
private navigationItems: NavigationItem[] = DEFAULT_ITEMS;
|
|
||||||
|
|
||||||
@query("ha-combo-box", true) private comboBox!: HaComboBox;
|
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
|
||||||
return html`
|
|
||||||
<ha-combo-box
|
|
||||||
.hass=${this.hass}
|
|
||||||
item-value-path="path"
|
|
||||||
item-label-path="path"
|
|
||||||
.value=${this._value}
|
|
||||||
allow-custom-value
|
|
||||||
.filteredItems=${this.navigationItems}
|
|
||||||
.label=${this.label}
|
|
||||||
.helper=${this.helper}
|
|
||||||
.disabled=${this.disabled}
|
|
||||||
.required=${this.required}
|
|
||||||
.renderer=${rowRenderer}
|
|
||||||
@opened-changed=${this._openedChanged}
|
|
||||||
@value-changed=${this._valueChanged}
|
|
||||||
@filter-changed=${this._filterChanged}
|
|
||||||
>
|
|
||||||
</ha-combo-box>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _openedChanged(ev: PolymerChangedEvent<boolean>) {
|
|
||||||
this._opened = ev.detail.value;
|
|
||||||
if (this._opened && !this.navigationItemsLoaded) {
|
|
||||||
this._loadNavigationItems();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _loadNavigationItems() {
|
|
||||||
this.navigationItemsLoaded = true;
|
|
||||||
|
|
||||||
const panels = Object.entries(this.hass!.panels).map(([id, panel]) => ({
|
|
||||||
id,
|
|
||||||
...panel,
|
|
||||||
}));
|
|
||||||
const lovelacePanels = panels.filter(
|
|
||||||
(panel) => panel.component_name === "lovelace"
|
|
||||||
);
|
|
||||||
|
|
||||||
const viewConfigs = await Promise.all(
|
|
||||||
lovelacePanels.map((panel) =>
|
|
||||||
fetchConfig(
|
|
||||||
this.hass!.connection,
|
|
||||||
// path should be null to fetch default lovelace panel
|
|
||||||
panel.url_path === "lovelace" ? null : panel.url_path,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
.then((config) => [panel.id, config] as [string, LovelaceConfig])
|
|
||||||
.catch((_) => [panel.id, undefined] as [string, undefined])
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
const panelViewConfig = new Map(viewConfigs);
|
|
||||||
|
|
||||||
this.navigationItems = [];
|
|
||||||
|
|
||||||
for (const panel of panels) {
|
|
||||||
this.navigationItems.push(createPanelNavigationItem(this.hass!, panel));
|
|
||||||
|
|
||||||
const config = panelViewConfig.get(panel.id);
|
|
||||||
|
|
||||||
if (!config) continue;
|
|
||||||
|
|
||||||
config.views.forEach((view, index) =>
|
|
||||||
this.navigationItems.push(
|
|
||||||
createViewNavigationItem(panel.url_path, view, index)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.comboBox.filteredItems = this.navigationItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected shouldUpdate(changedProps: PropertyValues) {
|
|
||||||
return !this._opened || changedProps.has("_opened");
|
|
||||||
}
|
|
||||||
|
|
||||||
private _valueChanged(ev: PolymerChangedEvent<string>) {
|
|
||||||
ev.stopPropagation();
|
|
||||||
this._setValue(ev.detail.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private _setValue(value: string) {
|
|
||||||
this.value = value;
|
|
||||||
fireEvent(
|
|
||||||
this,
|
|
||||||
"value-changed",
|
|
||||||
{ value: this._value },
|
|
||||||
{
|
|
||||||
bubbles: false,
|
|
||||||
composed: false,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private _filterChanged(ev: CustomEvent): void {
|
|
||||||
const filterString = ev.detail.value.toLowerCase();
|
|
||||||
const characterCount = filterString.length;
|
|
||||||
if (characterCount >= 2) {
|
|
||||||
const filteredItems: NavigationItem[] = [];
|
|
||||||
|
|
||||||
this.navigationItems.forEach((item) => {
|
|
||||||
if (
|
|
||||||
item.path.toLowerCase().includes(filterString) ||
|
|
||||||
item.title.toLowerCase().includes(filterString)
|
|
||||||
) {
|
|
||||||
filteredItems.push(item);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (filteredItems.length > 0) {
|
|
||||||
this.comboBox.filteredItems = filteredItems;
|
|
||||||
} else {
|
|
||||||
this.comboBox.filteredItems = [];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.comboBox.filteredItems = this.navigationItems;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private get _value() {
|
|
||||||
return this.value || "";
|
|
||||||
}
|
|
||||||
|
|
||||||
static get styles() {
|
|
||||||
return css`
|
|
||||||
ha-icon,
|
|
||||||
ha-svg-icon {
|
|
||||||
color: var(--primary-text-color);
|
|
||||||
position: relative;
|
|
||||||
bottom: 0px;
|
|
||||||
}
|
|
||||||
*[slot="prefix"] {
|
|
||||||
margin-right: 8px;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface HTMLElementTagNameMap {
|
|
||||||
"ha-navigation-picker": HaNavigationPicker;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,47 +0,0 @@
|
|||||||
import { html, LitElement } from "lit";
|
|
||||||
import { customElement, property } from "lit/decorators";
|
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
|
||||||
import { NavigationSelector } from "../../data/selector";
|
|
||||||
import { HomeAssistant } from "../../types";
|
|
||||||
import "../ha-navigation-picker";
|
|
||||||
|
|
||||||
@customElement("ha-selector-navigation")
|
|
||||||
export class HaNavigationSelector extends LitElement {
|
|
||||||
@property() public hass!: HomeAssistant;
|
|
||||||
|
|
||||||
@property() public selector!: NavigationSelector;
|
|
||||||
|
|
||||||
@property() public value?: string;
|
|
||||||
|
|
||||||
@property() public label?: string;
|
|
||||||
|
|
||||||
@property() public helper?: string;
|
|
||||||
|
|
||||||
@property({ type: Boolean, reflect: true }) public disabled = false;
|
|
||||||
|
|
||||||
@property({ type: Boolean }) public required = true;
|
|
||||||
|
|
||||||
protected render() {
|
|
||||||
return html`
|
|
||||||
<ha-navigation-picker
|
|
||||||
.hass=${this.hass}
|
|
||||||
.label=${this.label}
|
|
||||||
.value=${this.value}
|
|
||||||
.required=${this.required}
|
|
||||||
.disabled=${this.disabled}
|
|
||||||
.helper=${this.helper}
|
|
||||||
@value-changed=${this._valueChanged}
|
|
||||||
></ha-navigation-picker>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _valueChanged(ev: CustomEvent) {
|
|
||||||
fireEvent(this, "value-changed", { value: ev.detail.value });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface HTMLElementTagNameMap {
|
|
||||||
"ha-selector-navigation": HaNavigationSelector;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -51,9 +51,8 @@ export class HaNumberSelector extends LitElement {
|
|||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
<ha-textfield
|
<ha-textfield
|
||||||
.inputMode=${(this.selector.number.step || 1) % 1 !== 0
|
inputMode="numeric"
|
||||||
? "decimal"
|
pattern="[0-9]+([\\.][0-9]+)?"
|
||||||
: "numeric"}
|
|
||||||
.label=${this.selector.number.mode !== "box" ? undefined : this.label}
|
.label=${this.selector.number.mode !== "box" ? undefined : this.label}
|
||||||
.placeholder=${this.placeholder}
|
.placeholder=${this.placeholder}
|
||||||
class=${classMap({ single: this.selector.number.mode === "box" })}
|
class=${classMap({ single: this.selector.number.mode === "box" })}
|
||||||
|
@@ -13,7 +13,6 @@ import type { HaComboBox } from "../ha-combo-box";
|
|||||||
import "../ha-formfield";
|
import "../ha-formfield";
|
||||||
import "../ha-radio";
|
import "../ha-radio";
|
||||||
import "../ha-select";
|
import "../ha-select";
|
||||||
import "../ha-input-helper-text";
|
|
||||||
|
|
||||||
@customElement("ha-selector-select")
|
@customElement("ha-selector-select")
|
||||||
export class HaSelectSelector extends LitElement {
|
export class HaSelectSelector extends LitElement {
|
||||||
@@ -41,7 +40,7 @@ export class HaSelectSelector extends LitElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!this.selector.select.custom_value && this._mode === "list") {
|
if (!this.selector.select.custom_value && this._mode === "list") {
|
||||||
if (!this.selector.select.multiple) {
|
if (!this.selector.select.multiple || this.required) {
|
||||||
return html`
|
return html`
|
||||||
<div>
|
<div>
|
||||||
${this.label}
|
${this.label}
|
||||||
@@ -51,7 +50,7 @@ export class HaSelectSelector extends LitElement {
|
|||||||
<ha-radio
|
<ha-radio
|
||||||
.checked=${item.value === this.value}
|
.checked=${item.value === this.value}
|
||||||
.value=${item.value}
|
.value=${item.value}
|
||||||
.disabled=${item.disabled || this.disabled}
|
.disabled=${this.disabled}
|
||||||
@change=${this._valueChanged}
|
@change=${this._valueChanged}
|
||||||
></ha-radio>
|
></ha-radio>
|
||||||
</ha-formfield>
|
</ha-formfield>
|
||||||
@@ -64,14 +63,13 @@ export class HaSelectSelector extends LitElement {
|
|||||||
|
|
||||||
return html`
|
return html`
|
||||||
<div>
|
<div>
|
||||||
${this.label}
|
${this.label}${options.map(
|
||||||
${options.map(
|
|
||||||
(item: SelectOption) => html`
|
(item: SelectOption) => html`
|
||||||
<ha-formfield .label=${item.label}>
|
<ha-formfield .label=${item.label}>
|
||||||
<ha-checkbox
|
<ha-checkbox
|
||||||
.checked=${this.value?.includes(item.value)}
|
.checked=${this.value?.includes(item.value)}
|
||||||
.value=${item.value}
|
.value=${item.value}
|
||||||
.disabled=${item.disabled || this.disabled}
|
.disabled=${this.disabled}
|
||||||
@change=${this._checkboxChanged}
|
@change=${this._checkboxChanged}
|
||||||
></ha-checkbox>
|
></ha-checkbox>
|
||||||
</ha-formfield>
|
</ha-formfield>
|
||||||
@@ -114,9 +112,7 @@ export class HaSelectSelector extends LitElement {
|
|||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.required=${this.required && !value.length}
|
.required=${this.required && !value.length}
|
||||||
.value=${this._filter}
|
.value=${this._filter}
|
||||||
.items=${options.filter(
|
.items=${options.filter((item) => !this.value?.includes(item.value))}
|
||||||
(option) => !option.disabled && !value?.includes(option.value)
|
|
||||||
)}
|
|
||||||
@filter-changed=${this._filterChanged}
|
@filter-changed=${this._filterChanged}
|
||||||
@value-changed=${this._comboBoxValueChanged}
|
@value-changed=${this._comboBoxValueChanged}
|
||||||
></ha-combo-box>
|
></ha-combo-box>
|
||||||
@@ -140,7 +136,7 @@ export class HaSelectSelector extends LitElement {
|
|||||||
.helper=${this.helper}
|
.helper=${this.helper}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
.items=${options.filter((item) => !item.disabled)}
|
.items=${options}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
@filter-changed=${this._filterChanged}
|
@filter-changed=${this._filterChanged}
|
||||||
@value-changed=${this._comboBoxValueChanged}
|
@value-changed=${this._comboBoxValueChanged}
|
||||||
@@ -161,9 +157,7 @@ export class HaSelectSelector extends LitElement {
|
|||||||
>
|
>
|
||||||
${options.map(
|
${options.map(
|
||||||
(item: SelectOption) => html`
|
(item: SelectOption) => html`
|
||||||
<mwc-list-item .value=${item.value} .disabled=${item.disabled}
|
<mwc-list-item .value=${item.value}>${item.label}</mwc-list-item>
|
||||||
>${item.label}</mwc-list-item
|
|
||||||
>
|
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
</ha-select>
|
</ha-select>
|
||||||
@@ -291,9 +285,6 @@ export class HaSelectSelector extends LitElement {
|
|||||||
ha-formfield {
|
ha-formfield {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
mwc-list-item[disabled] {
|
|
||||||
--mdc-theme-text-primary-on-background: var(--disabled-text-color);
|
|
||||||
}
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,7 +16,6 @@ import "./ha-selector-device";
|
|||||||
import "./ha-selector-duration";
|
import "./ha-selector-duration";
|
||||||
import "./ha-selector-entity";
|
import "./ha-selector-entity";
|
||||||
import "./ha-selector-file";
|
import "./ha-selector-file";
|
||||||
import "./ha-selector-navigation";
|
|
||||||
import "./ha-selector-number";
|
import "./ha-selector-number";
|
||||||
import "./ha-selector-object";
|
import "./ha-selector-object";
|
||||||
import "./ha-selector-select";
|
import "./ha-selector-select";
|
||||||
|
@@ -55,14 +55,12 @@ export class HaServiceControl extends LitElement {
|
|||||||
data?: Record<string, any>;
|
data?: Record<string, any>;
|
||||||
};
|
};
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
@state() private _value!: this["value"];
|
||||||
|
|
||||||
@property({ reflect: true, type: Boolean }) public narrow!: boolean;
|
@property({ reflect: true, type: Boolean }) public narrow!: boolean;
|
||||||
|
|
||||||
@property({ type: Boolean }) public showAdvanced?: boolean;
|
@property({ type: Boolean }) public showAdvanced?: boolean;
|
||||||
|
|
||||||
@state() private _value!: this["value"];
|
|
||||||
|
|
||||||
@state() private _checkedKeys = new Set();
|
@state() private _checkedKeys = new Set();
|
||||||
|
|
||||||
@state() private _manifest?: IntegrationManifest;
|
@state() private _manifest?: IntegrationManifest;
|
||||||
@@ -229,7 +227,6 @@ export class HaServiceControl extends LitElement {
|
|||||||
return html`<ha-service-picker
|
return html`<ha-service-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.value=${this._value?.service}
|
.value=${this._value?.service}
|
||||||
.disabled=${this.disabled}
|
|
||||||
@value-changed=${this._serviceChanged}
|
@value-changed=${this._serviceChanged}
|
||||||
></ha-service-picker>
|
></ha-service-picker>
|
||||||
<div class="description">
|
<div class="description">
|
||||||
@@ -276,7 +273,6 @@ export class HaServiceControl extends LitElement {
|
|||||||
.selector=${serviceData.target
|
.selector=${serviceData.target
|
||||||
? { target: serviceData.target }
|
? { target: serviceData.target }
|
||||||
: { target: {} }}
|
: { target: {} }}
|
||||||
.disabled=${this.disabled}
|
|
||||||
@value-changed=${this._targetChanged}
|
@value-changed=${this._targetChanged}
|
||||||
.value=${this._value?.target}
|
.value=${this._value?.target}
|
||||||
></ha-selector
|
></ha-selector
|
||||||
@@ -284,7 +280,6 @@ export class HaServiceControl extends LitElement {
|
|||||||
: entityId
|
: entityId
|
||||||
? html`<ha-entity-picker
|
? html`<ha-entity-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.disabled=${this.disabled}
|
|
||||||
.value=${this._value?.data?.entity_id}
|
.value=${this._value?.data?.entity_id}
|
||||||
.label=${entityId.description}
|
.label=${entityId.description}
|
||||||
@value-changed=${this._entityPicked}
|
@value-changed=${this._entityPicked}
|
||||||
@@ -296,7 +291,6 @@ export class HaServiceControl extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.label=${this.hass.localize("ui.components.service-control.data")}
|
.label=${this.hass.localize("ui.components.service-control.data")}
|
||||||
.name=${"data"}
|
.name=${"data"}
|
||||||
.readOnly=${this.disabled}
|
|
||||||
.defaultValue=${this._value?.data}
|
.defaultValue=${this._value?.data}
|
||||||
@value-changed=${this._dataChanged}
|
@value-changed=${this._dataChanged}
|
||||||
></ha-yaml-editor>`
|
></ha-yaml-editor>`
|
||||||
@@ -317,18 +311,16 @@ export class HaServiceControl extends LitElement {
|
|||||||
.checked=${this._checkedKeys.has(dataField.key) ||
|
.checked=${this._checkedKeys.has(dataField.key) ||
|
||||||
(this._value?.data &&
|
(this._value?.data &&
|
||||||
this._value.data[dataField.key] !== undefined)}
|
this._value.data[dataField.key] !== undefined)}
|
||||||
.disabled=${this.disabled}
|
|
||||||
@change=${this._checkboxChanged}
|
@change=${this._checkboxChanged}
|
||||||
slot="prefix"
|
slot="prefix"
|
||||||
></ha-checkbox>`}
|
></ha-checkbox>`}
|
||||||
<span slot="heading">${dataField.name || dataField.key}</span>
|
<span slot="heading">${dataField.name || dataField.key}</span>
|
||||||
<span slot="description">${dataField?.description}</span>
|
<span slot="description">${dataField?.description}</span>
|
||||||
<ha-selector
|
<ha-selector
|
||||||
.disabled=${this.disabled ||
|
.disabled=${showOptional &&
|
||||||
(showOptional &&
|
!this._checkedKeys.has(dataField.key) &&
|
||||||
!this._checkedKeys.has(dataField.key) &&
|
(!this._value?.data ||
|
||||||
(!this._value?.data ||
|
this._value.data[dataField.key] === undefined)}
|
||||||
this._value.data[dataField.key] === undefined))}
|
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.selector=${dataField.selector}
|
.selector=${dataField.selector}
|
||||||
.key=${dataField.key}
|
.key=${dataField.key}
|
||||||
|
@@ -20,8 +20,6 @@ const rowRenderer: ComboBoxLitRenderer<{ service: string; name: string }> = (
|
|||||||
class HaServicePicker extends LitElement {
|
class HaServicePicker extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
|
||||||
|
|
||||||
@property() public value?: string;
|
@property() public value?: string;
|
||||||
|
|
||||||
@state() private _filter?: string;
|
@state() private _filter?: string;
|
||||||
@@ -37,7 +35,6 @@ class HaServicePicker extends LitElement {
|
|||||||
this._filter
|
this._filter
|
||||||
)}
|
)}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
.disabled=${this.disabled}
|
|
||||||
.renderer=${rowRenderer}
|
.renderer=${rowRenderer}
|
||||||
item-value-path="service"
|
item-value-path="service"
|
||||||
item-label-path="name"
|
item-label-path="name"
|
||||||
|
@@ -221,15 +221,13 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
private _sortable?: SortableInstance;
|
private _sortable?: SortableInstance;
|
||||||
|
|
||||||
public hassSubscribe(): UnsubscribeFunc[] {
|
public hassSubscribe(): UnsubscribeFunc[] {
|
||||||
return this.hass.user?.is_admin
|
return [
|
||||||
? [
|
subscribeRepairsIssueRegistry(this.hass.connection!, (repairs) => {
|
||||||
subscribeRepairsIssueRegistry(this.hass.connection!, (repairs) => {
|
this._issuesCount = repairs.issues.filter(
|
||||||
this._issuesCount = repairs.issues.filter(
|
(issue) => !issue.ignored
|
||||||
(issue) => !issue.ignored
|
).length;
|
||||||
).length;
|
}),
|
||||||
}),
|
];
|
||||||
]
|
|
||||||
: [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
|
@@ -82,13 +82,6 @@ export class HaTextField extends TextFieldBase {
|
|||||||
direction: var(--direction);
|
direction: var(--direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
.mdc-floating-label:not(.mdc-floating-label--float-above) {
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
width: inherit;
|
|
||||||
padding-right: 30px;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
input {
|
input {
|
||||||
text-align: var(--text-field-text-align, start);
|
text-align: var(--text-field-text-align, start);
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,7 @@ export const traceTabStyles = css`
|
|||||||
}
|
}
|
||||||
|
|
||||||
.tabs > *.active {
|
.tabs > *.active {
|
||||||
border-bottom-color: var(--primary-color);
|
border-bottom-color: var(--accent-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.tabs > *:focus,
|
.tabs > *:focus,
|
||||||
|
@@ -8,10 +8,6 @@ export interface ApplicationCredentialsConfig {
|
|||||||
integrations: Record<string, ApplicationCredentialsDomainConfig>;
|
integrations: Record<string, ApplicationCredentialsDomainConfig>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplicationCredentialsConfigEntry {
|
|
||||||
application_credentials_id?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ApplicationCredential {
|
export interface ApplicationCredential {
|
||||||
id: string;
|
id: string;
|
||||||
domain: string;
|
domain: string;
|
||||||
@@ -25,15 +21,6 @@ export const fetchApplicationCredentialsConfig = async (hass: HomeAssistant) =>
|
|||||||
type: "application_credentials/config",
|
type: "application_credentials/config",
|
||||||
});
|
});
|
||||||
|
|
||||||
export const fetchApplicationCredentialsConfigEntry = async (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
configEntryId: string
|
|
||||||
) =>
|
|
||||||
hass.callWS<ApplicationCredentialsConfigEntry>({
|
|
||||||
type: "application_credentials/config_entry",
|
|
||||||
config_entry_id: configEntryId,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const fetchApplicationCredentials = async (hass: HomeAssistant) =>
|
export const fetchApplicationCredentials = async (hass: HomeAssistant) =>
|
||||||
hass.callWS<ApplicationCredential[]>({
|
hass.callWS<ApplicationCredential[]>({
|
||||||
type: "application_credentials/list",
|
type: "application_credentials/list",
|
||||||
|
@@ -9,7 +9,6 @@ import { DeviceCondition, DeviceTrigger } from "./device_automation";
|
|||||||
import { Action, MODES } from "./script";
|
import { Action, MODES } from "./script";
|
||||||
|
|
||||||
export const AUTOMATION_DEFAULT_MODE: typeof MODES[number] = "single";
|
export const AUTOMATION_DEFAULT_MODE: typeof MODES[number] = "single";
|
||||||
export const AUTOMATION_DEFAULT_MAX = 10;
|
|
||||||
|
|
||||||
export interface AutomationEntity extends HassEntityBase {
|
export interface AutomationEntity extends HassEntityBase {
|
||||||
attributes: HassEntityAttributeBase & {
|
attributes: HassEntityAttributeBase & {
|
||||||
@@ -311,37 +310,14 @@ export const deleteAutomation = (hass: HomeAssistant, id: string) =>
|
|||||||
|
|
||||||
let inititialAutomationEditorData: Partial<AutomationConfig> | undefined;
|
let inititialAutomationEditorData: Partial<AutomationConfig> | undefined;
|
||||||
|
|
||||||
export const fetchAutomationFileConfig = (hass: HomeAssistant, id: string) =>
|
export const getAutomationConfig = (hass: HomeAssistant, id: string) =>
|
||||||
hass.callApi<AutomationConfig>("GET", `config/automation/config/${id}`);
|
hass.callApi<AutomationConfig>("GET", `config/automation/config/${id}`);
|
||||||
|
|
||||||
export const getAutomationStateConfig = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
entity_id: string
|
|
||||||
) =>
|
|
||||||
hass.callWS<{ config: AutomationConfig }>({
|
|
||||||
type: "automation/config",
|
|
||||||
entity_id,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const saveAutomationConfig = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
id: string,
|
|
||||||
config: AutomationConfig
|
|
||||||
) => hass.callApi<void>("POST", `config/automation/config/${id}`, config);
|
|
||||||
|
|
||||||
export const showAutomationEditor = (data?: Partial<AutomationConfig>) => {
|
export const showAutomationEditor = (data?: Partial<AutomationConfig>) => {
|
||||||
inititialAutomationEditorData = data;
|
inititialAutomationEditorData = data;
|
||||||
navigate("/config/automation/edit/new");
|
navigate("/config/automation/edit/new");
|
||||||
};
|
};
|
||||||
|
|
||||||
export const duplicateAutomation = (config: AutomationConfig) => {
|
|
||||||
showAutomationEditor({
|
|
||||||
...config,
|
|
||||||
id: undefined,
|
|
||||||
alias: undefined,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getAutomationEditorInitData = () => {
|
export const getAutomationEditorInitData = () => {
|
||||||
const data = inititialAutomationEditorData;
|
const data = inititialAutomationEditorData;
|
||||||
inititialAutomationEditorData = undefined;
|
inititialAutomationEditorData = undefined;
|
||||||
|
@@ -1,15 +1,7 @@
|
|||||||
import { formatDuration } from "../common/datetime/format_duration";
|
|
||||||
import secondsToDuration from "../common/datetime/seconds_to_duration";
|
import secondsToDuration from "../common/datetime/seconds_to_duration";
|
||||||
import { ensureArray } from "../common/ensure-array";
|
|
||||||
import { computeStateName } from "../common/entity/compute_state_name";
|
import { computeStateName } from "../common/entity/compute_state_name";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import { Condition, Trigger } from "./automation";
|
import { Condition, Trigger } from "./automation";
|
||||||
import {
|
|
||||||
DeviceCondition,
|
|
||||||
DeviceTrigger,
|
|
||||||
localizeDeviceAutomationCondition,
|
|
||||||
localizeDeviceAutomationTrigger,
|
|
||||||
} from "./device_automation";
|
|
||||||
import { formatAttributeName } from "./entity_attributes";
|
import { formatAttributeName } from "./entity_attributes";
|
||||||
|
|
||||||
export const describeTrigger = (
|
export const describeTrigger = (
|
||||||
@@ -76,7 +68,7 @@ export const describeTrigger = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// State Trigger
|
// State Trigger
|
||||||
if (trigger.platform === "state") {
|
if (trigger.platform === "state" && trigger.entity_id) {
|
||||||
let base = "When";
|
let base = "When";
|
||||||
let entities = "";
|
let entities = "";
|
||||||
|
|
||||||
@@ -97,17 +89,12 @@ export const describeTrigger = (
|
|||||||
} ${computeStateName(states[entity]) || entity}`;
|
} ${computeStateName(states[entity]) || entity}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (trigger.entity_id) {
|
} else {
|
||||||
entities = states[trigger.entity_id]
|
entities = states[trigger.entity_id]
|
||||||
? computeStateName(states[trigger.entity_id])
|
? computeStateName(states[trigger.entity_id])
|
||||||
: trigger.entity_id;
|
: trigger.entity_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!entities) {
|
|
||||||
// no entity_id or empty array
|
|
||||||
entities = "something";
|
|
||||||
}
|
|
||||||
|
|
||||||
base += ` ${entities} changes`;
|
base += ` ${entities} changes`;
|
||||||
|
|
||||||
if (trigger.from) {
|
if (trigger.from) {
|
||||||
@@ -141,19 +128,17 @@ export const describeTrigger = (
|
|||||||
base += ` to ${to}`;
|
base += ` to ${to}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trigger.for) {
|
if ("for" in trigger) {
|
||||||
let duration: string | null;
|
let duration: string;
|
||||||
if (typeof trigger.for === "number") {
|
if (typeof trigger.for === "number") {
|
||||||
duration = secondsToDuration(trigger.for);
|
duration = `for ${secondsToDuration(trigger.for)!}`;
|
||||||
} else if (typeof trigger.for === "string") {
|
} else if (typeof trigger.for === "string") {
|
||||||
duration = trigger.for;
|
duration = `for ${trigger.for}`;
|
||||||
} else {
|
} else {
|
||||||
duration = formatDuration(trigger.for);
|
duration = `for ${JSON.stringify(trigger.for)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (duration) {
|
base += ` for ${duration}`;
|
||||||
base += ` for ${duration}`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return base;
|
return base;
|
||||||
@@ -189,11 +174,7 @@ export const describeTrigger = (
|
|||||||
// Time Trigger
|
// Time Trigger
|
||||||
if (trigger.platform === "time" && trigger.at) {
|
if (trigger.platform === "time" && trigger.at) {
|
||||||
const at = trigger.at.includes(".")
|
const at = trigger.at.includes(".")
|
||||||
? `entity ${
|
? hass.states[trigger.at] || trigger.at
|
||||||
hass.states[trigger.at]
|
|
||||||
? computeStateName(hass.states[trigger.at])
|
|
||||||
: trigger.at
|
|
||||||
}`
|
|
||||||
: trigger.at;
|
: trigger.at;
|
||||||
|
|
||||||
return `When the time is equal to ${at}`;
|
return `When the time is equal to ${at}`;
|
||||||
@@ -299,7 +280,7 @@ export const describeTrigger = (
|
|||||||
}
|
}
|
||||||
// MQTT Trigger
|
// MQTT Trigger
|
||||||
if (trigger.platform === "mqtt") {
|
if (trigger.platform === "mqtt") {
|
||||||
return "When an MQTT message has been received";
|
return "When a MQTT payload has been received";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Template Trigger
|
// Template Trigger
|
||||||
@@ -311,25 +292,7 @@ export const describeTrigger = (
|
|||||||
if (trigger.platform === "webhook") {
|
if (trigger.platform === "webhook") {
|
||||||
return "When a Webhook payload has been received";
|
return "When a Webhook payload has been received";
|
||||||
}
|
}
|
||||||
|
return `${trigger.platform || "Unknown"} trigger`;
|
||||||
if (trigger.platform === "device") {
|
|
||||||
if (!trigger.device_id) {
|
|
||||||
return "Device trigger";
|
|
||||||
}
|
|
||||||
const config = trigger as DeviceTrigger;
|
|
||||||
const localized = localizeDeviceAutomationTrigger(hass, config);
|
|
||||||
if (localized) {
|
|
||||||
return localized;
|
|
||||||
}
|
|
||||||
const stateObj = hass.states[config.entity_id as string];
|
|
||||||
return `${stateObj ? computeStateName(stateObj) : config.entity_id} ${
|
|
||||||
config.type
|
|
||||||
}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${
|
|
||||||
trigger.platform ? trigger.platform.replace(/_/g, " ") : "Unknown"
|
|
||||||
} trigger`;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const describeCondition = (
|
export const describeCondition = (
|
||||||
@@ -341,64 +304,15 @@ export const describeCondition = (
|
|||||||
return condition.alias;
|
return condition.alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!condition.condition) {
|
if (["or", "and", "not"].includes(condition.condition)) {
|
||||||
const shorthands: Array<"and" | "or" | "not"> = ["and", "or", "not"];
|
return `multiple conditions using "${condition.condition}"`;
|
||||||
for (const key of shorthands) {
|
|
||||||
if (!(key in condition)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (ensureArray(condition[key])) {
|
|
||||||
condition = {
|
|
||||||
condition: key,
|
|
||||||
conditions: condition[key],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (condition.condition === "or") {
|
|
||||||
const conditions = ensureArray(condition.conditions);
|
|
||||||
|
|
||||||
let count = "condition";
|
|
||||||
|
|
||||||
if (conditions && conditions.length > 0) {
|
|
||||||
count = `of ${conditions.length} conditions`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `Test if any ${count} matches`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (condition.condition === "and") {
|
|
||||||
const conditions = ensureArray(condition.conditions);
|
|
||||||
|
|
||||||
const count =
|
|
||||||
conditions && conditions.length > 0
|
|
||||||
? `${conditions.length} `
|
|
||||||
: "multiple";
|
|
||||||
|
|
||||||
return `Test if ${count} conditions match`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (condition.condition === "not") {
|
|
||||||
const conditions = ensureArray(condition.conditions);
|
|
||||||
|
|
||||||
const what =
|
|
||||||
conditions && conditions.length > 0
|
|
||||||
? `none of ${conditions.length} conditions match`
|
|
||||||
: "no condition matches";
|
|
||||||
|
|
||||||
return `Test if ${what}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// State Condition
|
// State Condition
|
||||||
if (condition.condition === "state") {
|
if (condition.condition === "state" && condition.entity_id) {
|
||||||
let base = "Confirm";
|
let base = "Confirm";
|
||||||
const stateObj = hass.states[condition.entity_id];
|
const stateObj = hass.states[condition.entity_id];
|
||||||
const entity = stateObj
|
const entity = stateObj ? computeStateName(stateObj) : condition.entity_id;
|
||||||
? computeStateName(stateObj)
|
|
||||||
: condition.entity_id
|
|
||||||
? condition.entity_id
|
|
||||||
: "an entity";
|
|
||||||
|
|
||||||
if ("attribute" in condition) {
|
if ("attribute" in condition) {
|
||||||
base += ` ${condition.attribute} from`;
|
base += ` ${condition.attribute} from`;
|
||||||
@@ -414,14 +328,10 @@ export const describeCondition = (
|
|||||||
: ""
|
: ""
|
||||||
} ${state}`;
|
} ${state}`;
|
||||||
}
|
}
|
||||||
} else if (condition.state) {
|
} else {
|
||||||
states = condition.state.toString();
|
states = condition.state.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!states) {
|
|
||||||
states = "a state";
|
|
||||||
}
|
|
||||||
|
|
||||||
base += ` ${entity} is ${states}`;
|
base += ` ${entity} is ${states}`;
|
||||||
|
|
||||||
if ("for" in condition) {
|
if ("for" in condition) {
|
||||||
@@ -557,29 +467,5 @@ export const describeCondition = (
|
|||||||
}`;
|
}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (condition.condition === "device") {
|
return `${condition.condition} condition`;
|
||||||
if (!condition.device_id) {
|
|
||||||
return "Device condition";
|
|
||||||
}
|
|
||||||
const config = condition as DeviceCondition;
|
|
||||||
const localized = localizeDeviceAutomationCondition(hass, config);
|
|
||||||
if (localized) {
|
|
||||||
return localized;
|
|
||||||
}
|
|
||||||
const stateObj = hass.states[config.entity_id as string];
|
|
||||||
return `${stateObj ? computeStateName(stateObj) : config.entity_id} ${
|
|
||||||
config.type
|
|
||||||
}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (condition.condition === "trigger") {
|
|
||||||
if (!condition.id) {
|
|
||||||
return "Trigger condition";
|
|
||||||
}
|
|
||||||
return `When triggered by ${condition.id}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${
|
|
||||||
condition.condition ? condition.condition.replace(/_/g, " ") : "Unknown"
|
|
||||||
} condition`;
|
|
||||||
};
|
};
|
||||||
|
@@ -6,7 +6,6 @@ import { timeCacheEntityPromiseFunc } from "../common/util/time-cache-entity-pro
|
|||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
import { getSignedPath } from "./auth";
|
import { getSignedPath } from "./auth";
|
||||||
|
|
||||||
export const CAMERA_ORIENTATIONS = [1, 2, 3, 4, 6, 8];
|
|
||||||
export const CAMERA_SUPPORT_ON_OFF = 1;
|
export const CAMERA_SUPPORT_ON_OFF = 1;
|
||||||
export const CAMERA_SUPPORT_STREAM = 2;
|
export const CAMERA_SUPPORT_STREAM = 2;
|
||||||
|
|
||||||
@@ -27,7 +26,6 @@ export interface CameraEntity extends HassEntityBase {
|
|||||||
|
|
||||||
export interface CameraPreferences {
|
export interface CameraPreferences {
|
||||||
preload_stream: boolean;
|
preload_stream: boolean;
|
||||||
orientation: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CameraThumbnail {
|
export interface CameraThumbnail {
|
||||||
@@ -111,13 +109,11 @@ export const fetchCameraPrefs = (hass: HomeAssistant, entityId: string) =>
|
|||||||
entity_id: entityId,
|
entity_id: entityId,
|
||||||
});
|
});
|
||||||
|
|
||||||
type ValueOf<T extends any[]> = T[number];
|
|
||||||
export const updateCameraPrefs = (
|
export const updateCameraPrefs = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entityId: string,
|
entityId: string,
|
||||||
prefs: {
|
prefs: {
|
||||||
preload_stream?: boolean;
|
preload_stream?: boolean;
|
||||||
orientation?: ValueOf<typeof CAMERA_ORIENTATIONS>;
|
|
||||||
}
|
}
|
||||||
) =>
|
) =>
|
||||||
hass.callWS<CameraPreferences>({
|
hass.callWS<CameraPreferences>({
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
|
|
||||||
export interface ConfigEntry {
|
export interface ConfigEntry {
|
||||||
@@ -45,29 +44,6 @@ export const RECOVERABLE_STATES: ConfigEntry["state"][] = [
|
|||||||
"setup_retry",
|
"setup_retry",
|
||||||
];
|
];
|
||||||
|
|
||||||
export interface ConfigEntryUpdate {
|
|
||||||
// null means no update as is the current state
|
|
||||||
type: null | "added" | "removed" | "updated";
|
|
||||||
entry: ConfigEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const subscribeConfigEntries = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
callbackFunction: (message: ConfigEntryUpdate[]) => void,
|
|
||||||
filters?: { type?: "helper" | "integration"; domain?: string }
|
|
||||||
): Promise<UnsubscribeFunc> => {
|
|
||||||
const params: any = {
|
|
||||||
type: "config_entries/subscribe",
|
|
||||||
};
|
|
||||||
if (filters && filters.type) {
|
|
||||||
params.type_filter = filters.type;
|
|
||||||
}
|
|
||||||
return hass.connection.subscribeMessage<ConfigEntryUpdate[]>(
|
|
||||||
(message) => callbackFunction(message),
|
|
||||||
params
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getConfigEntries = (
|
export const getConfigEntries = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
filters?: { type?: "helper" | "integration"; domain?: string }
|
filters?: { type?: "helper" | "integration"; domain?: string }
|
||||||
|
@@ -4,16 +4,46 @@ import {
|
|||||||
} from "home-assistant-js-websocket";
|
} from "home-assistant-js-websocket";
|
||||||
import { supportsFeature } from "../common/entity/supports-feature";
|
import { supportsFeature } from "../common/entity/supports-feature";
|
||||||
|
|
||||||
export const enum CoverEntityFeature {
|
export const SUPPORT_OPEN = 1;
|
||||||
OPEN = 1,
|
export const SUPPORT_CLOSE = 2;
|
||||||
CLOSE = 2,
|
export const SUPPORT_SET_POSITION = 4;
|
||||||
SET_POSITION = 4,
|
export const SUPPORT_STOP = 8;
|
||||||
STOP = 8,
|
export const SUPPORT_OPEN_TILT = 16;
|
||||||
OPEN_TILT = 16,
|
export const SUPPORT_CLOSE_TILT = 32;
|
||||||
CLOSE_TILT = 32,
|
export const SUPPORT_STOP_TILT = 64;
|
||||||
STOP_TILT = 64,
|
export const SUPPORT_SET_TILT_POSITION = 128;
|
||||||
SET_TILT_POSITION = 128,
|
|
||||||
}
|
export const FEATURE_CLASS_NAMES = {
|
||||||
|
4: "has-set_position",
|
||||||
|
16: "has-open_tilt",
|
||||||
|
32: "has-close_tilt",
|
||||||
|
64: "has-stop_tilt",
|
||||||
|
128: "has-set_tilt_position",
|
||||||
|
};
|
||||||
|
|
||||||
|
export const supportsOpen = (stateObj) =>
|
||||||
|
supportsFeature(stateObj, SUPPORT_OPEN);
|
||||||
|
|
||||||
|
export const supportsClose = (stateObj) =>
|
||||||
|
supportsFeature(stateObj, SUPPORT_CLOSE);
|
||||||
|
|
||||||
|
export const supportsSetPosition = (stateObj) =>
|
||||||
|
supportsFeature(stateObj, SUPPORT_SET_POSITION);
|
||||||
|
|
||||||
|
export const supportsStop = (stateObj) =>
|
||||||
|
supportsFeature(stateObj, SUPPORT_STOP);
|
||||||
|
|
||||||
|
export const supportsOpenTilt = (stateObj) =>
|
||||||
|
supportsFeature(stateObj, SUPPORT_OPEN_TILT);
|
||||||
|
|
||||||
|
export const supportsCloseTilt = (stateObj) =>
|
||||||
|
supportsFeature(stateObj, SUPPORT_CLOSE_TILT);
|
||||||
|
|
||||||
|
export const supportsStopTilt = (stateObj) =>
|
||||||
|
supportsFeature(stateObj, SUPPORT_STOP_TILT);
|
||||||
|
|
||||||
|
export const supportsSetTiltPosition = (stateObj) =>
|
||||||
|
supportsFeature(stateObj, SUPPORT_SET_TILT_POSITION);
|
||||||
|
|
||||||
export function isFullyOpen(stateObj: CoverEntity) {
|
export function isFullyOpen(stateObj: CoverEntity) {
|
||||||
if (stateObj.attributes.current_position !== undefined) {
|
if (stateObj.attributes.current_position !== undefined) {
|
||||||
@@ -47,19 +77,17 @@ export function isClosing(stateObj: CoverEntity) {
|
|||||||
|
|
||||||
export function isTiltOnly(stateObj: CoverEntity) {
|
export function isTiltOnly(stateObj: CoverEntity) {
|
||||||
const supportsCover =
|
const supportsCover =
|
||||||
supportsFeature(stateObj, CoverEntityFeature.OPEN) ||
|
supportsOpen(stateObj) || supportsClose(stateObj) || supportsStop(stateObj);
|
||||||
supportsFeature(stateObj, CoverEntityFeature.CLOSE) ||
|
|
||||||
supportsFeature(stateObj, CoverEntityFeature.STOP);
|
|
||||||
const supportsTilt =
|
const supportsTilt =
|
||||||
supportsFeature(stateObj, CoverEntityFeature.OPEN_TILT) ||
|
supportsOpenTilt(stateObj) ||
|
||||||
supportsFeature(stateObj, CoverEntityFeature.CLOSE_TILT) ||
|
supportsCloseTilt(stateObj) ||
|
||||||
supportsFeature(stateObj, CoverEntityFeature.STOP_TILT);
|
supportsStopTilt(stateObj);
|
||||||
return supportsTilt && !supportsCover;
|
return supportsTilt && !supportsCover;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CoverEntityAttributes extends HassEntityAttributeBase {
|
interface CoverEntityAttributes extends HassEntityAttributeBase {
|
||||||
current_position?: number;
|
current_position: number;
|
||||||
current_tilt_position?: number;
|
current_tilt_position: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CoverEntity extends HassEntityBase {
|
export interface CoverEntity extends HassEntityBase {
|
||||||
|
@@ -20,8 +20,7 @@ import {
|
|||||||
getStatisticMetadata,
|
getStatisticMetadata,
|
||||||
Statistics,
|
Statistics,
|
||||||
StatisticsMetaData,
|
StatisticsMetaData,
|
||||||
StatisticsUnitConfiguration,
|
} from "./history";
|
||||||
} from "./recorder";
|
|
||||||
|
|
||||||
const energyCollectionKeys: (string | undefined)[] = [];
|
const energyCollectionKeys: (string | undefined)[] = [];
|
||||||
|
|
||||||
@@ -29,6 +28,7 @@ export const emptyFlowFromGridSourceEnergyPreference =
|
|||||||
(): FlowFromGridSourceEnergyPreference => ({
|
(): FlowFromGridSourceEnergyPreference => ({
|
||||||
stat_energy_from: "",
|
stat_energy_from: "",
|
||||||
stat_cost: null,
|
stat_cost: null,
|
||||||
|
entity_energy_from: null,
|
||||||
entity_energy_price: null,
|
entity_energy_price: null,
|
||||||
number_energy_price: null,
|
number_energy_price: null,
|
||||||
});
|
});
|
||||||
@@ -37,6 +37,7 @@ export const emptyFlowToGridSourceEnergyPreference =
|
|||||||
(): FlowToGridSourceEnergyPreference => ({
|
(): FlowToGridSourceEnergyPreference => ({
|
||||||
stat_energy_to: "",
|
stat_energy_to: "",
|
||||||
stat_compensation: null,
|
stat_compensation: null,
|
||||||
|
entity_energy_to: null,
|
||||||
entity_energy_price: null,
|
entity_energy_price: null,
|
||||||
number_energy_price: null,
|
number_energy_price: null,
|
||||||
});
|
});
|
||||||
@@ -66,6 +67,7 @@ export const emptyGasEnergyPreference = (): GasSourceTypeEnergyPreference => ({
|
|||||||
type: "gas",
|
type: "gas",
|
||||||
stat_energy_from: "",
|
stat_energy_from: "",
|
||||||
stat_cost: null,
|
stat_cost: null,
|
||||||
|
entity_energy_from: null,
|
||||||
entity_energy_price: null,
|
entity_energy_price: null,
|
||||||
number_energy_price: null,
|
number_energy_price: null,
|
||||||
});
|
});
|
||||||
@@ -90,6 +92,7 @@ export interface FlowFromGridSourceEnergyPreference {
|
|||||||
stat_cost: string | null;
|
stat_cost: string | null;
|
||||||
|
|
||||||
// Can be used to generate costs if stat_cost omitted
|
// Can be used to generate costs if stat_cost omitted
|
||||||
|
entity_energy_from: string | null;
|
||||||
entity_energy_price: string | null;
|
entity_energy_price: string | null;
|
||||||
number_energy_price: number | null;
|
number_energy_price: number | null;
|
||||||
}
|
}
|
||||||
@@ -101,7 +104,8 @@ export interface FlowToGridSourceEnergyPreference {
|
|||||||
// $ meter
|
// $ meter
|
||||||
stat_compensation: string | null;
|
stat_compensation: string | null;
|
||||||
|
|
||||||
// Can be used to generate costs if stat_compensation omitted
|
// Can be used to generate costs if stat_cost omitted
|
||||||
|
entity_energy_to: string | null;
|
||||||
entity_energy_price: string | null;
|
entity_energy_price: string | null;
|
||||||
number_energy_price: number | null;
|
number_energy_price: number | null;
|
||||||
}
|
}
|
||||||
@@ -137,6 +141,7 @@ export interface GasSourceTypeEnergyPreference {
|
|||||||
stat_cost: string | null;
|
stat_cost: string | null;
|
||||||
|
|
||||||
// Can be used to generate costs if stat_cost omitted
|
// Can be used to generate costs if stat_cost omitted
|
||||||
|
entity_energy_from: string | null;
|
||||||
entity_energy_price: string | null;
|
entity_energy_price: string | null;
|
||||||
number_energy_price: number | null;
|
number_energy_price: number | null;
|
||||||
unit_of_measurement?: string | null;
|
unit_of_measurement?: string | null;
|
||||||
@@ -353,19 +358,12 @@ const getEnergyData = async (
|
|||||||
// Subtract 1 hour from start to get starting point data
|
// Subtract 1 hour from start to get starting point data
|
||||||
const startMinHour = addHours(start, -1);
|
const startMinHour = addHours(start, -1);
|
||||||
|
|
||||||
const lengthUnit = hass.config.unit_system.length || "";
|
|
||||||
const units: StatisticsUnitConfiguration = {
|
|
||||||
energy: "kWh",
|
|
||||||
volume: lengthUnit === "km" ? "m³" : "ft³",
|
|
||||||
};
|
|
||||||
|
|
||||||
const stats = await fetchStatistics(
|
const stats = await fetchStatistics(
|
||||||
hass!,
|
hass!,
|
||||||
startMinHour,
|
startMinHour,
|
||||||
end,
|
end,
|
||||||
statIDs,
|
statIDs,
|
||||||
period,
|
period
|
||||||
units
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let statsCompare;
|
let statsCompare;
|
||||||
@@ -387,8 +385,7 @@ const getEnergyData = async (
|
|||||||
compareStartMinHour,
|
compareStartMinHour,
|
||||||
endCompare,
|
endCompare,
|
||||||
statIDs,
|
statIDs,
|
||||||
period,
|
period
|
||||||
units
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -600,14 +597,20 @@ export const getEnergySolarForecasts = (hass: HomeAssistant) =>
|
|||||||
type: "energy/solar_forecast",
|
type: "energy/solar_forecast",
|
||||||
});
|
});
|
||||||
|
|
||||||
const energyGasUnitClass = ["volume", "energy"] as const;
|
export const ENERGY_GAS_VOLUME_UNITS = ["m³"];
|
||||||
export type EnergyGasUnitClass = typeof energyGasUnitClass[number];
|
export const ENERGY_GAS_ENERGY_UNITS = ["kWh"];
|
||||||
|
export const ENERGY_GAS_UNITS = [
|
||||||
|
...ENERGY_GAS_VOLUME_UNITS,
|
||||||
|
...ENERGY_GAS_ENERGY_UNITS,
|
||||||
|
];
|
||||||
|
|
||||||
export const getEnergyGasUnitClass = (
|
export type EnergyGasUnit = "volume" | "energy";
|
||||||
|
|
||||||
|
export const getEnergyGasUnitCategory = (
|
||||||
prefs: EnergyPreferences,
|
prefs: EnergyPreferences,
|
||||||
statisticsMetaData: Record<string, StatisticsMetaData> = {},
|
statisticsMetaData: Record<string, StatisticsMetaData> = {},
|
||||||
excludeSource?: string
|
excludeSource?: string
|
||||||
): EnergyGasUnitClass | undefined => {
|
): EnergyGasUnit | undefined => {
|
||||||
for (const source of prefs.energy_sources) {
|
for (const source of prefs.energy_sources) {
|
||||||
if (source.type !== "gas") {
|
if (source.type !== "gas") {
|
||||||
continue;
|
continue;
|
||||||
@@ -616,29 +619,29 @@ export const getEnergyGasUnitClass = (
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const statisticIdWithMeta = statisticsMetaData[source.stat_energy_from];
|
const statisticIdWithMeta = statisticsMetaData[source.stat_energy_from];
|
||||||
if (
|
if (statisticIdWithMeta) {
|
||||||
energyGasUnitClass.includes(
|
return ENERGY_GAS_VOLUME_UNITS.includes(
|
||||||
statisticIdWithMeta.unit_class as EnergyGasUnitClass
|
statisticIdWithMeta.display_unit_of_measurement
|
||||||
)
|
)
|
||||||
) {
|
? "volume"
|
||||||
return statisticIdWithMeta.unit_class as EnergyGasUnitClass;
|
: "energy";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getEnergyGasUnit = (
|
export const getEnergyGasUnit = (
|
||||||
hass: HomeAssistant,
|
|
||||||
prefs: EnergyPreferences,
|
prefs: EnergyPreferences,
|
||||||
statisticsMetaData: Record<string, StatisticsMetaData> = {}
|
statisticsMetaData: Record<string, StatisticsMetaData> = {}
|
||||||
): string | undefined => {
|
): string | undefined => {
|
||||||
const unitClass = getEnergyGasUnitClass(prefs, statisticsMetaData);
|
for (const source of prefs.energy_sources) {
|
||||||
if (unitClass === undefined) {
|
if (source.type !== "gas") {
|
||||||
return undefined;
|
continue;
|
||||||
|
}
|
||||||
|
const statisticIdWithMeta = statisticsMetaData[source.stat_energy_from];
|
||||||
|
if (statisticIdWithMeta?.display_unit_of_measurement) {
|
||||||
|
return statisticIdWithMeta.display_unit_of_measurement;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return unitClass === "energy"
|
return undefined;
|
||||||
? "kWh"
|
|
||||||
: hass.config.unit_system.length === "km"
|
|
||||||
? "m³"
|
|
||||||
: "ft³";
|
|
||||||
};
|
};
|
||||||
|
@@ -1,13 +1,11 @@
|
|||||||
import { Connection, createCollection } from "home-assistant-js-websocket";
|
import { Connection, createCollection } from "home-assistant-js-websocket";
|
||||||
import { Store } from "home-assistant-js-websocket/dist/store";
|
import { Store } from "home-assistant-js-websocket/dist/store";
|
||||||
import memoizeOne from "memoize-one";
|
|
||||||
import { computeStateName } from "../common/entity/compute_state_name";
|
import { computeStateName } from "../common/entity/compute_state_name";
|
||||||
import { caseInsensitiveStringCompare } from "../common/string/compare";
|
import { caseInsensitiveStringCompare } from "../common/string/compare";
|
||||||
import { debounce } from "../common/util/debounce";
|
import { debounce } from "../common/util/debounce";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
|
|
||||||
export interface EntityRegistryEntry {
|
export interface EntityRegistryEntry {
|
||||||
id: string;
|
|
||||||
entity_id: string;
|
entity_id: string;
|
||||||
name: string | null;
|
name: string | null;
|
||||||
icon: string | null;
|
icon: string | null;
|
||||||
@@ -20,10 +18,10 @@ export interface EntityRegistryEntry {
|
|||||||
entity_category: "config" | "diagnostic" | null;
|
entity_category: "config" | "diagnostic" | null;
|
||||||
has_entity_name: boolean;
|
has_entity_name: boolean;
|
||||||
original_name?: string;
|
original_name?: string;
|
||||||
unique_id: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ExtEntityRegistryEntry extends EntityRegistryEntry {
|
export interface ExtEntityRegistryEntry extends EntityRegistryEntry {
|
||||||
|
unique_id: string;
|
||||||
capabilities: Record<string, unknown>;
|
capabilities: Record<string, unknown>;
|
||||||
original_icon?: string;
|
original_icon?: string;
|
||||||
device_class?: string;
|
device_class?: string;
|
||||||
@@ -61,7 +59,7 @@ export interface EntityRegistryEntryUpdateParams {
|
|||||||
hidden_by: string | null;
|
hidden_by: string | null;
|
||||||
new_entity_id?: string;
|
new_entity_id?: string;
|
||||||
options_domain?: string;
|
options_domain?: string;
|
||||||
options?: SensorEntityOptions | NumberEntityOptions | WeatherEntityOptions;
|
options?: SensorEntityOptions | WeatherEntityOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const findBatteryEntity = (
|
export const findBatteryEntity = (
|
||||||
@@ -93,10 +91,7 @@ export const computeEntityRegistryName = (
|
|||||||
return entry.name;
|
return entry.name;
|
||||||
}
|
}
|
||||||
const state = hass.states[entry.entity_id];
|
const state = hass.states[entry.entity_id];
|
||||||
if (state) {
|
return state ? computeStateName(state) : entry.entity_id;
|
||||||
return computeStateName(state);
|
|
||||||
}
|
|
||||||
return entry.original_name ? entry.original_name : entry.entity_id;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getExtendedEntityRegistryEntry = (
|
export const getExtendedEntityRegistryEntry = (
|
||||||
@@ -166,16 +161,6 @@ export const sortEntityRegistryByName = (entries: EntityRegistryEntry[]) =>
|
|||||||
caseInsensitiveStringCompare(entry1.name || "", entry2.name || "")
|
caseInsensitiveStringCompare(entry1.name || "", entry2.name || "")
|
||||||
);
|
);
|
||||||
|
|
||||||
export const entityRegistryById = memoizeOne(
|
|
||||||
(entries: HomeAssistant["entities"]) => {
|
|
||||||
const entities: HomeAssistant["entities"] = {};
|
|
||||||
for (const entity of Object.values(entries)) {
|
|
||||||
entities[entity.id] = entity;
|
|
||||||
}
|
|
||||||
return entities;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const getEntityPlatformLookup = (
|
export const getEntityPlatformLookup = (
|
||||||
entities: EntityRegistryEntry[]
|
entities: EntityRegistryEntry[]
|
||||||
): Record<string, string> => {
|
): Record<string, string> => {
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
import { HassEntities, HassEntity } from "home-assistant-js-websocket";
|
import { HassEntities, HassEntity } from "home-assistant-js-websocket";
|
||||||
import { computeDomain } from "../common/entity/compute_domain";
|
import { computeDomain } from "../common/entity/compute_domain";
|
||||||
import { computeStateDisplayFromEntityAttributes } from "../common/entity/compute_state_display";
|
import { computeStateDisplayFromEntityAttributes } from "../common/entity/compute_state_display";
|
||||||
import { computeStateNameFromEntityAttributes } from "../common/entity/compute_state_name";
|
import {
|
||||||
|
computeStateName,
|
||||||
|
computeStateNameFromEntityAttributes,
|
||||||
|
} from "../common/entity/compute_state_name";
|
||||||
import { LocalizeFunc } from "../common/translations/localize";
|
import { LocalizeFunc } from "../common/translations/localize";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
import { FrontendLocaleData } from "./translation";
|
import { FrontendLocaleData } from "./translation";
|
||||||
@@ -60,6 +63,87 @@ export interface HistoryResult {
|
|||||||
timeline: TimelineEntity[];
|
timeline: TimelineEntity[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type StatisticType = "sum" | "min" | "max" | "mean";
|
||||||
|
|
||||||
|
export interface Statistics {
|
||||||
|
[statisticId: string]: StatisticValue[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StatisticValue {
|
||||||
|
statistic_id: string;
|
||||||
|
start: string;
|
||||||
|
end: string;
|
||||||
|
last_reset: string | null;
|
||||||
|
max: number | null;
|
||||||
|
mean: number | null;
|
||||||
|
min: number | null;
|
||||||
|
sum: number | null;
|
||||||
|
state: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StatisticsMetaData {
|
||||||
|
display_unit_of_measurement: string;
|
||||||
|
statistics_unit_of_measurement: string;
|
||||||
|
statistic_id: string;
|
||||||
|
source: string;
|
||||||
|
name?: string | null;
|
||||||
|
has_sum: boolean;
|
||||||
|
has_mean: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type StatisticsValidationResult =
|
||||||
|
| StatisticsValidationResultNoState
|
||||||
|
| StatisticsValidationResultEntityNotRecorded
|
||||||
|
| StatisticsValidationResultEntityNoLongerRecorded
|
||||||
|
| StatisticsValidationResultUnsupportedStateClass
|
||||||
|
| StatisticsValidationResultUnitsChanged
|
||||||
|
| StatisticsValidationResultUnsupportedUnitMetadata
|
||||||
|
| StatisticsValidationResultUnsupportedUnitState;
|
||||||
|
|
||||||
|
export interface StatisticsValidationResultNoState {
|
||||||
|
type: "no_state";
|
||||||
|
data: { statistic_id: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StatisticsValidationResultEntityNoLongerRecorded {
|
||||||
|
type: "entity_no_longer_recorded";
|
||||||
|
data: { statistic_id: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StatisticsValidationResultEntityNotRecorded {
|
||||||
|
type: "entity_not_recorded";
|
||||||
|
data: { statistic_id: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StatisticsValidationResultUnsupportedStateClass {
|
||||||
|
type: "unsupported_state_class";
|
||||||
|
data: { statistic_id: string; state_class: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StatisticsValidationResultUnitsChanged {
|
||||||
|
type: "units_changed";
|
||||||
|
data: { statistic_id: string; state_unit: string; metadata_unit: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StatisticsValidationResultUnsupportedUnitMetadata {
|
||||||
|
type: "unsupported_unit_metadata";
|
||||||
|
data: {
|
||||||
|
statistic_id: string;
|
||||||
|
device_class: string;
|
||||||
|
metadata_unit: string;
|
||||||
|
supported_unit: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StatisticsValidationResultUnsupportedUnitState {
|
||||||
|
type: "unsupported_unit_state";
|
||||||
|
data: { statistic_id: string; device_class: string; metadata_unit: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StatisticsValidationResults {
|
||||||
|
[statisticId: string]: StatisticsValidationResult[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface HistoryStates {
|
export interface HistoryStates {
|
||||||
[entityId: string]: EntityHistoryState[];
|
[entityId: string]: EntityHistoryState[];
|
||||||
}
|
}
|
||||||
@@ -365,3 +449,132 @@ export const computeHistory = (
|
|||||||
|
|
||||||
return { line: unitStates, timeline: timelineDevices };
|
return { line: unitStates, timeline: timelineDevices };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Statistics
|
||||||
|
|
||||||
|
export const getStatisticIds = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
statistic_type?: "mean" | "sum"
|
||||||
|
) =>
|
||||||
|
hass.callWS<StatisticsMetaData[]>({
|
||||||
|
type: "history/list_statistic_ids",
|
||||||
|
statistic_type,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const getStatisticMetadata = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
statistic_ids?: string[]
|
||||||
|
) =>
|
||||||
|
hass.callWS<StatisticsMetaData[]>({
|
||||||
|
type: "recorder/get_statistics_metadata",
|
||||||
|
statistic_ids,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const fetchStatistics = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
startTime: Date,
|
||||||
|
endTime?: Date,
|
||||||
|
statistic_ids?: string[],
|
||||||
|
period: "5minute" | "hour" | "day" | "month" = "hour"
|
||||||
|
) =>
|
||||||
|
hass.callWS<Statistics>({
|
||||||
|
type: "history/statistics_during_period",
|
||||||
|
start_time: startTime.toISOString(),
|
||||||
|
end_time: endTime?.toISOString(),
|
||||||
|
statistic_ids,
|
||||||
|
period,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const validateStatistics = (hass: HomeAssistant) =>
|
||||||
|
hass.callWS<StatisticsValidationResults>({
|
||||||
|
type: "recorder/validate_statistics",
|
||||||
|
});
|
||||||
|
|
||||||
|
export const updateStatisticsMetadata = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
statistic_id: string,
|
||||||
|
unit_of_measurement: string | null
|
||||||
|
) =>
|
||||||
|
hass.callWS<void>({
|
||||||
|
type: "recorder/update_statistics_metadata",
|
||||||
|
statistic_id,
|
||||||
|
unit_of_measurement,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const clearStatistics = (hass: HomeAssistant, statistic_ids: string[]) =>
|
||||||
|
hass.callWS<void>({
|
||||||
|
type: "recorder/clear_statistics",
|
||||||
|
statistic_ids,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const calculateStatisticSumGrowth = (
|
||||||
|
values: StatisticValue[]
|
||||||
|
): number | null => {
|
||||||
|
if (!values || values.length < 2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const endSum = values[values.length - 1].sum;
|
||||||
|
if (endSum === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const startSum = values[0].sum;
|
||||||
|
if (startSum === null) {
|
||||||
|
return endSum;
|
||||||
|
}
|
||||||
|
return endSum - startSum;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const calculateStatisticsSumGrowth = (
|
||||||
|
data: Statistics,
|
||||||
|
stats: string[]
|
||||||
|
): number | null => {
|
||||||
|
let totalGrowth: number | null = null;
|
||||||
|
|
||||||
|
for (const stat of stats) {
|
||||||
|
if (!(stat in data)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const statGrowth = calculateStatisticSumGrowth(data[stat]);
|
||||||
|
|
||||||
|
if (statGrowth === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (totalGrowth === null) {
|
||||||
|
totalGrowth = statGrowth;
|
||||||
|
} else {
|
||||||
|
totalGrowth += statGrowth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalGrowth;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const statisticsHaveType = (
|
||||||
|
stats: StatisticValue[],
|
||||||
|
type: StatisticType
|
||||||
|
) => stats.some((stat) => stat[type] !== null);
|
||||||
|
|
||||||
|
export const adjustStatisticsSum = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
statistic_id: string,
|
||||||
|
start_time: string,
|
||||||
|
adjustment: number
|
||||||
|
): Promise<void> =>
|
||||||
|
hass.callWS({
|
||||||
|
type: "recorder/adjust_sum_statistics",
|
||||||
|
statistic_id,
|
||||||
|
start_time,
|
||||||
|
adjustment,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const getStatisticLabel = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
statisticsId: string,
|
||||||
|
statisticsMetaData: StatisticsMetaData | undefined
|
||||||
|
): string => {
|
||||||
|
const entity = hass.states[statisticsId];
|
||||||
|
if (entity) {
|
||||||
|
return computeStateName(entity);
|
||||||
|
}
|
||||||
|
return statisticsMetaData?.name || statisticsId;
|
||||||
|
};
|
||||||
|
@@ -1,37 +0,0 @@
|
|||||||
import { HomeAssistant } from "../types";
|
|
||||||
|
|
||||||
export type IotStandards = "zwave" | "zigbee" | "homekit" | "matter";
|
|
||||||
|
|
||||||
export interface Integration {
|
|
||||||
name?: string;
|
|
||||||
config_flow?: boolean;
|
|
||||||
integrations?: Integrations;
|
|
||||||
iot_standards?: IotStandards[];
|
|
||||||
is_built_in?: boolean;
|
|
||||||
iot_class?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Integrations {
|
|
||||||
[domain: string]: Integration;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IntegrationDescriptions {
|
|
||||||
core: {
|
|
||||||
integration: Integrations;
|
|
||||||
hardware: Integrations;
|
|
||||||
helper: Integrations;
|
|
||||||
translated_name: string[];
|
|
||||||
};
|
|
||||||
custom: {
|
|
||||||
integration: Integrations;
|
|
||||||
hardware: Integrations;
|
|
||||||
helper: Integrations;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getIntegrationDescriptions = (
|
|
||||||
hass: HomeAssistant
|
|
||||||
): Promise<IntegrationDescriptions> =>
|
|
||||||
hass.callWS<IntegrationDescriptions>({
|
|
||||||
type: "integration/descriptions",
|
|
||||||
});
|
|
@@ -3,83 +3,76 @@ import {
|
|||||||
HassEntityBase,
|
HassEntityBase,
|
||||||
} from "home-assistant-js-websocket";
|
} from "home-assistant-js-websocket";
|
||||||
|
|
||||||
export const enum LightEntityFeature {
|
export const enum LightColorModes {
|
||||||
EFFECT = 4,
|
|
||||||
FLASH = 8,
|
|
||||||
TRANSITION = 32,
|
|
||||||
}
|
|
||||||
|
|
||||||
export const enum LightColorMode {
|
|
||||||
UNKNOWN = "unknown",
|
UNKNOWN = "unknown",
|
||||||
ONOFF = "onoff",
|
ONOFF = "onoff",
|
||||||
BRIGHTNESS = "brightness",
|
BRIGHTNESS = "brightness",
|
||||||
COLOR_TEMP = "color_temp",
|
COLOR_TEMP = "color_temp",
|
||||||
|
WHITE = "white",
|
||||||
HS = "hs",
|
HS = "hs",
|
||||||
XY = "xy",
|
XY = "xy",
|
||||||
RGB = "rgb",
|
RGB = "rgb",
|
||||||
RGBW = "rgbw",
|
RGBW = "rgbw",
|
||||||
RGBWW = "rgbww",
|
RGBWW = "rgbww",
|
||||||
WHITE = "white",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const modesSupportingColor = [
|
const modesSupportingColor = [
|
||||||
LightColorMode.HS,
|
LightColorModes.HS,
|
||||||
LightColorMode.XY,
|
LightColorModes.XY,
|
||||||
LightColorMode.RGB,
|
LightColorModes.RGB,
|
||||||
LightColorMode.RGBW,
|
LightColorModes.RGBW,
|
||||||
LightColorMode.RGBWW,
|
LightColorModes.RGBWW,
|
||||||
];
|
];
|
||||||
|
|
||||||
const modesSupportingBrightness = [
|
const modesSupportingDimming = [
|
||||||
...modesSupportingColor,
|
...modesSupportingColor,
|
||||||
LightColorMode.COLOR_TEMP,
|
LightColorModes.COLOR_TEMP,
|
||||||
LightColorMode.BRIGHTNESS,
|
LightColorModes.BRIGHTNESS,
|
||||||
LightColorMode.WHITE,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const SUPPORT_EFFECT = 4;
|
||||||
|
export const SUPPORT_FLASH = 8;
|
||||||
|
export const SUPPORT_TRANSITION = 32;
|
||||||
|
|
||||||
export const lightSupportsColorMode = (
|
export const lightSupportsColorMode = (
|
||||||
entity: LightEntity,
|
entity: LightEntity,
|
||||||
mode: LightColorMode
|
mode: LightColorModes
|
||||||
) => entity.attributes.supported_color_modes?.includes(mode) || false;
|
) => entity.attributes.supported_color_modes?.includes(mode);
|
||||||
|
|
||||||
export const lightIsInColorMode = (entity: LightEntity) =>
|
export const lightIsInColorMode = (entity: LightEntity) =>
|
||||||
(entity.attributes.color_mode &&
|
modesSupportingColor.includes(entity.attributes.color_mode);
|
||||||
modesSupportingColor.includes(entity.attributes.color_mode)) ||
|
|
||||||
false;
|
|
||||||
|
|
||||||
export const lightSupportsColor = (entity: LightEntity) =>
|
export const lightSupportsColor = (entity: LightEntity) =>
|
||||||
entity.attributes.supported_color_modes?.some((mode) =>
|
entity.attributes.supported_color_modes?.some((mode) =>
|
||||||
modesSupportingColor.includes(mode)
|
modesSupportingColor.includes(mode)
|
||||||
);
|
);
|
||||||
|
|
||||||
export const lightSupportsBrightness = (entity: LightEntity) =>
|
export const lightSupportsDimming = (entity: LightEntity) =>
|
||||||
entity.attributes.supported_color_modes?.some((mode) =>
|
entity.attributes.supported_color_modes?.some((mode) =>
|
||||||
modesSupportingBrightness.includes(mode)
|
modesSupportingDimming.includes(mode)
|
||||||
) || false;
|
);
|
||||||
|
|
||||||
export const getLightCurrentModeRgbColor = (
|
export const getLightCurrentModeRgbColor = (entity: LightEntity): number[] =>
|
||||||
entity: LightEntity
|
entity.attributes.color_mode === LightColorModes.RGBWW
|
||||||
): number[] | undefined =>
|
|
||||||
entity.attributes.color_mode === LightColorMode.RGBWW
|
|
||||||
? entity.attributes.rgbww_color
|
? entity.attributes.rgbww_color
|
||||||
: entity.attributes.color_mode === LightColorMode.RGBW
|
: entity.attributes.color_mode === LightColorModes.RGBW
|
||||||
? entity.attributes.rgbw_color
|
? entity.attributes.rgbw_color
|
||||||
: entity.attributes.rgb_color;
|
: entity.attributes.rgb_color;
|
||||||
|
|
||||||
interface LightEntityAttributes extends HassEntityAttributeBase {
|
interface LightEntityAttributes extends HassEntityAttributeBase {
|
||||||
min_mireds?: number;
|
min_mireds: number;
|
||||||
max_mireds?: number;
|
max_mireds: number;
|
||||||
brightness?: number;
|
friendly_name: string;
|
||||||
xy_color?: [number, number];
|
brightness: number;
|
||||||
hs_color?: [number, number];
|
hs_color: [number, number];
|
||||||
color_temp?: number;
|
rgb_color: [number, number, number];
|
||||||
rgb_color?: [number, number, number];
|
rgbw_color: [number, number, number, number];
|
||||||
rgbw_color?: [number, number, number, number];
|
rgbww_color: [number, number, number, number, number];
|
||||||
rgbww_color?: [number, number, number, number, number];
|
color_temp: number;
|
||||||
effect?: string;
|
effect?: string;
|
||||||
effect_list?: string[] | null;
|
effect_list: string[] | null;
|
||||||
supported_color_modes?: LightColorMode[];
|
supported_color_modes: LightColorModes[];
|
||||||
color_mode?: LightColorMode;
|
color_mode: LightColorModes;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LightEntity extends HassEntityBase {
|
export interface LightEntity extends HassEntityBase {
|
||||||
|
@@ -93,8 +93,6 @@ export interface LovelaceViewConfig {
|
|||||||
panel?: boolean;
|
panel?: boolean;
|
||||||
background?: string;
|
background?: string;
|
||||||
visible?: boolean | ShowViewConfig[];
|
visible?: boolean | ShowViewConfig[];
|
||||||
subview?: boolean;
|
|
||||||
back_path?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LovelaceViewElement extends HTMLElement {
|
export interface LovelaceViewElement extends HTMLElement {
|
||||||
|
@@ -51,7 +51,6 @@ interface MediaPlayerEntityAttributes extends HassEntityAttributeBase {
|
|||||||
media_duration?: number;
|
media_duration?: number;
|
||||||
media_position?: number;
|
media_position?: number;
|
||||||
media_title?: string;
|
media_title?: string;
|
||||||
media_channel?: string;
|
|
||||||
icon?: string;
|
icon?: string;
|
||||||
entity_picture_local?: string;
|
entity_picture_local?: string;
|
||||||
is_volume_muted?: boolean;
|
is_volume_muted?: boolean;
|
||||||
@@ -236,9 +235,6 @@ export const computeMediaDescription = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "channel":
|
|
||||||
secondaryTitle = stateObj.attributes.media_channel!;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
secondaryTitle = stateObj.attributes.app_name || "";
|
secondaryTitle = stateObj.attributes.app_name || "";
|
||||||
}
|
}
|
||||||
|
@@ -1,291 +0,0 @@
|
|||||||
import { computeStateName } from "../common/entity/compute_state_name";
|
|
||||||
import { HomeAssistant } from "../types";
|
|
||||||
|
|
||||||
export type StatisticType = "state" | "sum" | "min" | "max" | "mean";
|
|
||||||
|
|
||||||
export interface Statistics {
|
|
||||||
[statisticId: string]: StatisticValue[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StatisticValue {
|
|
||||||
statistic_id: string;
|
|
||||||
start: string;
|
|
||||||
end: string;
|
|
||||||
last_reset: string | null;
|
|
||||||
max: number | null;
|
|
||||||
mean: number | null;
|
|
||||||
min: number | null;
|
|
||||||
sum: number | null;
|
|
||||||
state: number | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StatisticsMetaData {
|
|
||||||
statistics_unit_of_measurement: string | null;
|
|
||||||
statistic_id: string;
|
|
||||||
source: string;
|
|
||||||
name?: string | null;
|
|
||||||
has_sum: boolean;
|
|
||||||
has_mean: boolean;
|
|
||||||
unit_class: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type StatisticsValidationResult =
|
|
||||||
| StatisticsValidationResultNoState
|
|
||||||
| StatisticsValidationResultEntityNotRecorded
|
|
||||||
| StatisticsValidationResultEntityNoLongerRecorded
|
|
||||||
| StatisticsValidationResultUnsupportedStateClass
|
|
||||||
| StatisticsValidationResultUnitsChanged
|
|
||||||
| StatisticsValidationResultUnitsChangedCanConvert
|
|
||||||
| StatisticsValidationResultUnsupportedUnitMetadata
|
|
||||||
| StatisticsValidationResultUnsupportedUnitMetadataCanConvert
|
|
||||||
| StatisticsValidationResultUnsupportedUnitState;
|
|
||||||
|
|
||||||
export interface StatisticsValidationResultNoState {
|
|
||||||
type: "no_state";
|
|
||||||
data: { statistic_id: string };
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StatisticsValidationResultEntityNoLongerRecorded {
|
|
||||||
type: "entity_no_longer_recorded";
|
|
||||||
data: { statistic_id: string };
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StatisticsValidationResultEntityNotRecorded {
|
|
||||||
type: "entity_not_recorded";
|
|
||||||
data: { statistic_id: string };
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StatisticsValidationResultUnsupportedStateClass {
|
|
||||||
type: "unsupported_state_class";
|
|
||||||
data: { statistic_id: string; state_class: string };
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StatisticsValidationResultUnitsChanged {
|
|
||||||
type: "units_changed";
|
|
||||||
data: { statistic_id: string; state_unit: string; metadata_unit: string };
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StatisticsValidationResultUnitsChangedCanConvert {
|
|
||||||
type: "units_changed_can_convert";
|
|
||||||
data: { statistic_id: string; state_unit: string; metadata_unit: string };
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StatisticsValidationResultUnsupportedUnitMetadata {
|
|
||||||
type: "unsupported_unit_metadata";
|
|
||||||
data: {
|
|
||||||
statistic_id: string;
|
|
||||||
device_class: string;
|
|
||||||
metadata_unit: string;
|
|
||||||
supported_unit: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StatisticsValidationResultUnsupportedUnitMetadataCanConvert {
|
|
||||||
type: "unsupported_unit_metadata_can_convert";
|
|
||||||
data: {
|
|
||||||
statistic_id: string;
|
|
||||||
device_class: string;
|
|
||||||
metadata_unit: string;
|
|
||||||
supported_unit: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StatisticsUnitConfiguration {
|
|
||||||
energy?: "Wh" | "kWh" | "MWh";
|
|
||||||
power?: "W" | "kW";
|
|
||||||
pressure?:
|
|
||||||
| "Pa"
|
|
||||||
| "hPa"
|
|
||||||
| "kPa"
|
|
||||||
| "bar"
|
|
||||||
| "cbar"
|
|
||||||
| "mbar"
|
|
||||||
| "inHg"
|
|
||||||
| "psi"
|
|
||||||
| "mmHg";
|
|
||||||
temperature?: "°C" | "°F" | "K";
|
|
||||||
volume?: "ft³" | "m³";
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StatisticsValidationResultUnsupportedUnitState {
|
|
||||||
type: "unsupported_unit_state";
|
|
||||||
data: { statistic_id: string; device_class: string; metadata_unit: string };
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StatisticsValidationResults {
|
|
||||||
[statisticId: string]: StatisticsValidationResult[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getStatisticIds = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
statistic_type?: "mean" | "sum"
|
|
||||||
) =>
|
|
||||||
hass.callWS<StatisticsMetaData[]>({
|
|
||||||
type: "recorder/list_statistic_ids",
|
|
||||||
statistic_type,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getStatisticMetadata = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
statistic_ids?: string[]
|
|
||||||
) =>
|
|
||||||
hass.callWS<StatisticsMetaData[]>({
|
|
||||||
type: "recorder/get_statistics_metadata",
|
|
||||||
statistic_ids,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const fetchStatistics = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
startTime: Date,
|
|
||||||
endTime?: Date,
|
|
||||||
statistic_ids?: string[],
|
|
||||||
period: "5minute" | "hour" | "day" | "month" = "hour",
|
|
||||||
units?: StatisticsUnitConfiguration
|
|
||||||
) =>
|
|
||||||
hass.callWS<Statistics>({
|
|
||||||
type: "recorder/statistics_during_period",
|
|
||||||
start_time: startTime.toISOString(),
|
|
||||||
end_time: endTime?.toISOString(),
|
|
||||||
statistic_ids,
|
|
||||||
period,
|
|
||||||
units,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const validateStatistics = (hass: HomeAssistant) =>
|
|
||||||
hass.callWS<StatisticsValidationResults>({
|
|
||||||
type: "recorder/validate_statistics",
|
|
||||||
});
|
|
||||||
|
|
||||||
export const updateStatisticsMetadata = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
statistic_id: string,
|
|
||||||
unit_of_measurement: string | null
|
|
||||||
) =>
|
|
||||||
hass.callWS<void>({
|
|
||||||
type: "recorder/update_statistics_metadata",
|
|
||||||
statistic_id,
|
|
||||||
unit_of_measurement,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const changeStatisticUnit = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
statistic_id: string,
|
|
||||||
old_unit_of_measurement: string | null,
|
|
||||||
new_unit_of_measurement: string | null
|
|
||||||
) =>
|
|
||||||
hass.callWS<void>({
|
|
||||||
type: "recorder/change_statistics_unit",
|
|
||||||
statistic_id,
|
|
||||||
old_unit_of_measurement,
|
|
||||||
new_unit_of_measurement,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const clearStatistics = (hass: HomeAssistant, statistic_ids: string[]) =>
|
|
||||||
hass.callWS<void>({
|
|
||||||
type: "recorder/clear_statistics",
|
|
||||||
statistic_ids,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const calculateStatisticSumGrowth = (
|
|
||||||
values: StatisticValue[]
|
|
||||||
): number | null => {
|
|
||||||
if (!values || values.length < 2) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const endSum = values[values.length - 1].sum;
|
|
||||||
if (endSum === null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const startSum = values[0].sum;
|
|
||||||
if (startSum === null) {
|
|
||||||
return endSum;
|
|
||||||
}
|
|
||||||
return endSum - startSum;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const calculateStatisticsSumGrowth = (
|
|
||||||
data: Statistics,
|
|
||||||
stats: string[]
|
|
||||||
): number | null => {
|
|
||||||
let totalGrowth: number | null = null;
|
|
||||||
|
|
||||||
for (const stat of stats) {
|
|
||||||
if (!(stat in data)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const statGrowth = calculateStatisticSumGrowth(data[stat]);
|
|
||||||
|
|
||||||
if (statGrowth === null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (totalGrowth === null) {
|
|
||||||
totalGrowth = statGrowth;
|
|
||||||
} else {
|
|
||||||
totalGrowth += statGrowth;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return totalGrowth;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const statisticsHaveType = (
|
|
||||||
stats: StatisticValue[],
|
|
||||||
type: StatisticType
|
|
||||||
) => stats.some((stat) => stat[type] !== null);
|
|
||||||
|
|
||||||
const mean_stat_types: readonly StatisticType[] = ["mean", "min", "max"];
|
|
||||||
const sum_stat_types: readonly StatisticType[] = ["sum"];
|
|
||||||
|
|
||||||
export const statisticsMetaHasType = (
|
|
||||||
metadata: StatisticsMetaData,
|
|
||||||
type: StatisticType
|
|
||||||
) => {
|
|
||||||
if (mean_stat_types.includes(type) && metadata.has_mean) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (sum_stat_types.includes(type) && metadata.has_sum) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const adjustStatisticsSum = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
statistic_id: string,
|
|
||||||
start_time: string,
|
|
||||||
adjustment: number,
|
|
||||||
adjustment_unit_of_measurement: string | null
|
|
||||||
): Promise<void> =>
|
|
||||||
hass.callWS({
|
|
||||||
type: "recorder/adjust_sum_statistics",
|
|
||||||
statistic_id,
|
|
||||||
start_time,
|
|
||||||
adjustment,
|
|
||||||
adjustment_unit_of_measurement,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getStatisticLabel = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
statisticsId: string,
|
|
||||||
statisticsMetaData: StatisticsMetaData | undefined
|
|
||||||
): string => {
|
|
||||||
const entity = hass.states[statisticsId];
|
|
||||||
if (entity) {
|
|
||||||
return computeStateName(entity);
|
|
||||||
}
|
|
||||||
return statisticsMetaData?.name || statisticsId;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getDisplayUnit = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
statisticsId: string | undefined,
|
|
||||||
statisticsMetaData: StatisticsMetaData | undefined
|
|
||||||
): string | null | undefined => {
|
|
||||||
let unit: string | undefined;
|
|
||||||
if (statisticsId) {
|
|
||||||
unit = hass.states[statisticsId]?.attributes.unit_of_measurement;
|
|
||||||
}
|
|
||||||
return unit === undefined
|
|
||||||
? statisticsMetaData?.statistics_unit_of_measurement
|
|
||||||
: unit;
|
|
||||||
};
|
|
@@ -14,11 +14,8 @@ export const SCENE_IGNORED_DOMAINS = [
|
|||||||
"input_button",
|
"input_button",
|
||||||
"persistent_notification",
|
"persistent_notification",
|
||||||
"person",
|
"person",
|
||||||
"scene",
|
|
||||||
"schedule",
|
|
||||||
"sensor",
|
"sensor",
|
||||||
"sun",
|
"sun",
|
||||||
"update",
|
|
||||||
"weather",
|
"weather",
|
||||||
"zone",
|
"zone",
|
||||||
];
|
];
|
||||||
|
@@ -15,6 +15,7 @@ import {
|
|||||||
Describe,
|
Describe,
|
||||||
boolean,
|
boolean,
|
||||||
} from "superstruct";
|
} from "superstruct";
|
||||||
|
import { computeObjectId } from "../common/entity/compute_object_id";
|
||||||
import { navigate } from "../common/navigate";
|
import { navigate } from "../common/navigate";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
import {
|
import {
|
||||||
@@ -277,9 +278,9 @@ export type ActionType = keyof ActionTypes;
|
|||||||
|
|
||||||
export const triggerScript = (
|
export const triggerScript = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
scriptId: string,
|
entityId: string,
|
||||||
variables?: Record<string, unknown>
|
variables?: Record<string, unknown>
|
||||||
) => hass.callService("script", scriptId, variables);
|
) => hass.callService("script", computeObjectId(entityId), variables);
|
||||||
|
|
||||||
export const canRun = (state: ScriptEntity) => {
|
export const canRun = (state: ScriptEntity) => {
|
||||||
if (state.state === "off") {
|
if (state.state === "off") {
|
||||||
@@ -300,15 +301,6 @@ export const deleteScript = (hass: HomeAssistant, objectId: string) =>
|
|||||||
|
|
||||||
let inititialScriptEditorData: Partial<ScriptConfig> | undefined;
|
let inititialScriptEditorData: Partial<ScriptConfig> | undefined;
|
||||||
|
|
||||||
export const fetchScriptFileConfig = (hass: HomeAssistant, objectId: string) =>
|
|
||||||
hass.callApi<ScriptConfig>("GET", `config/script/config/${objectId}`);
|
|
||||||
|
|
||||||
export const getScriptStateConfig = (hass: HomeAssistant, entity_id: string) =>
|
|
||||||
hass.callWS<{ config: ScriptConfig }>({
|
|
||||||
type: "script/config",
|
|
||||||
entity_id,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const showScriptEditor = (data?: Partial<ScriptConfig>) => {
|
export const showScriptEditor = (data?: Partial<ScriptConfig>) => {
|
||||||
inititialScriptEditorData = data;
|
inititialScriptEditorData = data;
|
||||||
navigate("/config/script/edit/new");
|
navigate("/config/script/edit/new");
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
import { formatDuration } from "../common/datetime/format_duration";
|
|
||||||
import secondsToDuration from "../common/datetime/seconds_to_duration";
|
import secondsToDuration from "../common/datetime/seconds_to_duration";
|
||||||
import { ensureArray } from "../common/ensure-array";
|
import { ensureArray } from "../common/ensure-array";
|
||||||
import { computeStateName } from "../common/entity/compute_state_name";
|
import { computeStateName } from "../common/entity/compute_state_name";
|
||||||
@@ -6,13 +5,6 @@ import { isTemplate } from "../common/string/has-template";
|
|||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
import { Condition } from "./automation";
|
import { Condition } from "./automation";
|
||||||
import { describeCondition, describeTrigger } from "./automation_i18n";
|
import { describeCondition, describeTrigger } from "./automation_i18n";
|
||||||
import { localizeDeviceAutomationAction } from "./device_automation";
|
|
||||||
import { computeDeviceName } from "./device_registry";
|
|
||||||
import {
|
|
||||||
computeEntityRegistryName,
|
|
||||||
entityRegistryById,
|
|
||||||
} from "./entity_registry";
|
|
||||||
import { domainToName } from "./integration";
|
|
||||||
import {
|
import {
|
||||||
ActionType,
|
ActionType,
|
||||||
ActionTypes,
|
ActionTypes,
|
||||||
@@ -55,13 +47,9 @@ export const describeAction = <T extends ActionType>(
|
|||||||
) {
|
) {
|
||||||
base = "Call a service based on a template";
|
base = "Call a service based on a template";
|
||||||
} else if (config.service) {
|
} else if (config.service) {
|
||||||
const [domain, serviceName] = config.service.split(".", 2);
|
base = `Call service ${config.service}`;
|
||||||
const service = hass.services[domain][serviceName];
|
|
||||||
base = service
|
|
||||||
? `${domainToName(hass.localize, domain)}: ${service.name}`
|
|
||||||
: `Call service: ${config.service}`;
|
|
||||||
} else {
|
} else {
|
||||||
return "Call a service";
|
return actionType;
|
||||||
}
|
}
|
||||||
if (config.target) {
|
if (config.target) {
|
||||||
const targets: string[] = [];
|
const targets: string[] = [];
|
||||||
@@ -78,49 +66,26 @@ export const describeAction = <T extends ActionType>(
|
|||||||
? config.target[key]
|
? config.target[key]
|
||||||
: [config.target[key]];
|
: [config.target[key]];
|
||||||
|
|
||||||
|
const values: string[] = [];
|
||||||
|
|
||||||
|
let renderValues = true;
|
||||||
|
|
||||||
for (const targetThing of keyConf) {
|
for (const targetThing of keyConf) {
|
||||||
if (isTemplate(targetThing)) {
|
if (isTemplate(targetThing)) {
|
||||||
targets.push(`templated ${label}`);
|
targets.push(`templated ${label}`);
|
||||||
|
renderValues = false;
|
||||||
break;
|
break;
|
||||||
} else if (key === "entity_id") {
|
|
||||||
if (targetThing.includes(".")) {
|
|
||||||
const state = hass.states[targetThing];
|
|
||||||
if (state) {
|
|
||||||
targets.push(computeStateName(state));
|
|
||||||
} else {
|
|
||||||
targets.push(targetThing);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const entityReg = entityRegistryById(hass.entities)[targetThing];
|
|
||||||
if (entityReg) {
|
|
||||||
targets.push(
|
|
||||||
computeEntityRegistryName(hass, entityReg) || targetThing
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
targets.push("unknown entity");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (key === "device_id") {
|
|
||||||
const device = hass.devices[targetThing];
|
|
||||||
if (device) {
|
|
||||||
targets.push(computeDeviceName(device, hass));
|
|
||||||
} else {
|
|
||||||
targets.push("unknown device");
|
|
||||||
}
|
|
||||||
} else if (key === "area_id") {
|
|
||||||
const area = hass.areas[targetThing];
|
|
||||||
if (area?.name) {
|
|
||||||
targets.push(area.name);
|
|
||||||
} else {
|
|
||||||
targets.push("unknown area");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
targets.push(targetThing);
|
values.push(targetThing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (renderValues) {
|
||||||
|
targets.push(`${label} ${values.join(", ")}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (targets.length > 0) {
|
if (targets.length > 0) {
|
||||||
base += ` ${targets.join(", ")}`;
|
base += ` on ${targets.join(", ")}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,11 +102,9 @@ export const describeAction = <T extends ActionType>(
|
|||||||
} else if (typeof config.delay === "string") {
|
} else if (typeof config.delay === "string") {
|
||||||
duration = isTemplate(config.delay)
|
duration = isTemplate(config.delay)
|
||||||
? "based on a template"
|
? "based on a template"
|
||||||
: `for ${config.delay || "a duration"}`;
|
: `for ${config.delay}`;
|
||||||
} else if (config.delay) {
|
|
||||||
duration = `for ${formatDuration(config.delay)}`;
|
|
||||||
} else {
|
} else {
|
||||||
duration = "for a duration";
|
duration = `for ${JSON.stringify(config.delay)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `Delay ${duration}`;
|
return `Delay ${duration}`;
|
||||||
@@ -155,12 +118,13 @@ export const describeAction = <T extends ActionType>(
|
|||||||
} else {
|
} else {
|
||||||
entityId = config.target?.entity_id || config.entity_id;
|
entityId = config.target?.entity_id || config.entity_id;
|
||||||
}
|
}
|
||||||
if (!entityId) {
|
|
||||||
return "Activate a scene";
|
|
||||||
}
|
|
||||||
const sceneStateObj = entityId ? hass.states[entityId] : undefined;
|
const sceneStateObj = entityId ? hass.states[entityId] : undefined;
|
||||||
return `Active scene ${
|
return `Scene ${
|
||||||
sceneStateObj ? computeStateName(sceneStateObj) : entityId
|
sceneStateObj
|
||||||
|
? computeStateName(sceneStateObj)
|
||||||
|
: "scene" in config
|
||||||
|
? config.scene
|
||||||
|
: config.target?.entity_id || config.entity_id || ""
|
||||||
}`;
|
}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,22 +132,16 @@ export const describeAction = <T extends ActionType>(
|
|||||||
const config = action as PlayMediaAction;
|
const config = action as PlayMediaAction;
|
||||||
const entityId = config.target?.entity_id || config.entity_id;
|
const entityId = config.target?.entity_id || config.entity_id;
|
||||||
const mediaStateObj = entityId ? hass.states[entityId] : undefined;
|
const mediaStateObj = entityId ? hass.states[entityId] : undefined;
|
||||||
return `Play ${
|
return `Play ${config.metadata.title || config.data.media_content_id} on ${
|
||||||
config.metadata.title || config.data.media_content_id || "media"
|
|
||||||
} on ${
|
|
||||||
mediaStateObj
|
mediaStateObj
|
||||||
? computeStateName(mediaStateObj)
|
? computeStateName(mediaStateObj)
|
||||||
: entityId || "a media player"
|
: config.target?.entity_id || config.entity_id
|
||||||
}`;
|
}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionType === "wait_for_trigger") {
|
if (actionType === "wait_for_trigger") {
|
||||||
const config = action as WaitForTriggerAction;
|
const config = action as WaitForTriggerAction;
|
||||||
const triggers = ensureArray(config.wait_for_trigger);
|
return `Wait for ${ensureArray(config.wait_for_trigger)
|
||||||
if (!triggers || triggers.length === 0) {
|
|
||||||
return "Wait for a trigger";
|
|
||||||
}
|
|
||||||
return `Wait for ${triggers
|
|
||||||
.map((trigger) => describeTrigger(trigger, hass))
|
.map((trigger) => describeTrigger(trigger, hass))
|
||||||
.join(", ")}`;
|
.join(", ")}`;
|
||||||
}
|
}
|
||||||
@@ -206,26 +164,22 @@ export const describeAction = <T extends ActionType>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (actionType === "check_condition") {
|
if (actionType === "check_condition") {
|
||||||
return describeCondition(action as Condition, hass);
|
return `Test ${describeCondition(action as Condition, hass)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionType === "stop") {
|
if (actionType === "stop") {
|
||||||
const config = action as StopAction;
|
const config = action as StopAction;
|
||||||
return `Stop${config.stop ? ` because: ${config.stop}` : ""}`;
|
return `Stopped${config.stop ? ` because: ${config.stop}` : ""}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionType === "if") {
|
if (actionType === "if") {
|
||||||
const config = action as IfAction;
|
const config = action as IfAction;
|
||||||
return `Perform an action if: ${
|
return `Perform an action if: ${
|
||||||
!config.if
|
typeof config.if === "string"
|
||||||
? ""
|
|
||||||
: typeof config.if === "string"
|
|
||||||
? config.if
|
? config.if
|
||||||
: ensureArray(config.if).length > 1
|
: ensureArray(config.if).length > 1
|
||||||
? `${ensureArray(config.if).length} conditions`
|
? `${ensureArray(config.if).length} conditions`
|
||||||
: ensureArray(config.if).length
|
: describeCondition(ensureArray(config.if)[0], hass)
|
||||||
? describeCondition(ensureArray(config.if)[0], hass)
|
|
||||||
: ""
|
|
||||||
}${config.else ? " (or else!)" : ""}`;
|
}${config.else ? " (or else!)" : ""}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,13 +219,6 @@ export const describeAction = <T extends ActionType>(
|
|||||||
|
|
||||||
if (actionType === "device_action") {
|
if (actionType === "device_action") {
|
||||||
const config = action as DeviceAction;
|
const config = action as DeviceAction;
|
||||||
if (!config.device_id) {
|
|
||||||
return "Device action";
|
|
||||||
}
|
|
||||||
const localized = localizeDeviceAutomationAction(hass, config);
|
|
||||||
if (localized) {
|
|
||||||
return localized;
|
|
||||||
}
|
|
||||||
const stateObj = hass.states[config.entity_id as string];
|
const stateObj = hass.states[config.entity_id as string];
|
||||||
return `${config.type || "Perform action with"} ${
|
return `${config.type || "Perform action with"} ${
|
||||||
stateObj ? computeStateName(stateObj) : config.entity_id
|
stateObj ? computeStateName(stateObj) : config.entity_id
|
||||||
|
@@ -21,7 +21,6 @@ export type Selector =
|
|||||||
| IconSelector
|
| IconSelector
|
||||||
| LocationSelector
|
| LocationSelector
|
||||||
| MediaSelector
|
| MediaSelector
|
||||||
| NavigationSelector
|
|
||||||
| NumberSelector
|
| NumberSelector
|
||||||
| ObjectSelector
|
| ObjectSelector
|
||||||
| SelectSelector
|
| SelectSelector
|
||||||
@@ -172,11 +171,6 @@ export interface MediaSelectorValue {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NavigationSelector {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
||||||
navigation: {};
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NumberSelector {
|
export interface NumberSelector {
|
||||||
number: {
|
number: {
|
||||||
min?: number;
|
min?: number;
|
||||||
@@ -195,7 +189,6 @@ export interface ObjectSelector {
|
|||||||
export interface SelectOption {
|
export interface SelectOption {
|
||||||
value: string;
|
value: string;
|
||||||
label: string;
|
label: string;
|
||||||
disabled?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SelectSelector {
|
export interface SelectSelector {
|
||||||
|
@@ -1,13 +1,6 @@
|
|||||||
|
import { SupportedBrandObj } from "../dialogs/config-flow/step-flow-pick-handler";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
|
|
||||||
export interface SupportedBrandObj {
|
|
||||||
name: string;
|
|
||||||
slug: string;
|
|
||||||
is_add?: boolean;
|
|
||||||
is_helper?: boolean;
|
|
||||||
supported_flows: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export type SupportedBrandHandler = Record<string, string>;
|
export type SupportedBrandHandler = Record<string, string>;
|
||||||
|
|
||||||
export const getSupportedBrands = (hass: HomeAssistant) =>
|
export const getSupportedBrands = (hass: HomeAssistant) =>
|
||||||
|
@@ -309,7 +309,7 @@ export const fetchCommandsForCluster = (
|
|||||||
cluster_type: clusterType,
|
cluster_type: clusterType,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const fetchClustersForZhaDevice = (
|
export const fetchClustersForZhaNode = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
ieeeAddress: string
|
ieeeAddress: string
|
||||||
): Promise<Cluster[]> =>
|
): Promise<Cluster[]> =>
|
||||||
|
@@ -85,13 +85,6 @@ enum Protocols {
|
|||||||
ZWaveLongRange = 1,
|
ZWaveLongRange = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum NodeType {
|
|
||||||
Controller,
|
|
||||||
/** @deprecated Use `NodeType["End Node"]` instead */
|
|
||||||
"Routing End Node",
|
|
||||||
"End Node" = 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum FirmwareUpdateStatus {
|
export enum FirmwareUpdateStatus {
|
||||||
Error_Timeout = -1,
|
Error_Timeout = -1,
|
||||||
Error_Checksum = 0,
|
Error_Checksum = 0,
|
||||||
@@ -149,12 +142,12 @@ export interface ZWaveJSController {
|
|||||||
sdk_version: string;
|
sdk_version: string;
|
||||||
type: number;
|
type: number;
|
||||||
own_node_id: number;
|
own_node_id: number;
|
||||||
is_primary: boolean;
|
is_secondary: boolean;
|
||||||
is_using_home_id_from_other_network: boolean;
|
is_using_home_id_from_other_network: boolean;
|
||||||
is_sis_present: boolean;
|
is_sis_present: boolean;
|
||||||
was_real_primary: boolean;
|
was_real_primary: boolean;
|
||||||
is_suc: boolean;
|
is_static_update_controller: boolean;
|
||||||
node_type: NodeType;
|
is_slave: boolean;
|
||||||
firmware_version: string;
|
firmware_version: string;
|
||||||
manufacturer_id: number;
|
manufacturer_id: number;
|
||||||
product_id: number;
|
product_id: number;
|
||||||
|
@@ -170,6 +170,7 @@ class DialogConfigEntrySystemOptions extends LitElement {
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
this._params!.entryUpdated(result.config_entry);
|
||||||
this.closeDialog();
|
this.closeDialog();
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
this._error = err.message || "Unknown error";
|
this._error = err.message || "Unknown error";
|
||||||
|
@@ -5,6 +5,7 @@ import { IntegrationManifest } from "../../data/integration";
|
|||||||
export interface ConfigEntrySystemOptionsDialogParams {
|
export interface ConfigEntrySystemOptionsDialogParams {
|
||||||
entry: ConfigEntry;
|
entry: ConfigEntry;
|
||||||
manifest?: IntegrationManifest;
|
manifest?: IntegrationManifest;
|
||||||
|
entryUpdated(entry: ConfigEntry): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadConfigEntrySystemOptionsDialog = () =>
|
export const loadConfigEntrySystemOptionsDialog = () =>
|
||||||
|
@@ -18,7 +18,9 @@ import {
|
|||||||
AreaRegistryEntry,
|
AreaRegistryEntry,
|
||||||
subscribeAreaRegistry,
|
subscribeAreaRegistry,
|
||||||
} from "../../data/area_registry";
|
} from "../../data/area_registry";
|
||||||
|
import { fetchConfigFlowInProgress } from "../../data/config_flow";
|
||||||
import {
|
import {
|
||||||
|
DataEntryFlowProgress,
|
||||||
DataEntryFlowStep,
|
DataEntryFlowStep,
|
||||||
subscribeDataEntryFlowProgressed,
|
subscribeDataEntryFlowProgressed,
|
||||||
} from "../../data/data_entry_flow";
|
} from "../../data/data_entry_flow";
|
||||||
@@ -26,12 +28,14 @@ import {
|
|||||||
DeviceRegistryEntry,
|
DeviceRegistryEntry,
|
||||||
subscribeDeviceRegistry,
|
subscribeDeviceRegistry,
|
||||||
} from "../../data/device_registry";
|
} from "../../data/device_registry";
|
||||||
|
import { fetchIntegrationManifest } from "../../data/integration";
|
||||||
import { haStyleDialog } from "../../resources/styles";
|
import { haStyleDialog } from "../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import { documentationUrl } from "../../util/documentation-url";
|
import { documentationUrl } from "../../util/documentation-url";
|
||||||
import { showAlertDialog } from "../generic/show-dialog-box";
|
import { showAlertDialog } from "../generic/show-dialog-box";
|
||||||
import {
|
import {
|
||||||
DataEntryFlowDialogParams,
|
DataEntryFlowDialogParams,
|
||||||
|
FlowHandlers,
|
||||||
LoadingReason,
|
LoadingReason,
|
||||||
} from "./show-dialog-data-entry-flow";
|
} from "./show-dialog-data-entry-flow";
|
||||||
import "./step-flow-abort";
|
import "./step-flow-abort";
|
||||||
@@ -40,6 +44,8 @@ import "./step-flow-external";
|
|||||||
import "./step-flow-form";
|
import "./step-flow-form";
|
||||||
import "./step-flow-loading";
|
import "./step-flow-loading";
|
||||||
import "./step-flow-menu";
|
import "./step-flow-menu";
|
||||||
|
import "./step-flow-pick-flow";
|
||||||
|
import "./step-flow-pick-handler";
|
||||||
import "./step-flow-progress";
|
import "./step-flow-progress";
|
||||||
|
|
||||||
let instance = 0;
|
let instance = 0;
|
||||||
@@ -80,8 +86,12 @@ class DataEntryFlowDialog extends LitElement {
|
|||||||
|
|
||||||
@state() private _areas?: AreaRegistryEntry[];
|
@state() private _areas?: AreaRegistryEntry[];
|
||||||
|
|
||||||
|
@state() private _handlers?: FlowHandlers;
|
||||||
|
|
||||||
@state() private _handler?: string;
|
@state() private _handler?: string;
|
||||||
|
|
||||||
|
@state() private _flowsInProgress?: DataEntryFlowProgress[];
|
||||||
|
|
||||||
private _unsubAreas?: UnsubscribeFunc;
|
private _unsubAreas?: UnsubscribeFunc;
|
||||||
|
|
||||||
private _unsubDevices?: UnsubscribeFunc;
|
private _unsubDevices?: UnsubscribeFunc;
|
||||||
@@ -92,39 +102,15 @@ class DataEntryFlowDialog extends LitElement {
|
|||||||
this._params = params;
|
this._params = params;
|
||||||
this._instance = instance++;
|
this._instance = instance++;
|
||||||
|
|
||||||
const curInstance = this._instance;
|
|
||||||
let step: DataEntryFlowStep;
|
|
||||||
|
|
||||||
if (params.startFlowHandler) {
|
if (params.startFlowHandler) {
|
||||||
|
this._checkFlowsInProgress(params.startFlowHandler);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.continueFlowId) {
|
||||||
this._loading = "loading_flow";
|
this._loading = "loading_flow";
|
||||||
this._handler = params.startFlowHandler;
|
const curInstance = this._instance;
|
||||||
try {
|
let step: DataEntryFlowStep;
|
||||||
step = await this._params!.flowConfig.createFlow(
|
|
||||||
this.hass,
|
|
||||||
params.startFlowHandler
|
|
||||||
);
|
|
||||||
} catch (err: any) {
|
|
||||||
this.closeDialog();
|
|
||||||
let message = err.message || err.body || "Unknown error";
|
|
||||||
if (typeof message !== "string") {
|
|
||||||
message = JSON.stringify(message);
|
|
||||||
}
|
|
||||||
showAlertDialog(this, {
|
|
||||||
title: this.hass.localize(
|
|
||||||
"ui.panel.config.integrations.config_flow.error"
|
|
||||||
),
|
|
||||||
text: `${this.hass.localize(
|
|
||||||
"ui.panel.config.integrations.config_flow.could_not_load"
|
|
||||||
)}: ${message}`,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Happens if second showDialog called
|
|
||||||
if (curInstance !== this._instance) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (params.continueFlowId) {
|
|
||||||
this._loading = "loading_flow";
|
|
||||||
try {
|
try {
|
||||||
step = await params.flowConfig.fetchFlow(
|
step = await params.flowConfig.fetchFlow(
|
||||||
this.hass,
|
this.hass,
|
||||||
@@ -146,17 +132,32 @@ class DataEntryFlowDialog extends LitElement {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
// Happens if second showDialog called
|
||||||
|
if (curInstance !== this._instance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._processStep(step);
|
||||||
|
this._loading = undefined;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Happens if second showDialog called
|
// Create a new config flow. Show picker
|
||||||
if (curInstance !== this._instance) {
|
if (!params.flowConfig.getFlowHandlers) {
|
||||||
return;
|
throw new Error("No getFlowHandlers defined in flow config");
|
||||||
}
|
}
|
||||||
|
this._step = null;
|
||||||
|
|
||||||
this._processStep(step);
|
// We only load the handlers once
|
||||||
this._loading = undefined;
|
if (this._handlers === undefined) {
|
||||||
|
this._loading = "loading_handlers";
|
||||||
|
try {
|
||||||
|
this._handlers = await params.flowConfig.getFlowHandlers(this.hass);
|
||||||
|
} finally {
|
||||||
|
this._loading = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public closeDialog() {
|
public closeDialog() {
|
||||||
@@ -184,6 +185,7 @@ class DataEntryFlowDialog extends LitElement {
|
|||||||
this._step = undefined;
|
this._step = undefined;
|
||||||
this._params = undefined;
|
this._params = undefined;
|
||||||
this._devices = undefined;
|
this._devices = undefined;
|
||||||
|
this._flowsInProgress = undefined;
|
||||||
this._handler = undefined;
|
this._handler = undefined;
|
||||||
if (this._unsubAreas) {
|
if (this._unsubAreas) {
|
||||||
this._unsubAreas();
|
this._unsubAreas();
|
||||||
@@ -216,12 +218,15 @@ class DataEntryFlowDialog extends LitElement {
|
|||||||
hideActions
|
hideActions
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
${this._loading || this._step === null
|
${this._loading ||
|
||||||
|
(this._step === null &&
|
||||||
|
this._handlers === undefined &&
|
||||||
|
this._handler === undefined)
|
||||||
? html`
|
? html`
|
||||||
<step-flow-loading
|
<step-flow-loading
|
||||||
.flowConfig=${this._params.flowConfig}
|
.flowConfig=${this._params.flowConfig}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.loadingReason=${this._loading}
|
.loadingReason=${this._loading || "loading_handlers"}
|
||||||
.handler=${this._handler}
|
.handler=${this._handler}
|
||||||
.step=${this._step}
|
.step=${this._step}
|
||||||
></step-flow-loading>
|
></step-flow-loading>
|
||||||
@@ -268,7 +273,24 @@ class DataEntryFlowDialog extends LitElement {
|
|||||||
dialogAction="close"
|
dialogAction="close"
|
||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
</div>
|
</div>
|
||||||
${this._step.type === "form"
|
${this._step === null
|
||||||
|
? this._handler
|
||||||
|
? html`<step-flow-pick-flow
|
||||||
|
.flowConfig=${this._params.flowConfig}
|
||||||
|
.hass=${this.hass}
|
||||||
|
.handler=${this._handler}
|
||||||
|
.flowsInProgress=${this._flowsInProgress}
|
||||||
|
></step-flow-pick-flow>`
|
||||||
|
: // Show handler picker
|
||||||
|
html`
|
||||||
|
<step-flow-pick-handler
|
||||||
|
.hass=${this.hass}
|
||||||
|
.handlers=${this._handlers}
|
||||||
|
.initialFilter=${this._params.searchQuery}
|
||||||
|
@handler-picked=${this._handlerPicked}
|
||||||
|
></step-flow-pick-handler>
|
||||||
|
`
|
||||||
|
: this._step.type === "form"
|
||||||
? html`
|
? html`
|
||||||
<step-flow-form
|
<step-flow-form
|
||||||
.flowConfig=${this._params.flowConfig}
|
.flowConfig=${this._params.flowConfig}
|
||||||
@@ -378,6 +400,64 @@ class DataEntryFlowDialog extends LitElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _checkFlowsInProgress(handler: string) {
|
||||||
|
this._loading = "loading_handlers";
|
||||||
|
this._handler = handler;
|
||||||
|
|
||||||
|
const flowsInProgress = (
|
||||||
|
await fetchConfigFlowInProgress(this.hass.connection)
|
||||||
|
).filter((flow) => flow.handler === handler);
|
||||||
|
|
||||||
|
if (!flowsInProgress.length) {
|
||||||
|
// No flows in progress, create a new flow
|
||||||
|
this._loading = "loading_flow";
|
||||||
|
let step: DataEntryFlowStep;
|
||||||
|
try {
|
||||||
|
step = await this._params!.flowConfig.createFlow(this.hass, handler);
|
||||||
|
} catch (err: any) {
|
||||||
|
this.closeDialog();
|
||||||
|
const message =
|
||||||
|
err?.status_code === 404
|
||||||
|
? this.hass.localize(
|
||||||
|
"ui.panel.config.integrations.config_flow.no_config_flow"
|
||||||
|
)
|
||||||
|
: `${this.hass.localize(
|
||||||
|
"ui.panel.config.integrations.config_flow.could_not_load"
|
||||||
|
)}: ${err?.body?.message || err?.message}`;
|
||||||
|
|
||||||
|
showAlertDialog(this, {
|
||||||
|
title: this.hass.localize(
|
||||||
|
"ui.panel.config.integrations.config_flow.error"
|
||||||
|
),
|
||||||
|
text: message,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
this._handler = undefined;
|
||||||
|
}
|
||||||
|
this._processStep(step);
|
||||||
|
if (this._params!.manifest === undefined) {
|
||||||
|
try {
|
||||||
|
this._params!.manifest = await fetchIntegrationManifest(
|
||||||
|
this.hass,
|
||||||
|
this._params?.domain || step.handler
|
||||||
|
);
|
||||||
|
} catch (_) {
|
||||||
|
// No manifest
|
||||||
|
this._params!.manifest = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this._step = null;
|
||||||
|
this._flowsInProgress = flowsInProgress;
|
||||||
|
}
|
||||||
|
this._loading = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handlerPicked(ev) {
|
||||||
|
this._checkFlowsInProgress(ev.detail.handler);
|
||||||
|
}
|
||||||
|
|
||||||
private async _processStep(
|
private async _processStep(
|
||||||
step: DataEntryFlowStep | undefined | Promise<DataEntryFlowStep>
|
step: DataEntryFlowStep | undefined | Promise<DataEntryFlowStep>
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
@@ -3,9 +3,11 @@ import {
|
|||||||
createConfigFlow,
|
createConfigFlow,
|
||||||
deleteConfigFlow,
|
deleteConfigFlow,
|
||||||
fetchConfigFlow,
|
fetchConfigFlow,
|
||||||
|
getConfigFlowHandlers,
|
||||||
handleConfigFlowStep,
|
handleConfigFlowStep,
|
||||||
} from "../../data/config_flow";
|
} from "../../data/config_flow";
|
||||||
import { domainToName } from "../../data/integration";
|
import { domainToName } from "../../data/integration";
|
||||||
|
import { getSupportedBrands } from "../../data/supported_brands";
|
||||||
import {
|
import {
|
||||||
DataEntryFlowDialogParams,
|
DataEntryFlowDialogParams,
|
||||||
loadDataEntryFlowDialog,
|
loadDataEntryFlowDialog,
|
||||||
@@ -20,6 +22,16 @@ export const showConfigFlowDialog = (
|
|||||||
): void =>
|
): void =>
|
||||||
showFlowDialog(element, dialogParams, {
|
showFlowDialog(element, dialogParams, {
|
||||||
loadDevicesAndAreas: true,
|
loadDevicesAndAreas: true,
|
||||||
|
getFlowHandlers: async (hass) => {
|
||||||
|
const [integrations, helpers, supportedBrands] = await Promise.all([
|
||||||
|
getConfigFlowHandlers(hass, "integration"),
|
||||||
|
getConfigFlowHandlers(hass, "helper"),
|
||||||
|
getSupportedBrands(hass),
|
||||||
|
hass.loadBackendTranslation("title", undefined, true),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return { integrations, helpers, supportedBrands };
|
||||||
|
},
|
||||||
createFlow: async (hass, handler) => {
|
createFlow: async (hass, handler) => {
|
||||||
const [step] = await Promise.all([
|
const [step] = await Promise.all([
|
||||||
createConfigFlow(hass, handler),
|
createConfigFlow(hass, handler),
|
||||||
|
@@ -22,6 +22,8 @@ export interface FlowHandlers {
|
|||||||
export interface FlowConfig {
|
export interface FlowConfig {
|
||||||
loadDevicesAndAreas: boolean;
|
loadDevicesAndAreas: boolean;
|
||||||
|
|
||||||
|
getFlowHandlers?: (hass: HomeAssistant) => Promise<FlowHandlers>;
|
||||||
|
|
||||||
createFlow(hass: HomeAssistant, handler: string): Promise<DataEntryFlowStep>;
|
createFlow(hass: HomeAssistant, handler: string): Promise<DataEntryFlowStep>;
|
||||||
|
|
||||||
fetchFlow(hass: HomeAssistant, flowId: string): Promise<DataEntryFlowStep>;
|
fetchFlow(hass: HomeAssistant, flowId: string): Promise<DataEntryFlowStep>;
|
||||||
|
@@ -12,6 +12,8 @@ import { DataEntryFlowStepAbort } from "../../data/data_entry_flow";
|
|||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import { showAddApplicationCredentialDialog } from "../../panels/config/application_credentials/show-dialog-add-application-credential";
|
import { showAddApplicationCredentialDialog } from "../../panels/config/application_credentials/show-dialog-add-application-credential";
|
||||||
import { configFlowContentStyles } from "./styles";
|
import { configFlowContentStyles } from "./styles";
|
||||||
|
import { showConfirmationDialog } from "../generic/show-dialog-box";
|
||||||
|
import { domainToName } from "../../data/integration";
|
||||||
import { DataEntryFlowDialogParams } from "./show-dialog-data-entry-flow";
|
import { DataEntryFlowDialogParams } from "./show-dialog-data-entry-flow";
|
||||||
import { showConfigFlowDialog } from "./show-dialog-config-flow";
|
import { showConfigFlowDialog } from "./show-dialog-config-flow";
|
||||||
|
|
||||||
@@ -52,11 +54,21 @@ class StepFlowAbort extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _handleMissingCreds() {
|
private async _handleMissingCreds() {
|
||||||
|
const confirm = await showConfirmationDialog(this, {
|
||||||
|
title: this.hass.localize(
|
||||||
|
"ui.panel.config.integrations.config_flow.missing_credentials",
|
||||||
|
{
|
||||||
|
integration: domainToName(this.hass.localize, this.domain),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
});
|
||||||
this._flowDone();
|
this._flowDone();
|
||||||
|
if (!confirm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Prompt to enter credentials and restart integration setup
|
// Prompt to enter credentials and restart integration setup
|
||||||
showAddApplicationCredentialDialog(this.params.dialogParentElement!, {
|
showAddApplicationCredentialDialog(this.params.dialogParentElement!, {
|
||||||
selectedDomain: this.domain,
|
selectedDomain: this.domain,
|
||||||
manifest: this.params.manifest,
|
|
||||||
applicationCredentialAddedCallback: () => {
|
applicationCredentialAddedCallback: () => {
|
||||||
showConfigFlowDialog(this.params.dialogParentElement!, {
|
showConfigFlowDialog(this.params.dialogParentElement!, {
|
||||||
dialogClosedCallback: this.params.dialogClosedCallback,
|
dialogClosedCallback: this.params.dialogClosedCallback,
|
||||||
|
130
src/dialogs/config-flow/step-flow-pick-flow.ts
Normal file
130
src/dialogs/config-flow/step-flow-pick-flow.ts
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
import "@polymer/paper-item";
|
||||||
|
import "@polymer/paper-item/paper-icon-item";
|
||||||
|
import "@polymer/paper-item/paper-item";
|
||||||
|
import "@polymer/paper-item/paper-item-body";
|
||||||
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
|
import { customElement, property } from "lit/decorators";
|
||||||
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
|
import "../../components/ha-icon-next";
|
||||||
|
import { localizeConfigFlowTitle } from "../../data/config_flow";
|
||||||
|
import { DataEntryFlowProgress } from "../../data/data_entry_flow";
|
||||||
|
import { domainToName } from "../../data/integration";
|
||||||
|
import { HomeAssistant } from "../../types";
|
||||||
|
import { brandsUrl } from "../../util/brands-url";
|
||||||
|
import { FlowConfig } from "./show-dialog-data-entry-flow";
|
||||||
|
import { configFlowContentStyles } from "./styles";
|
||||||
|
|
||||||
|
@customElement("step-flow-pick-flow")
|
||||||
|
class StepFlowPickFlow extends LitElement {
|
||||||
|
public flowConfig!: FlowConfig;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property({ attribute: false })
|
||||||
|
public flowsInProgress!: DataEntryFlowProgress[];
|
||||||
|
|
||||||
|
@property() public handler!: string;
|
||||||
|
|
||||||
|
protected render(): TemplateResult {
|
||||||
|
return html`
|
||||||
|
<h2>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.integrations.config_flow.pick_flow_step.title"
|
||||||
|
)}
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
${this.flowsInProgress.map(
|
||||||
|
(flow) => html` <paper-icon-item
|
||||||
|
@click=${this._flowInProgressPicked}
|
||||||
|
.flow=${flow}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
slot="item-icon"
|
||||||
|
loading="lazy"
|
||||||
|
src=${brandsUrl({
|
||||||
|
domain: flow.handler,
|
||||||
|
type: "icon",
|
||||||
|
useFallback: true,
|
||||||
|
darkOptimized: this.hass.themes?.darkMode,
|
||||||
|
})}
|
||||||
|
referrerpolicy="no-referrer"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<paper-item-body>
|
||||||
|
${localizeConfigFlowTitle(this.hass.localize, flow)}
|
||||||
|
</paper-item-body>
|
||||||
|
<ha-icon-next></ha-icon-next>
|
||||||
|
</paper-icon-item>`
|
||||||
|
)}
|
||||||
|
<paper-item @click=${this._startNewFlowPicked} .handler=${this.handler}>
|
||||||
|
<paper-item-body>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.integrations.config_flow.pick_flow_step.new_flow",
|
||||||
|
"integration",
|
||||||
|
domainToName(this.hass.localize, this.handler)
|
||||||
|
)}
|
||||||
|
</paper-item-body>
|
||||||
|
<ha-icon-next></ha-icon-next>
|
||||||
|
</paper-item>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _startNewFlowPicked(ev) {
|
||||||
|
this._startFlow(ev.currentTarget.handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _startFlow(handler: string) {
|
||||||
|
fireEvent(this, "flow-update", {
|
||||||
|
stepPromise: this.flowConfig.createFlow(this.hass, handler),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _flowInProgressPicked(ev) {
|
||||||
|
const flow: DataEntryFlowProgress = ev.currentTarget.flow;
|
||||||
|
fireEvent(this, "flow-update", {
|
||||||
|
stepPromise: this.flowConfig.fetchFlow(this.hass, flow.flow_id),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResultGroup {
|
||||||
|
return [
|
||||||
|
configFlowContentStyles,
|
||||||
|
css`
|
||||||
|
img {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
|
ha-icon-next {
|
||||||
|
margin-right: 8px;
|
||||||
|
}
|
||||||
|
div {
|
||||||
|
overflow: auto;
|
||||||
|
max-height: 600px;
|
||||||
|
margin: 16px 0;
|
||||||
|
}
|
||||||
|
h2 {
|
||||||
|
padding-inline-end: 66px;
|
||||||
|
direction: var(--direction);
|
||||||
|
}
|
||||||
|
@media all and (max-height: 900px) {
|
||||||
|
div {
|
||||||
|
max-height: calc(100vh - 134px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
paper-icon-item,
|
||||||
|
paper-item {
|
||||||
|
cursor: pointer;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"step-flow-pick-flow": StepFlowPickFlow;
|
||||||
|
}
|
||||||
|
}
|
372
src/dialogs/config-flow/step-flow-pick-handler.ts
Normal file
372
src/dialogs/config-flow/step-flow-pick-handler.ts
Normal file
@@ -0,0 +1,372 @@
|
|||||||
|
import "@material/mwc-list/mwc-list";
|
||||||
|
import "@material/mwc-list/mwc-list-item";
|
||||||
|
import Fuse from "fuse.js";
|
||||||
|
import {
|
||||||
|
css,
|
||||||
|
CSSResultGroup,
|
||||||
|
html,
|
||||||
|
LitElement,
|
||||||
|
PropertyValues,
|
||||||
|
TemplateResult,
|
||||||
|
} from "lit";
|
||||||
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import { styleMap } from "lit/directives/style-map";
|
||||||
|
import memoizeOne from "memoize-one";
|
||||||
|
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
||||||
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
|
import { protocolIntegrationPicked } from "../../common/integrations/protocolIntegrationPicked";
|
||||||
|
import { navigate } from "../../common/navigate";
|
||||||
|
import { caseInsensitiveStringCompare } from "../../common/string/compare";
|
||||||
|
import { LocalizeFunc } from "../../common/translations/localize";
|
||||||
|
import "../../components/ha-icon-next";
|
||||||
|
import "../../components/search-input";
|
||||||
|
import { domainToName } from "../../data/integration";
|
||||||
|
import { haStyleScrollbar } from "../../resources/styles";
|
||||||
|
import { HomeAssistant } from "../../types";
|
||||||
|
import { brandsUrl } from "../../util/brands-url";
|
||||||
|
import { documentationUrl } from "../../util/documentation-url";
|
||||||
|
import { showConfirmationDialog } from "../generic/show-dialog-box";
|
||||||
|
import { FlowHandlers } from "./show-dialog-data-entry-flow";
|
||||||
|
import { configFlowContentStyles } from "./styles";
|
||||||
|
|
||||||
|
interface HandlerObj {
|
||||||
|
name: string;
|
||||||
|
slug: string;
|
||||||
|
is_add?: boolean;
|
||||||
|
is_helper?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SupportedBrandObj extends HandlerObj {
|
||||||
|
supported_flows: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
// for fire event
|
||||||
|
interface HASSDomEvents {
|
||||||
|
"handler-picked": {
|
||||||
|
handler: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@customElement("step-flow-pick-handler")
|
||||||
|
class StepFlowPickHandler extends LitElement {
|
||||||
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public handlers!: FlowHandlers;
|
||||||
|
|
||||||
|
@property() public initialFilter?: string;
|
||||||
|
|
||||||
|
@state() private _filter?: string;
|
||||||
|
|
||||||
|
private _width?: number;
|
||||||
|
|
||||||
|
private _height?: number;
|
||||||
|
|
||||||
|
private _filterHandlers = memoizeOne(
|
||||||
|
(
|
||||||
|
h: FlowHandlers,
|
||||||
|
filter?: string,
|
||||||
|
_localize?: LocalizeFunc
|
||||||
|
): [(HandlerObj | SupportedBrandObj)[], HandlerObj[]] => {
|
||||||
|
const integrations: (HandlerObj | SupportedBrandObj)[] =
|
||||||
|
h.integrations.map((handler) => ({
|
||||||
|
name: domainToName(this.hass.localize, handler),
|
||||||
|
slug: handler,
|
||||||
|
}));
|
||||||
|
|
||||||
|
for (const [domain, domainBrands] of Object.entries(h.supportedBrands)) {
|
||||||
|
for (const [slug, name] of Object.entries(domainBrands)) {
|
||||||
|
integrations.push({
|
||||||
|
slug,
|
||||||
|
name,
|
||||||
|
supported_flows: [domain],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter) {
|
||||||
|
const options: Fuse.IFuseOptions<HandlerObj> = {
|
||||||
|
keys: ["name", "slug"],
|
||||||
|
isCaseSensitive: false,
|
||||||
|
minMatchCharLength: 2,
|
||||||
|
threshold: 0.2,
|
||||||
|
};
|
||||||
|
const helpers: HandlerObj[] = h.helpers.map((handler) => ({
|
||||||
|
name: domainToName(this.hass.localize, handler),
|
||||||
|
slug: handler,
|
||||||
|
is_helper: true,
|
||||||
|
}));
|
||||||
|
return [
|
||||||
|
new Fuse(integrations, options)
|
||||||
|
.search(filter)
|
||||||
|
.map((result) => result.item),
|
||||||
|
new Fuse(helpers, options)
|
||||||
|
.search(filter)
|
||||||
|
.map((result) => result.item),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
integrations.sort((a, b) =>
|
||||||
|
caseInsensitiveStringCompare(a.name, b.name)
|
||||||
|
),
|
||||||
|
[],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
protected render(): TemplateResult {
|
||||||
|
const [integrations, helpers] = this._getHandlers();
|
||||||
|
|
||||||
|
const addDeviceRows: HandlerObj[] = ["zha", "zwave_js"]
|
||||||
|
.filter((domain) => isComponentLoaded(this.hass, domain))
|
||||||
|
.map((domain) => ({
|
||||||
|
name: this.hass.localize(
|
||||||
|
`ui.panel.config.integrations.add_${domain}_device`
|
||||||
|
),
|
||||||
|
slug: domain,
|
||||||
|
is_add: true,
|
||||||
|
}))
|
||||||
|
.sort((a, b) => caseInsensitiveStringCompare(a.name, b.name));
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<h2>${this.hass.localize("ui.panel.config.integrations.new")}</h2>
|
||||||
|
<search-input
|
||||||
|
.hass=${this.hass}
|
||||||
|
autofocus
|
||||||
|
.filter=${this._filter}
|
||||||
|
@value-changed=${this._filterChanged}
|
||||||
|
.label=${this.hass.localize("ui.panel.config.integrations.search")}
|
||||||
|
@keypress=${this._maybeSubmit}
|
||||||
|
></search-input>
|
||||||
|
<mwc-list
|
||||||
|
style=${styleMap({
|
||||||
|
width: `${this._width}px`,
|
||||||
|
height: `${this._height}px`,
|
||||||
|
})}
|
||||||
|
class="ha-scrollbar"
|
||||||
|
>
|
||||||
|
${addDeviceRows.length
|
||||||
|
? html`
|
||||||
|
${addDeviceRows.map((handler) => this._renderRow(handler))}
|
||||||
|
<li divider padded class="divider" role="separator"></li>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
${integrations.length
|
||||||
|
? integrations.map((handler) => this._renderRow(handler))
|
||||||
|
: html`
|
||||||
|
<p>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.integrations.note_about_integrations"
|
||||||
|
)}<br />
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.integrations.note_about_website_reference"
|
||||||
|
)}<a
|
||||||
|
href=${documentationUrl(
|
||||||
|
this.hass,
|
||||||
|
`/integrations/${
|
||||||
|
this._filter ? `#search/${this._filter}` : ""
|
||||||
|
}`
|
||||||
|
)}
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
>${this.hass.localize(
|
||||||
|
"ui.panel.config.integrations.home_assistant_website"
|
||||||
|
)}</a
|
||||||
|
>.
|
||||||
|
</p>
|
||||||
|
`}
|
||||||
|
${helpers.length
|
||||||
|
? html`
|
||||||
|
<li divider padded class="divider" role="separator"></li>
|
||||||
|
${helpers.map((handler) => this._renderRow(handler))}
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
</mwc-list>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _renderRow(handler: HandlerObj) {
|
||||||
|
return html`
|
||||||
|
<mwc-list-item
|
||||||
|
graphic="medium"
|
||||||
|
.hasMeta=${!handler.is_add}
|
||||||
|
.handler=${handler}
|
||||||
|
@click=${this._handlerPicked}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
slot="graphic"
|
||||||
|
loading="lazy"
|
||||||
|
src=${brandsUrl({
|
||||||
|
domain: handler.slug,
|
||||||
|
type: "icon",
|
||||||
|
useFallback: true,
|
||||||
|
darkOptimized: this.hass.themes?.darkMode,
|
||||||
|
})}
|
||||||
|
referrerpolicy="no-referrer"
|
||||||
|
/>
|
||||||
|
<span>${handler.name} ${handler.is_helper ? " (helper)" : ""}</span>
|
||||||
|
${handler.is_add ? "" : html`<ha-icon-next slot="meta"></ha-icon-next>`}
|
||||||
|
</mwc-list-item>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
public willUpdate(changedProps: PropertyValues): void {
|
||||||
|
super.willUpdate(changedProps);
|
||||||
|
if (this._filter === undefined && this.initialFilter !== undefined) {
|
||||||
|
this._filter = this.initialFilter;
|
||||||
|
}
|
||||||
|
if (this.initialFilter !== undefined && this._filter === "") {
|
||||||
|
this.initialFilter = undefined;
|
||||||
|
this._filter = "";
|
||||||
|
this._width = undefined;
|
||||||
|
this._height = undefined;
|
||||||
|
} else if (
|
||||||
|
this.hasUpdated &&
|
||||||
|
changedProps.has("_filter") &&
|
||||||
|
(!this._width || !this._height)
|
||||||
|
) {
|
||||||
|
// Store the width and height so that when we search, box doesn't jump
|
||||||
|
const boundingRect =
|
||||||
|
this.shadowRoot!.querySelector("mwc-list")!.getBoundingClientRect();
|
||||||
|
this._width = boundingRect.width;
|
||||||
|
this._height = boundingRect.height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected firstUpdated(changedProps) {
|
||||||
|
super.firstUpdated(changedProps);
|
||||||
|
setTimeout(
|
||||||
|
() => this.shadowRoot!.querySelector("search-input")!.focus(),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _getHandlers() {
|
||||||
|
return this._filterHandlers(
|
||||||
|
this.handlers,
|
||||||
|
this._filter,
|
||||||
|
this.hass.localize
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _filterChanged(e) {
|
||||||
|
this._filter = e.detail.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _handlerPicked(ev) {
|
||||||
|
const handler: HandlerObj | SupportedBrandObj = ev.currentTarget.handler;
|
||||||
|
|
||||||
|
if (handler.is_add) {
|
||||||
|
this._handleAddPicked(handler.slug);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handler.is_helper) {
|
||||||
|
navigate(`/config/helpers/add?domain=${handler.slug}`);
|
||||||
|
// This closes dialog.
|
||||||
|
fireEvent(this, "flow-update");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("supported_flows" in handler) {
|
||||||
|
const slug = handler.supported_flows[0];
|
||||||
|
|
||||||
|
showConfirmationDialog(this, {
|
||||||
|
text: this.hass.localize(
|
||||||
|
"ui.panel.config.integrations.config_flow.supported_brand_flow",
|
||||||
|
{
|
||||||
|
supported_brand: handler.name,
|
||||||
|
flow_domain_name: domainToName(this.hass.localize, slug),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
confirm: () => {
|
||||||
|
if (["zha", "zwave_js"].includes(slug)) {
|
||||||
|
this._handleAddPicked(slug);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fireEvent(this, "handler-picked", {
|
||||||
|
handler: slug,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fireEvent(this, "handler-picked", {
|
||||||
|
handler: handler.slug,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _handleAddPicked(slug: string): Promise<void> {
|
||||||
|
await protocolIntegrationPicked(this, this.hass, slug);
|
||||||
|
// This closes dialog.
|
||||||
|
fireEvent(this, "flow-update");
|
||||||
|
}
|
||||||
|
|
||||||
|
private _maybeSubmit(ev: KeyboardEvent) {
|
||||||
|
if (ev.key !== "Enter") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const handlers = this._getHandlers();
|
||||||
|
|
||||||
|
if (handlers.length > 0) {
|
||||||
|
fireEvent(this, "handler-picked", {
|
||||||
|
handler: handlers[0][0].slug,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResultGroup {
|
||||||
|
return [
|
||||||
|
configFlowContentStyles,
|
||||||
|
haStyleScrollbar,
|
||||||
|
css`
|
||||||
|
img {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
|
search-input {
|
||||||
|
display: block;
|
||||||
|
margin: 16px 16px 0;
|
||||||
|
}
|
||||||
|
ha-icon-next {
|
||||||
|
margin-right: 8px;
|
||||||
|
}
|
||||||
|
mwc-list {
|
||||||
|
overflow: auto;
|
||||||
|
max-height: 600px;
|
||||||
|
}
|
||||||
|
.divider {
|
||||||
|
border-bottom-color: var(--divider-color);
|
||||||
|
}
|
||||||
|
h2 {
|
||||||
|
padding-inline-end: 66px;
|
||||||
|
direction: var(--direction);
|
||||||
|
}
|
||||||
|
@media all and (max-height: 900px) {
|
||||||
|
mwc-list {
|
||||||
|
max-height: calc(100vh - 134px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
text-align: center;
|
||||||
|
padding: 16px;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
p > a {
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"step-flow-pick-handler": StepFlowPickHandler;
|
||||||
|
}
|
||||||
|
}
|
@@ -2,7 +2,6 @@ import "@material/mwc-button/mwc-button";
|
|||||||
import { mdiAlertOutline } from "@mdi/js";
|
import { mdiAlertOutline } from "@mdi/js";
|
||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
|
||||||
import { ifDefined } from "lit/directives/if-defined";
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import "../../components/ha-dialog";
|
import "../../components/ha-dialog";
|
||||||
@@ -97,9 +96,6 @@ class DialogBox extends LitElement {
|
|||||||
@click=${this._confirm}
|
@click=${this._confirm}
|
||||||
?dialogInitialFocus=${!this._params.prompt}
|
?dialogInitialFocus=${!this._params.prompt}
|
||||||
slot="primaryAction"
|
slot="primaryAction"
|
||||||
class=${classMap({
|
|
||||||
destructive: this._params.destructive || false,
|
|
||||||
})}
|
|
||||||
>
|
>
|
||||||
${this._params.confirmText
|
${this._params.confirmText
|
||||||
? this._params.confirmText
|
? this._params.confirmText
|
||||||
@@ -157,9 +153,6 @@ class DialogBox extends LitElement {
|
|||||||
.secondary {
|
.secondary {
|
||||||
color: var(--secondary-text-color);
|
color: var(--secondary-text-color);
|
||||||
}
|
}
|
||||||
.destructive {
|
|
||||||
--mdc-theme-primary: var(--error-color);
|
|
||||||
}
|
|
||||||
ha-dialog {
|
ha-dialog {
|
||||||
--mdc-dialog-heading-ink-color: var(--primary-text-color);
|
--mdc-dialog-heading-ink-color: var(--primary-text-color);
|
||||||
--mdc-dialog-content-ink-color: var(--primary-text-color);
|
--mdc-dialog-content-ink-color: var(--primary-text-color);
|
||||||
|
@@ -16,7 +16,6 @@ export interface ConfirmationDialogParams extends BaseDialogBoxParams {
|
|||||||
dismissText?: string;
|
dismissText?: string;
|
||||||
confirm?: () => void;
|
confirm?: () => void;
|
||||||
cancel?: () => void;
|
cancel?: () => void;
|
||||||
destructive?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PromptDialogParams extends BaseDialogBoxParams {
|
export interface PromptDialogParams extends BaseDialogBoxParams {
|
||||||
|
@@ -377,14 +377,12 @@ class MoreInfoClimate extends LitElement {
|
|||||||
|
|
||||||
private _handlePresetmodeChanged(ev) {
|
private _handlePresetmodeChanged(ev) {
|
||||||
const newVal = ev.target.value || null;
|
const newVal = ev.target.value || null;
|
||||||
if (newVal) {
|
this._callServiceHelper(
|
||||||
this._callServiceHelper(
|
this.stateObj!.attributes.preset_mode,
|
||||||
this.stateObj!.attributes.preset_mode,
|
newVal,
|
||||||
newVal,
|
"set_preset_mode",
|
||||||
"set_preset_mode",
|
{ preset_mode: newVal }
|
||||||
{ preset_mode: newVal }
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _callServiceHelper(
|
private async _callServiceHelper(
|
||||||
|
@@ -1,29 +1,19 @@
|
|||||||
import { css, CSSResult, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResult, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { attributeClassNames } from "../../../common/entity/attribute_class_names";
|
import { attributeClassNames } from "../../../common/entity/attribute_class_names";
|
||||||
import {
|
import { featureClassNames } from "../../../common/entity/feature_class_names";
|
||||||
FeatureClassNames,
|
|
||||||
featureClassNames,
|
|
||||||
} from "../../../common/entity/feature_class_names";
|
|
||||||
import { supportsFeature } from "../../../common/entity/supports-feature";
|
|
||||||
import "../../../components/ha-attributes";
|
import "../../../components/ha-attributes";
|
||||||
import "../../../components/ha-cover-tilt-controls";
|
import "../../../components/ha-cover-tilt-controls";
|
||||||
import "../../../components/ha-labeled-slider";
|
import "../../../components/ha-labeled-slider";
|
||||||
import {
|
import {
|
||||||
CoverEntity,
|
CoverEntity,
|
||||||
CoverEntityFeature,
|
FEATURE_CLASS_NAMES,
|
||||||
isTiltOnly,
|
isTiltOnly,
|
||||||
|
supportsSetPosition,
|
||||||
|
supportsSetTiltPosition,
|
||||||
} from "../../../data/cover";
|
} from "../../../data/cover";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
|
|
||||||
export const FEATURE_CLASS_NAMES: FeatureClassNames<CoverEntityFeature> = {
|
|
||||||
[CoverEntityFeature.SET_POSITION]: "has-set_position",
|
|
||||||
[CoverEntityFeature.OPEN_TILT]: "has-open_tilt",
|
|
||||||
[CoverEntityFeature.CLOSE_TILT]: "has-close_tilt",
|
|
||||||
[CoverEntityFeature.STOP_TILT]: "has-stop_tilt",
|
|
||||||
[CoverEntityFeature.SET_TILT_POSITION]: "has-set_tilt_position",
|
|
||||||
};
|
|
||||||
|
|
||||||
@customElement("more-info-cover")
|
@customElement("more-info-cover")
|
||||||
class MoreInfoCover extends LitElement {
|
class MoreInfoCover extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
@@ -44,16 +34,13 @@ class MoreInfoCover extends LitElement {
|
|||||||
.caption=${this.hass.localize("ui.card.cover.position")}
|
.caption=${this.hass.localize("ui.card.cover.position")}
|
||||||
pin=""
|
pin=""
|
||||||
.value=${this.stateObj.attributes.current_position}
|
.value=${this.stateObj.attributes.current_position}
|
||||||
.disabled=${!supportsFeature(
|
.disabled=${!supportsSetPosition(this.stateObj)}
|
||||||
this.stateObj,
|
|
||||||
CoverEntityFeature.SET_POSITION
|
|
||||||
)}
|
|
||||||
@change=${this._coverPositionSliderChanged}
|
@change=${this._coverPositionSliderChanged}
|
||||||
></ha-labeled-slider>
|
></ha-labeled-slider>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="tilt">
|
<div class="tilt">
|
||||||
${supportsFeature(this.stateObj, CoverEntityFeature.SET_TILT_POSITION)
|
${supportsSetTiltPosition(this.stateObj)
|
||||||
? // Either render the labeled slider and put the tilt buttons into its slot
|
? // Either render the labeled slider and put the tilt buttons into its slot
|
||||||
// or (if tilt position is not supported and therefore no slider is shown)
|
// or (if tilt position is not supported and therefore no slider is shown)
|
||||||
// render a title <div> (same style as for a labeled slider) and directly put
|
// render a title <div> (same style as for a labeled slider) and directly put
|
||||||
|
@@ -20,13 +20,13 @@ import "../../../components/ha-labeled-slider";
|
|||||||
import "../../../components/ha-select";
|
import "../../../components/ha-select";
|
||||||
import {
|
import {
|
||||||
getLightCurrentModeRgbColor,
|
getLightCurrentModeRgbColor,
|
||||||
LightColorMode,
|
LightColorModes,
|
||||||
LightEntity,
|
LightEntity,
|
||||||
LightEntityFeature,
|
|
||||||
lightIsInColorMode,
|
lightIsInColorMode,
|
||||||
lightSupportsColor,
|
lightSupportsColor,
|
||||||
lightSupportsColorMode,
|
lightSupportsColorMode,
|
||||||
lightSupportsBrightness,
|
lightSupportsDimming,
|
||||||
|
SUPPORT_EFFECT,
|
||||||
} from "../../../data/light";
|
} from "../../../data/light";
|
||||||
import type { HomeAssistant } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ class MoreInfoLight extends LitElement {
|
|||||||
|
|
||||||
@state() private _colorPickerColor?: [number, number, number];
|
@state() private _colorPickerColor?: [number, number, number];
|
||||||
|
|
||||||
@state() private _mode?: "color" | LightColorMode;
|
@state() private _mode?: "color" | LightColorModes;
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (!this.hass || !this.stateObj) {
|
if (!this.hass || !this.stateObj) {
|
||||||
@@ -65,29 +65,29 @@ class MoreInfoLight extends LitElement {
|
|||||||
|
|
||||||
const supportsTemp = lightSupportsColorMode(
|
const supportsTemp = lightSupportsColorMode(
|
||||||
this.stateObj,
|
this.stateObj,
|
||||||
LightColorMode.COLOR_TEMP
|
LightColorModes.COLOR_TEMP
|
||||||
);
|
);
|
||||||
|
|
||||||
const supportsWhite = lightSupportsColorMode(
|
const supportsWhite = lightSupportsColorMode(
|
||||||
this.stateObj,
|
this.stateObj,
|
||||||
LightColorMode.WHITE
|
LightColorModes.WHITE
|
||||||
);
|
);
|
||||||
|
|
||||||
const supportsRgbww = lightSupportsColorMode(
|
const supportsRgbww = lightSupportsColorMode(
|
||||||
this.stateObj,
|
this.stateObj,
|
||||||
LightColorMode.RGBWW
|
LightColorModes.RGBWW
|
||||||
);
|
);
|
||||||
|
|
||||||
const supportsRgbw =
|
const supportsRgbw =
|
||||||
!supportsRgbww &&
|
!supportsRgbww &&
|
||||||
lightSupportsColorMode(this.stateObj, LightColorMode.RGBW);
|
lightSupportsColorMode(this.stateObj, LightColorModes.RGBW);
|
||||||
|
|
||||||
const supportsColor =
|
const supportsColor =
|
||||||
supportsRgbww || supportsRgbw || lightSupportsColor(this.stateObj);
|
supportsRgbww || supportsRgbw || lightSupportsColor(this.stateObj);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<div class="content">
|
<div class="content">
|
||||||
${lightSupportsBrightness(this.stateObj)
|
${lightSupportsDimming(this.stateObj)
|
||||||
? html`
|
? html`
|
||||||
<ha-labeled-slider
|
<ha-labeled-slider
|
||||||
caption=${this.hass.localize("ui.card.light.brightness")}
|
caption=${this.hass.localize("ui.card.light.brightness")}
|
||||||
@@ -113,7 +113,7 @@ class MoreInfoLight extends LitElement {
|
|||||||
: ""}
|
: ""}
|
||||||
${supportsTemp &&
|
${supportsTemp &&
|
||||||
((!supportsColor && !supportsWhite) ||
|
((!supportsColor && !supportsWhite) ||
|
||||||
this._mode === LightColorMode.COLOR_TEMP)
|
this._mode === LightColorModes.COLOR_TEMP)
|
||||||
? html`
|
? html`
|
||||||
<ha-labeled-slider
|
<ha-labeled-slider
|
||||||
class="color_temp"
|
class="color_temp"
|
||||||
@@ -204,7 +204,7 @@ class MoreInfoLight extends LitElement {
|
|||||||
: ""}
|
: ""}
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
${supportsFeature(this.stateObj, LightEntityFeature.EFFECT) &&
|
${supportsFeature(this.stateObj, SUPPORT_EFFECT) &&
|
||||||
this.stateObj!.attributes.effect_list?.length
|
this.stateObj!.attributes.effect_list?.length
|
||||||
? html`
|
? html`
|
||||||
<hr />
|
<hr />
|
||||||
@@ -260,31 +260,31 @@ class MoreInfoLight extends LitElement {
|
|||||||
let brightnessAdjust = 100;
|
let brightnessAdjust = 100;
|
||||||
this._brightnessAdjusted = undefined;
|
this._brightnessAdjusted = undefined;
|
||||||
if (
|
if (
|
||||||
stateObj.attributes.color_mode === LightColorMode.RGB &&
|
stateObj.attributes.color_mode === LightColorModes.RGB &&
|
||||||
!lightSupportsColorMode(stateObj, LightColorMode.RGBWW) &&
|
!lightSupportsColorMode(stateObj, LightColorModes.RGBWW) &&
|
||||||
!lightSupportsColorMode(stateObj, LightColorMode.RGBW)
|
!lightSupportsColorMode(stateObj, LightColorModes.RGBW)
|
||||||
) {
|
) {
|
||||||
const maxVal = Math.max(...stateObj.attributes.rgb_color!);
|
const maxVal = Math.max(...stateObj.attributes.rgb_color);
|
||||||
if (maxVal < 255) {
|
if (maxVal < 255) {
|
||||||
this._brightnessAdjusted = maxVal;
|
this._brightnessAdjusted = maxVal;
|
||||||
brightnessAdjust = (this._brightnessAdjusted / 255) * 100;
|
brightnessAdjust = (this._brightnessAdjusted / 255) * 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._brightnessSliderValue = Math.round(
|
this._brightnessSliderValue = Math.round(
|
||||||
((stateObj.attributes.brightness || 0) * brightnessAdjust) / 255
|
(stateObj.attributes.brightness * brightnessAdjust) / 255
|
||||||
);
|
);
|
||||||
this._ctSliderValue = stateObj.attributes.color_temp;
|
this._ctSliderValue = stateObj.attributes.color_temp;
|
||||||
this._wvSliderValue =
|
this._wvSliderValue =
|
||||||
stateObj.attributes.color_mode === LightColorMode.RGBW
|
stateObj.attributes.color_mode === LightColorModes.RGBW
|
||||||
? Math.round((stateObj.attributes.rgbw_color![3] * 100) / 255)
|
? Math.round((stateObj.attributes.rgbw_color[3] * 100) / 255)
|
||||||
: undefined;
|
: undefined;
|
||||||
this._cwSliderValue =
|
this._cwSliderValue =
|
||||||
stateObj.attributes.color_mode === LightColorMode.RGBWW
|
stateObj.attributes.color_mode === LightColorModes.RGBWW
|
||||||
? Math.round((stateObj.attributes.rgbww_color![3] * 100) / 255)
|
? Math.round((stateObj.attributes.rgbww_color[3] * 100) / 255)
|
||||||
: undefined;
|
: undefined;
|
||||||
this._wwSliderValue =
|
this._wwSliderValue =
|
||||||
stateObj.attributes.color_mode === LightColorMode.RGBWW
|
stateObj.attributes.color_mode === LightColorModes.RGBWW
|
||||||
? Math.round((stateObj.attributes.rgbww_color![4] * 100) / 255)
|
? Math.round((stateObj.attributes.rgbww_color[4] * 100) / 255)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const currentRgbColor = getLightCurrentModeRgbColor(stateObj);
|
const currentRgbColor = getLightCurrentModeRgbColor(stateObj);
|
||||||
@@ -307,10 +307,10 @@ class MoreInfoLight extends LitElement {
|
|||||||
(supportsTemp: boolean, supportsWhite: boolean) => {
|
(supportsTemp: boolean, supportsWhite: boolean) => {
|
||||||
const modes = [{ label: "Color", value: "color" }];
|
const modes = [{ label: "Color", value: "color" }];
|
||||||
if (supportsTemp) {
|
if (supportsTemp) {
|
||||||
modes.push({ label: "Temperature", value: LightColorMode.COLOR_TEMP });
|
modes.push({ label: "Temperature", value: LightColorModes.COLOR_TEMP });
|
||||||
}
|
}
|
||||||
if (supportsWhite) {
|
if (supportsWhite) {
|
||||||
modes.push({ label: "White", value: LightColorMode.WHITE });
|
modes.push({ label: "White", value: LightColorModes.WHITE });
|
||||||
}
|
}
|
||||||
return modes;
|
return modes;
|
||||||
}
|
}
|
||||||
@@ -342,7 +342,7 @@ class MoreInfoLight extends LitElement {
|
|||||||
|
|
||||||
this._brightnessSliderValue = bri;
|
this._brightnessSliderValue = bri;
|
||||||
|
|
||||||
if (this._mode === LightColorMode.WHITE) {
|
if (this._mode === LightColorModes.WHITE) {
|
||||||
this.hass.callService("light", "turn_on", {
|
this.hass.callService("light", "turn_on", {
|
||||||
entity_id: this.stateObj!.entity_id,
|
entity_id: this.stateObj!.entity_id,
|
||||||
white: Math.min(255, Math.round((bri * 255) / 100)),
|
white: Math.min(255, Math.round((bri * 255) / 100)),
|
||||||
@@ -486,7 +486,7 @@ class MoreInfoLight extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _setRgbWColor(rgbColor: [number, number, number]) {
|
private _setRgbWColor(rgbColor: [number, number, number]) {
|
||||||
if (lightSupportsColorMode(this.stateObj!, LightColorMode.RGBWW)) {
|
if (lightSupportsColorMode(this.stateObj!, LightColorModes.RGBWW)) {
|
||||||
const rgbww_color: [number, number, number, number, number] = this
|
const rgbww_color: [number, number, number, number, number] = this
|
||||||
.stateObj!.attributes.rgbww_color
|
.stateObj!.attributes.rgbww_color
|
||||||
? [...this.stateObj!.attributes.rgbww_color]
|
? [...this.stateObj!.attributes.rgbww_color]
|
||||||
@@ -495,7 +495,7 @@ class MoreInfoLight extends LitElement {
|
|||||||
entity_id: this.stateObj!.entity_id,
|
entity_id: this.stateObj!.entity_id,
|
||||||
rgbww_color: rgbColor.concat(rgbww_color.slice(3)),
|
rgbww_color: rgbColor.concat(rgbww_color.slice(3)),
|
||||||
});
|
});
|
||||||
} else if (lightSupportsColorMode(this.stateObj!, LightColorMode.RGBW)) {
|
} else if (lightSupportsColorMode(this.stateObj!, LightColorModes.RGBW)) {
|
||||||
const rgbw_color: [number, number, number, number] = this.stateObj!
|
const rgbw_color: [number, number, number, number] = this.stateObj!
|
||||||
.attributes.rgbw_color
|
.attributes.rgbw_color
|
||||||
? [...this.stateObj!.attributes.rgbw_color]
|
? [...this.stateObj!.attributes.rgbw_color]
|
||||||
@@ -524,8 +524,8 @@ class MoreInfoLight extends LitElement {
|
|||||||
];
|
];
|
||||||
|
|
||||||
if (
|
if (
|
||||||
lightSupportsColorMode(this.stateObj!, LightColorMode.RGBWW) ||
|
lightSupportsColorMode(this.stateObj!, LightColorModes.RGBWW) ||
|
||||||
lightSupportsColorMode(this.stateObj!, LightColorMode.RGBW)
|
lightSupportsColorMode(this.stateObj!, LightColorModes.RGBW)
|
||||||
) {
|
) {
|
||||||
this._setRgbWColor(
|
this._setRgbWColor(
|
||||||
this._colorBrightnessSliderValue
|
this._colorBrightnessSliderValue
|
||||||
@@ -535,7 +535,7 @@ class MoreInfoLight extends LitElement {
|
|||||||
)
|
)
|
||||||
: [ev.detail.rgb.r, ev.detail.rgb.g, ev.detail.rgb.b]
|
: [ev.detail.rgb.r, ev.detail.rgb.g, ev.detail.rgb.b]
|
||||||
);
|
);
|
||||||
} else if (lightSupportsColorMode(this.stateObj!, LightColorMode.RGB)) {
|
} else if (lightSupportsColorMode(this.stateObj!, LightColorModes.RGB)) {
|
||||||
const rgb_color: [number, number, number] = [
|
const rgb_color: [number, number, number] = [
|
||||||
ev.detail.rgb.r,
|
ev.detail.rgb.r,
|
||||||
ev.detail.rgb.g,
|
ev.detail.rgb.g,
|
||||||
|
@@ -167,8 +167,7 @@ class MoreInfoMediaPlayer extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
${![UNAVAILABLE, UNKNOWN, "off"].includes(stateObj.state) &&
|
${supportsFeature(stateObj, SUPPORT_SELECT_SOUND_MODE) &&
|
||||||
supportsFeature(stateObj, SUPPORT_SELECT_SOUND_MODE) &&
|
|
||||||
stateObj.attributes.sound_mode_list?.length
|
stateObj.attributes.sound_mode_list?.length
|
||||||
? html`
|
? html`
|
||||||
<div class="sound-input">
|
<div class="sound-input">
|
||||||
|
@@ -90,7 +90,7 @@ export class MoreInfoDialog extends LitElement {
|
|||||||
const stateObj = this.hass.states[entityId];
|
const stateObj = this.hass.states[entityId];
|
||||||
|
|
||||||
const domain = computeDomain(entityId);
|
const domain = computeDomain(entityId);
|
||||||
const name = (stateObj && computeStateName(stateObj)) || entityId;
|
const name = stateObj ? computeStateName(stateObj) : entityId;
|
||||||
const tabs = this._getTabs(entityId, this.hass.user!.is_admin);
|
const tabs = this._getTabs(entityId, this.hass.user!.is_admin);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
|
@@ -7,7 +7,7 @@ This is the entry point for providing external app stuff from app entrypoint.
|
|||||||
|
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { HomeAssistantMain } from "../layouts/home-assistant-main";
|
import { HomeAssistantMain } from "../layouts/home-assistant-main";
|
||||||
import type { EMIncomingMessageCommands } from "./external_messaging";
|
import type { EMExternalMessageCommands } from "./external_messaging";
|
||||||
|
|
||||||
export const attachExternalToApp = (hassMainEl: HomeAssistantMain) => {
|
export const attachExternalToApp = (hassMainEl: HomeAssistantMain) => {
|
||||||
window.addEventListener("haptic", (ev) =>
|
window.addEventListener("haptic", (ev) =>
|
||||||
@@ -24,7 +24,7 @@ export const attachExternalToApp = (hassMainEl: HomeAssistantMain) => {
|
|||||||
|
|
||||||
const handleExternalMessage = (
|
const handleExternalMessage = (
|
||||||
hassMainEl: HomeAssistantMain,
|
hassMainEl: HomeAssistantMain,
|
||||||
msg: EMIncomingMessageCommands
|
msg: EMExternalMessageCommands
|
||||||
): boolean => {
|
): boolean => {
|
||||||
const bus = hassMainEl.hass.auth.external!;
|
const bus = hassMainEl.hass.auth.external!;
|
||||||
|
|
||||||
|
@@ -8,6 +8,7 @@ interface CommandInFlight {
|
|||||||
export interface EMMessage {
|
export interface EMMessage {
|
||||||
id?: number;
|
id?: number;
|
||||||
type: string;
|
type: string;
|
||||||
|
payload?: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EMError {
|
interface EMError {
|
||||||
@@ -29,120 +30,34 @@ interface EMMessageResultError {
|
|||||||
error: EMError;
|
error: EMError;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EMOutgoingMessageConfigGet extends EMMessage {
|
interface EMExternalMessageRestart {
|
||||||
type: "config/get";
|
|
||||||
}
|
|
||||||
|
|
||||||
interface EMOutgoingMessageMatterCommission extends EMMessage {
|
|
||||||
type: "matter/commission";
|
|
||||||
}
|
|
||||||
|
|
||||||
type EMOutgoingMessageWithAnswer = {
|
|
||||||
"config/get": {
|
|
||||||
request: EMOutgoingMessageConfigGet;
|
|
||||||
response: ExternalConfig;
|
|
||||||
};
|
|
||||||
"matter/commission": {
|
|
||||||
request: EMOutgoingMessageMatterCommission;
|
|
||||||
response: {
|
|
||||||
code: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
interface EMOutgoingMessageExoplayerPlayHLS extends EMMessage {
|
|
||||||
type: "exoplayer/play_hls";
|
|
||||||
payload: {
|
|
||||||
url: string;
|
|
||||||
muted: boolean;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
interface EMOutgoingMessageExoplayerResize extends EMMessage {
|
|
||||||
type: "exoplayer/resize";
|
|
||||||
payload: {
|
|
||||||
left: number;
|
|
||||||
top: number;
|
|
||||||
right: number;
|
|
||||||
bottom: number;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
interface EMOutgoingMessageExoplayerStop extends EMMessage {
|
|
||||||
type: "exoplayer/stop";
|
|
||||||
}
|
|
||||||
|
|
||||||
interface EMOutgoingMessageThemeUpdate extends EMMessage {
|
|
||||||
type: "theme-update";
|
|
||||||
}
|
|
||||||
|
|
||||||
interface EMOutgoingMessageHaptic extends EMMessage {
|
|
||||||
type: "haptic";
|
|
||||||
payload: { hapticType: string };
|
|
||||||
}
|
|
||||||
|
|
||||||
interface EMOutgoingMessageConnectionStatus extends EMMessage {
|
|
||||||
type: "connection-status";
|
|
||||||
payload: { event: string };
|
|
||||||
}
|
|
||||||
|
|
||||||
interface EMOutgoingMessageAppConfiguration extends EMMessage {
|
|
||||||
type: "config_screen/show";
|
|
||||||
}
|
|
||||||
|
|
||||||
interface EMOutgoingMessageTagWrite extends EMMessage {
|
|
||||||
type: "tag/write";
|
|
||||||
payload: {
|
|
||||||
name: string | null;
|
|
||||||
tag: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
interface EMOutgoingMessageSidebarShow extends EMMessage {
|
|
||||||
type: "sidebar/show";
|
|
||||||
}
|
|
||||||
|
|
||||||
type EMOutgoingMessageWithoutAnswer =
|
|
||||||
| EMOutgoingMessageHaptic
|
|
||||||
| EMOutgoingMessageConnectionStatus
|
|
||||||
| EMOutgoingMessageAppConfiguration
|
|
||||||
| EMOutgoingMessageTagWrite
|
|
||||||
| EMOutgoingMessageSidebarShow
|
|
||||||
| EMOutgoingMessageExoplayerPlayHLS
|
|
||||||
| EMOutgoingMessageExoplayerResize
|
|
||||||
| EMOutgoingMessageExoplayerStop
|
|
||||||
| EMOutgoingMessageThemeUpdate
|
|
||||||
| EMMessageResultSuccess
|
|
||||||
| EMMessageResultError;
|
|
||||||
|
|
||||||
interface EMIncomingMessageRestart {
|
|
||||||
id: number;
|
id: number;
|
||||||
type: "command";
|
type: "command";
|
||||||
command: "restart";
|
command: "restart";
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EMIncomingMessageShowNotifications {
|
interface EMExternMessageShowNotifications {
|
||||||
id: number;
|
id: number;
|
||||||
type: "command";
|
type: "command";
|
||||||
command: "notifications/show";
|
command: "notifications/show";
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EMIncomingMessageCommands =
|
export type EMExternalMessageCommands =
|
||||||
| EMIncomingMessageRestart
|
| EMExternalMessageRestart
|
||||||
| EMIncomingMessageShowNotifications;
|
| EMExternMessageShowNotifications;
|
||||||
|
|
||||||
type EMIncomingMessage =
|
type ExternalMessage =
|
||||||
| EMMessageResultSuccess
|
| EMMessageResultSuccess
|
||||||
| EMMessageResultError
|
| EMMessageResultError
|
||||||
| EMIncomingMessageCommands;
|
| EMExternalMessageCommands;
|
||||||
|
|
||||||
type EMIncomingMessageHandler = (msg: EMIncomingMessageCommands) => boolean;
|
type ExternalMessageHandler = (msg: EMExternalMessageCommands) => boolean;
|
||||||
|
|
||||||
export interface ExternalConfig {
|
export interface ExternalConfig {
|
||||||
hasSettingsScreen: boolean;
|
hasSettingsScreen: boolean;
|
||||||
hasSidebar: boolean;
|
hasSidebar: boolean;
|
||||||
canWriteTag: boolean;
|
canWriteTag: boolean;
|
||||||
hasExoPlayer: boolean;
|
hasExoPlayer: boolean;
|
||||||
canCommissionMatter: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ExternalMessaging {
|
export class ExternalMessaging {
|
||||||
@@ -152,7 +67,7 @@ export class ExternalMessaging {
|
|||||||
|
|
||||||
public msgId = 0;
|
public msgId = 0;
|
||||||
|
|
||||||
private _commandHandler?: EMIncomingMessageHandler;
|
private _commandHandler?: ExternalMessageHandler;
|
||||||
|
|
||||||
public async attach() {
|
public async attach() {
|
||||||
window[CALLBACK_EXTERNAL_BUS] = (msg) => this.receiveMessage(msg);
|
window[CALLBACK_EXTERNAL_BUS] = (msg) => this.receiveMessage(msg);
|
||||||
@@ -162,12 +77,12 @@ export class ExternalMessaging {
|
|||||||
payload: { event: ev.detail },
|
payload: { event: ev.detail },
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
this.config = await this.sendMessage<"config/get">({
|
this.config = await this.sendMessage<ExternalConfig>({
|
||||||
type: "config/get",
|
type: "config/get",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public addCommandHandler(handler: EMIncomingMessageHandler) {
|
public addCommandHandler(handler: ExternalMessageHandler) {
|
||||||
this._commandHandler = handler;
|
this._commandHandler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,33 +90,31 @@ export class ExternalMessaging {
|
|||||||
* Send message to external app that expects a response.
|
* Send message to external app that expects a response.
|
||||||
* @param msg message to send
|
* @param msg message to send
|
||||||
*/
|
*/
|
||||||
public sendMessage<T extends keyof EMOutgoingMessageWithAnswer>(
|
public sendMessage<T>(msg: EMMessage): Promise<T> {
|
||||||
msg: EMOutgoingMessageWithAnswer[T]["request"]
|
|
||||||
): Promise<EMOutgoingMessageWithAnswer[T]["response"]> {
|
|
||||||
const msgId = ++this.msgId;
|
const msgId = ++this.msgId;
|
||||||
msg.id = msgId;
|
msg.id = msgId;
|
||||||
|
|
||||||
this._sendExternal(msg);
|
this.fireMessage(msg);
|
||||||
|
|
||||||
return new Promise<EMOutgoingMessageWithAnswer[T]["response"]>(
|
return new Promise<T>((resolve, reject) => {
|
||||||
(resolve, reject) => {
|
this.commands[msgId] = { resolve, reject };
|
||||||
this.commands[msgId] = { resolve, reject };
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send message to external app without expecting a response.
|
* Send message to external app without expecting a response.
|
||||||
* @param msg message to send
|
* @param msg message to send
|
||||||
*/
|
*/
|
||||||
public fireMessage(msg: EMOutgoingMessageWithoutAnswer) {
|
public fireMessage(
|
||||||
|
msg: EMMessage | EMMessageResultSuccess | EMMessageResultError
|
||||||
|
) {
|
||||||
if (!msg.id) {
|
if (!msg.id) {
|
||||||
msg.id = ++this.msgId;
|
msg.id = ++this.msgId;
|
||||||
}
|
}
|
||||||
this._sendExternal(msg);
|
this._sendExternal(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public receiveMessage(msg: EMIncomingMessage) {
|
public receiveMessage(msg: ExternalMessage) {
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log("Receiving message from external app", msg);
|
console.log("Receiving message from external app", msg);
|
||||||
|
@@ -1,15 +1,6 @@
|
|||||||
import {
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
css,
|
|
||||||
CSSResultGroup,
|
|
||||||
html,
|
|
||||||
LitElement,
|
|
||||||
PropertyValues,
|
|
||||||
TemplateResult,
|
|
||||||
} from "lit";
|
|
||||||
import { customElement, eventOptions, property } from "lit/decorators";
|
import { customElement, eventOptions, property } from "lit/decorators";
|
||||||
import { restoreScroll } from "../common/decorators/restore-scroll";
|
import { restoreScroll } from "../common/decorators/restore-scroll";
|
||||||
import { toggleAttribute } from "../common/dom/toggle_attribute";
|
|
||||||
import { computeRTL } from "../common/util/compute_rtl";
|
|
||||||
import "../components/ha-icon-button-arrow-prev";
|
import "../components/ha-icon-button-arrow-prev";
|
||||||
import "../components/ha-menu-button";
|
import "../components/ha-menu-button";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
@@ -24,8 +15,6 @@ class HassSubpage extends LitElement {
|
|||||||
|
|
||||||
@property({ type: String, attribute: "back-path" }) public backPath?: string;
|
@property({ type: String, attribute: "back-path" }) public backPath?: string;
|
||||||
|
|
||||||
@property() public backCallback?: () => void;
|
|
||||||
|
|
||||||
@property({ type: Boolean, reflect: true }) public narrow = false;
|
@property({ type: Boolean, reflect: true }) public narrow = false;
|
||||||
|
|
||||||
@property({ type: Boolean }) public supervisor = false;
|
@property({ type: Boolean }) public supervisor = false;
|
||||||
@@ -33,17 +22,6 @@ class HassSubpage extends LitElement {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@restoreScroll(".content") private _savedScrollPos?: number;
|
@restoreScroll(".content") private _savedScrollPos?: number;
|
||||||
|
|
||||||
protected willUpdate(changedProps: PropertyValues): void {
|
|
||||||
super.willUpdate(changedProps);
|
|
||||||
if (!changedProps.has("hass")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
|
|
||||||
if (!oldHass || oldHass.locale !== this.hass.locale) {
|
|
||||||
toggleAttribute(this, "rtl", computeRTL(this.hass));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<div class="toolbar">
|
<div class="toolbar">
|
||||||
@@ -74,9 +52,6 @@ class HassSubpage extends LitElement {
|
|||||||
<slot name="toolbar-icon"></slot>
|
<slot name="toolbar-icon"></slot>
|
||||||
</div>
|
</div>
|
||||||
<div class="content" @scroll=${this._saveScrollPos}><slot></slot></div>
|
<div class="content" @scroll=${this._saveScrollPos}><slot></slot></div>
|
||||||
<div id="fab">
|
|
||||||
<slot name="fab"></slot>
|
|
||||||
</div>
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,10 +61,6 @@ class HassSubpage extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _backTapped(): void {
|
private _backTapped(): void {
|
||||||
if (this.backCallback) {
|
|
||||||
this.backCallback();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
history.back();
|
history.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,29 +116,6 @@ class HassSubpage extends LitElement {
|
|||||||
overflow: auto;
|
overflow: auto;
|
||||||
-webkit-overflow-scrolling: touch;
|
-webkit-overflow-scrolling: touch;
|
||||||
}
|
}
|
||||||
|
|
||||||
#fab {
|
|
||||||
position: fixed;
|
|
||||||
right: calc(16px + env(safe-area-inset-right));
|
|
||||||
bottom: calc(16px + env(safe-area-inset-bottom));
|
|
||||||
z-index: 1;
|
|
||||||
}
|
|
||||||
:host([narrow]) #fab.tabs {
|
|
||||||
bottom: calc(84px + env(safe-area-inset-bottom));
|
|
||||||
}
|
|
||||||
#fab[is-wide] {
|
|
||||||
bottom: 24px;
|
|
||||||
right: 24px;
|
|
||||||
}
|
|
||||||
:host([rtl]) #fab {
|
|
||||||
right: auto;
|
|
||||||
left: calc(16px + env(safe-area-inset-left));
|
|
||||||
}
|
|
||||||
:host([rtl][is-wide]) #fab {
|
|
||||||
bottom: 24px;
|
|
||||||
left: 24px;
|
|
||||||
right: auto;
|
|
||||||
}
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -375,9 +375,3 @@ export class HaTabsSubpageDataTable extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface HTMLElementTagNameMap {
|
|
||||||
"hass-tabs-subpage-data-table": HaTabsSubpageDataTable;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -1,26 +1,23 @@
|
|||||||
import "@material/mwc-button";
|
import "@material/mwc-button";
|
||||||
import "@material/mwc-list/mwc-list-item";
|
import "@material/mwc-list/mwc-list-item";
|
||||||
import { mdiOpenInNew } from "@mdi/js";
|
|
||||||
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
|
||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import "../../../components/ha-alert";
|
|
||||||
import "../../../components/ha-circular-progress";
|
import "../../../components/ha-circular-progress";
|
||||||
import "../../../components/ha-combo-box";
|
import "../../../components/ha-combo-box";
|
||||||
import { createCloseHeading } from "../../../components/ha-dialog";
|
import { createCloseHeading } from "../../../components/ha-dialog";
|
||||||
import "../../../components/ha-markdown";
|
import "../../../components/ha-markdown";
|
||||||
import "../../../components/ha-textfield";
|
import "../../../components/ha-textfield";
|
||||||
import {
|
import {
|
||||||
ApplicationCredential,
|
|
||||||
ApplicationCredentialsConfig,
|
|
||||||
createApplicationCredential,
|
|
||||||
fetchApplicationCredentialsConfig,
|
fetchApplicationCredentialsConfig,
|
||||||
|
createApplicationCredential,
|
||||||
|
ApplicationCredentialsConfig,
|
||||||
|
ApplicationCredential,
|
||||||
} from "../../../data/application_credential";
|
} from "../../../data/application_credential";
|
||||||
import { domainToName, IntegrationManifest } from "../../../data/integration";
|
import { domainToName } from "../../../data/integration";
|
||||||
import { haStyleDialog } from "../../../resources/styles";
|
import { haStyleDialog } from "../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { documentationUrl } from "../../../util/documentation-url";
|
|
||||||
import { AddApplicationCredentialDialogParams } from "./show-dialog-add-application-credential";
|
import { AddApplicationCredentialDialogParams } from "./show-dialog-add-application-credential";
|
||||||
|
|
||||||
interface Domain {
|
interface Domain {
|
||||||
@@ -45,8 +42,6 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
|
|
||||||
@state() private _domain?: string;
|
@state() private _domain?: string;
|
||||||
|
|
||||||
@state() private _manifest?: IntegrationManifest | null;
|
|
||||||
|
|
||||||
@state() private _name?: string;
|
@state() private _name?: string;
|
||||||
|
|
||||||
@state() private _description?: string;
|
@state() private _description?: string;
|
||||||
@@ -61,8 +56,8 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
|
|
||||||
public showDialog(params: AddApplicationCredentialDialogParams) {
|
public showDialog(params: AddApplicationCredentialDialogParams) {
|
||||||
this._params = params;
|
this._params = params;
|
||||||
this._domain = params.selectedDomain;
|
this._domain =
|
||||||
this._manifest = params.manifest;
|
params.selectedDomain !== undefined ? params.selectedDomain : "";
|
||||||
this._name = "";
|
this._name = "";
|
||||||
this._description = "";
|
this._description = "";
|
||||||
this._clientId = "";
|
this._clientId = "";
|
||||||
@@ -79,7 +74,7 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
name: domainToName(this.hass.localize, domain),
|
name: domainToName(this.hass.localize, domain),
|
||||||
}));
|
}));
|
||||||
await this.hass.loadBackendTranslation("application_credentials");
|
await this.hass.loadBackendTranslation("application_credentials");
|
||||||
if (this._domain) {
|
if (this._domain !== "") {
|
||||||
this._updateDescription();
|
this._updateDescription();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,9 +83,6 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
if (!this._params || !this._domains) {
|
if (!this._params || !this._domains) {
|
||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
const selectedDomainName = this._params.selectedDomain
|
|
||||||
? domainToName(this.hass.localize, this._domain!)
|
|
||||||
: "";
|
|
||||||
return html`
|
return html`
|
||||||
<ha-dialog
|
<ha-dialog
|
||||||
open
|
open
|
||||||
@@ -105,76 +97,23 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
${this._error
|
${this._error ? html` <div class="error">${this._error}</div> ` : ""}
|
||||||
? html`<ha-alert alert-type="error">${this._error}</ha-alert> `
|
<ha-combo-box
|
||||||
: ""}
|
name="domain"
|
||||||
${this._params.selectedDomain && !this._description
|
.hass=${this.hass}
|
||||||
? html`<p>
|
.disabled=${!!this._params.selectedDomain}
|
||||||
${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.application_credentials.editor.missing_credentials",
|
"ui.panel.config.application_credentials.editor.domain"
|
||||||
{
|
)}
|
||||||
integration: selectedDomainName,
|
.value=${this._domain}
|
||||||
}
|
.renderer=${rowRenderer}
|
||||||
)}
|
.items=${this._domains}
|
||||||
${this._manifest?.is_built_in || this._manifest?.documentation
|
item-id-path="id"
|
||||||
? html`<a
|
item-value-path="id"
|
||||||
href=${this._manifest.is_built_in
|
item-label-path="name"
|
||||||
? documentationUrl(
|
required
|
||||||
this.hass,
|
@value-changed=${this._handleDomainPicked}
|
||||||
`/integrations/${this._domain}`
|
></ha-combo-box>
|
||||||
)
|
|
||||||
: this._manifest.documentation}
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
>
|
|
||||||
${this.hass.localize(
|
|
||||||
"ui.panel.config.application_credentials.editor.missing_credentials_domain_link",
|
|
||||||
{
|
|
||||||
integration: selectedDomainName,
|
|
||||||
}
|
|
||||||
)}
|
|
||||||
<ha-svg-icon .path=${mdiOpenInNew}></ha-svg-icon>
|
|
||||||
</a>`
|
|
||||||
: ""}
|
|
||||||
</p>`
|
|
||||||
: ""}
|
|
||||||
${!this._params.selectedDomain || !this._description
|
|
||||||
? html`<p>
|
|
||||||
${this.hass.localize(
|
|
||||||
"ui.panel.config.application_credentials.editor.description"
|
|
||||||
)}
|
|
||||||
<a
|
|
||||||
href=${documentationUrl(
|
|
||||||
this.hass!,
|
|
||||||
"/integrations/application_credentials"
|
|
||||||
)}
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
>
|
|
||||||
${this.hass!.localize(
|
|
||||||
"ui.panel.config.application_credentials.editor.view_documentation"
|
|
||||||
)}
|
|
||||||
<ha-svg-icon .path=${mdiOpenInNew}></ha-svg-icon>
|
|
||||||
</a>
|
|
||||||
</p>`
|
|
||||||
: ""}
|
|
||||||
${this._params.selectedDomain
|
|
||||||
? ""
|
|
||||||
: html`<ha-combo-box
|
|
||||||
name="domain"
|
|
||||||
.hass=${this.hass}
|
|
||||||
.label=${this.hass.localize(
|
|
||||||
"ui.panel.config.application_credentials.editor.domain"
|
|
||||||
)}
|
|
||||||
.value=${this._domain}
|
|
||||||
.renderer=${rowRenderer}
|
|
||||||
.items=${this._domains}
|
|
||||||
item-id-path="id"
|
|
||||||
item-value-path="id"
|
|
||||||
item-label-path="name"
|
|
||||||
required
|
|
||||||
@value-changed=${this._handleDomainPicked}
|
|
||||||
></ha-combo-box>`}
|
|
||||||
${this._description
|
${this._description
|
||||||
? html`<ha-markdown
|
? html`<ha-markdown
|
||||||
breaks
|
breaks
|
||||||
@@ -204,10 +143,6 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
@input=${this._handleValueChanged}
|
@input=${this._handleValueChanged}
|
||||||
error-message=${this.hass.localize("ui.common.error_required")}
|
error-message=${this.hass.localize("ui.common.error_required")}
|
||||||
dialogInitialFocus
|
dialogInitialFocus
|
||||||
.helper=${this.hass.localize(
|
|
||||||
"ui.panel.config.application_credentials.editor.client_id_helper"
|
|
||||||
)}
|
|
||||||
helperPersistent
|
|
||||||
></ha-textfield>
|
></ha-textfield>
|
||||||
<ha-textfield
|
<ha-textfield
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
@@ -219,10 +154,6 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
required
|
required
|
||||||
@input=${this._handleValueChanged}
|
@input=${this._handleValueChanged}
|
||||||
error-message=${this.hass.localize("ui.common.error_required")}
|
error-message=${this.hass.localize("ui.common.error_required")}
|
||||||
.helper=${this.hass.localize(
|
|
||||||
"ui.panel.config.application_credentials.editor.client_secret_helper"
|
|
||||||
)}
|
|
||||||
helperPersistent
|
|
||||||
></ha-textfield>
|
></ha-textfield>
|
||||||
</div>
|
</div>
|
||||||
${this._loading
|
${this._loading
|
||||||
@@ -232,18 +163,15 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
: html`
|
: html`
|
||||||
<mwc-button slot="primaryAction" @click=${this._abortDialog}>
|
|
||||||
${this.hass.localize("ui.common.cancel")}
|
|
||||||
</mwc-button>
|
|
||||||
<mwc-button
|
<mwc-button
|
||||||
slot="primaryAction"
|
slot="primaryAction"
|
||||||
.disabled=${!this._domain ||
|
.disabled=${!this._domain ||
|
||||||
!this._clientId ||
|
!this._clientId ||
|
||||||
!this._clientSecret}
|
!this._clientSecret}
|
||||||
@click=${this._addApplicationCredential}
|
@click=${this._createApplicationCredential}
|
||||||
>
|
>
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.application_credentials.editor.add"
|
"ui.panel.config.application_credentials.editor.create"
|
||||||
)}
|
)}
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
`}
|
`}
|
||||||
@@ -263,11 +191,7 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
this._updateDescription();
|
this._updateDescription();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _updateDescription() {
|
private _updateDescription() {
|
||||||
await this.hass.loadBackendTranslation(
|
|
||||||
"application_credentials",
|
|
||||||
this._domain
|
|
||||||
);
|
|
||||||
const info = this._config!.integrations[this._domain!];
|
const info = this._config!.integrations[this._domain!];
|
||||||
this._description = this.hass.localize(
|
this._description = this.hass.localize(
|
||||||
`component.${this._domain}.application_credentials.description`,
|
`component.${this._domain}.application_credentials.description`,
|
||||||
@@ -289,7 +213,7 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
this.closeDialog();
|
this.closeDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _addApplicationCredential(ev) {
|
private async _createApplicationCredential(ev) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
if (!this._domain || !this._clientId || !this._clientSecret) {
|
if (!this._domain || !this._clientId || !this._clientSecret) {
|
||||||
return;
|
return;
|
||||||
@@ -336,15 +260,6 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
display: block;
|
display: block;
|
||||||
margin-bottom: 24px;
|
margin-bottom: 24px;
|
||||||
}
|
}
|
||||||
a {
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
a ha-svg-icon {
|
|
||||||
--mdc-icon-size: 16px;
|
|
||||||
}
|
|
||||||
ha-markdown {
|
|
||||||
margin-bottom: 16px;
|
|
||||||
}
|
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import { ApplicationCredential } from "../../../data/application_credential";
|
import { ApplicationCredential } from "../../../data/application_credential";
|
||||||
import { IntegrationManifest } from "../../../data/integration";
|
|
||||||
|
|
||||||
export interface AddApplicationCredentialDialogParams {
|
export interface AddApplicationCredentialDialogParams {
|
||||||
applicationCredentialAddedCallback: (
|
applicationCredentialAddedCallback: (
|
||||||
@@ -8,7 +7,6 @@ export interface AddApplicationCredentialDialogParams {
|
|||||||
) => void;
|
) => void;
|
||||||
dialogAbortedCallback?: () => void;
|
dialogAbortedCallback?: () => void;
|
||||||
selectedDomain?: string;
|
selectedDomain?: string;
|
||||||
manifest?: IntegrationManifest | null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadAddApplicationCredentialDialog = () =>
|
export const loadAddApplicationCredentialDialog = () =>
|
||||||
|
@@ -45,14 +45,13 @@ import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box
|
|||||||
import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog";
|
import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog";
|
||||||
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant, Route } from "../../../types";
|
||||||
import "../../logbook/ha-logbook";
|
import "../../logbook/ha-logbook";
|
||||||
|
import { configSections } from "../ha-panel-config";
|
||||||
import {
|
import {
|
||||||
loadAreaRegistryDetailDialog,
|
loadAreaRegistryDetailDialog,
|
||||||
showAreaRegistryDetailDialog,
|
showAreaRegistryDetailDialog,
|
||||||
} from "./show-dialog-area-registry-detail";
|
} from "./show-dialog-area-registry-detail";
|
||||||
import "../../../layouts/hass-error-screen";
|
|
||||||
import "../../../layouts/hass-subpage";
|
|
||||||
|
|
||||||
declare type NameAndEntity<EntityType extends HassEntity> = {
|
declare type NameAndEntity<EntityType extends HassEntity> = {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -67,9 +66,11 @@ class HaConfigAreaPage extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@property({ type: Boolean, reflect: true }) public narrow!: boolean;
|
@property({ type: Boolean, reflect: true }) public narrow!: boolean;
|
||||||
|
|
||||||
@property({ type: Boolean }) public isWide!: boolean;
|
@property() public isWide!: boolean;
|
||||||
|
|
||||||
@property({ type: Boolean }) public showAdvanced!: boolean;
|
@property() public showAdvanced!: boolean;
|
||||||
|
|
||||||
|
@property() public route!: Route;
|
||||||
|
|
||||||
@state() public _areas!: AreaRegistryEntry[];
|
@state() public _areas!: AreaRegistryEntry[];
|
||||||
|
|
||||||
@@ -241,20 +242,43 @@ class HaConfigAreaPage extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<hass-subpage
|
<hass-tabs-subpage
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
.header=${area.name}
|
.tabs=${configSections.areas}
|
||||||
|
.route=${this.route}
|
||||||
>
|
>
|
||||||
<ha-icon-button
|
${this.narrow
|
||||||
.path=${mdiPencil}
|
? html`<span slot="header"> ${area.name} </span>
|
||||||
.entry=${area}
|
<ha-icon-button
|
||||||
@click=${this._showSettings}
|
.path=${mdiPencil}
|
||||||
slot="toolbar-icon"
|
.entry=${area}
|
||||||
.label=${this.hass.localize("ui.panel.config.areas.edit_settings")}
|
@click=${this._showSettings}
|
||||||
></ha-icon-button>
|
slot="toolbar-icon"
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.areas.edit_settings"
|
||||||
|
)}
|
||||||
|
></ha-icon-button>`
|
||||||
|
: ""}
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
${!this.narrow
|
||||||
|
? html`
|
||||||
|
<div class="fullwidth">
|
||||||
|
<h1>
|
||||||
|
${area.name}
|
||||||
|
<ha-icon-button
|
||||||
|
.path=${mdiPencil}
|
||||||
|
.entry=${area}
|
||||||
|
@click=${this._showSettings}
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.areas.edit_settings"
|
||||||
|
)}
|
||||||
|
></ha-icon-button>
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
<div class="column">
|
<div class="column">
|
||||||
${area.picture
|
${area.picture
|
||||||
? html`<div class="img-container">
|
? html`<div class="img-container">
|
||||||
@@ -480,7 +504,7 @@ class HaConfigAreaPage extends SubscribeMixin(LitElement) {
|
|||||||
: ""}
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</hass-subpage>
|
</hass-tabs-subpage>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
import { ActionDetail } from "@material/mwc-list/mwc-list-foundation";
|
import { ActionDetail } from "@material/mwc-list/mwc-list-foundation";
|
||||||
import "@material/mwc-list/mwc-list-item";
|
import "@material/mwc-list/mwc-list-item";
|
||||||
import {
|
import {
|
||||||
|
mdiArrowDown,
|
||||||
|
mdiArrowUp,
|
||||||
mdiCheck,
|
mdiCheck,
|
||||||
mdiContentDuplicate,
|
mdiContentDuplicate,
|
||||||
mdiDelete,
|
mdiDelete,
|
||||||
@@ -15,15 +17,13 @@ import { customElement, property, query, state } from "lit/decorators";
|
|||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
import { dynamicElement } from "../../../../common/dom/dynamic-element-directive";
|
import { dynamicElement } from "../../../../common/dom/dynamic-element-directive";
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import { capitalizeFirstLetter } from "../../../../common/string/capitalize-first-letter";
|
|
||||||
import { handleStructError } from "../../../../common/structs/handle-errors";
|
import { handleStructError } from "../../../../common/structs/handle-errors";
|
||||||
import "../../../../components/ha-alert";
|
import "../../../../components/ha-alert";
|
||||||
import "../../../../components/ha-button-menu";
|
import "../../../../components/ha-button-menu";
|
||||||
import "../../../../components/ha-card";
|
import "../../../../components/ha-card";
|
||||||
import "../../../../components/ha-expansion-panel";
|
|
||||||
import "../../../../components/ha-icon-button";
|
import "../../../../components/ha-icon-button";
|
||||||
|
import "../../../../components/ha-expansion-panel";
|
||||||
import type { HaYamlEditor } from "../../../../components/ha-yaml-editor";
|
import type { HaYamlEditor } from "../../../../components/ha-yaml-editor";
|
||||||
import { ACTION_TYPES } from "../../../../data/action";
|
|
||||||
import { validateConfig } from "../../../../data/config";
|
import { validateConfig } from "../../../../data/config";
|
||||||
import { Action, getActionType } from "../../../../data/script";
|
import { Action, getActionType } from "../../../../data/script";
|
||||||
import { describeAction } from "../../../../data/script_i18n";
|
import { describeAction } from "../../../../data/script_i18n";
|
||||||
@@ -50,6 +50,8 @@ import "./types/ha-automation-action-service";
|
|||||||
import "./types/ha-automation-action-stop";
|
import "./types/ha-automation-action-stop";
|
||||||
import "./types/ha-automation-action-wait_for_trigger";
|
import "./types/ha-automation-action-wait_for_trigger";
|
||||||
import "./types/ha-automation-action-wait_template";
|
import "./types/ha-automation-action-wait_template";
|
||||||
|
import { ACTION_TYPES } from "../../../../data/action";
|
||||||
|
import { capitalizeFirstLetter } from "../../../../common/string/capitalize-first-letter";
|
||||||
|
|
||||||
const getType = (action: Action | undefined) => {
|
const getType = (action: Action | undefined) => {
|
||||||
if (!action) {
|
if (!action) {
|
||||||
@@ -64,6 +66,13 @@ const getType = (action: Action | undefined) => {
|
|||||||
return Object.keys(ACTION_TYPES).find((option) => option in action);
|
return Object.keys(ACTION_TYPES).find((option) => option in action);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
// for fire event
|
||||||
|
interface HASSDomEvents {
|
||||||
|
"move-action": { direction: "up" | "down" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export interface ActionElement extends LitElement {
|
export interface ActionElement extends LitElement {
|
||||||
action: Action;
|
action: Action;
|
||||||
}
|
}
|
||||||
@@ -98,14 +107,12 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
|
|
||||||
@property() public action!: Action;
|
@property() public action!: Action;
|
||||||
|
|
||||||
|
@property() public index!: number;
|
||||||
|
|
||||||
|
@property() public totalActions!: number;
|
||||||
|
|
||||||
@property({ type: Boolean }) public narrow = false;
|
@property({ type: Boolean }) public narrow = false;
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
|
||||||
|
|
||||||
@property({ type: Boolean }) public hideMenu = false;
|
|
||||||
|
|
||||||
@property({ type: Boolean }) public reOrderMode = false;
|
|
||||||
|
|
||||||
@state() private _warnings?: string[];
|
@state() private _warnings?: string[];
|
||||||
|
|
||||||
@state() private _uiModeAvailable = true;
|
@state() private _uiModeAvailable = true;
|
||||||
@@ -150,124 +157,125 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
</div>`
|
</div>`
|
||||||
: ""}
|
: ""}
|
||||||
<ha-expansion-panel leftChevron>
|
<ha-expansion-panel leftChevron>
|
||||||
<h3 slot="header">
|
<div slot="header">
|
||||||
<ha-svg-icon
|
<ha-svg-icon
|
||||||
class="action-icon"
|
class="action-icon"
|
||||||
.path=${ACTION_TYPES[type!]}
|
.path=${ACTION_TYPES[type!]}
|
||||||
></ha-svg-icon>
|
></ha-svg-icon>
|
||||||
${capitalizeFirstLetter(describeAction(this.hass, this.action))}
|
${capitalizeFirstLetter(describeAction(this.hass, this.action))}
|
||||||
</h3>
|
</div>
|
||||||
|
|
||||||
<slot name="icons" slot="icons"></slot>
|
${this.index !== 0
|
||||||
${this.hideMenu
|
? html`
|
||||||
? ""
|
<ha-icon-button
|
||||||
: html`
|
|
||||||
<ha-button-menu
|
|
||||||
slot="icons"
|
slot="icons"
|
||||||
fixed
|
.label=${this.hass.localize(
|
||||||
corner="BOTTOM_START"
|
"ui.panel.config.automation.editor.move_up"
|
||||||
@action=${this._handleAction}
|
)}
|
||||||
@click=${preventDefault}
|
.path=${mdiArrowUp}
|
||||||
>
|
@click=${this._moveUp}
|
||||||
<ha-icon-button
|
></ha-icon-button>
|
||||||
slot="trigger"
|
`
|
||||||
.label=${this.hass.localize("ui.common.menu")}
|
: ""}
|
||||||
.path=${mdiDotsVertical}
|
${this.index !== this.totalActions - 1
|
||||||
></ha-icon-button>
|
? html`
|
||||||
<mwc-list-item graphic="icon">
|
<ha-icon-button
|
||||||
${this.hass.localize(
|
slot="icons"
|
||||||
"ui.panel.config.automation.editor.actions.run"
|
.label=${this.hass.localize(
|
||||||
)}
|
"ui.panel.config.automation.editor.move_down"
|
||||||
<ha-svg-icon slot="graphic" .path=${mdiPlay}></ha-svg-icon>
|
)}
|
||||||
</mwc-list-item>
|
.path=${mdiArrowDown}
|
||||||
|
@click=${this._moveDown}
|
||||||
|
></ha-icon-button>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
<ha-button-menu
|
||||||
|
slot="icons"
|
||||||
|
fixed
|
||||||
|
corner="BOTTOM_START"
|
||||||
|
@action=${this._handleAction}
|
||||||
|
@click=${preventDefault}
|
||||||
|
>
|
||||||
|
<ha-icon-button
|
||||||
|
slot="trigger"
|
||||||
|
.label=${this.hass.localize("ui.common.menu")}
|
||||||
|
.path=${mdiDotsVertical}
|
||||||
|
></ha-icon-button>
|
||||||
|
<mwc-list-item graphic="icon">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.actions.run"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon slot="graphic" .path=${mdiPlay}></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<mwc-list-item graphic="icon" .disabled=${this.disabled}>
|
<mwc-list-item graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.actions.rename"
|
"ui.panel.config.automation.editor.actions.rename"
|
||||||
)}
|
)}
|
||||||
<ha-svg-icon
|
<ha-svg-icon slot="graphic" .path=${mdiRenameBox}></ha-svg-icon>
|
||||||
slot="graphic"
|
</mwc-list-item>
|
||||||
.path=${mdiRenameBox}
|
<mwc-list-item graphic="icon">
|
||||||
></ha-svg-icon>
|
${this.hass.localize(
|
||||||
</mwc-list-item>
|
"ui.panel.config.automation.editor.actions.duplicate"
|
||||||
<mwc-list-item graphic="icon" .disabled=${this.disabled}>
|
)}
|
||||||
${this.hass.localize(
|
<ha-svg-icon
|
||||||
"ui.panel.config.automation.editor.actions.duplicate"
|
slot="graphic"
|
||||||
)}
|
.path=${mdiContentDuplicate}
|
||||||
<ha-svg-icon
|
></ha-svg-icon>
|
||||||
slot="graphic"
|
</mwc-list-item>
|
||||||
.path=${mdiContentDuplicate}
|
|
||||||
></ha-svg-icon>
|
|
||||||
</mwc-list-item>
|
|
||||||
|
|
||||||
<li divider role="separator"></li>
|
<li divider role="separator"></li>
|
||||||
|
|
||||||
<mwc-list-item
|
<mwc-list-item .disabled=${!this._uiModeAvailable} graphic="icon">
|
||||||
.disabled=${!this._uiModeAvailable}
|
${this.hass.localize("ui.panel.config.automation.editor.edit_ui")}
|
||||||
graphic="icon"
|
${!yamlMode
|
||||||
>
|
? html`<ha-svg-icon
|
||||||
${this.hass.localize(
|
slot="graphic"
|
||||||
"ui.panel.config.automation.editor.edit_ui"
|
.path=${mdiCheck}
|
||||||
)}
|
></ha-svg-icon>`
|
||||||
${!yamlMode
|
: ``}
|
||||||
? html`<ha-svg-icon
|
</mwc-list-item>
|
||||||
class="selected_menu_item"
|
|
||||||
slot="graphic"
|
|
||||||
.path=${mdiCheck}
|
|
||||||
></ha-svg-icon>`
|
|
||||||
: ``}
|
|
||||||
</mwc-list-item>
|
|
||||||
|
|
||||||
<mwc-list-item
|
<mwc-list-item .disabled=${!this._uiModeAvailable} graphic="icon">
|
||||||
.disabled=${!this._uiModeAvailable}
|
${this.hass.localize(
|
||||||
graphic="icon"
|
"ui.panel.config.automation.editor.edit_yaml"
|
||||||
>
|
)}
|
||||||
${this.hass.localize(
|
${yamlMode
|
||||||
"ui.panel.config.automation.editor.edit_yaml"
|
? html`<ha-svg-icon
|
||||||
)}
|
slot="graphic"
|
||||||
${yamlMode
|
.path=${mdiCheck}
|
||||||
? html`<ha-svg-icon
|
></ha-svg-icon>`
|
||||||
class="selected_menu_item"
|
: ``}
|
||||||
slot="graphic"
|
</mwc-list-item>
|
||||||
.path=${mdiCheck}
|
|
||||||
></ha-svg-icon>`
|
|
||||||
: ``}
|
|
||||||
</mwc-list-item>
|
|
||||||
|
|
||||||
<li divider role="separator"></li>
|
<li divider role="separator"></li>
|
||||||
|
|
||||||
<mwc-list-item graphic="icon" .disabled=${this.disabled}>
|
|
||||||
${this.action.enabled === false
|
|
||||||
? this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.actions.enable"
|
|
||||||
)
|
|
||||||
: this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.actions.disable"
|
|
||||||
)}
|
|
||||||
<ha-svg-icon
|
|
||||||
slot="graphic"
|
|
||||||
.path=${this.action.enabled === false
|
|
||||||
? mdiPlayCircleOutline
|
|
||||||
: mdiStopCircleOutline}
|
|
||||||
></ha-svg-icon>
|
|
||||||
</mwc-list-item>
|
|
||||||
<mwc-list-item
|
|
||||||
class="warning"
|
|
||||||
graphic="icon"
|
|
||||||
.disabled=${this.disabled}
|
|
||||||
>
|
|
||||||
${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.actions.delete"
|
|
||||||
)}
|
|
||||||
<ha-svg-icon
|
|
||||||
class="warning"
|
|
||||||
slot="graphic"
|
|
||||||
.path=${mdiDelete}
|
|
||||||
></ha-svg-icon>
|
|
||||||
</mwc-list-item>
|
|
||||||
</ha-button-menu>
|
|
||||||
`}
|
|
||||||
|
|
||||||
|
<mwc-list-item graphic="icon">
|
||||||
|
${this.action.enabled === false
|
||||||
|
? this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.actions.enable"
|
||||||
|
)
|
||||||
|
: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.actions.disable"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon
|
||||||
|
slot="graphic"
|
||||||
|
.path=${this.action.enabled === false
|
||||||
|
? mdiPlayCircleOutline
|
||||||
|
: mdiStopCircleOutline}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
<mwc-list-item class="warning" graphic="icon">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.actions.delete"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon
|
||||||
|
class="warning"
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiDelete}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
</ha-button-menu>
|
||||||
<div
|
<div
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
"card-content": true,
|
"card-content": true,
|
||||||
@@ -308,7 +316,6 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
<ha-yaml-editor
|
<ha-yaml-editor
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.defaultValue=${this.action}
|
.defaultValue=${this.action}
|
||||||
.readOnly=${this.disabled}
|
|
||||||
@value-changed=${this._onYamlChange}
|
@value-changed=${this._onYamlChange}
|
||||||
></ha-yaml-editor>
|
></ha-yaml-editor>
|
||||||
`
|
`
|
||||||
@@ -318,8 +325,6 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
hass: this.hass,
|
hass: this.hass,
|
||||||
action: this.action,
|
action: this.action,
|
||||||
narrow: this.narrow,
|
narrow: this.narrow,
|
||||||
reOrderMode: this.reOrderMode,
|
|
||||||
disabled: this.disabled,
|
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
`}
|
`}
|
||||||
@@ -339,6 +344,16 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _moveUp(ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
fireEvent(this, "move-action", { direction: "up" });
|
||||||
|
}
|
||||||
|
|
||||||
|
private _moveDown(ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
fireEvent(this, "move-action", { direction: "down" });
|
||||||
|
}
|
||||||
|
|
||||||
private async _handleAction(ev: CustomEvent<ActionDetail>) {
|
private async _handleAction(ev: CustomEvent<ActionDetail>) {
|
||||||
switch (ev.detail.index) {
|
switch (ev.detail.index) {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -412,15 +427,11 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
|
|
||||||
private _onDelete() {
|
private _onDelete() {
|
||||||
showConfirmationDialog(this, {
|
showConfirmationDialog(this, {
|
||||||
title: this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.actions.delete_confirm_title"
|
|
||||||
),
|
|
||||||
text: this.hass.localize(
|
text: this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.actions.delete_confirm_text"
|
"ui.panel.config.automation.editor.actions.delete_confirm"
|
||||||
),
|
),
|
||||||
dismissText: this.hass.localize("ui.common.cancel"),
|
dismissText: this.hass.localize("ui.common.cancel"),
|
||||||
confirmText: this.hass.localize("ui.common.delete"),
|
confirmText: this.hass.localize("ui.common.delete"),
|
||||||
destructive: true,
|
|
||||||
confirm: () => {
|
confirm: () => {
|
||||||
fireEvent(this, "value-changed", { value: null });
|
fireEvent(this, "value-changed", { value: null });
|
||||||
},
|
},
|
||||||
@@ -496,18 +507,13 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
--expansion-panel-summary-padding: 0 0 0 8px;
|
--expansion-panel-summary-padding: 0 0 0 8px;
|
||||||
--expansion-panel-content-padding: 0;
|
--expansion-panel-content-padding: 0;
|
||||||
}
|
}
|
||||||
h3 {
|
|
||||||
margin: 0;
|
|
||||||
font-size: inherit;
|
|
||||||
font-weight: inherit;
|
|
||||||
}
|
|
||||||
.action-icon {
|
.action-icon {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
@media (min-width: 870px) {
|
@media (min-width: 870px) {
|
||||||
.action-icon {
|
.action-icon {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
color: var(--secondary-text-color);
|
color: var(--primary-color);
|
||||||
opacity: 0.9;
|
opacity: 0.9;
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
@@ -528,12 +534,6 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
.warning ul {
|
.warning ul {
|
||||||
margin: 4px 0;
|
margin: 4px 0;
|
||||||
}
|
}
|
||||||
.selected_menu_item {
|
|
||||||
color: var(--primary-color);
|
|
||||||
}
|
|
||||||
li[role="separator"] {
|
|
||||||
border-bottom-color: var(--divider-color);
|
|
||||||
}
|
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@@ -1,25 +1,15 @@
|
|||||||
|
import { repeat } from "lit/directives/repeat";
|
||||||
|
import { mdiPlus } from "@mdi/js";
|
||||||
|
import deepClone from "deep-clone-simple";
|
||||||
import "@material/mwc-button";
|
import "@material/mwc-button";
|
||||||
import type { ActionDetail } from "@material/mwc-list";
|
import type { ActionDetail } from "@material/mwc-list";
|
||||||
import { mdiArrowDown, mdiArrowUp, mdiDrag, mdiPlus } from "@mdi/js";
|
import memoizeOne from "memoize-one";
|
||||||
import deepClone from "deep-clone-simple";
|
|
||||||
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { repeat } from "lit/directives/repeat";
|
|
||||||
import memoizeOne from "memoize-one";
|
|
||||||
import type { SortableEvent } from "sortablejs";
|
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import { stringCompare } from "../../../../common/string/compare";
|
|
||||||
import { LocalizeFunc } from "../../../../common/translations/localize";
|
|
||||||
import "../../../../components/ha-button-menu";
|
|
||||||
import type { HaSelect } from "../../../../components/ha-select";
|
|
||||||
import "../../../../components/ha-svg-icon";
|
import "../../../../components/ha-svg-icon";
|
||||||
import { ACTION_TYPES } from "../../../../data/action";
|
import "../../../../components/ha-button-menu";
|
||||||
import { Action } from "../../../../data/script";
|
import { Action } from "../../../../data/script";
|
||||||
import { sortableStyles } from "../../../../resources/ha-sortable-style";
|
|
||||||
import {
|
|
||||||
loadSortable,
|
|
||||||
SortableInstance,
|
|
||||||
} from "../../../../resources/sortable.ondemand";
|
|
||||||
import { HomeAssistant } from "../../../../types";
|
import { HomeAssistant } from "../../../../types";
|
||||||
import "./ha-automation-action-row";
|
import "./ha-automation-action-row";
|
||||||
import type HaAutomationActionRow from "./ha-automation-action-row";
|
import type HaAutomationActionRow from "./ha-automation-action-row";
|
||||||
@@ -37,6 +27,10 @@ import "./types/ha-automation-action-service";
|
|||||||
import "./types/ha-automation-action-stop";
|
import "./types/ha-automation-action-stop";
|
||||||
import "./types/ha-automation-action-wait_for_trigger";
|
import "./types/ha-automation-action-wait_for_trigger";
|
||||||
import "./types/ha-automation-action-wait_template";
|
import "./types/ha-automation-action-wait_template";
|
||||||
|
import { ACTION_TYPES } from "../../../../data/action";
|
||||||
|
import { stringCompare } from "../../../../common/string/compare";
|
||||||
|
import { LocalizeFunc } from "../../../../common/translations/localize";
|
||||||
|
import type { HaSelect } from "../../../../components/ha-select";
|
||||||
|
|
||||||
@customElement("ha-automation-action")
|
@customElement("ha-automation-action")
|
||||||
export default class HaAutomationAction extends LitElement {
|
export default class HaAutomationAction extends LitElement {
|
||||||
@@ -44,76 +38,34 @@ export default class HaAutomationAction extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public narrow = false;
|
@property({ type: Boolean }) public narrow = false;
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
|
||||||
|
|
||||||
@property() public actions!: Action[];
|
@property() public actions!: Action[];
|
||||||
|
|
||||||
@property({ type: Boolean }) public reOrderMode = false;
|
|
||||||
|
|
||||||
private _focusLastActionOnChange = false;
|
private _focusLastActionOnChange = false;
|
||||||
|
|
||||||
private _actionKeys = new WeakMap<Action, string>();
|
private _actionKeys = new WeakMap<Action, string>();
|
||||||
|
|
||||||
private _sortable?: SortableInstance;
|
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
<div class="actions">
|
${repeat(
|
||||||
${repeat(
|
this.actions,
|
||||||
this.actions,
|
(action) => this._getKey(action),
|
||||||
(action) => this._getKey(action),
|
(action, idx) => html`
|
||||||
(action, idx) => html`
|
<ha-automation-action-row
|
||||||
<ha-automation-action-row
|
.index=${idx}
|
||||||
.index=${idx}
|
.totalActions=${this.actions.length}
|
||||||
.action=${action}
|
.action=${action}
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
.disabled=${this.disabled}
|
@duplicate=${this._duplicateAction}
|
||||||
.hideMenu=${this.reOrderMode}
|
@move-action=${this._move}
|
||||||
.reOrderMode=${this.reOrderMode}
|
@value-changed=${this._actionChanged}
|
||||||
@duplicate=${this._duplicateAction}
|
.hass=${this.hass}
|
||||||
@value-changed=${this._actionChanged}
|
></ha-automation-action-row>
|
||||||
.hass=${this.hass}
|
`
|
||||||
>
|
)}
|
||||||
${this.reOrderMode
|
<ha-button-menu fixed @action=${this._addAction}>
|
||||||
? html`
|
|
||||||
<ha-icon-button
|
|
||||||
.index=${idx}
|
|
||||||
slot="icons"
|
|
||||||
.label=${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.move_up"
|
|
||||||
)}
|
|
||||||
.path=${mdiArrowUp}
|
|
||||||
@click=${this._moveUp}
|
|
||||||
.disabled=${idx === 0}
|
|
||||||
></ha-icon-button>
|
|
||||||
<ha-icon-button
|
|
||||||
.index=${idx}
|
|
||||||
slot="icons"
|
|
||||||
.label=${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.move_down"
|
|
||||||
)}
|
|
||||||
.path=${mdiArrowDown}
|
|
||||||
@click=${this._moveDown}
|
|
||||||
.disabled=${idx === this.actions.length - 1}
|
|
||||||
></ha-icon-button>
|
|
||||||
<div class="handle" slot="icons">
|
|
||||||
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
|
|
||||||
</div>
|
|
||||||
`
|
|
||||||
: ""}
|
|
||||||
</ha-automation-action-row>
|
|
||||||
`
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<ha-button-menu
|
|
||||||
fixed
|
|
||||||
@action=${this._addAction}
|
|
||||||
.disabled=${this.disabled}
|
|
||||||
>
|
|
||||||
<mwc-button
|
<mwc-button
|
||||||
slot="trigger"
|
slot="trigger"
|
||||||
outlined
|
outlined
|
||||||
.disabled=${this.disabled}
|
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.actions.add"
|
"ui.panel.config.automation.editor.actions.add"
|
||||||
)}
|
)}
|
||||||
@@ -134,13 +86,6 @@ export default class HaAutomationAction extends LitElement {
|
|||||||
protected updated(changedProps: PropertyValues) {
|
protected updated(changedProps: PropertyValues) {
|
||||||
super.updated(changedProps);
|
super.updated(changedProps);
|
||||||
|
|
||||||
if (changedProps.has("reOrderMode")) {
|
|
||||||
if (this.reOrderMode) {
|
|
||||||
this._createSortable();
|
|
||||||
} else {
|
|
||||||
this._destroySortable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (changedProps.has("actions") && this._focusLastActionOnChange) {
|
if (changedProps.has("actions") && this._focusLastActionOnChange) {
|
||||||
this._focusLastActionOnChange = false;
|
this._focusLastActionOnChange = false;
|
||||||
|
|
||||||
@@ -155,33 +100,6 @@ export default class HaAutomationAction extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _createSortable() {
|
|
||||||
const Sortable = await loadSortable();
|
|
||||||
this._sortable = new Sortable(this.shadowRoot!.querySelector(".actions")!, {
|
|
||||||
animation: 150,
|
|
||||||
fallbackClass: "sortable-fallback",
|
|
||||||
handle: ".handle",
|
|
||||||
onChoose: (evt: SortableEvent) => {
|
|
||||||
(evt.item as any).placeholder =
|
|
||||||
document.createComment("sort-placeholder");
|
|
||||||
evt.item.after((evt.item as any).placeholder);
|
|
||||||
},
|
|
||||||
onEnd: (evt: SortableEvent) => {
|
|
||||||
// put back in original location
|
|
||||||
if ((evt.item as any).placeholder) {
|
|
||||||
(evt.item as any).placeholder.replaceWith(evt.item);
|
|
||||||
delete (evt.item as any).placeholder;
|
|
||||||
}
|
|
||||||
this._dragged(evt);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private _destroySortable() {
|
|
||||||
this._sortable?.destroy();
|
|
||||||
this._sortable = undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _getKey(action: Action) {
|
private _getKey(action: Action) {
|
||||||
if (!this._actionKeys.has(action)) {
|
if (!this._actionKeys.has(action)) {
|
||||||
this._actionKeys.set(action, Math.random().toString());
|
this._actionKeys.set(action, Math.random().toString());
|
||||||
@@ -203,24 +121,12 @@ export default class HaAutomationAction extends LitElement {
|
|||||||
fireEvent(this, "value-changed", { value: actions });
|
fireEvent(this, "value-changed", { value: actions });
|
||||||
}
|
}
|
||||||
|
|
||||||
private _moveUp(ev) {
|
private _move(ev: CustomEvent) {
|
||||||
|
// Prevent possible parent action-row from also moving
|
||||||
|
ev.stopPropagation();
|
||||||
|
|
||||||
const index = (ev.target as any).index;
|
const index = (ev.target as any).index;
|
||||||
const newIndex = index - 1;
|
const newIndex = ev.detail.direction === "up" ? index - 1 : index + 1;
|
||||||
this._move(index, newIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
private _moveDown(ev) {
|
|
||||||
const index = (ev.target as any).index;
|
|
||||||
const newIndex = index + 1;
|
|
||||||
this._move(index, newIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
private _dragged(ev: SortableEvent): void {
|
|
||||||
if (ev.oldIndex === ev.newIndex) return;
|
|
||||||
this._move(ev.oldIndex!, ev.newIndex!);
|
|
||||||
}
|
|
||||||
|
|
||||||
private _move(index: number, newIndex: number) {
|
|
||||||
const actions = this.actions.concat();
|
const actions = this.actions.concat();
|
||||||
const action = actions.splice(index, 1)[0];
|
const action = actions.splice(index, 1)[0];
|
||||||
actions.splice(newIndex, 0, action);
|
actions.splice(newIndex, 0, action);
|
||||||
@@ -271,27 +177,16 @@ export default class HaAutomationAction extends LitElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return css`
|
||||||
sortableStyles,
|
ha-automation-action-row {
|
||||||
css`
|
display: block;
|
||||||
ha-automation-action-row {
|
margin-bottom: 16px;
|
||||||
display: block;
|
scroll-margin-top: 48px;
|
||||||
margin-bottom: 16px;
|
}
|
||||||
scroll-margin-top: 48px;
|
ha-svg-icon {
|
||||||
}
|
height: 20px;
|
||||||
ha-svg-icon {
|
}
|
||||||
height: 20px;
|
`;
|
||||||
}
|
|
||||||
.handle {
|
|
||||||
cursor: move;
|
|
||||||
padding: 12px;
|
|
||||||
}
|
|
||||||
.handle ha-svg-icon {
|
|
||||||
pointer-events: none;
|
|
||||||
height: 24px;
|
|
||||||
}
|
|
||||||
`,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user