mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-13 13:00:24 +00:00
Compare commits
175 Commits
fix-entity
...
pr/13837
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72ad0f0f61 | ||
|
|
95bbf6e0d2 | ||
|
|
e31d1aace0 | ||
|
|
726ed32626 | ||
|
|
87dedeb9b3 | ||
|
|
0f534423a4 | ||
|
|
131957fbb3 | ||
|
|
f9d119d33d | ||
|
|
d3b97ae91c | ||
|
|
5146fa1d9e | ||
|
|
fc86a66c33 | ||
|
|
3959a7475c | ||
|
|
61d09072a7 | ||
|
|
4a07d3d39b | ||
|
|
be30cdb51f | ||
|
|
894258d7b8 | ||
|
|
296d5f8ffe | ||
|
|
d1c2020ee4 | ||
|
|
3c1b2aa4f3 | ||
|
|
17a11809de | ||
|
|
3083d5b04c | ||
|
|
0848c096b9 | ||
|
|
8d5c36a96a | ||
|
|
cc76a6c5ed | ||
|
|
01fd2787be | ||
|
|
c79955e76a | ||
|
|
51874329d1 | ||
|
|
6252955bb5 | ||
|
|
5422fda990 | ||
|
|
db8bc9d34a | ||
|
|
9f19bdde65 | ||
|
|
7336c1280f | ||
|
|
8e245c8a83 | ||
|
|
5a150ac80d | ||
|
|
eac13980ff | ||
|
|
977fdd9fbb | ||
|
|
cedde3d6a2 | ||
|
|
56c78ae108 | ||
|
|
82a641a200 | ||
|
|
04181e9c28 | ||
|
|
4b8960c236 | ||
|
|
fc104e7280 | ||
|
|
8c125f4dee | ||
|
|
b93f457d53 | ||
|
|
e8ce6ad919 | ||
|
|
0ce695577c | ||
|
|
50b67751d9 | ||
|
|
05515f21c3 | ||
|
|
063c377797 | ||
|
|
aee11da671 | ||
|
|
5fcb219fcd | ||
|
|
a97dfbb51f | ||
|
|
c5f4e8ffdd | ||
|
|
7ffd30643a | ||
|
|
dcfcd54f10 | ||
|
|
3b103619ec | ||
|
|
614c1574ca | ||
|
|
e1e3f9d925 | ||
|
|
0ba4a07b92 | ||
|
|
5a5f31b32c | ||
|
|
ff92768973 | ||
|
|
bb0529ecd2 | ||
|
|
bc62e9372b | ||
|
|
087a897cbe | ||
|
|
589efa8cc5 | ||
|
|
c93179c307 | ||
|
|
9e416e829c | ||
|
|
e13c632afa | ||
|
|
544c8fe3bb | ||
|
|
81b21f874b | ||
|
|
ea319d55ef | ||
|
|
8c03bbdccc | ||
|
|
321914d53a | ||
|
|
490d46396e | ||
|
|
3c62bc9b18 | ||
|
|
48b10005e3 | ||
|
|
b3d64fc52a | ||
|
|
23e5a47b3b | ||
|
|
5d4c090b26 | ||
|
|
b84240edbc | ||
|
|
f4dc74b2e8 | ||
|
|
c95d19299b | ||
|
|
7696df56ac | ||
|
|
771733d326 | ||
|
|
4f3c708109 | ||
|
|
d2078a7e50 | ||
|
|
d70cb24722 | ||
|
|
6902537666 | ||
|
|
9ea1f61971 | ||
|
|
782c95cf04 | ||
|
|
d5d6216cfe | ||
|
|
1086c85964 | ||
|
|
47c0901df2 | ||
|
|
d323ab6726 | ||
|
|
07b5856190 | ||
|
|
462dee0351 | ||
|
|
f181a085de | ||
|
|
bf5589b88d | ||
|
|
fd431f36f7 | ||
|
|
7acf3a049e | ||
|
|
cfb0e8b39e | ||
|
|
a3abbf3812 | ||
|
|
980156d23a | ||
|
|
37c2a3636e | ||
|
|
b682d13486 | ||
|
|
7f82b90c25 | ||
|
|
3e9d6ea2c5 | ||
|
|
57c5c1c191 | ||
|
|
b553a3fd92 | ||
|
|
d1964e92ea | ||
|
|
a889969bb8 | ||
|
|
f80b2c578b | ||
|
|
d13c6d3e7b | ||
|
|
e78c875e8e | ||
|
|
5e8c54b00f | ||
|
|
71bc74893f | ||
|
|
df72e5099e | ||
|
|
e6862daa38 | ||
|
|
66db8c999f | ||
|
|
00bc315fc1 | ||
|
|
f461825a59 | ||
|
|
8c98326e31 | ||
|
|
7bb619b0c3 | ||
|
|
07bc9081b8 | ||
|
|
91fa5972d1 | ||
|
|
ccd617d68e | ||
|
|
8a7f35cee6 | ||
|
|
e510e5b371 | ||
|
|
aa6ee0f6d2 | ||
|
|
f3449c4d9b | ||
|
|
3c289deb21 | ||
|
|
847d163cc8 | ||
|
|
28d11703fc | ||
|
|
1f003ae3be | ||
|
|
a57d7813e7 | ||
|
|
5842b10a10 | ||
|
|
8ee9655bd5 | ||
|
|
3ef567dcd5 | ||
|
|
37f6b4f6be | ||
|
|
a817faae54 | ||
|
|
ab745f6e8e | ||
|
|
02d608b704 | ||
|
|
310df387e7 | ||
|
|
fe8e79a67f | ||
|
|
8ffe676827 | ||
|
|
f032d0dbcf | ||
|
|
81cc745c0a | ||
|
|
43f9c9ebc9 | ||
|
|
a9d1feb196 | ||
|
|
72aea57105 | ||
|
|
031ecf5be8 | ||
|
|
93e7927686 | ||
|
|
320d8e6190 | ||
|
|
efa4f65686 | ||
|
|
ec257710ff | ||
|
|
ffad6f340f | ||
|
|
9f9b0b6457 | ||
|
|
a4227680de | ||
|
|
5cfd263617 | ||
|
|
430e671901 | ||
|
|
8fcd396445 | ||
|
|
e273b6b659 | ||
|
|
2751adf440 | ||
|
|
d661450121 | ||
|
|
4511ded205 | ||
|
|
2bf0c5d72d | ||
|
|
604e5d5e09 | ||
|
|
774aee406c | ||
|
|
775837b60f | ||
|
|
030b2b921a | ||
|
|
229bc26327 | ||
|
|
99e85173eb | ||
|
|
be0c22d7ae | ||
|
|
fee1092a08 | ||
|
|
d041bd9fd3 |
4
.github/workflows/demo.yaml
vendored
4
.github/workflows/demo.yaml
vendored
@@ -27,9 +27,7 @@ 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
|
||||||
uses: netlify/actions/cli@master
|
run: npx netlify-cli deploy --dir=demo/dist --prod
|
||||||
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@v5.1.1
|
uses: actions/stale@v6.0.0
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
days-before-stale: 90
|
days-before-stale: 90
|
||||||
|
|||||||
@@ -61,12 +61,14 @@ 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",
|
||||||
@@ -74,12 +76,14 @@ 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,14 +11,12 @@ 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,
|
||||||
},
|
},
|
||||||
@@ -27,14 +25,12 @@ 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,
|
||||||
},
|
},
|
||||||
@@ -55,7 +51,6 @@ 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/history";
|
import { StatisticValue } from "../../../src/data/recorder";
|
||||||
import { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
import { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
||||||
|
|
||||||
interface HistoryQueryParams {
|
interface HistoryQueryParams {
|
||||||
|
|||||||
56
gallery/src/pages/Text/remove-delete-add-create.markdown
Normal file
56
gallery/src/pages/Text/remove-delete-add-create.markdown
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
---
|
||||||
|
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).
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
---
|
---
|
||||||
title: Dialgos
|
title: Dialogs
|
||||||
subtitle: Dialogs provide important prompts in a user flow.
|
subtitle: Dialogs provide important prompts in a user flow.
|
||||||
---
|
---
|
||||||
|
|
||||||
# Material Desing 3
|
# Material Design 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,6 +195,48 @@ 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,10 +191,12 @@ 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,16 +1,7 @@
|
|||||||
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 {
|
import { CoverEntityFeature } from "../../../../src/data/cover";
|
||||||
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 {
|
||||||
@@ -22,113 +13,127 @@ 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: SUPPORT_OPEN + SUPPORT_STOP + SUPPORT_CLOSE,
|
supported_features:
|
||||||
|
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:
|
||||||
SUPPORT_OPEN + SUPPORT_STOP + SUPPORT_CLOSE + SUPPORT_SET_POSITION,
|
CoverEntityFeature.OPEN +
|
||||||
|
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:
|
||||||
SUPPORT_OPEN + SUPPORT_STOP + SUPPORT_CLOSE + SUPPORT_SET_POSITION,
|
CoverEntityFeature.OPEN +
|
||||||
|
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:
|
||||||
SUPPORT_OPEN + SUPPORT_STOP + SUPPORT_CLOSE + SUPPORT_SET_POSITION,
|
CoverEntityFeature.OPEN +
|
||||||
|
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:
|
||||||
SUPPORT_OPEN_TILT + SUPPORT_STOP_TILT + SUPPORT_CLOSE_TILT,
|
CoverEntityFeature.OPEN_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:
|
||||||
SUPPORT_OPEN_TILT +
|
CoverEntityFeature.OPEN_TILT +
|
||||||
SUPPORT_STOP_TILT +
|
CoverEntityFeature.STOP_TILT +
|
||||||
SUPPORT_CLOSE_TILT +
|
CoverEntityFeature.CLOSE_TILT +
|
||||||
SUPPORT_SET_TILT_POSITION,
|
CoverEntityFeature.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:
|
||||||
SUPPORT_OPEN_TILT +
|
CoverEntityFeature.OPEN_TILT +
|
||||||
SUPPORT_STOP_TILT +
|
CoverEntityFeature.STOP_TILT +
|
||||||
SUPPORT_CLOSE_TILT +
|
CoverEntityFeature.CLOSE_TILT +
|
||||||
SUPPORT_SET_TILT_POSITION,
|
CoverEntityFeature.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:
|
||||||
SUPPORT_OPEN_TILT +
|
CoverEntityFeature.OPEN_TILT +
|
||||||
SUPPORT_STOP_TILT +
|
CoverEntityFeature.STOP_TILT +
|
||||||
SUPPORT_CLOSE_TILT +
|
CoverEntityFeature.CLOSE_TILT +
|
||||||
SUPPORT_SET_TILT_POSITION,
|
CoverEntityFeature.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:
|
||||||
SUPPORT_OPEN +
|
CoverEntityFeature.OPEN +
|
||||||
SUPPORT_STOP +
|
CoverEntityFeature.STOP +
|
||||||
SUPPORT_CLOSE +
|
CoverEntityFeature.CLOSE +
|
||||||
SUPPORT_SET_POSITION +
|
CoverEntityFeature.SET_POSITION +
|
||||||
SUPPORT_OPEN_TILT +
|
CoverEntityFeature.OPEN_TILT +
|
||||||
SUPPORT_STOP_TILT +
|
CoverEntityFeature.STOP_TILT +
|
||||||
SUPPORT_CLOSE_TILT +
|
CoverEntityFeature.CLOSE_TILT +
|
||||||
SUPPORT_SET_TILT_POSITION,
|
CoverEntityFeature.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:
|
||||||
SUPPORT_OPEN +
|
CoverEntityFeature.OPEN +
|
||||||
SUPPORT_STOP +
|
CoverEntityFeature.STOP +
|
||||||
SUPPORT_CLOSE +
|
CoverEntityFeature.CLOSE +
|
||||||
SUPPORT_OPEN_TILT +
|
CoverEntityFeature.OPEN_TILT +
|
||||||
SUPPORT_STOP_TILT +
|
CoverEntityFeature.STOP_TILT +
|
||||||
SUPPORT_CLOSE_TILT +
|
CoverEntityFeature.CLOSE_TILT +
|
||||||
SUPPORT_SET_TILT_POSITION,
|
CoverEntityFeature.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:
|
||||||
SUPPORT_OPEN +
|
CoverEntityFeature.OPEN +
|
||||||
SUPPORT_STOP +
|
CoverEntityFeature.STOP +
|
||||||
SUPPORT_CLOSE +
|
CoverEntityFeature.CLOSE +
|
||||||
SUPPORT_SET_POSITION +
|
CoverEntityFeature.SET_POSITION +
|
||||||
SUPPORT_OPEN_TILT +
|
CoverEntityFeature.OPEN_TILT +
|
||||||
SUPPORT_STOP_TILT +
|
CoverEntityFeature.STOP_TILT +
|
||||||
SUPPORT_CLOSE_TILT,
|
CoverEntityFeature.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:
|
||||||
SUPPORT_SET_POSITION +
|
CoverEntityFeature.SET_POSITION +
|
||||||
SUPPORT_OPEN_TILT +
|
CoverEntityFeature.OPEN_TILT +
|
||||||
SUPPORT_STOP_TILT +
|
CoverEntityFeature.STOP_TILT +
|
||||||
SUPPORT_CLOSE_TILT,
|
CoverEntityFeature.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:
|
||||||
SUPPORT_SET_POSITION +
|
CoverEntityFeature.SET_POSITION +
|
||||||
SUPPORT_OPEN_TILT +
|
CoverEntityFeature.OPEN_TILT +
|
||||||
SUPPORT_STOP_TILT +
|
CoverEntityFeature.STOP_TILT +
|
||||||
SUPPORT_CLOSE_TILT +
|
CoverEntityFeature.CLOSE_TILT +
|
||||||
SUPPORT_SET_TILT_POSITION,
|
CoverEntityFeature.SET_TILT_POSITION,
|
||||||
current_position: 30,
|
current_position: 30,
|
||||||
current_tilt_position: 70,
|
current_tilt_position: 70,
|
||||||
}),
|
}),
|
||||||
|
|||||||
3
gallery/src/pages/more-info/input-number.markdown
Normal file
3
gallery/src/pages/more-info/input-number.markdown
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
title: Input Number
|
||||||
|
---
|
||||||
60
gallery/src/pages/more-info/input-number.ts
Normal file
60
gallery/src/pages/more-info/input-number.ts
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
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,12 +1,7 @@
|
|||||||
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 {
|
import { LightColorMode, LightEntityFeature } from "../../../../src/data/light";
|
||||||
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 {
|
||||||
@@ -22,8 +17,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: [LightColorModes.BRIGHTNESS],
|
supported_color_modes: [LightColorMode.BRIGHTNESS],
|
||||||
color_mode: LightColorModes.BRIGHTNESS,
|
color_mode: LightColorMode.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",
|
||||||
@@ -32,10 +27,10 @@ const ENTITIES = [
|
|||||||
min_mireds: 30,
|
min_mireds: 30,
|
||||||
max_mireds: 150,
|
max_mireds: 150,
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorModes.BRIGHTNESS,
|
LightColorMode.BRIGHTNESS,
|
||||||
LightColorModes.COLOR_TEMP,
|
LightColorMode.COLOR_TEMP,
|
||||||
],
|
],
|
||||||
color_mode: LightColorModes.COLOR_TEMP,
|
color_mode: LightColorMode.COLOR_TEMP,
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_hs_light", "on", {
|
getEntity("light", "color_hs_light", "on", {
|
||||||
friendly_name: "Color HS Light",
|
friendly_name: "Color HS Light",
|
||||||
@@ -44,13 +39,16 @@ 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: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
supported_features:
|
||||||
|
LightEntityFeature.EFFECT +
|
||||||
|
LightEntityFeature.FLASH +
|
||||||
|
LightEntityFeature.TRANSITION,
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorModes.BRIGHTNESS,
|
LightColorMode.BRIGHTNESS,
|
||||||
LightColorModes.COLOR_TEMP,
|
LightColorMode.COLOR_TEMP,
|
||||||
LightColorModes.HS,
|
LightColorMode.HS,
|
||||||
],
|
],
|
||||||
color_mode: LightColorModes.HS,
|
color_mode: LightColorMode.HS,
|
||||||
effect_list: ["random", "colorloop"],
|
effect_list: ["random", "colorloop"],
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_rgb_ct_light", "on", {
|
getEntity("light", "color_rgb_ct_light", "on", {
|
||||||
@@ -59,22 +57,28 @@ const ENTITIES = [
|
|||||||
color_temp: 75,
|
color_temp: 75,
|
||||||
min_mireds: 30,
|
min_mireds: 30,
|
||||||
max_mireds: 150,
|
max_mireds: 150,
|
||||||
supported_features: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
supported_features:
|
||||||
|
LightEntityFeature.EFFECT +
|
||||||
|
LightEntityFeature.FLASH +
|
||||||
|
LightEntityFeature.TRANSITION,
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorModes.BRIGHTNESS,
|
LightColorMode.BRIGHTNESS,
|
||||||
LightColorModes.COLOR_TEMP,
|
LightColorMode.COLOR_TEMP,
|
||||||
LightColorModes.RGB,
|
LightColorMode.RGB,
|
||||||
],
|
],
|
||||||
color_mode: LightColorModes.COLOR_TEMP,
|
color_mode: LightColorMode.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: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
supported_features:
|
||||||
supported_color_modes: [LightColorModes.BRIGHTNESS, LightColorModes.RGB],
|
LightEntityFeature.EFFECT +
|
||||||
color_mode: LightColorModes.RGB,
|
LightEntityFeature.FLASH +
|
||||||
|
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", {
|
||||||
@@ -83,13 +87,16 @@ 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: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
supported_features:
|
||||||
|
LightEntityFeature.EFFECT +
|
||||||
|
LightEntityFeature.FLASH +
|
||||||
|
LightEntityFeature.TRANSITION,
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorModes.BRIGHTNESS,
|
LightColorMode.BRIGHTNESS,
|
||||||
LightColorModes.COLOR_TEMP,
|
LightColorMode.COLOR_TEMP,
|
||||||
LightColorModes.RGBW,
|
LightColorMode.RGBW,
|
||||||
],
|
],
|
||||||
color_mode: LightColorModes.RGBW,
|
color_mode: LightColorMode.RGBW,
|
||||||
effect_list: ["random", "colorloop"],
|
effect_list: ["random", "colorloop"],
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_rgbww_light", "on", {
|
getEntity("light", "color_rgbww_light", "on", {
|
||||||
@@ -98,13 +105,16 @@ 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: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
supported_features:
|
||||||
|
LightEntityFeature.EFFECT +
|
||||||
|
LightEntityFeature.FLASH +
|
||||||
|
LightEntityFeature.TRANSITION,
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorModes.BRIGHTNESS,
|
LightColorMode.BRIGHTNESS,
|
||||||
LightColorModes.COLOR_TEMP,
|
LightColorMode.COLOR_TEMP,
|
||||||
LightColorModes.RGBWW,
|
LightColorMode.RGBWW,
|
||||||
],
|
],
|
||||||
color_mode: LightColorModes.RGBWW,
|
color_mode: LightColorMode.RGBWW,
|
||||||
effect_list: ["random", "colorloop"],
|
effect_list: ["random", "colorloop"],
|
||||||
}),
|
}),
|
||||||
getEntity("light", "color_xy_light", "on", {
|
getEntity("light", "color_xy_light", "on", {
|
||||||
@@ -114,13 +124,16 @@ 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: SUPPORT_EFFECT + SUPPORT_FLASH + SUPPORT_TRANSITION,
|
supported_features:
|
||||||
|
LightEntityFeature.EFFECT +
|
||||||
|
LightEntityFeature.FLASH +
|
||||||
|
LightEntityFeature.TRANSITION,
|
||||||
supported_color_modes: [
|
supported_color_modes: [
|
||||||
LightColorModes.BRIGHTNESS,
|
LightColorMode.BRIGHTNESS,
|
||||||
LightColorModes.COLOR_TEMP,
|
LightColorMode.COLOR_TEMP,
|
||||||
LightColorModes.XY,
|
LightColorMode.XY,
|
||||||
],
|
],
|
||||||
color_mode: LightColorModes.XY,
|
color_mode: LightColorMode.XY,
|
||||||
effect_list: ["random", "colorloop"],
|
effect_list: ["random", "colorloop"],
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1024,10 +1024,13 @@ class HassioAddonInfo extends LitElement {
|
|||||||
button.progress = true;
|
button.progress = true;
|
||||||
|
|
||||||
const confirmed = await showConfirmationDialog(this, {
|
const confirmed = await showConfirmationDialog(this, {
|
||||||
title: this.addon.name,
|
title: this.supervisor.localize("dialog.uninstall_addon.title", {
|
||||||
text: "Are you sure you want to uninstall this add-on?",
|
name: this.addon.name,
|
||||||
confirmText: "uninstall add-on",
|
}),
|
||||||
dismissText: "no",
|
text: this.supervisor.localize("dialog.uninstall_addon.text"),
|
||||||
|
confirmText: this.supervisor.localize("dialog.uninstall_addon.uninstall"),
|
||||||
|
dismissText: this.supervisor.localize("common.cancel"),
|
||||||
|
destructive: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!confirmed) {
|
if (!confirmed) {
|
||||||
|
|||||||
@@ -18,9 +18,11 @@ 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("common.restart_name", "name", addon.name),
|
title: supervisor.localize("dialog.restart_addon.title", {
|
||||||
|
name: addon.name,
|
||||||
|
}),
|
||||||
text: supervisor.localize("dialog.restart_addon.text"),
|
text: supervisor.localize("dialog.restart_addon.text"),
|
||||||
confirmText: supervisor.localize("dialog.restart_addon.confirm_text"),
|
confirmText: supervisor.localize("dialog.restart_addon.restart"),
|
||||||
dismissText: supervisor.localize("common.cancel"),
|
dismissText: supervisor.localize("common.cancel"),
|
||||||
});
|
});
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
@@ -28,11 +30,9 @@ 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(
|
title: supervisor.localize("common.failed_to_restart_name", {
|
||||||
"common.failed_to_restart_name",
|
name: addon.name,
|
||||||
"name",
|
}),
|
||||||
addon.name
|
|
||||||
),
|
|
||||||
text: extractApiErrorMessage(err),
|
text: extractApiErrorMessage(err),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ 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,
|
||||||
@@ -230,36 +231,27 @@ class HassioSupervisorInfo extends LitElement {
|
|||||||
button.progress = true;
|
button.progress = true;
|
||||||
|
|
||||||
if (this.supervisor.supervisor.channel === "stable") {
|
if (this.supervisor.supervisor.channel === "stable") {
|
||||||
const confirmed = await showConfirmationDialog(this, {
|
showJoinBetaDialog(this, {
|
||||||
title: this.supervisor.localize("system.supervisor.warning"),
|
join: async () => {
|
||||||
text: html`${this.supervisor.localize("system.supervisor.beta_warning")}
|
await this._setChannel("beta");
|
||||||
<br />
|
button.progress = false;
|
||||||
<b> ${this.supervisor.localize("system.supervisor.beta_backup")} </b>
|
},
|
||||||
<br /><br />
|
cancel: () => {
|
||||||
${this.supervisor.localize("system.supervisor.beta_release_items")}
|
button.progress = false;
|
||||||
<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 {
|
||||||
if (!confirmed) {
|
await this._setChannel("stable");
|
||||||
button.progress = false;
|
button.progress = false;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _setChannel(
|
||||||
|
channel: SupervisorOptions["channel"]
|
||||||
|
): Promise<void> {
|
||||||
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();
|
||||||
@@ -270,8 +262,6 @@ 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.1.5",
|
"@vaadin/combo-box": "^23.2.0",
|
||||||
"@vaadin/vaadin-themable-mixin": "^23.1.5",
|
"@vaadin/vaadin-themable-mixin": "^23.2.0",
|
||||||
"@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.1",
|
"hls.js": "^1.2.3",
|
||||||
"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 = "20220816.0"
|
version = "20220907.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,6 +46,14 @@ 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,6 +6,7 @@ import {
|
|||||||
mdiAlert,
|
mdiAlert,
|
||||||
mdiAngleAcute,
|
mdiAngleAcute,
|
||||||
mdiAppleSafari,
|
mdiAppleSafari,
|
||||||
|
mdiArrowLeftRight,
|
||||||
mdiBell,
|
mdiBell,
|
||||||
mdiBookmark,
|
mdiBookmark,
|
||||||
mdiBrightness5,
|
mdiBrightness5,
|
||||||
@@ -25,7 +26,6 @@ import {
|
|||||||
mdiFlower,
|
mdiFlower,
|
||||||
mdiFormatListBulleted,
|
mdiFormatListBulleted,
|
||||||
mdiFormTextbox,
|
mdiFormTextbox,
|
||||||
mdiGasCylinder,
|
|
||||||
mdiGauge,
|
mdiGauge,
|
||||||
mdiGestureTapButton,
|
mdiGestureTapButton,
|
||||||
mdiGoogleAssistant,
|
mdiGoogleAssistant,
|
||||||
@@ -37,6 +37,8 @@ import {
|
|||||||
mdiLightningBolt,
|
mdiLightningBolt,
|
||||||
mdiMailbox,
|
mdiMailbox,
|
||||||
mdiMapMarkerRadius,
|
mdiMapMarkerRadius,
|
||||||
|
mdiMeterGas,
|
||||||
|
mdiMicrophoneMessage,
|
||||||
mdiMolecule,
|
mdiMolecule,
|
||||||
mdiMoleculeCo,
|
mdiMoleculeCo,
|
||||||
mdiMoleculeCo2,
|
mdiMoleculeCo2,
|
||||||
@@ -47,13 +49,14 @@ import {
|
|||||||
mdiRobotVacuum,
|
mdiRobotVacuum,
|
||||||
mdiScriptText,
|
mdiScriptText,
|
||||||
mdiSineWave,
|
mdiSineWave,
|
||||||
mdiMicrophoneMessage,
|
mdiSpeedometer,
|
||||||
mdiThermometer,
|
mdiThermometer,
|
||||||
mdiThermostat,
|
mdiThermostat,
|
||||||
mdiTimerOutline,
|
mdiTimerOutline,
|
||||||
mdiVideo,
|
mdiVideo,
|
||||||
mdiWaterPercent,
|
mdiWaterPercent,
|
||||||
mdiWeatherCloudy,
|
mdiWeatherCloudy,
|
||||||
|
mdiWeight,
|
||||||
mdiWhiteBalanceSunny,
|
mdiWhiteBalanceSunny,
|
||||||
mdiWifi,
|
mdiWifi,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
@@ -121,11 +124,13 @@ 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: mdiGasCylinder,
|
gas: mdiMeterGas,
|
||||||
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,
|
||||||
@@ -139,11 +144,14 @@ 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. */
|
||||||
|
|||||||
28
src/common/datetime/format_duration.ts
Normal file
28
src/common/datetime/format_duration.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
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,17 +2,18 @@ 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 {
|
||||||
UPDATE_SUPPORT_PROGRESS,
|
|
||||||
updateIsInstallingFromAttributes,
|
updateIsInstallingFromAttributes,
|
||||||
|
UPDATE_SUPPORT_PROGRESS,
|
||||||
} 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 { supportsFeatureFromAttributes } from "./supports-feature";
|
|
||||||
import { formatDuration, UNIT_TO_SECOND_CONVERT } from "../datetime/duration";
|
|
||||||
import { computeDomain } from "./compute_domain";
|
import { computeDomain } from "./compute_domain";
|
||||||
|
import { supportsFeatureFromAttributes } from "./supports-feature";
|
||||||
|
|
||||||
export const computeStateDisplay = (
|
export const computeStateDisplay = (
|
||||||
localize: LocalizeFunc,
|
localize: LocalizeFunc,
|
||||||
@@ -67,7 +68,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,10 +1,14 @@
|
|||||||
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: { [feature: number]: string }
|
classNames: FeatureClassNames
|
||||||
) => {
|
) => {
|
||||||
if (!stateObj || !stateObj.attributes.supported_features) {
|
if (!stateObj || !stateObj.attributes.supported_features) {
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ 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: [
|
||||||
@@ -239,10 +240,13 @@ export const getStates = (
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "light":
|
case "light":
|
||||||
if (attribute === "effect") {
|
if (attribute === "effect" && state.attributes.effect_list) {
|
||||||
result.push(...state.attributes.effect_list);
|
result.push(...state.attributes.effect_list);
|
||||||
} else if (attribute === "color_mode") {
|
} else if (
|
||||||
result.push(...state.attributes.color_modes);
|
attribute === "color_mode" &&
|
||||||
|
state.attributes.supported_color_modes
|
||||||
|
) {
|
||||||
|
result.push(...state.attributes.supported_color_modes);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "media_player":
|
case "media_player":
|
||||||
|
|||||||
4
src/common/string/title-case.ts
Normal file
4
src/common/string/title-case.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export const titleCase = (s) =>
|
||||||
|
s.replace(/^_*(.)|_+(.)/g, (_s, c, d) =>
|
||||||
|
c ? c.toUpperCase() : " " + d.toUpperCase()
|
||||||
|
);
|
||||||
18
src/common/translations/blank_before_percent.ts
Normal file
18
src/common/translations/blank_before_percent.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
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,6 +13,7 @@ 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 {
|
||||||
@@ -20,31 +21,37 @@ import {
|
|||||||
numberFormatToLocale,
|
numberFormatToLocale,
|
||||||
} from "../../common/number/format_number";
|
} from "../../common/number/format_number";
|
||||||
import {
|
import {
|
||||||
getStatisticIds,
|
|
||||||
getStatisticLabel,
|
getStatisticLabel,
|
||||||
|
getStatisticMetadata,
|
||||||
Statistics,
|
Statistics,
|
||||||
statisticsHaveType,
|
statisticsHaveType,
|
||||||
StatisticsMetaData,
|
|
||||||
StatisticType,
|
StatisticType,
|
||||||
} from "../../data/history";
|
} from "../../data/recorder";
|
||||||
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<StatisticType> = [
|
@property({ type: Array }) public statTypes: Array<ExtendedStatisticType> = [
|
||||||
"sum",
|
"sum",
|
||||||
"min",
|
"min",
|
||||||
"mean",
|
"mean",
|
||||||
@@ -191,18 +198,28 @@ class StatisticsChart extends LitElement {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _getStatisticIds() {
|
private _getStatisticsMetaData = memoizeOne(
|
||||||
this.statisticIds = await getStatisticIds(this.hass);
|
async (statisticIds: string[] | undefined) => {
|
||||||
}
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.statisticIds) {
|
const statisticsMetaData = await this._getStatisticsMetaData(
|
||||||
await this._getStatisticIds();
|
Object.keys(this.statisticsData)
|
||||||
}
|
);
|
||||||
|
|
||||||
let colorIndex = 0;
|
let colorIndex = 0;
|
||||||
const statisticsData = Object.values(this.statisticsData);
|
const statisticsData = Object.values(this.statisticsData);
|
||||||
@@ -233,9 +250,7 @@ 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 = this.statisticIds!.find(
|
const meta = statisticsMetaData?.[firstStat.statistic_id];
|
||||||
(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);
|
||||||
@@ -301,7 +316,7 @@ class StatisticsChart extends LitElement {
|
|||||||
: this.statTypes;
|
: this.statTypes;
|
||||||
|
|
||||||
sortedTypes.forEach((type) => {
|
sortedTypes.forEach((type) => {
|
||||||
if (statisticsHaveType(stats, type)) {
|
if (statisticsHaveType(stats, statTypeMap[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({
|
||||||
@@ -329,7 +344,6 @@ 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);
|
||||||
@@ -341,11 +355,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 (initVal === null) {
|
if (prevSum === null) {
|
||||||
initVal = val = stat.state || 0;
|
val = 0;
|
||||||
prevSum = stat.sum;
|
prevSum = stat.sum;
|
||||||
} else {
|
} else {
|
||||||
val = initVal + ((stat.sum || 0) - prevSum!);
|
val = (stat.sum || 0) - prevSum;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val = stat[type];
|
val = stat[type];
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ 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;
|
||||||
|
|
||||||
@@ -55,7 +57,7 @@ class HaEntityStatePicker extends LitElement {
|
|||||||
this.hass.locale,
|
this.hass.locale,
|
||||||
key
|
key
|
||||||
)
|
)
|
||||||
: key,
|
: formatAttributeValue(this.hass, key),
|
||||||
}))
|
}))
|
||||||
: [];
|
: [];
|
||||||
}
|
}
|
||||||
@@ -69,16 +71,7 @@ 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")}
|
||||||
@@ -95,12 +88,28 @@ 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>) {
|
||||||
this.value = ev.detail.value;
|
ev.stopPropagation();
|
||||||
|
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,10 +3,11 @@ 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 { computeStateName } from "../../common/entity/compute_state_name";
|
||||||
import { stringCompare } from "../../common/string/compare";
|
import { stringCompare } from "../../common/string/compare";
|
||||||
import { getStatisticIds, StatisticsMetaData } from "../../data/history";
|
import { getStatisticIds, 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";
|
||||||
@@ -39,22 +40,20 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
type: Array,
|
type: Array,
|
||||||
attribute: "include-statistics-unit-of-measurement",
|
attribute: "include-statistics-unit-of-measurement",
|
||||||
})
|
})
|
||||||
public includeStatisticsUnitOfMeasurement?: string[];
|
public includeStatisticsUnitOfMeasurement?: string | string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show only statistics displayed with these units of measurements.
|
* Show only statistics displayed with these units of measurements.
|
||||||
* @type {Array}
|
|
||||||
* @attr include-display-unit-of-measurement
|
* @attr include-display-unit-of-measurement
|
||||||
*/
|
*/
|
||||||
@property({ type: Array, attribute: "include-display-unit-of-measurement" })
|
@property({ attribute: "include-display-unit-of-measurement" })
|
||||||
public includeDisplayUnitOfMeasurement?: string[];
|
public includeDisplayUnitOfMeasurement?: string | string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show only statistics with these device classes.
|
* Show only statistics with these device classes.
|
||||||
* @type {Array}
|
|
||||||
* @attr include-device-classes
|
* @attr include-device-classes
|
||||||
*/
|
*/
|
||||||
@property({ type: Array, attribute: "include-device-classes" })
|
@property({ attribute: "include-device-classes" })
|
||||||
public includeDeviceClasses?: string[];
|
public includeDeviceClasses?: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,8 +96,8 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
private _getStatistics = memoizeOne(
|
private _getStatistics = memoizeOne(
|
||||||
(
|
(
|
||||||
statisticIds: StatisticsMetaData[],
|
statisticIds: StatisticsMetaData[],
|
||||||
includeStatisticsUnitOfMeasurement?: string[],
|
includeStatisticsUnitOfMeasurement?: string | string[],
|
||||||
includeDisplayUnitOfMeasurement?: string[],
|
includeDisplayUnitOfMeasurement?: string | string[],
|
||||||
includeDeviceClasses?: string[],
|
includeDeviceClasses?: string[],
|
||||||
entitiesOnly?: boolean
|
entitiesOnly?: boolean
|
||||||
): Array<{ id: string; name: string; state?: HassEntity }> => {
|
): Array<{ id: string; name: string; state?: HassEntity }> => {
|
||||||
@@ -114,17 +113,15 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (includeStatisticsUnitOfMeasurement) {
|
if (includeStatisticsUnitOfMeasurement) {
|
||||||
|
const includeUnits = ensureArray(includeStatisticsUnitOfMeasurement);
|
||||||
statisticIds = statisticIds.filter((meta) =>
|
statisticIds = statisticIds.filter((meta) =>
|
||||||
includeStatisticsUnitOfMeasurement.includes(
|
includeUnits.includes(meta.statistics_unit_of_measurement)
|
||||||
meta.statistics_unit_of_measurement
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (includeDisplayUnitOfMeasurement) {
|
if (includeDisplayUnitOfMeasurement) {
|
||||||
|
const includeUnits = ensureArray(includeDisplayUnitOfMeasurement);
|
||||||
statisticIds = statisticIds.filter((meta) =>
|
statisticIds = statisticIds.filter((meta) =>
|
||||||
includeDisplayUnitOfMeasurement.includes(
|
includeUnits.includes(meta.display_unit_of_measurement)
|
||||||
meta.display_unit_of_measurement
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,11 +22,52 @@ 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 displayed with these units of measurements.
|
||||||
|
* @attr include-display-unit-of-measurement
|
||||||
|
*/
|
||||||
|
@property({ attribute: "include-display-unit-of-measurement" })
|
||||||
|
public includeDisplayUnitOfMeasurement?: 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 includeDisplayUnitCurrent = ignoreRestriction
|
||||||
|
? undefined
|
||||||
|
: this.includeDisplayUnitOfMeasurement;
|
||||||
|
const includeStatisticsUnitCurrent = ignoreRestriction
|
||||||
|
? undefined
|
||||||
|
: this.includeStatisticsUnitOfMeasurement;
|
||||||
|
const includeStatisticTypesCurrent = ignoreRestriction
|
||||||
|
? undefined
|
||||||
|
: this.statisticTypes;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
${this._currentStatistics.map(
|
${this._currentStatistics.map(
|
||||||
(statisticId) => html`
|
(statisticId) => html`
|
||||||
@@ -34,8 +75,10 @@ class HaStatisticsPicker extends LitElement {
|
|||||||
<ha-statistic-picker
|
<ha-statistic-picker
|
||||||
.curValue=${statisticId}
|
.curValue=${statisticId}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
.includeDisplayUnitOfMeasurement=${includeDisplayUnitCurrent}
|
||||||
|
.includeStatisticsUnitOfMeasurement=${includeStatisticsUnitCurrent}
|
||||||
.value=${statisticId}
|
.value=${statisticId}
|
||||||
.statisticTypes=${this.statisticTypes}
|
.statisticTypes=${includeStatisticTypesCurrent}
|
||||||
.statisticIds=${this.statisticIds}
|
.statisticIds=${this.statisticIds}
|
||||||
.label=${this.pickedStatisticLabel}
|
.label=${this.pickedStatisticLabel}
|
||||||
@value-changed=${this._statisticChanged}
|
@value-changed=${this._statisticChanged}
|
||||||
@@ -46,6 +89,10 @@ class HaStatisticsPicker extends LitElement {
|
|||||||
<div>
|
<div>
|
||||||
<ha-statistic-picker
|
<ha-statistic-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
.includeDisplayUnitOfMeasurement=${this
|
||||||
|
.includeDisplayUnitOfMeasurement}
|
||||||
|
.includeStatisticsUnitOfMeasurement=${this
|
||||||
|
.includeStatisticsUnitOfMeasurement}
|
||||||
.statisticTypes=${this.statisticTypes}
|
.statisticTypes=${this.statisticTypes}
|
||||||
.statisticIds=${this.statisticIds}
|
.statisticIds=${this.statisticIds}
|
||||||
.label=${this.pickStatisticLabel}
|
.label=${this.pickStatisticLabel}
|
||||||
|
|||||||
@@ -290,6 +290,7 @@ 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,15 +3,14 @@ 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";
|
||||||
@@ -32,7 +31,7 @@ class HaCoverControls extends LitElement {
|
|||||||
<div class="state">
|
<div class="state">
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
hidden: !supportsOpen(this.stateObj),
|
hidden: !supportsFeature(this.stateObj, CoverEntityFeature.OPEN),
|
||||||
})}
|
})}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.dialogs.more_info_control.cover.open_cover"
|
"ui.dialogs.more_info_control.cover.open_cover"
|
||||||
@@ -44,7 +43,7 @@ class HaCoverControls extends LitElement {
|
|||||||
</ha-icon-button>
|
</ha-icon-button>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
hidden: !supportsStop(this.stateObj),
|
hidden: !supportsFeature(this.stateObj, CoverEntityFeature.STOP),
|
||||||
})}
|
})}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.dialogs.more_info_control.cover.stop_cover"
|
"ui.dialogs.more_info_control.cover.stop_cover"
|
||||||
@@ -55,7 +54,7 @@ class HaCoverControls extends LitElement {
|
|||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
hidden: !supportsClose(this.stateObj),
|
hidden: !supportsFeature(this.stateObj, CoverEntityFeature.CLOSE),
|
||||||
})}
|
})}
|
||||||
.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,13 +2,12 @@ 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";
|
||||||
@@ -27,7 +26,10 @@ class HaCoverTiltControls extends LitElement {
|
|||||||
|
|
||||||
return html` <ha-icon-button
|
return html` <ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
invisible: !supportsOpenTilt(this.stateObj),
|
invisible: !supportsFeature(
|
||||||
|
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"
|
||||||
@@ -38,7 +40,10 @@ class HaCoverTiltControls extends LitElement {
|
|||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
invisible: !supportsStopTilt(this.stateObj),
|
invisible: !supportsFeature(
|
||||||
|
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"
|
||||||
@@ -49,7 +54,10 @@ class HaCoverTiltControls extends LitElement {
|
|||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
invisible: !supportsCloseTilt(this.stateObj),
|
invisible: !supportsFeature(
|
||||||
|
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"
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ 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,6 +2,7 @@ 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";
|
||||||
@@ -133,7 +134,11 @@ 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.label === "%" ? "%" : ` ${this.label}`
|
this._segment_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!.sendMessage({
|
await this.hass!.auth.external!.fireMessage({
|
||||||
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,6 +3,8 @@ 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";
|
||||||
@@ -15,7 +17,9 @@ export interface IconOverflowMenuItem {
|
|||||||
narrowOnly?: boolean;
|
narrowOnly?: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
tooltip?: string;
|
tooltip?: string;
|
||||||
onClick: CallableFunction;
|
action: () => any;
|
||||||
|
warning?: boolean;
|
||||||
|
divider?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@customElement("ha-icon-overflow-menu")
|
@customElement("ha-icon-overflow-menu")
|
||||||
@@ -43,19 +47,23 @@ export class HaIconOverflowMenu extends LitElement {
|
|||||||
slot="trigger"
|
slot="trigger"
|
||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
|
|
||||||
${this.items.map(
|
${this.items.map((item) =>
|
||||||
(item) => html`
|
item.divider
|
||||||
<mwc-list-item
|
? html`<li divider role="separator"></li>`
|
||||||
graphic="icon"
|
: html`<mwc-list-item
|
||||||
.disabled=${item.disabled}
|
graphic="icon"
|
||||||
@click=${item.action}
|
?disabled=${item.disabled}
|
||||||
>
|
@click=${item.action}
|
||||||
<div slot="graphic">
|
class=${classMap({ warning: Boolean(item.warning) })}
|
||||||
<ha-svg-icon .path=${item.path}></ha-svg-icon>
|
>
|
||||||
</div>
|
<div slot="graphic">
|
||||||
${item.label}
|
<ha-svg-icon
|
||||||
</mwc-list-item>
|
class=${classMap({ warning: Boolean(item.warning) })}
|
||||||
`
|
.path=${item.path}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</div>
|
||||||
|
${item.label}
|
||||||
|
</mwc-list-item> `
|
||||||
)}
|
)}
|
||||||
</ha-button-menu>`
|
</ha-button-menu>`
|
||||||
: html`
|
: html`
|
||||||
@@ -63,6 +71,8 @@ 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">
|
||||||
@@ -73,7 +83,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> `
|
||||||
)}
|
)}
|
||||||
@@ -81,7 +91,8 @@ export class HaIconOverflowMenu extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _handleIconOverflowMenuOpened() {
|
protected _handleIconOverflowMenuOpened(e) {
|
||||||
|
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.
|
||||||
@@ -99,12 +110,22 @@ export class HaIconOverflowMenu extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static get styles() {
|
static get styles() {
|
||||||
return css`
|
return [
|
||||||
:host {
|
haStyle,
|
||||||
display: flex;
|
css`
|
||||||
justify-content: flex-end;
|
:host {
|
||||||
}
|
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, TemplateResult } from "lit";
|
import { css, 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 { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
@@ -13,7 +13,8 @@ type IconItem = {
|
|||||||
icon: string;
|
icon: string;
|
||||||
keywords: string[];
|
keywords: string[];
|
||||||
};
|
};
|
||||||
let iconItems: IconItem[] = [];
|
let iconItems: IconItem[] = [{ icon: "", keywords: [] }];
|
||||||
|
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
|
||||||
@@ -88,15 +89,16 @@ 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 && !iconItems.length) {
|
if (this._opened && !iconLoaded) {
|
||||||
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 as any).filteredItems = iconItems;
|
this.comboBox.filteredItems = iconItems;
|
||||||
|
|
||||||
Object.keys(customIcons).forEach((iconSet) => {
|
Object.keys(customIcons).forEach((iconSet) => {
|
||||||
this._loadCustomIconItems(iconSet);
|
this._loadCustomIconItems(iconSet);
|
||||||
@@ -116,13 +118,17 @@ export class HaIconPicker extends LitElement {
|
|||||||
keywords: icon.keywords ?? [],
|
keywords: icon.keywords ?? [],
|
||||||
}));
|
}));
|
||||||
iconItems.push(...customIconItems);
|
iconItems.push(...customIconItems);
|
||||||
(this.comboBox as any).filteredItems = iconItems;
|
this.comboBox.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);
|
||||||
@@ -161,14 +167,12 @@ export class HaIconPicker extends LitElement {
|
|||||||
filteredItems.push(...filteredItemsByKeywords);
|
filteredItems.push(...filteredItemsByKeywords);
|
||||||
|
|
||||||
if (filteredItems.length > 0) {
|
if (filteredItems.length > 0) {
|
||||||
(this.comboBox as any).filteredItems = filteredItems;
|
this.comboBox.filteredItems = filteredItems;
|
||||||
} else {
|
} else {
|
||||||
(this.comboBox as any).filteredItems = [
|
this.comboBox.filteredItems = [{ icon: filterString, keywords: [] }];
|
||||||
{ icon: filterString, keywords: [] },
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(this.comboBox as any).filteredItems = iconItems;
|
this.comboBox.filteredItems = iconItems;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
221
src/components/ha-navigation-picker.ts
Normal file
221
src/components/ha-navigation-picker.ts
Normal file
@@ -0,0 +1,221 @@
|
|||||||
|
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[] = [{ path: "", icon: "", title: "" }];
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
47
src/components/ha-selector/ha-selector-navigation.ts
Normal file
47
src/components/ha-selector/ha-selector-navigation.ts
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
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,8 +51,9 @@ export class HaNumberSelector extends LitElement {
|
|||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
<ha-textfield
|
<ha-textfield
|
||||||
inputMode="numeric"
|
.inputMode=${(this.selector.number.step || 1) % 1 !== 0
|
||||||
pattern="[0-9]+([\\.][0-9]+)?"
|
? "decimal"
|
||||||
|
: "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,6 +13,7 @@ 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 {
|
||||||
@@ -40,7 +41,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 || this.required) {
|
if (!this.selector.select.multiple) {
|
||||||
return html`
|
return html`
|
||||||
<div>
|
<div>
|
||||||
${this.label}
|
${this.label}
|
||||||
@@ -50,7 +51,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=${this.disabled}
|
.disabled=${item.disabled || this.disabled}
|
||||||
@change=${this._valueChanged}
|
@change=${this._valueChanged}
|
||||||
></ha-radio>
|
></ha-radio>
|
||||||
</ha-formfield>
|
</ha-formfield>
|
||||||
@@ -63,13 +64,14 @@ export class HaSelectSelector extends LitElement {
|
|||||||
|
|
||||||
return html`
|
return html`
|
||||||
<div>
|
<div>
|
||||||
${this.label}${options.map(
|
${this.label}
|
||||||
|
${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=${this.disabled}
|
.disabled=${item.disabled || this.disabled}
|
||||||
@change=${this._checkboxChanged}
|
@change=${this._checkboxChanged}
|
||||||
></ha-checkbox>
|
></ha-checkbox>
|
||||||
</ha-formfield>
|
</ha-formfield>
|
||||||
@@ -112,7 +114,9 @@ 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((item) => !this.value?.includes(item.value))}
|
.items=${options.filter(
|
||||||
|
(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>
|
||||||
@@ -136,7 +140,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}
|
.items=${options.filter((item) => !item.disabled)}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
@filter-changed=${this._filterChanged}
|
@filter-changed=${this._filterChanged}
|
||||||
@value-changed=${this._comboBoxValueChanged}
|
@value-changed=${this._comboBoxValueChanged}
|
||||||
@@ -157,7 +161,9 @@ export class HaSelectSelector extends LitElement {
|
|||||||
>
|
>
|
||||||
${options.map(
|
${options.map(
|
||||||
(item: SelectOption) => html`
|
(item: SelectOption) => html`
|
||||||
<mwc-list-item .value=${item.value}>${item.label}</mwc-list-item>
|
<mwc-list-item .value=${item.value} .disabled=${item.disabled}
|
||||||
|
>${item.label}</mwc-list-item
|
||||||
|
>
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
</ha-select>
|
</ha-select>
|
||||||
@@ -285,6 +291,9 @@ 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,6 +16,7 @@ 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";
|
||||||
|
|||||||
@@ -221,13 +221,15 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
private _sortable?: SortableInstance;
|
private _sortable?: SortableInstance;
|
||||||
|
|
||||||
public hassSubscribe(): UnsubscribeFunc[] {
|
public hassSubscribe(): UnsubscribeFunc[] {
|
||||||
return [
|
return this.hass.user?.is_admin
|
||||||
subscribeRepairsIssueRegistry(this.hass.connection!, (repairs) => {
|
? [
|
||||||
this._issuesCount = repairs.issues.filter(
|
subscribeRepairsIssueRegistry(this.hass.connection!, (repairs) => {
|
||||||
(issue) => !issue.ignored
|
this._issuesCount = repairs.issues.filter(
|
||||||
).length;
|
(issue) => !issue.ignored
|
||||||
}),
|
).length;
|
||||||
];
|
}),
|
||||||
|
]
|
||||||
|
: [];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
|
|||||||
@@ -82,6 +82,13 @@ 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(--accent-color);
|
border-bottom-color: var(--primary-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.tabs > *:focus,
|
.tabs > *:focus,
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ 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;
|
||||||
@@ -21,6 +25,15 @@ 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,6 +9,7 @@ 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 & {
|
||||||
@@ -313,11 +314,25 @@ let inititialAutomationEditorData: Partial<AutomationConfig> | undefined;
|
|||||||
export const getAutomationConfig = (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 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,7 +1,15 @@
|
|||||||
|
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 = (
|
||||||
@@ -68,7 +76,7 @@ export const describeTrigger = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// State Trigger
|
// State Trigger
|
||||||
if (trigger.platform === "state" && trigger.entity_id) {
|
if (trigger.platform === "state") {
|
||||||
let base = "When";
|
let base = "When";
|
||||||
let entities = "";
|
let entities = "";
|
||||||
|
|
||||||
@@ -89,12 +97,17 @@ export const describeTrigger = (
|
|||||||
} ${computeStateName(states[entity]) || entity}`;
|
} ${computeStateName(states[entity]) || entity}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if (trigger.entity_id) {
|
||||||
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) {
|
||||||
@@ -128,17 +141,19 @@ export const describeTrigger = (
|
|||||||
base += ` to ${to}`;
|
base += ` to ${to}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("for" in trigger) {
|
if (trigger.for) {
|
||||||
let duration: string;
|
let duration: string | null;
|
||||||
if (typeof trigger.for === "number") {
|
if (typeof trigger.for === "number") {
|
||||||
duration = `for ${secondsToDuration(trigger.for)!}`;
|
duration = secondsToDuration(trigger.for);
|
||||||
} else if (typeof trigger.for === "string") {
|
} else if (typeof trigger.for === "string") {
|
||||||
duration = `for ${trigger.for}`;
|
duration = trigger.for;
|
||||||
} else {
|
} else {
|
||||||
duration = `for ${JSON.stringify(trigger.for)}`;
|
duration = formatDuration(trigger.for);
|
||||||
}
|
}
|
||||||
|
|
||||||
base += ` for ${duration}`;
|
if (duration) {
|
||||||
|
base += ` for ${duration}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return base;
|
return base;
|
||||||
@@ -174,7 +189,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(".")
|
||||||
? hass.states[trigger.at] || trigger.at
|
? `entity ${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}`;
|
||||||
@@ -280,7 +295,7 @@ export const describeTrigger = (
|
|||||||
}
|
}
|
||||||
// MQTT Trigger
|
// MQTT Trigger
|
||||||
if (trigger.platform === "mqtt") {
|
if (trigger.platform === "mqtt") {
|
||||||
return "When a MQTT payload has been received";
|
return "When an MQTT message has been received";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Template Trigger
|
// Template Trigger
|
||||||
@@ -292,7 +307,25 @@ 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 = (
|
||||||
@@ -304,15 +337,64 @@ export const describeCondition = (
|
|||||||
return condition.alias;
|
return condition.alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (["or", "and", "not"].includes(condition.condition)) {
|
if (!condition.condition) {
|
||||||
return `multiple conditions using "${condition.condition}"`;
|
const shorthands: Array<"and" | "or" | "not"> = ["and", "or", "not"];
|
||||||
|
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" && condition.entity_id) {
|
if (condition.condition === "state") {
|
||||||
let base = "Confirm";
|
let base = "Confirm";
|
||||||
const stateObj = hass.states[condition.entity_id];
|
const stateObj = hass.states[condition.entity_id];
|
||||||
const entity = stateObj ? computeStateName(stateObj) : condition.entity_id;
|
const entity = stateObj
|
||||||
|
? 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`;
|
||||||
@@ -328,10 +410,14 @@ export const describeCondition = (
|
|||||||
: ""
|
: ""
|
||||||
} ${state}`;
|
} ${state}`;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (condition.state) {
|
||||||
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) {
|
||||||
@@ -467,5 +553,22 @@ export const describeCondition = (
|
|||||||
}`;
|
}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${condition.condition} condition`;
|
if (condition.condition === "device") {
|
||||||
|
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
|
||||||
|
}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${
|
||||||
|
condition.condition ? condition.condition.replace(/_/g, " ") : "Unknown"
|
||||||
|
} condition`;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
|
|
||||||
export interface ConfigEntry {
|
export interface ConfigEntry {
|
||||||
@@ -44,6 +45,29 @@ 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,46 +4,16 @@ 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 SUPPORT_OPEN = 1;
|
export const enum CoverEntityFeature {
|
||||||
export const SUPPORT_CLOSE = 2;
|
OPEN = 1,
|
||||||
export const SUPPORT_SET_POSITION = 4;
|
CLOSE = 2,
|
||||||
export const SUPPORT_STOP = 8;
|
SET_POSITION = 4,
|
||||||
export const SUPPORT_OPEN_TILT = 16;
|
STOP = 8,
|
||||||
export const SUPPORT_CLOSE_TILT = 32;
|
OPEN_TILT = 16,
|
||||||
export const SUPPORT_STOP_TILT = 64;
|
CLOSE_TILT = 32,
|
||||||
export const SUPPORT_SET_TILT_POSITION = 128;
|
STOP_TILT = 64,
|
||||||
|
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) {
|
||||||
@@ -77,17 +47,19 @@ export function isClosing(stateObj: CoverEntity) {
|
|||||||
|
|
||||||
export function isTiltOnly(stateObj: CoverEntity) {
|
export function isTiltOnly(stateObj: CoverEntity) {
|
||||||
const supportsCover =
|
const supportsCover =
|
||||||
supportsOpen(stateObj) || supportsClose(stateObj) || supportsStop(stateObj);
|
supportsFeature(stateObj, CoverEntityFeature.OPEN) ||
|
||||||
|
supportsFeature(stateObj, CoverEntityFeature.CLOSE) ||
|
||||||
|
supportsFeature(stateObj, CoverEntityFeature.STOP);
|
||||||
const supportsTilt =
|
const supportsTilt =
|
||||||
supportsOpenTilt(stateObj) ||
|
supportsFeature(stateObj, CoverEntityFeature.OPEN_TILT) ||
|
||||||
supportsCloseTilt(stateObj) ||
|
supportsFeature(stateObj, CoverEntityFeature.CLOSE_TILT) ||
|
||||||
supportsStopTilt(stateObj);
|
supportsFeature(stateObj, CoverEntityFeature.STOP_TILT);
|
||||||
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,7 +20,8 @@ import {
|
|||||||
getStatisticMetadata,
|
getStatisticMetadata,
|
||||||
Statistics,
|
Statistics,
|
||||||
StatisticsMetaData,
|
StatisticsMetaData,
|
||||||
} from "./history";
|
StatisticsUnitConfiguration,
|
||||||
|
} from "./recorder";
|
||||||
|
|
||||||
const energyCollectionKeys: (string | undefined)[] = [];
|
const energyCollectionKeys: (string | undefined)[] = [];
|
||||||
|
|
||||||
@@ -28,7 +29,6 @@ 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,7 +37,6 @@ 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,
|
||||||
});
|
});
|
||||||
@@ -67,7 +66,6 @@ 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,
|
||||||
});
|
});
|
||||||
@@ -92,7 +90,6 @@ 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;
|
||||||
}
|
}
|
||||||
@@ -104,8 +101,7 @@ export interface FlowToGridSourceEnergyPreference {
|
|||||||
// $ meter
|
// $ meter
|
||||||
stat_compensation: string | null;
|
stat_compensation: string | null;
|
||||||
|
|
||||||
// Can be used to generate costs if stat_cost omitted
|
// Can be used to generate costs if stat_compensation 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;
|
||||||
}
|
}
|
||||||
@@ -141,7 +137,6 @@ 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;
|
||||||
@@ -358,12 +353,19 @@ 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;
|
||||||
@@ -385,7 +387,8 @@ const getEnergyData = async (
|
|||||||
compareStartMinHour,
|
compareStartMinHour,
|
||||||
endCompare,
|
endCompare,
|
||||||
statIDs,
|
statIDs,
|
||||||
period
|
period,
|
||||||
|
units
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -621,7 +624,7 @@ export const getEnergyGasUnitCategory = (
|
|||||||
const statisticIdWithMeta = statisticsMetaData[source.stat_energy_from];
|
const statisticIdWithMeta = statisticsMetaData[source.stat_energy_from];
|
||||||
if (statisticIdWithMeta) {
|
if (statisticIdWithMeta) {
|
||||||
return ENERGY_GAS_VOLUME_UNITS.includes(
|
return ENERGY_GAS_VOLUME_UNITS.includes(
|
||||||
statisticIdWithMeta.display_unit_of_measurement
|
statisticIdWithMeta.statistics_unit_of_measurement
|
||||||
)
|
)
|
||||||
? "volume"
|
? "volume"
|
||||||
: "energy";
|
: "energy";
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
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;
|
||||||
@@ -18,10 +20,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;
|
||||||
@@ -59,7 +61,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 | WeatherEntityOptions;
|
options?: SensorEntityOptions | NumberEntityOptions | WeatherEntityOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const findBatteryEntity = (
|
export const findBatteryEntity = (
|
||||||
@@ -91,7 +93,10 @@ export const computeEntityRegistryName = (
|
|||||||
return entry.name;
|
return entry.name;
|
||||||
}
|
}
|
||||||
const state = hass.states[entry.entity_id];
|
const state = hass.states[entry.entity_id];
|
||||||
return state ? computeStateName(state) : entry.entity_id;
|
if (state) {
|
||||||
|
return computeStateName(state);
|
||||||
|
}
|
||||||
|
return entry.original_name ? entry.original_name : entry.entity_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getExtendedEntityRegistryEntry = (
|
export const getExtendedEntityRegistryEntry = (
|
||||||
@@ -161,6 +166,16 @@ 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,10 +1,7 @@
|
|||||||
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 {
|
import { computeStateNameFromEntityAttributes } from "../common/entity/compute_state_name";
|
||||||
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";
|
||||||
@@ -63,87 +60,6 @@ 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[];
|
||||||
}
|
}
|
||||||
@@ -449,132 +365,3 @@ 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;
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -3,76 +3,83 @@ import {
|
|||||||
HassEntityBase,
|
HassEntityBase,
|
||||||
} from "home-assistant-js-websocket";
|
} from "home-assistant-js-websocket";
|
||||||
|
|
||||||
export const enum LightColorModes {
|
export const enum LightEntityFeature {
|
||||||
|
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 = [
|
||||||
LightColorModes.HS,
|
LightColorMode.HS,
|
||||||
LightColorModes.XY,
|
LightColorMode.XY,
|
||||||
LightColorModes.RGB,
|
LightColorMode.RGB,
|
||||||
LightColorModes.RGBW,
|
LightColorMode.RGBW,
|
||||||
LightColorModes.RGBWW,
|
LightColorMode.RGBWW,
|
||||||
];
|
];
|
||||||
|
|
||||||
const modesSupportingDimming = [
|
const modesSupportingBrightness = [
|
||||||
...modesSupportingColor,
|
...modesSupportingColor,
|
||||||
LightColorModes.COLOR_TEMP,
|
LightColorMode.COLOR_TEMP,
|
||||||
LightColorModes.BRIGHTNESS,
|
LightColorMode.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: LightColorModes
|
mode: LightColorMode
|
||||||
) => entity.attributes.supported_color_modes?.includes(mode);
|
) => entity.attributes.supported_color_modes?.includes(mode) || false;
|
||||||
|
|
||||||
export const lightIsInColorMode = (entity: LightEntity) =>
|
export const lightIsInColorMode = (entity: LightEntity) =>
|
||||||
modesSupportingColor.includes(entity.attributes.color_mode);
|
(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 lightSupportsDimming = (entity: LightEntity) =>
|
export const lightSupportsBrightness = (entity: LightEntity) =>
|
||||||
entity.attributes.supported_color_modes?.some((mode) =>
|
entity.attributes.supported_color_modes?.some((mode) =>
|
||||||
modesSupportingDimming.includes(mode)
|
modesSupportingBrightness.includes(mode)
|
||||||
);
|
) || false;
|
||||||
|
|
||||||
export const getLightCurrentModeRgbColor = (entity: LightEntity): number[] =>
|
export const getLightCurrentModeRgbColor = (
|
||||||
entity.attributes.color_mode === LightColorModes.RGBWW
|
entity: LightEntity
|
||||||
|
): number[] | undefined =>
|
||||||
|
entity.attributes.color_mode === LightColorMode.RGBWW
|
||||||
? entity.attributes.rgbww_color
|
? entity.attributes.rgbww_color
|
||||||
: entity.attributes.color_mode === LightColorModes.RGBW
|
: entity.attributes.color_mode === LightColorMode.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;
|
||||||
friendly_name: string;
|
brightness?: number;
|
||||||
brightness: number;
|
xy_color?: [number, number];
|
||||||
hs_color: [number, number];
|
hs_color?: [number, number];
|
||||||
rgb_color: [number, number, number];
|
color_temp?: number;
|
||||||
rgbw_color: [number, number, number, number];
|
rgb_color?: [number, number, number];
|
||||||
rgbww_color: [number, number, number, number, number];
|
rgbw_color?: [number, number, number, number];
|
||||||
color_temp: number;
|
rgbww_color?: [number, number, number, number, number];
|
||||||
effect?: string;
|
effect?: string;
|
||||||
effect_list: string[] | null;
|
effect_list?: string[] | null;
|
||||||
supported_color_modes: LightColorModes[];
|
supported_color_modes?: LightColorMode[];
|
||||||
color_mode: LightColorModes;
|
color_mode?: LightColorMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LightEntity extends HassEntityBase {
|
export interface LightEntity extends HassEntityBase {
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ 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,6 +51,7 @@ 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;
|
||||||
@@ -235,6 +236,9 @@ 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 || "";
|
||||||
}
|
}
|
||||||
|
|||||||
247
src/data/recorder.ts
Normal file
247
src/data/recorder.ts
Normal file
@@ -0,0 +1,247 @@
|
|||||||
|
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 {
|
||||||
|
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 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 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,
|
||||||
|
display_unit: string
|
||||||
|
): Promise<void> =>
|
||||||
|
hass.callWS({
|
||||||
|
type: "recorder/adjust_sum_statistics",
|
||||||
|
statistic_id,
|
||||||
|
start_time,
|
||||||
|
adjustment,
|
||||||
|
display_unit,
|
||||||
|
});
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
@@ -14,8 +14,11 @@ 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,7 +15,6 @@ 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 {
|
||||||
@@ -278,9 +277,9 @@ export type ActionType = keyof ActionTypes;
|
|||||||
|
|
||||||
export const triggerScript = (
|
export const triggerScript = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entityId: string,
|
scriptId: string,
|
||||||
variables?: Record<string, unknown>
|
variables?: Record<string, unknown>
|
||||||
) => hass.callService("script", computeObjectId(entityId), variables);
|
) => hass.callService("script", scriptId, variables);
|
||||||
|
|
||||||
export const canRun = (state: ScriptEntity) => {
|
export const canRun = (state: ScriptEntity) => {
|
||||||
if (state.state === "off") {
|
if (state.state === "off") {
|
||||||
@@ -301,6 +300,9 @@ export const deleteScript = (hass: HomeAssistant, objectId: string) =>
|
|||||||
|
|
||||||
let inititialScriptEditorData: Partial<ScriptConfig> | undefined;
|
let inititialScriptEditorData: Partial<ScriptConfig> | undefined;
|
||||||
|
|
||||||
|
export const getScriptConfig = (hass: HomeAssistant, objectId: string) =>
|
||||||
|
hass.callApi<ScriptConfig>("GET", `config/script/config/${objectId}`);
|
||||||
|
|
||||||
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,3 +1,4 @@
|
|||||||
|
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";
|
||||||
@@ -5,6 +6,13 @@ 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,
|
||||||
@@ -47,9 +55,13 @@ 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) {
|
||||||
base = `Call service ${config.service}`;
|
const [domain, serviceName] = config.service.split(".", 2);
|
||||||
|
const service = hass.services[domain][serviceName];
|
||||||
|
base = service
|
||||||
|
? `${domainToName(hass.localize, domain)}: ${service.name}`
|
||||||
|
: `Call service: ${config.service}`;
|
||||||
} else {
|
} else {
|
||||||
return actionType;
|
return "Call a service";
|
||||||
}
|
}
|
||||||
if (config.target) {
|
if (config.target) {
|
||||||
const targets: string[] = [];
|
const targets: string[] = [];
|
||||||
@@ -66,26 +78,49 @@ 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 {
|
||||||
values.push(targetThing);
|
targets.push(targetThing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (renderValues) {
|
|
||||||
targets.push(`${label} ${values.join(", ")}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (targets.length > 0) {
|
if (targets.length > 0) {
|
||||||
base += ` on ${targets.join(", ")}`;
|
base += ` ${targets.join(", ")}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,9 +137,11 @@ 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}`;
|
: `for ${config.delay || "a duration"}`;
|
||||||
|
} else if (config.delay) {
|
||||||
|
duration = `for ${formatDuration(config.delay)}`;
|
||||||
} else {
|
} else {
|
||||||
duration = `for ${JSON.stringify(config.delay)}`;
|
duration = "for a duration";
|
||||||
}
|
}
|
||||||
|
|
||||||
return `Delay ${duration}`;
|
return `Delay ${duration}`;
|
||||||
@@ -118,13 +155,12 @@ 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 `Scene ${
|
return `Active scene ${
|
||||||
sceneStateObj
|
sceneStateObj ? computeStateName(sceneStateObj) : entityId
|
||||||
? computeStateName(sceneStateObj)
|
|
||||||
: "scene" in config
|
|
||||||
? config.scene
|
|
||||||
: config.target?.entity_id || config.entity_id || ""
|
|
||||||
}`;
|
}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,16 +168,22 @@ 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 ${config.metadata.title || config.data.media_content_id} on ${
|
return `Play ${
|
||||||
|
config.metadata.title || config.data.media_content_id || "media"
|
||||||
|
} on ${
|
||||||
mediaStateObj
|
mediaStateObj
|
||||||
? computeStateName(mediaStateObj)
|
? computeStateName(mediaStateObj)
|
||||||
: config.target?.entity_id || config.entity_id
|
: entityId || "a media player"
|
||||||
}`;
|
}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionType === "wait_for_trigger") {
|
if (actionType === "wait_for_trigger") {
|
||||||
const config = action as WaitForTriggerAction;
|
const config = action as WaitForTriggerAction;
|
||||||
return `Wait for ${ensureArray(config.wait_for_trigger)
|
const triggers = 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(", ")}`;
|
||||||
}
|
}
|
||||||
@@ -164,22 +206,26 @@ export const describeAction = <T extends ActionType>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (actionType === "check_condition") {
|
if (actionType === "check_condition") {
|
||||||
return `Test ${describeCondition(action as Condition, hass)}`;
|
return describeCondition(action as Condition, hass);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionType === "stop") {
|
if (actionType === "stop") {
|
||||||
const config = action as StopAction;
|
const config = action as StopAction;
|
||||||
return `Stopped${config.stop ? ` because: ${config.stop}` : ""}`;
|
return `Stop${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: ${
|
||||||
typeof config.if === "string"
|
!config.if
|
||||||
|
? ""
|
||||||
|
: 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`
|
||||||
: describeCondition(ensureArray(config.if)[0], hass)
|
: ensureArray(config.if).length
|
||||||
|
? describeCondition(ensureArray(config.if)[0], hass)
|
||||||
|
: ""
|
||||||
}${config.else ? " (or else!)" : ""}`;
|
}${config.else ? " (or else!)" : ""}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,6 +265,13 @@ 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,6 +21,7 @@ export type Selector =
|
|||||||
| IconSelector
|
| IconSelector
|
||||||
| LocationSelector
|
| LocationSelector
|
||||||
| MediaSelector
|
| MediaSelector
|
||||||
|
| NavigationSelector
|
||||||
| NumberSelector
|
| NumberSelector
|
||||||
| ObjectSelector
|
| ObjectSelector
|
||||||
| SelectSelector
|
| SelectSelector
|
||||||
@@ -171,6 +172,11 @@ 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;
|
||||||
@@ -189,6 +195,7 @@ 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 {
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ export const fetchCommandsForCluster = (
|
|||||||
cluster_type: clusterType,
|
cluster_type: clusterType,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const fetchClustersForZhaNode = (
|
export const fetchClustersForZhaDevice = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
ieeeAddress: string
|
ieeeAddress: string
|
||||||
): Promise<Cluster[]> =>
|
): Promise<Cluster[]> =>
|
||||||
|
|||||||
@@ -85,6 +85,13 @@ 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,
|
||||||
@@ -142,12 +149,12 @@ export interface ZWaveJSController {
|
|||||||
sdk_version: string;
|
sdk_version: string;
|
||||||
type: number;
|
type: number;
|
||||||
own_node_id: number;
|
own_node_id: number;
|
||||||
is_secondary: boolean;
|
is_primary: 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_static_update_controller: boolean;
|
is_suc: boolean;
|
||||||
is_slave: boolean;
|
node_type: NodeType;
|
||||||
firmware_version: string;
|
firmware_version: string;
|
||||||
manufacturer_id: number;
|
manufacturer_id: number;
|
||||||
product_id: number;
|
product_id: number;
|
||||||
|
|||||||
@@ -170,7 +170,6 @@ 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,7 +5,6 @@ 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 = () =>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ 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";
|
||||||
@@ -96,6 +97,9 @@ 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
|
||||||
@@ -153,6 +157,9 @@ 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,6 +16,7 @@ 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 {
|
||||||
|
|||||||
@@ -1,19 +1,29 @@
|
|||||||
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 { featureClassNames } from "../../../common/entity/feature_class_names";
|
import {
|
||||||
|
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,
|
||||||
FEATURE_CLASS_NAMES,
|
CoverEntityFeature,
|
||||||
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;
|
||||||
@@ -34,13 +44,16 @@ 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=${!supportsSetPosition(this.stateObj)}
|
.disabled=${!supportsFeature(
|
||||||
|
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">
|
||||||
${supportsSetTiltPosition(this.stateObj)
|
${supportsFeature(this.stateObj, CoverEntityFeature.SET_TILT_POSITION)
|
||||||
? // 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,
|
||||||
LightColorModes,
|
LightColorMode,
|
||||||
LightEntity,
|
LightEntity,
|
||||||
|
LightEntityFeature,
|
||||||
lightIsInColorMode,
|
lightIsInColorMode,
|
||||||
lightSupportsColor,
|
lightSupportsColor,
|
||||||
lightSupportsColorMode,
|
lightSupportsColorMode,
|
||||||
lightSupportsDimming,
|
lightSupportsBrightness,
|
||||||
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" | LightColorModes;
|
@state() private _mode?: "color" | LightColorMode;
|
||||||
|
|
||||||
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,
|
||||||
LightColorModes.COLOR_TEMP
|
LightColorMode.COLOR_TEMP
|
||||||
);
|
);
|
||||||
|
|
||||||
const supportsWhite = lightSupportsColorMode(
|
const supportsWhite = lightSupportsColorMode(
|
||||||
this.stateObj,
|
this.stateObj,
|
||||||
LightColorModes.WHITE
|
LightColorMode.WHITE
|
||||||
);
|
);
|
||||||
|
|
||||||
const supportsRgbww = lightSupportsColorMode(
|
const supportsRgbww = lightSupportsColorMode(
|
||||||
this.stateObj,
|
this.stateObj,
|
||||||
LightColorModes.RGBWW
|
LightColorMode.RGBWW
|
||||||
);
|
);
|
||||||
|
|
||||||
const supportsRgbw =
|
const supportsRgbw =
|
||||||
!supportsRgbww &&
|
!supportsRgbww &&
|
||||||
lightSupportsColorMode(this.stateObj, LightColorModes.RGBW);
|
lightSupportsColorMode(this.stateObj, LightColorMode.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">
|
||||||
${lightSupportsDimming(this.stateObj)
|
${lightSupportsBrightness(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 === LightColorModes.COLOR_TEMP)
|
this._mode === LightColorMode.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, SUPPORT_EFFECT) &&
|
${supportsFeature(this.stateObj, LightEntityFeature.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 === LightColorModes.RGB &&
|
stateObj.attributes.color_mode === LightColorMode.RGB &&
|
||||||
!lightSupportsColorMode(stateObj, LightColorModes.RGBWW) &&
|
!lightSupportsColorMode(stateObj, LightColorMode.RGBWW) &&
|
||||||
!lightSupportsColorMode(stateObj, LightColorModes.RGBW)
|
!lightSupportsColorMode(stateObj, LightColorMode.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 * brightnessAdjust) / 255
|
((stateObj.attributes.brightness || 0) * brightnessAdjust) / 255
|
||||||
);
|
);
|
||||||
this._ctSliderValue = stateObj.attributes.color_temp;
|
this._ctSliderValue = stateObj.attributes.color_temp;
|
||||||
this._wvSliderValue =
|
this._wvSliderValue =
|
||||||
stateObj.attributes.color_mode === LightColorModes.RGBW
|
stateObj.attributes.color_mode === LightColorMode.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 === LightColorModes.RGBWW
|
stateObj.attributes.color_mode === LightColorMode.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 === LightColorModes.RGBWW
|
stateObj.attributes.color_mode === LightColorMode.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: LightColorModes.COLOR_TEMP });
|
modes.push({ label: "Temperature", value: LightColorMode.COLOR_TEMP });
|
||||||
}
|
}
|
||||||
if (supportsWhite) {
|
if (supportsWhite) {
|
||||||
modes.push({ label: "White", value: LightColorModes.WHITE });
|
modes.push({ label: "White", value: LightColorMode.WHITE });
|
||||||
}
|
}
|
||||||
return modes;
|
return modes;
|
||||||
}
|
}
|
||||||
@@ -342,7 +342,7 @@ class MoreInfoLight extends LitElement {
|
|||||||
|
|
||||||
this._brightnessSliderValue = bri;
|
this._brightnessSliderValue = bri;
|
||||||
|
|
||||||
if (this._mode === LightColorModes.WHITE) {
|
if (this._mode === LightColorMode.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!, LightColorModes.RGBWW)) {
|
if (lightSupportsColorMode(this.stateObj!, LightColorMode.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!, LightColorModes.RGBW)) {
|
} else if (lightSupportsColorMode(this.stateObj!, LightColorMode.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!, LightColorModes.RGBWW) ||
|
lightSupportsColorMode(this.stateObj!, LightColorMode.RGBWW) ||
|
||||||
lightSupportsColorMode(this.stateObj!, LightColorModes.RGBW)
|
lightSupportsColorMode(this.stateObj!, LightColorMode.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!, LightColorModes.RGB)) {
|
} else if (lightSupportsColorMode(this.stateObj!, LightColorMode.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,7 +167,8 @@ class MoreInfoMediaPlayer extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
${supportsFeature(stateObj, SUPPORT_SELECT_SOUND_MODE) &&
|
${![UNAVAILABLE, UNKNOWN, "off"].includes(stateObj.state) &&
|
||||||
|
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 { EMExternalMessageCommands } from "./external_messaging";
|
import type { EMIncomingMessageCommands } 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: EMExternalMessageCommands
|
msg: EMIncomingMessageCommands
|
||||||
): boolean => {
|
): boolean => {
|
||||||
const bus = hassMainEl.hass.auth.external!;
|
const bus = hassMainEl.hass.auth.external!;
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ interface CommandInFlight {
|
|||||||
export interface EMMessage {
|
export interface EMMessage {
|
||||||
id?: number;
|
id?: number;
|
||||||
type: string;
|
type: string;
|
||||||
payload?: unknown;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EMError {
|
interface EMError {
|
||||||
@@ -30,34 +29,120 @@ interface EMMessageResultError {
|
|||||||
error: EMError;
|
error: EMError;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EMExternalMessageRestart {
|
interface EMOutgoingMessageConfigGet extends EMMessage {
|
||||||
|
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 EMExternMessageShowNotifications {
|
interface EMIncomingMessageShowNotifications {
|
||||||
id: number;
|
id: number;
|
||||||
type: "command";
|
type: "command";
|
||||||
command: "notifications/show";
|
command: "notifications/show";
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EMExternalMessageCommands =
|
export type EMIncomingMessageCommands =
|
||||||
| EMExternalMessageRestart
|
| EMIncomingMessageRestart
|
||||||
| EMExternMessageShowNotifications;
|
| EMIncomingMessageShowNotifications;
|
||||||
|
|
||||||
type ExternalMessage =
|
type EMIncomingMessage =
|
||||||
| EMMessageResultSuccess
|
| EMMessageResultSuccess
|
||||||
| EMMessageResultError
|
| EMMessageResultError
|
||||||
| EMExternalMessageCommands;
|
| EMIncomingMessageCommands;
|
||||||
|
|
||||||
type ExternalMessageHandler = (msg: EMExternalMessageCommands) => boolean;
|
type EMIncomingMessageHandler = (msg: EMIncomingMessageCommands) => 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 {
|
||||||
@@ -67,7 +152,7 @@ export class ExternalMessaging {
|
|||||||
|
|
||||||
public msgId = 0;
|
public msgId = 0;
|
||||||
|
|
||||||
private _commandHandler?: ExternalMessageHandler;
|
private _commandHandler?: EMIncomingMessageHandler;
|
||||||
|
|
||||||
public async attach() {
|
public async attach() {
|
||||||
window[CALLBACK_EXTERNAL_BUS] = (msg) => this.receiveMessage(msg);
|
window[CALLBACK_EXTERNAL_BUS] = (msg) => this.receiveMessage(msg);
|
||||||
@@ -77,12 +162,12 @@ export class ExternalMessaging {
|
|||||||
payload: { event: ev.detail },
|
payload: { event: ev.detail },
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
this.config = await this.sendMessage<ExternalConfig>({
|
this.config = await this.sendMessage<"config/get">({
|
||||||
type: "config/get",
|
type: "config/get",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public addCommandHandler(handler: ExternalMessageHandler) {
|
public addCommandHandler(handler: EMIncomingMessageHandler) {
|
||||||
this._commandHandler = handler;
|
this._commandHandler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,31 +175,33 @@ 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>(msg: EMMessage): Promise<T> {
|
public sendMessage<T extends keyof EMOutgoingMessageWithAnswer>(
|
||||||
|
msg: EMOutgoingMessageWithAnswer[T]["request"]
|
||||||
|
): Promise<EMOutgoingMessageWithAnswer[T]["response"]> {
|
||||||
const msgId = ++this.msgId;
|
const msgId = ++this.msgId;
|
||||||
msg.id = msgId;
|
msg.id = msgId;
|
||||||
|
|
||||||
this.fireMessage(msg);
|
this._sendExternal(msg);
|
||||||
|
|
||||||
return new Promise<T>((resolve, reject) => {
|
return new Promise<EMOutgoingMessageWithAnswer[T]["response"]>(
|
||||||
this.commands[msgId] = { resolve, reject };
|
(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(
|
public fireMessage(msg: EMOutgoingMessageWithoutAnswer) {
|
||||||
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: ExternalMessage) {
|
public receiveMessage(msg: EMIncomingMessage) {
|
||||||
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,6 +1,15 @@
|
|||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import {
|
||||||
|
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";
|
||||||
@@ -15,6 +24,8 @@ 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;
|
||||||
@@ -22,6 +33,17 @@ 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">
|
||||||
@@ -52,6 +74,9 @@ 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>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +86,10 @@ class HassSubpage extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _backTapped(): void {
|
private _backTapped(): void {
|
||||||
|
if (this.backCallback) {
|
||||||
|
this.backCallback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
history.back();
|
history.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,6 +145,29 @@ 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,3 +375,9 @@ export class HaTabsSubpageDataTable extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"hass-tabs-subpage-data-table": HaTabsSubpageDataTable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
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-circular-progress";
|
import "../../../components/ha-circular-progress";
|
||||||
import "../../../components/ha-combo-box";
|
import "../../../components/ha-combo-box";
|
||||||
@@ -10,14 +11,15 @@ import { createCloseHeading } from "../../../components/ha-dialog";
|
|||||||
import "../../../components/ha-markdown";
|
import "../../../components/ha-markdown";
|
||||||
import "../../../components/ha-textfield";
|
import "../../../components/ha-textfield";
|
||||||
import {
|
import {
|
||||||
fetchApplicationCredentialsConfig,
|
|
||||||
createApplicationCredential,
|
|
||||||
ApplicationCredentialsConfig,
|
|
||||||
ApplicationCredential,
|
ApplicationCredential,
|
||||||
|
ApplicationCredentialsConfig,
|
||||||
|
createApplicationCredential,
|
||||||
|
fetchApplicationCredentialsConfig,
|
||||||
} from "../../../data/application_credential";
|
} from "../../../data/application_credential";
|
||||||
import { domainToName } 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 {
|
||||||
@@ -98,6 +100,25 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
${this._error ? html` <div class="error">${this._error}</div> ` : ""}
|
${this._error ? html` <div class="error">${this._error}</div> ` : ""}
|
||||||
|
<p>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.application_credentials.editor.description"
|
||||||
|
)}
|
||||||
|
<br />
|
||||||
|
<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>
|
||||||
<ha-combo-box
|
<ha-combo-box
|
||||||
name="domain"
|
name="domain"
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@@ -143,6 +164,10 @@ 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(
|
||||||
@@ -154,6 +179,10 @@ 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
|
||||||
@@ -163,15 +192,18 @@ 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._createApplicationCredential}
|
@click=${this._addApplicationCredential}
|
||||||
>
|
>
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.application_credentials.editor.create"
|
"ui.panel.config.application_credentials.editor.add"
|
||||||
)}
|
)}
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
`}
|
`}
|
||||||
@@ -213,7 +245,7 @@ export class DialogAddApplicationCredential extends LitElement {
|
|||||||
this.closeDialog();
|
this.closeDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _createApplicationCredential(ev) {
|
private async _addApplicationCredential(ev) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
if (!this._domain || !this._clientId || !this._clientSecret) {
|
if (!this._domain || !this._clientId || !this._clientSecret) {
|
||||||
return;
|
return;
|
||||||
@@ -260,6 +292,12 @@ 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;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,13 +45,14 @@ 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, Route } from "../../../types";
|
import { HomeAssistant } 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;
|
||||||
@@ -66,11 +67,9 @@ class HaConfigAreaPage extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@property({ type: Boolean, reflect: true }) public narrow!: boolean;
|
@property({ type: Boolean, reflect: true }) public narrow!: boolean;
|
||||||
|
|
||||||
@property() public isWide!: boolean;
|
@property({ type: Boolean }) public isWide!: boolean;
|
||||||
|
|
||||||
@property() public showAdvanced!: boolean;
|
@property({ type: Boolean }) public showAdvanced!: boolean;
|
||||||
|
|
||||||
@property() public route!: Route;
|
|
||||||
|
|
||||||
@state() public _areas!: AreaRegistryEntry[];
|
@state() public _areas!: AreaRegistryEntry[];
|
||||||
|
|
||||||
@@ -242,43 +241,20 @@ class HaConfigAreaPage extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<hass-tabs-subpage
|
<hass-subpage
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
.tabs=${configSections.areas}
|
.header=${area.name}
|
||||||
.route=${this.route}
|
|
||||||
>
|
>
|
||||||
${this.narrow
|
<ha-icon-button
|
||||||
? html`<span slot="header"> ${area.name} </span>
|
.path=${mdiPencil}
|
||||||
<ha-icon-button
|
.entry=${area}
|
||||||
.path=${mdiPencil}
|
@click=${this._showSettings}
|
||||||
.entry=${area}
|
slot="toolbar-icon"
|
||||||
@click=${this._showSettings}
|
.label=${this.hass.localize("ui.panel.config.areas.edit_settings")}
|
||||||
slot="toolbar-icon"
|
></ha-icon-button>
|
||||||
.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">
|
||||||
@@ -504,7 +480,7 @@ class HaConfigAreaPage extends SubscribeMixin(LitElement) {
|
|||||||
: ""}
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</hass-tabs-subpage>
|
</hass-subpage>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
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,
|
||||||
@@ -17,13 +15,15 @@ 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-icon-button";
|
|
||||||
import "../../../../components/ha-expansion-panel";
|
import "../../../../components/ha-expansion-panel";
|
||||||
|
import "../../../../components/ha-icon-button";
|
||||||
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,8 +50,6 @@ 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) {
|
||||||
@@ -66,13 +64,6 @@ 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;
|
||||||
}
|
}
|
||||||
@@ -107,12 +98,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 hideMenu = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@state() private _warnings?: string[];
|
@state() private _warnings?: string[];
|
||||||
|
|
||||||
@state() private _uiModeAvailable = true;
|
@state() private _uiModeAvailable = true;
|
||||||
@@ -157,125 +148,120 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
</div>`
|
</div>`
|
||||||
: ""}
|
: ""}
|
||||||
<ha-expansion-panel leftChevron>
|
<ha-expansion-panel leftChevron>
|
||||||
<div slot="header">
|
<h3 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))}
|
||||||
</div>
|
</h3>
|
||||||
|
|
||||||
${this.index !== 0
|
<slot name="icons" slot="icons"></slot>
|
||||||
? html`
|
${this.hideMenu
|
||||||
<ha-icon-button
|
? ""
|
||||||
|
: html`
|
||||||
|
<ha-button-menu
|
||||||
slot="icons"
|
slot="icons"
|
||||||
.label=${this.hass.localize(
|
fixed
|
||||||
"ui.panel.config.automation.editor.move_up"
|
corner="BOTTOM_START"
|
||||||
)}
|
@action=${this._handleAction}
|
||||||
.path=${mdiArrowUp}
|
@click=${preventDefault}
|
||||||
@click=${this._moveUp}
|
>
|
||||||
></ha-icon-button>
|
<ha-icon-button
|
||||||
`
|
slot="trigger"
|
||||||
: ""}
|
.label=${this.hass.localize("ui.common.menu")}
|
||||||
${this.index !== this.totalActions - 1
|
.path=${mdiDotsVertical}
|
||||||
? html`
|
></ha-icon-button>
|
||||||
<ha-icon-button
|
<mwc-list-item graphic="icon">
|
||||||
slot="icons"
|
${this.hass.localize(
|
||||||
.label=${this.hass.localize(
|
"ui.panel.config.automation.editor.actions.run"
|
||||||
"ui.panel.config.automation.editor.move_down"
|
)}
|
||||||
)}
|
<ha-svg-icon slot="graphic" .path=${mdiPlay}></ha-svg-icon>
|
||||||
.path=${mdiArrowDown}
|
</mwc-list-item>
|
||||||
@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">
|
<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 slot="graphic" .path=${mdiRenameBox}></ha-svg-icon>
|
<ha-svg-icon
|
||||||
</mwc-list-item>
|
slot="graphic"
|
||||||
<mwc-list-item graphic="icon">
|
.path=${mdiRenameBox}
|
||||||
${this.hass.localize(
|
></ha-svg-icon>
|
||||||
"ui.panel.config.automation.editor.actions.duplicate"
|
</mwc-list-item>
|
||||||
)}
|
<mwc-list-item graphic="icon">
|
||||||
<ha-svg-icon
|
${this.hass.localize(
|
||||||
slot="graphic"
|
"ui.panel.config.automation.editor.actions.duplicate"
|
||||||
.path=${mdiContentDuplicate}
|
)}
|
||||||
></ha-svg-icon>
|
<ha-svg-icon
|
||||||
</mwc-list-item>
|
slot="graphic"
|
||||||
|
.path=${mdiContentDuplicate}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<li divider role="separator"></li>
|
<li divider role="separator"></li>
|
||||||
|
|
||||||
<mwc-list-item .disabled=${!this._uiModeAvailable} graphic="icon">
|
<mwc-list-item
|
||||||
${this.hass.localize("ui.panel.config.automation.editor.edit_ui")}
|
.disabled=${!this._uiModeAvailable}
|
||||||
${!yamlMode
|
graphic="icon"
|
||||||
? html`<ha-svg-icon
|
>
|
||||||
slot="graphic"
|
${this.hass.localize(
|
||||||
.path=${mdiCheck}
|
"ui.panel.config.automation.editor.edit_ui"
|
||||||
></ha-svg-icon>`
|
)}
|
||||||
: ``}
|
${!yamlMode
|
||||||
</mwc-list-item>
|
? html`<ha-svg-icon
|
||||||
|
class="selected_menu_item"
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiCheck}
|
||||||
|
></ha-svg-icon>`
|
||||||
|
: ``}
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<mwc-list-item .disabled=${!this._uiModeAvailable} graphic="icon">
|
<mwc-list-item
|
||||||
${this.hass.localize(
|
.disabled=${!this._uiModeAvailable}
|
||||||
"ui.panel.config.automation.editor.edit_yaml"
|
graphic="icon"
|
||||||
)}
|
>
|
||||||
${yamlMode
|
${this.hass.localize(
|
||||||
? html`<ha-svg-icon
|
"ui.panel.config.automation.editor.edit_yaml"
|
||||||
slot="graphic"
|
)}
|
||||||
.path=${mdiCheck}
|
${yamlMode
|
||||||
></ha-svg-icon>`
|
? html`<ha-svg-icon
|
||||||
: ``}
|
class="selected_menu_item"
|
||||||
</mwc-list-item>
|
slot="graphic"
|
||||||
|
.path=${mdiCheck}
|
||||||
|
></ha-svg-icon>`
|
||||||
|
: ``}
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<li divider role="separator"></li>
|
<li divider role="separator"></li>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
`}
|
||||||
|
|
||||||
<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,
|
||||||
@@ -325,6 +311,7 @@ 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,
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
`}
|
`}
|
||||||
@@ -344,16 +331,6 @@ 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:
|
||||||
@@ -427,11 +404,15 @@ 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"
|
"ui.panel.config.automation.editor.actions.delete_confirm_text"
|
||||||
),
|
),
|
||||||
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 });
|
||||||
},
|
},
|
||||||
@@ -507,13 +488,18 @@ 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(--primary-color);
|
color: var(--secondary-text-color);
|
||||||
opacity: 0.9;
|
opacity: 0.9;
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
@@ -534,6 +520,12 @@ 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,15 +1,25 @@
|
|||||||
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 memoizeOne from "memoize-one";
|
import { mdiArrowDown, mdiArrowUp, mdiDrag, mdiPlus } from "@mdi/js";
|
||||||
|
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 "../../../../components/ha-svg-icon";
|
import { stringCompare } from "../../../../common/string/compare";
|
||||||
|
import { LocalizeFunc } from "../../../../common/translations/localize";
|
||||||
import "../../../../components/ha-button-menu";
|
import "../../../../components/ha-button-menu";
|
||||||
|
import type { HaSelect } from "../../../../components/ha-select";
|
||||||
|
import "../../../../components/ha-svg-icon";
|
||||||
|
import { ACTION_TYPES } from "../../../../data/action";
|
||||||
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";
|
||||||
@@ -27,10 +37,6 @@ 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 {
|
||||||
@@ -40,28 +46,62 @@ export default class HaAutomationAction extends LitElement {
|
|||||||
|
|
||||||
@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`
|
||||||
${repeat(
|
<div class="actions">
|
||||||
this.actions,
|
${repeat(
|
||||||
(action) => this._getKey(action),
|
this.actions,
|
||||||
(action, idx) => html`
|
(action) => this._getKey(action),
|
||||||
<ha-automation-action-row
|
(action, idx) => html`
|
||||||
.index=${idx}
|
<ha-automation-action-row
|
||||||
.totalActions=${this.actions.length}
|
.index=${idx}
|
||||||
.action=${action}
|
.action=${action}
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
@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
|
||||||
|
? 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}>
|
<ha-button-menu fixed @action=${this._addAction}>
|
||||||
<mwc-button
|
<mwc-button
|
||||||
slot="trigger"
|
slot="trigger"
|
||||||
@@ -86,6 +126,13 @@ 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;
|
||||||
|
|
||||||
@@ -100,6 +147,33 @@ 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());
|
||||||
@@ -121,12 +195,24 @@ export default class HaAutomationAction extends LitElement {
|
|||||||
fireEvent(this, "value-changed", { value: actions });
|
fireEvent(this, "value-changed", { value: actions });
|
||||||
}
|
}
|
||||||
|
|
||||||
private _move(ev: CustomEvent) {
|
private _moveUp(ev) {
|
||||||
// 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 = ev.detail.direction === "up" ? index - 1 : index + 1;
|
const newIndex = 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);
|
||||||
@@ -177,16 +263,27 @@ export default class HaAutomationAction extends LitElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return [
|
||||||
ha-automation-action-row {
|
sortableStyles,
|
||||||
display: block;
|
css`
|
||||||
margin-bottom: 16px;
|
ha-automation-action-row {
|
||||||
scroll-margin-top: 48px;
|
display: block;
|
||||||
}
|
margin-bottom: 16px;
|
||||||
ha-svg-icon {
|
scroll-margin-top: 48px;
|
||||||
height: 20px;
|
}
|
||||||
}
|
ha-svg-icon {
|
||||||
`;
|
height: 20px;
|
||||||
|
}
|
||||||
|
.handle {
|
||||||
|
cursor: move;
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
.handle ha-svg-icon {
|
||||||
|
pointer-events: none;
|
||||||
|
height: 24px;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import { Action, ChooseAction } from "../../../../../data/script";
|
|||||||
import { haStyle } from "../../../../../resources/styles";
|
import { haStyle } from "../../../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../../../types";
|
import { HomeAssistant } from "../../../../../types";
|
||||||
import { ActionElement } from "../ha-automation-action-row";
|
import { ActionElement } from "../ha-automation-action-row";
|
||||||
import "../../../../../components/ha-form/ha-form";
|
|
||||||
|
|
||||||
@customElement("ha-automation-action-choose")
|
@customElement("ha-automation-action-choose")
|
||||||
export class HaChooseAction extends LitElement implements ActionElement {
|
export class HaChooseAction extends LitElement implements ActionElement {
|
||||||
@@ -17,6 +16,8 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
@property() public action!: ChooseAction;
|
@property() public action!: ChooseAction;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@state() private _showDefault = false;
|
@state() private _showDefault = false;
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
@@ -52,6 +53,7 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
</h3>
|
</h3>
|
||||||
<ha-automation-condition
|
<ha-automation-condition
|
||||||
.conditions=${option.conditions}
|
.conditions=${option.conditions}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.idx=${idx}
|
.idx=${idx}
|
||||||
@value-changed=${this._conditionChanged}
|
@value-changed=${this._conditionChanged}
|
||||||
@@ -61,13 +63,13 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
"ui.panel.config.automation.editor.actions.type.choose.sequence"
|
"ui.panel.config.automation.editor.actions.type.choose.sequence"
|
||||||
)}:
|
)}:
|
||||||
</h3>
|
</h3>
|
||||||
<ha-form
|
<ha-automation-action
|
||||||
|
.actions=${option.sequence || []}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.schema=${[{ name: "sequence", selector: { action: {} } }]}
|
|
||||||
.data=${option}
|
|
||||||
.idx=${idx}
|
.idx=${idx}
|
||||||
@value-changed=${this._actionChanged}
|
@value-changed=${this._actionChanged}
|
||||||
></ha-form>
|
></ha-automation-action>
|
||||||
</div>
|
</div>
|
||||||
</ha-card>`
|
</ha-card>`
|
||||||
)}
|
)}
|
||||||
@@ -89,6 +91,7 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
</h2>
|
</h2>
|
||||||
<ha-automation-action
|
<ha-automation-action
|
||||||
.actions=${action.default || []}
|
.actions=${action.default || []}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
@value-changed=${this._defaultChanged}
|
@value-changed=${this._defaultChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
@@ -122,7 +125,7 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
private _actionChanged(ev: CustomEvent) {
|
private _actionChanged(ev: CustomEvent) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const value = ev.detail.value.sequence as Action[];
|
const value = ev.detail.value as Action[];
|
||||||
const index = (ev.target as any).idx;
|
const index = (ev.target as any).idx;
|
||||||
const choose = this.action.choose
|
const choose = this.action.choose
|
||||||
? [...ensureArray(this.action.choose)]
|
? [...ensureArray(this.action.choose)]
|
||||||
@@ -181,9 +184,6 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
right: 0;
|
right: 0;
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
}
|
}
|
||||||
ha-form::part(root) {
|
|
||||||
overflow: visible;
|
|
||||||
}
|
|
||||||
ha-svg-icon {
|
ha-svg-icon {
|
||||||
height: 20px;
|
height: 20px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ export class HaIfAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public action!: IfAction;
|
@property({ attribute: false }) public action!: IfAction;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@state() private _showElse = false;
|
@state() private _showElse = false;
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
@@ -35,8 +37,9 @@ export class HaIfAction extends LitElement implements ActionElement {
|
|||||||
</h3>
|
</h3>
|
||||||
<ha-automation-condition
|
<ha-automation-condition
|
||||||
.conditions=${action.if}
|
.conditions=${action.if}
|
||||||
.hass=${this.hass}
|
.reOrderMode=${this.reOrderMode}
|
||||||
@value-changed=${this._ifChanged}
|
@value-changed=${this._ifChanged}
|
||||||
|
.hass=${this.hass}
|
||||||
></ha-automation-condition>
|
></ha-automation-condition>
|
||||||
|
|
||||||
<h3>
|
<h3>
|
||||||
@@ -46,6 +49,7 @@ export class HaIfAction extends LitElement implements ActionElement {
|
|||||||
</h3>
|
</h3>
|
||||||
<ha-automation-action
|
<ha-automation-action
|
||||||
.actions=${action.then}
|
.actions=${action.then}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
@value-changed=${this._thenChanged}
|
@value-changed=${this._thenChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
@@ -58,6 +62,7 @@ export class HaIfAction extends LitElement implements ActionElement {
|
|||||||
</h3>
|
</h3>
|
||||||
<ha-automation-action
|
<ha-automation-action
|
||||||
.actions=${action.else || []}
|
.actions=${action.else || []}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
@value-changed=${this._elseChanged}
|
@value-changed=${this._elseChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ export class HaParallelAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public action!: ParallelAction;
|
@property({ attribute: false }) public action!: ParallelAction;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
return {
|
return {
|
||||||
parallel: [],
|
parallel: [],
|
||||||
@@ -26,6 +28,7 @@ export class HaParallelAction extends LitElement implements ActionElement {
|
|||||||
return html`
|
return html`
|
||||||
<ha-automation-action
|
<ha-automation-action
|
||||||
.actions=${action.parallel}
|
.actions=${action.parallel}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
@value-changed=${this._actionsChanged}
|
@value-changed=${this._actionsChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ export class HaRepeatAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public action!: RepeatAction;
|
@property({ attribute: false }) public action!: RepeatAction;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
return { repeat: { count: 2, sequence: [] } };
|
return { repeat: { count: 2, sequence: [] } };
|
||||||
}
|
}
|
||||||
@@ -95,6 +97,7 @@ export class HaRepeatAction extends LitElement implements ActionElement {
|
|||||||
</h3>
|
</h3>
|
||||||
<ha-automation-action
|
<ha-automation-action
|
||||||
.actions=${action.sequence}
|
.actions=${action.sequence}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
@value-changed=${this._actionChanged}
|
@value-changed=${this._actionChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
@@ -112,6 +115,7 @@ export class HaRepeatAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
value: {
|
value: {
|
||||||
|
...this.action,
|
||||||
repeat: { [type]: value, sequence: this.action.repeat.sequence },
|
repeat: { [type]: value, sequence: this.action.repeat.sequence },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -122,6 +126,7 @@ export class HaRepeatAction extends LitElement implements ActionElement {
|
|||||||
const value = ev.detail.value as Condition[];
|
const value = ev.detail.value as Condition[];
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
value: {
|
value: {
|
||||||
|
...this.action,
|
||||||
repeat: {
|
repeat: {
|
||||||
...this.action.repeat,
|
...this.action.repeat,
|
||||||
[getType(this.action.repeat)!]: value,
|
[getType(this.action.repeat)!]: value,
|
||||||
@@ -135,6 +140,7 @@ export class HaRepeatAction extends LitElement implements ActionElement {
|
|||||||
const value = ev.detail.value as Action[];
|
const value = ev.detail.value as Action[];
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
value: {
|
value: {
|
||||||
|
...this.action,
|
||||||
repeat: {
|
repeat: {
|
||||||
...this.action.repeat,
|
...this.action.repeat,
|
||||||
sequence: value,
|
sequence: value,
|
||||||
@@ -150,6 +156,7 @@ export class HaRepeatAction extends LitElement implements ActionElement {
|
|||||||
}
|
}
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
value: {
|
value: {
|
||||||
|
...this.action,
|
||||||
repeat: {
|
repeat: {
|
||||||
...this.action.repeat,
|
...this.action.repeat,
|
||||||
count: newVal,
|
count: newVal,
|
||||||
|
|||||||
@@ -0,0 +1,167 @@
|
|||||||
|
import "@material/mwc-button";
|
||||||
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
|
import { createCloseHeading } from "../../../../components/ha-dialog";
|
||||||
|
import "../../../../components/ha-textfield";
|
||||||
|
import "../../../../components/ha-select";
|
||||||
|
import { HassDialog } from "../../../../dialogs/make-dialog-manager";
|
||||||
|
import { haStyle, haStyleDialog } from "../../../../resources/styles";
|
||||||
|
import type { HomeAssistant } from "../../../../types";
|
||||||
|
import type { AutomationModeDialog } from "./show-dialog-automation-mode";
|
||||||
|
import {
|
||||||
|
AUTOMATION_DEFAULT_MAX,
|
||||||
|
AUTOMATION_DEFAULT_MODE,
|
||||||
|
} from "../../../../data/automation";
|
||||||
|
import { documentationUrl } from "../../../../util/documentation-url";
|
||||||
|
import { isMaxMode, MODES } from "../../../../data/script";
|
||||||
|
import "@material/mwc-list/mwc-list-item";
|
||||||
|
import { stopPropagation } from "../../../../common/dom/stop_propagation";
|
||||||
|
|
||||||
|
@customElement("ha-dialog-automation-mode")
|
||||||
|
class DialogAutomationMode extends LitElement implements HassDialog {
|
||||||
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@state() private _opened = false;
|
||||||
|
|
||||||
|
private _params!: AutomationModeDialog;
|
||||||
|
|
||||||
|
@state() private _newMode: typeof MODES[number] = AUTOMATION_DEFAULT_MODE;
|
||||||
|
|
||||||
|
@state() private _newMax?: number;
|
||||||
|
|
||||||
|
public showDialog(params: AutomationModeDialog): void {
|
||||||
|
this._opened = true;
|
||||||
|
this._params = params;
|
||||||
|
this._newMode = params.config.mode || AUTOMATION_DEFAULT_MODE;
|
||||||
|
this._newMax = isMaxMode(this._newMode)
|
||||||
|
? params.config.max || AUTOMATION_DEFAULT_MAX
|
||||||
|
: undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
public closeDialog(): void {
|
||||||
|
this._params.onClose();
|
||||||
|
|
||||||
|
if (this._opened) {
|
||||||
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
|
}
|
||||||
|
this._opened = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render(): TemplateResult {
|
||||||
|
if (!this._opened) {
|
||||||
|
return html``;
|
||||||
|
}
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<ha-dialog
|
||||||
|
open
|
||||||
|
scrimClickAction
|
||||||
|
@closed=${this.closeDialog}
|
||||||
|
.heading=${createCloseHeading(
|
||||||
|
this.hass,
|
||||||
|
this.hass.localize("ui.panel.config.automation.editor.change_mode")
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<ha-select
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.modes.label"
|
||||||
|
)}
|
||||||
|
.value=${this._newMode}
|
||||||
|
@selected=${this._modeChanged}
|
||||||
|
@closed=${stopPropagation}
|
||||||
|
fixedMenuPosition
|
||||||
|
.helper=${html`
|
||||||
|
<a
|
||||||
|
style="color: var(--secondary-text-color)"
|
||||||
|
href=${documentationUrl(this.hass, "/docs/automation/modes/")}
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
>${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.modes.learn_more"
|
||||||
|
)}</a
|
||||||
|
>
|
||||||
|
`}
|
||||||
|
>
|
||||||
|
${MODES.map(
|
||||||
|
(mode) => html`
|
||||||
|
<mwc-list-item .value=${mode}>
|
||||||
|
${this.hass.localize(
|
||||||
|
`ui.panel.config.automation.editor.modes.${mode}`
|
||||||
|
) || mode}
|
||||||
|
</mwc-list-item>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</ha-select>
|
||||||
|
${isMaxMode(this._newMode)
|
||||||
|
? html`
|
||||||
|
<br /><ha-textfield
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
`ui.panel.config.automation.editor.max.${this._newMode}`
|
||||||
|
)}
|
||||||
|
type="number"
|
||||||
|
name="max"
|
||||||
|
.value=${this._newMax?.toString() ?? ""}
|
||||||
|
@change=${this._valueChanged}
|
||||||
|
class="max"
|
||||||
|
>
|
||||||
|
</ha-textfield>
|
||||||
|
`
|
||||||
|
: html``}
|
||||||
|
|
||||||
|
<mwc-button @click=${this.closeDialog} slot="secondaryAction">
|
||||||
|
${this.hass.localize("ui.dialogs.generic.cancel")}
|
||||||
|
</mwc-button>
|
||||||
|
<mwc-button @click=${this._save} slot="primaryAction">
|
||||||
|
${this.hass.localize("ui.panel.config.automation.editor.change_mode")}
|
||||||
|
</mwc-button>
|
||||||
|
</ha-dialog>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _modeChanged(ev) {
|
||||||
|
const mode = ev.target.value;
|
||||||
|
this._newMode = mode;
|
||||||
|
if (!isMaxMode(mode)) {
|
||||||
|
this._newMax = undefined;
|
||||||
|
} else if (!this._newMax) {
|
||||||
|
this._newMax = AUTOMATION_DEFAULT_MAX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _valueChanged(ev: CustomEvent) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
const target = ev.target as any;
|
||||||
|
if (target.name === "max") {
|
||||||
|
this._newMax = Number(target.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _save(): void {
|
||||||
|
this._params.updateAutomation({
|
||||||
|
...this._params.config,
|
||||||
|
mode: this._newMode,
|
||||||
|
max: this._newMax,
|
||||||
|
});
|
||||||
|
this.closeDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResultGroup {
|
||||||
|
return [
|
||||||
|
haStyle,
|
||||||
|
haStyleDialog,
|
||||||
|
css`
|
||||||
|
ha-select,
|
||||||
|
ha-textfield {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-dialog-automation-mode": DialogAutomationMode;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
|
import type { AutomationConfig } from "../../../../data/automation";
|
||||||
|
|
||||||
|
export const loadAutomationModeDialog = () =>
|
||||||
|
import("./dialog-automation-mode");
|
||||||
|
|
||||||
|
export interface AutomationModeDialog {
|
||||||
|
config: AutomationConfig;
|
||||||
|
updateAutomation: (config: AutomationConfig) => void;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const showAutomationModeDialog = (
|
||||||
|
element: HTMLElement,
|
||||||
|
dialogParams: AutomationModeDialog
|
||||||
|
): void => {
|
||||||
|
fireEvent(element, "show-dialog", {
|
||||||
|
dialogTag: "ha-dialog-automation-mode",
|
||||||
|
dialogImport: loadAutomationModeDialog,
|
||||||
|
dialogParams,
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
import "@material/mwc-button";
|
||||||
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
|
import { createCloseHeading } from "../../../../components/ha-dialog";
|
||||||
|
import { HassDialog } from "../../../../dialogs/make-dialog-manager";
|
||||||
|
import { haStyle, haStyleDialog } from "../../../../resources/styles";
|
||||||
|
import type { HomeAssistant } from "../../../../types";
|
||||||
|
import type { AutomationRenameDialog } from "./show-dialog-automation-rename";
|
||||||
|
import "../../../../components/ha-textarea";
|
||||||
|
import "../../../../components/ha-alert";
|
||||||
|
import "../../../../components/ha-textfield";
|
||||||
|
|
||||||
|
@customElement("ha-dialog-automation-rename")
|
||||||
|
class DialogAutomationRename extends LitElement implements HassDialog {
|
||||||
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@state() private _opened = false;
|
||||||
|
|
||||||
|
@state() private _error?: string;
|
||||||
|
|
||||||
|
private _params!: AutomationRenameDialog;
|
||||||
|
|
||||||
|
private _newName?: string;
|
||||||
|
|
||||||
|
private _newDescription?: string;
|
||||||
|
|
||||||
|
public showDialog(params: AutomationRenameDialog): void {
|
||||||
|
this._opened = true;
|
||||||
|
this._params = params;
|
||||||
|
this._newName =
|
||||||
|
params.config.alias ||
|
||||||
|
this.hass.localize("ui.panel.config.automation.editor.default_name");
|
||||||
|
this._newDescription = params.config.description || "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public closeDialog(): void {
|
||||||
|
this._params.onClose();
|
||||||
|
|
||||||
|
if (this._opened) {
|
||||||
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
|
}
|
||||||
|
this._opened = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render(): TemplateResult {
|
||||||
|
if (!this._opened) {
|
||||||
|
return html``;
|
||||||
|
}
|
||||||
|
return html`
|
||||||
|
<ha-dialog
|
||||||
|
open
|
||||||
|
scrimClickAction
|
||||||
|
@closed=${this.closeDialog}
|
||||||
|
.heading=${createCloseHeading(
|
||||||
|
this.hass,
|
||||||
|
this.hass.localize(
|
||||||
|
this._params.config.alias
|
||||||
|
? "ui.panel.config.automation.editor.rename"
|
||||||
|
: "ui.panel.config.automation.editor.save"
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
${this._error
|
||||||
|
? html`<ha-alert alert-type="error"
|
||||||
|
>${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.missing_name"
|
||||||
|
)}</ha-alert
|
||||||
|
>`
|
||||||
|
: ""}
|
||||||
|
<ha-textfield
|
||||||
|
dialogInitialFocus
|
||||||
|
.value=${this._newName}
|
||||||
|
.placeholder=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.default_name"
|
||||||
|
)}
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.alias"
|
||||||
|
)}
|
||||||
|
required
|
||||||
|
type="string"
|
||||||
|
@input=${this._valueChanged}
|
||||||
|
></ha-textfield>
|
||||||
|
|
||||||
|
<ha-textarea
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.description.label"
|
||||||
|
)}
|
||||||
|
.placeholder=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.description.placeholder"
|
||||||
|
)}
|
||||||
|
name="description"
|
||||||
|
autogrow
|
||||||
|
.value=${this._newDescription}
|
||||||
|
@input=${this._valueChanged}
|
||||||
|
></ha-textarea>
|
||||||
|
|
||||||
|
<mwc-button @click=${this.closeDialog} slot="secondaryAction">
|
||||||
|
${this.hass.localize("ui.dialogs.generic.cancel")}
|
||||||
|
</mwc-button>
|
||||||
|
<mwc-button @click=${this._save} slot="primaryAction">
|
||||||
|
${this.hass.localize(
|
||||||
|
this._params.config.alias
|
||||||
|
? "ui.panel.config.automation.editor.rename"
|
||||||
|
: "ui.panel.config.automation.editor.save"
|
||||||
|
)}
|
||||||
|
</mwc-button>
|
||||||
|
</ha-dialog>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _valueChanged(ev: CustomEvent) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
const target = ev.target as any;
|
||||||
|
if (target.name === "description") {
|
||||||
|
this._newDescription = target.value;
|
||||||
|
} else {
|
||||||
|
this._newName = target.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _save(): void {
|
||||||
|
if (!this._newName) {
|
||||||
|
this._error = "Name is required";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._params.updateAutomation({
|
||||||
|
...this._params.config,
|
||||||
|
alias: this._newName,
|
||||||
|
description: this._newDescription,
|
||||||
|
});
|
||||||
|
this.closeDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResultGroup {
|
||||||
|
return [
|
||||||
|
haStyle,
|
||||||
|
haStyleDialog,
|
||||||
|
css`
|
||||||
|
ha-textfield,
|
||||||
|
ha-textarea {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
ha-alert {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-dialog-automation-rename": DialogAutomationRename;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
|
import type { AutomationConfig } from "../../../../data/automation";
|
||||||
|
|
||||||
|
export const loadAutomationRenameDialog = () =>
|
||||||
|
import("./dialog-automation-rename");
|
||||||
|
|
||||||
|
export interface AutomationRenameDialog {
|
||||||
|
config: AutomationConfig;
|
||||||
|
updateAutomation: (config: AutomationConfig) => void;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const showAutomationRenameDialog = (
|
||||||
|
element: HTMLElement,
|
||||||
|
dialogParams: AutomationRenameDialog
|
||||||
|
): void => {
|
||||||
|
fireEvent(element, "show-dialog", {
|
||||||
|
dialogTag: "ha-dialog-automation-rename",
|
||||||
|
dialogImport: loadAutomationRenameDialog,
|
||||||
|
dialogParams,
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
import "@material/mwc-button/mwc-button";
|
import "@material/mwc-button/mwc-button";
|
||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
import { css, CSSResultGroup, html, LitElement } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import "../../../components/entity/ha-entity-toggle";
|
|
||||||
import "../../../components/ha-blueprint-picker";
|
import "../../../components/ha-blueprint-picker";
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
import "../../../components/ha-circular-progress";
|
import "../../../components/ha-circular-progress";
|
||||||
@@ -11,10 +10,8 @@ import "../../../components/ha-markdown";
|
|||||||
import "../../../components/ha-selector/ha-selector";
|
import "../../../components/ha-selector/ha-selector";
|
||||||
import "../../../components/ha-settings-row";
|
import "../../../components/ha-settings-row";
|
||||||
import "../../../components/ha-textfield";
|
import "../../../components/ha-textfield";
|
||||||
import {
|
import "../../../components/ha-alert";
|
||||||
BlueprintAutomationConfig,
|
import { BlueprintAutomationConfig } from "../../../data/automation";
|
||||||
triggerAutomationActions,
|
|
||||||
} from "../../../data/automation";
|
|
||||||
import {
|
import {
|
||||||
BlueprintOrError,
|
BlueprintOrError,
|
||||||
Blueprints,
|
Blueprints,
|
||||||
@@ -38,8 +35,6 @@ export class HaBlueprintAutomationEditor extends LitElement {
|
|||||||
|
|
||||||
@state() private _blueprints?: Blueprints;
|
@state() private _blueprints?: Blueprints;
|
||||||
|
|
||||||
@state() private _showDescription = false;
|
|
||||||
|
|
||||||
protected firstUpdated(changedProps) {
|
protected firstUpdated(changedProps) {
|
||||||
super.firstUpdated(changedProps);
|
super.firstUpdated(changedProps);
|
||||||
this._getBlueprints();
|
this._getBlueprints();
|
||||||
@@ -52,89 +47,26 @@ export class HaBlueprintAutomationEditor extends LitElement {
|
|||||||
return this._blueprints[this.config.use_blueprint.path];
|
return this._blueprints[this.config.use_blueprint.path];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected willUpdate(changedProps: PropertyValues): void {
|
|
||||||
super.willUpdate(changedProps);
|
|
||||||
if (
|
|
||||||
!this._showDescription &&
|
|
||||||
changedProps.has("config") &&
|
|
||||||
this.config.description
|
|
||||||
) {
|
|
||||||
this._showDescription = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
const blueprint = this._blueprint;
|
const blueprint = this._blueprint;
|
||||||
return html`
|
return html`
|
||||||
<ha-config-section vertical .isWide=${this.isWide}>
|
${this.stateObj?.state === "off"
|
||||||
${!this.narrow
|
? html`
|
||||||
? html` <span slot="header">${this.config.alias}</span> `
|
<ha-alert alert-type="info">
|
||||||
: ""}
|
${this.hass.localize(
|
||||||
<span slot="introduction">
|
"ui.panel.config.automation.editor.disabled"
|
||||||
${this.hass.localize(
|
)}
|
||||||
"ui.panel.config.automation.editor.introduction"
|
<mwc-button slot="action" @click=${this._enable}>
|
||||||
)}
|
${this.hass.localize(
|
||||||
</span>
|
"ui.panel.config.automation.editor.enable"
|
||||||
<ha-card outlined>
|
)}
|
||||||
<div class="card-content">
|
</mwc-button>
|
||||||
${this._showDescription
|
</ha-alert>
|
||||||
? html`
|
`
|
||||||
<ha-textarea
|
: ""}
|
||||||
.label=${this.hass.localize(
|
${this.config.description
|
||||||
"ui.panel.config.automation.editor.description.label"
|
? html`<p class="description">${this.config.description}</p>`
|
||||||
)}
|
: ""}
|
||||||
.placeholder=${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.description.placeholder"
|
|
||||||
)}
|
|
||||||
name="description"
|
|
||||||
autogrow
|
|
||||||
.value=${this.config.description || ""}
|
|
||||||
@change=${this._valueChanged}
|
|
||||||
></ha-textarea>
|
|
||||||
`
|
|
||||||
: html`
|
|
||||||
<div class="link-button-row">
|
|
||||||
<button class="link" @click=${this._addDescription}>
|
|
||||||
${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.description.add"
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
`}
|
|
||||||
</div>
|
|
||||||
${this.stateObj
|
|
||||||
? html`
|
|
||||||
<div class="card-actions layout horizontal justified center">
|
|
||||||
<div class="layout horizontal center">
|
|
||||||
<ha-entity-toggle
|
|
||||||
.hass=${this.hass}
|
|
||||||
.stateObj=${this.stateObj!}
|
|
||||||
></ha-entity-toggle>
|
|
||||||
${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.enable_disable"
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<a href="/config/automation/trace/${this.config.id}">
|
|
||||||
<mwc-button>
|
|
||||||
${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.show_trace"
|
|
||||||
)}
|
|
||||||
</mwc-button>
|
|
||||||
</a>
|
|
||||||
<mwc-button
|
|
||||||
@click=${this._runActions}
|
|
||||||
.stateObj=${this.stateObj}
|
|
||||||
>
|
|
||||||
${this.hass.localize("ui.card.automation.trigger")}
|
|
||||||
</mwc-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`
|
|
||||||
: ""}
|
|
||||||
</ha-card>
|
|
||||||
</ha-config-section>
|
|
||||||
|
|
||||||
<ha-card
|
<ha-card
|
||||||
outlined
|
outlined
|
||||||
class="blueprint"
|
class="blueprint"
|
||||||
@@ -220,10 +152,6 @@ export class HaBlueprintAutomationEditor extends LitElement {
|
|||||||
this._blueprints = await fetchBlueprints(this.hass, "automation");
|
this._blueprints = await fetchBlueprints(this.hass, "automation");
|
||||||
}
|
}
|
||||||
|
|
||||||
private _runActions(ev: Event) {
|
|
||||||
triggerAutomationActions(this.hass, (ev.target as any).stateObj.entity_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
private _blueprintChanged(ev) {
|
private _blueprintChanged(ev) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
if (this.config.use_blueprint.path === ev.detail.value) {
|
if (this.config.use_blueprint.path === ev.detail.value) {
|
||||||
@@ -268,33 +196,24 @@ export class HaBlueprintAutomationEditor extends LitElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _valueChanged(ev: CustomEvent) {
|
private async _enable(): Promise<void> {
|
||||||
ev.stopPropagation();
|
if (!this.hass || !this.stateObj) {
|
||||||
const target = ev.target as any;
|
|
||||||
const name = target.name;
|
|
||||||
if (!name) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const newVal = target.value;
|
await this.hass.callService("automation", "turn_on", {
|
||||||
if ((this.config![name] || "") === newVal) {
|
entity_id: this.stateObj.entity_id,
|
||||||
return;
|
|
||||||
}
|
|
||||||
fireEvent(this, "value-changed", {
|
|
||||||
value: { ...this.config!, [name]: newVal },
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _addDescription() {
|
|
||||||
this._showDescription = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return [
|
||||||
haStyle,
|
haStyle,
|
||||||
css`
|
css`
|
||||||
|
:host {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
ha-card.blueprint {
|
ha-card.blueprint {
|
||||||
max-width: 1040px;
|
margin: 0 auto;
|
||||||
margin: 24px auto;
|
|
||||||
}
|
}
|
||||||
.padding {
|
.padding {
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
@@ -305,7 +224,6 @@ export class HaBlueprintAutomationEditor extends LitElement {
|
|||||||
.blueprint-picker-container {
|
.blueprint-picker-container {
|
||||||
padding: 0 16px 16px;
|
padding: 0 16px 16px;
|
||||||
}
|
}
|
||||||
ha-textarea,
|
|
||||||
ha-textfield,
|
ha-textfield,
|
||||||
ha-blueprint-picker {
|
ha-blueprint-picker {
|
||||||
display: block;
|
display: block;
|
||||||
@@ -313,14 +231,18 @@ export class HaBlueprintAutomationEditor extends LitElement {
|
|||||||
h3 {
|
h3 {
|
||||||
margin: 16px;
|
margin: 16px;
|
||||||
}
|
}
|
||||||
span[slot="introduction"] a {
|
.introduction {
|
||||||
|
margin-top: 0;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
.introduction a {
|
||||||
color: var(--primary-color);
|
color: var(--primary-color);
|
||||||
}
|
}
|
||||||
p {
|
p {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
ha-entity-toggle {
|
.description {
|
||||||
margin-right: 8px;
|
margin-bottom: 16px;
|
||||||
}
|
}
|
||||||
ha-settings-row {
|
ha-settings-row {
|
||||||
--paper-time-input-justify-content: flex-end;
|
--paper-time-input-justify-content: flex-end;
|
||||||
@@ -328,6 +250,10 @@ export class HaBlueprintAutomationEditor extends LitElement {
|
|||||||
--settings-row-prefix-display: contents;
|
--settings-row-prefix-display: contents;
|
||||||
border-top: 1px solid var(--divider-color);
|
border-top: 1px solid var(--divider-color);
|
||||||
}
|
}
|
||||||
|
ha-alert {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ export default class HaAutomationConditionEditor extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public yamlMode = false;
|
@property({ type: Boolean }) public yamlMode = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
private _processedCondition = memoizeOne((condition) =>
|
private _processedCondition = memoizeOne((condition) =>
|
||||||
expandConditionWithShorthand(condition)
|
expandConditionWithShorthand(condition)
|
||||||
);
|
);
|
||||||
@@ -60,7 +62,11 @@ export default class HaAutomationConditionEditor extends LitElement {
|
|||||||
<div>
|
<div>
|
||||||
${dynamicElement(
|
${dynamicElement(
|
||||||
`ha-automation-condition-${condition.condition}`,
|
`ha-automation-condition-${condition.condition}`,
|
||||||
{ hass: this.hass, condition: condition }
|
{
|
||||||
|
hass: this.hass,
|
||||||
|
condition: condition,
|
||||||
|
reOrderMode: this.reOrderMode,
|
||||||
|
}
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
`}
|
`}
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ export default class HaAutomationConditionRow extends LitElement {
|
|||||||
|
|
||||||
@property() public condition!: Condition;
|
@property() public condition!: Condition;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public hideMenu = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@state() private _yamlMode = false;
|
@state() private _yamlMode = false;
|
||||||
|
|
||||||
@state() private _warnings?: string[];
|
@state() private _warnings?: string[];
|
||||||
@@ -93,7 +97,7 @@ export default class HaAutomationConditionRow extends LitElement {
|
|||||||
: ""}
|
: ""}
|
||||||
|
|
||||||
<ha-expansion-panel leftChevron>
|
<ha-expansion-panel leftChevron>
|
||||||
<div slot="header">
|
<h3 slot="header">
|
||||||
<ha-svg-icon
|
<ha-svg-icon
|
||||||
class="condition-icon"
|
class="condition-icon"
|
||||||
.path=${CONDITION_TYPES[this.condition.condition]}
|
.path=${CONDITION_TYPES[this.condition.condition]}
|
||||||
@@ -101,96 +105,108 @@ export default class HaAutomationConditionRow extends LitElement {
|
|||||||
${capitalizeFirstLetter(
|
${capitalizeFirstLetter(
|
||||||
describeCondition(this.condition, this.hass)
|
describeCondition(this.condition, this.hass)
|
||||||
)}
|
)}
|
||||||
</div>
|
</h3>
|
||||||
|
|
||||||
<ha-button-menu
|
<slot name="icons" slot="icons"></slot>
|
||||||
slot="icons"
|
${this.hideMenu
|
||||||
fixed
|
? ""
|
||||||
corner="BOTTOM_START"
|
: html`
|
||||||
@action=${this._handleAction}
|
<ha-button-menu
|
||||||
@click=${preventDefault}
|
slot="icons"
|
||||||
>
|
fixed
|
||||||
<ha-icon-button
|
corner="BOTTOM_START"
|
||||||
slot="trigger"
|
@action=${this._handleAction}
|
||||||
.label=${this.hass.localize("ui.common.menu")}
|
@click=${preventDefault}
|
||||||
.path=${mdiDotsVertical}
|
>
|
||||||
>
|
<ha-icon-button
|
||||||
</ha-icon-button>
|
slot="trigger"
|
||||||
|
.label=${this.hass.localize("ui.common.menu")}
|
||||||
|
.path=${mdiDotsVertical}
|
||||||
|
>
|
||||||
|
</ha-icon-button>
|
||||||
|
|
||||||
<mwc-list-item graphic="icon">
|
<mwc-list-item graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.conditions.test"
|
"ui.panel.config.automation.editor.conditions.test"
|
||||||
)}
|
)}
|
||||||
<ha-svg-icon slot="graphic" .path=${mdiFlask}></ha-svg-icon>
|
<ha-svg-icon slot="graphic" .path=${mdiFlask}></ha-svg-icon>
|
||||||
</mwc-list-item>
|
</mwc-list-item>
|
||||||
<mwc-list-item graphic="icon">
|
<mwc-list-item graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.conditions.rename"
|
"ui.panel.config.automation.editor.conditions.rename"
|
||||||
)}
|
)}
|
||||||
<ha-svg-icon slot="graphic" .path=${mdiRenameBox}></ha-svg-icon>
|
<ha-svg-icon
|
||||||
</mwc-list-item>
|
slot="graphic"
|
||||||
<mwc-list-item graphic="icon">
|
.path=${mdiRenameBox}
|
||||||
${this.hass.localize(
|
></ha-svg-icon>
|
||||||
"ui.panel.config.automation.editor.actions.duplicate"
|
</mwc-list-item>
|
||||||
)}
|
<mwc-list-item graphic="icon">
|
||||||
<ha-svg-icon
|
${this.hass.localize(
|
||||||
slot="graphic"
|
"ui.panel.config.automation.editor.actions.duplicate"
|
||||||
.path=${mdiContentDuplicate}
|
)}
|
||||||
></ha-svg-icon>
|
<ha-svg-icon
|
||||||
</mwc-list-item>
|
slot="graphic"
|
||||||
|
.path=${mdiContentDuplicate}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<li divider role="separator"></li>
|
<li divider role="separator"></li>
|
||||||
|
|
||||||
<mwc-list-item graphic="icon">
|
<mwc-list-item graphic="icon">
|
||||||
${this.hass.localize("ui.panel.config.automation.editor.edit_ui")}
|
${this.hass.localize(
|
||||||
${!this._yamlMode
|
"ui.panel.config.automation.editor.edit_ui"
|
||||||
? html`<ha-svg-icon
|
)}
|
||||||
slot="graphic"
|
${!this._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>
|
||||||
|
|
||||||
<mwc-list-item graphic="icon">
|
<mwc-list-item graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.edit_yaml"
|
"ui.panel.config.automation.editor.edit_yaml"
|
||||||
)}
|
)}
|
||||||
${this._yamlMode
|
${this._yamlMode
|
||||||
? html`<ha-svg-icon
|
? html`<ha-svg-icon
|
||||||
slot="graphic"
|
class="selected_menu_item"
|
||||||
.path=${mdiCheck}
|
slot="graphic"
|
||||||
></ha-svg-icon>`
|
.path=${mdiCheck}
|
||||||
: ``}
|
></ha-svg-icon>`
|
||||||
</mwc-list-item>
|
: ``}
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<li divider role="separator"></li>
|
<li divider role="separator"></li>
|
||||||
|
|
||||||
<mwc-list-item graphic="icon">
|
<mwc-list-item graphic="icon">
|
||||||
${this.condition.enabled === false
|
${this.condition.enabled === false
|
||||||
? this.hass.localize(
|
? this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.actions.enable"
|
"ui.panel.config.automation.editor.actions.enable"
|
||||||
)
|
)
|
||||||
: this.hass.localize(
|
: this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.actions.disable"
|
"ui.panel.config.automation.editor.actions.disable"
|
||||||
)}
|
)}
|
||||||
<ha-svg-icon
|
<ha-svg-icon
|
||||||
slot="graphic"
|
slot="graphic"
|
||||||
.path=${this.condition.enabled === false
|
.path=${this.condition.enabled === false
|
||||||
? mdiPlayCircleOutline
|
? mdiPlayCircleOutline
|
||||||
: mdiStopCircleOutline}
|
: mdiStopCircleOutline}
|
||||||
></ha-svg-icon>
|
></ha-svg-icon>
|
||||||
</mwc-list-item>
|
</mwc-list-item>
|
||||||
<mwc-list-item class="warning" graphic="icon">
|
<mwc-list-item class="warning" graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.actions.delete"
|
"ui.panel.config.automation.editor.actions.delete"
|
||||||
)}
|
)}
|
||||||
<ha-svg-icon
|
<ha-svg-icon
|
||||||
class="warning"
|
class="warning"
|
||||||
slot="graphic"
|
slot="graphic"
|
||||||
.path=${mdiDelete}
|
.path=${mdiDelete}
|
||||||
></ha-svg-icon>
|
></ha-svg-icon>
|
||||||
</mwc-list-item>
|
</mwc-list-item>
|
||||||
</ha-button-menu>
|
</ha-button-menu>
|
||||||
|
`}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
@@ -224,6 +240,7 @@ export default class HaAutomationConditionRow extends LitElement {
|
|||||||
.yamlMode=${this._yamlMode}
|
.yamlMode=${this._yamlMode}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.condition=${this.condition}
|
.condition=${this.condition}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
></ha-automation-condition-editor>
|
></ha-automation-condition-editor>
|
||||||
</div>
|
</div>
|
||||||
</ha-expansion-panel>
|
</ha-expansion-panel>
|
||||||
@@ -297,11 +314,15 @@ export default class HaAutomationConditionRow extends LitElement {
|
|||||||
|
|
||||||
private _onDelete() {
|
private _onDelete() {
|
||||||
showConfirmationDialog(this, {
|
showConfirmationDialog(this, {
|
||||||
|
title: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.conditions.delete_confirm_title"
|
||||||
|
),
|
||||||
text: this.hass.localize(
|
text: this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.conditions.delete_confirm"
|
"ui.panel.config.automation.editor.conditions.delete_confirm_text"
|
||||||
),
|
),
|
||||||
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 });
|
||||||
},
|
},
|
||||||
@@ -423,13 +444,18 @@ export default class HaAutomationConditionRow 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;
|
||||||
|
}
|
||||||
.condition-icon {
|
.condition-icon {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
@media (min-width: 870px) {
|
@media (min-width: 870px) {
|
||||||
.condition-icon {
|
.condition-icon {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
color: var(--primary-color);
|
color: var(--secondary-text-color);
|
||||||
opacity: 0.9;
|
opacity: 0.9;
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
@@ -472,6 +498,12 @@ export default class HaAutomationConditionRow extends LitElement {
|
|||||||
.testing.pass {
|
.testing.pass {
|
||||||
background-color: var(--success-color);
|
background-color: var(--success-color);
|
||||||
}
|
}
|
||||||
|
.selected_menu_item {
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
li[role="separator"] {
|
||||||
|
border-bottom-color: var(--divider-color);
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
import { mdiPlus } from "@mdi/js";
|
|
||||||
import { repeat } from "lit/directives/repeat";
|
|
||||||
import deepClone from "deep-clone-simple";
|
|
||||||
import "@material/mwc-button";
|
import "@material/mwc-button";
|
||||||
|
import type { ActionDetail } from "@material/mwc-list";
|
||||||
|
import { mdiArrowDown, mdiArrowUp, mdiDrag, mdiPlus } from "@mdi/js";
|
||||||
|
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 memoizeOne from "memoize-one";
|
||||||
import type { ActionDetail } from "@material/mwc-list";
|
import type { SortableEvent } from "sortablejs";
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import "../../../../components/ha-svg-icon";
|
|
||||||
import "../../../../components/ha-button-menu";
|
import "../../../../components/ha-button-menu";
|
||||||
|
import "../../../../components/ha-svg-icon";
|
||||||
import type { Condition } from "../../../../data/automation";
|
import type { Condition } from "../../../../data/automation";
|
||||||
import type { HomeAssistant } from "../../../../types";
|
import type { HomeAssistant } from "../../../../types";
|
||||||
import "./ha-automation-condition-row";
|
import "./ha-automation-condition-row";
|
||||||
@@ -16,6 +17,14 @@ import type HaAutomationConditionRow from "./ha-automation-condition-row";
|
|||||||
// Uncommenting these and this element doesn't load
|
// Uncommenting these and this element doesn't load
|
||||||
// import "./types/ha-automation-condition-not";
|
// import "./types/ha-automation-condition-not";
|
||||||
// import "./types/ha-automation-condition-or";
|
// import "./types/ha-automation-condition-or";
|
||||||
|
import { stringCompare } from "../../../../common/string/compare";
|
||||||
|
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
||||||
|
import type { HaSelect } from "../../../../components/ha-select";
|
||||||
|
import { CONDITION_TYPES } from "../../../../data/condition";
|
||||||
|
import {
|
||||||
|
loadSortable,
|
||||||
|
SortableInstance,
|
||||||
|
} from "../../../../resources/sortable.ondemand";
|
||||||
import "./types/ha-automation-condition-and";
|
import "./types/ha-automation-condition-and";
|
||||||
import "./types/ha-automation-condition-device";
|
import "./types/ha-automation-condition-device";
|
||||||
import "./types/ha-automation-condition-numeric_state";
|
import "./types/ha-automation-condition-numeric_state";
|
||||||
@@ -25,10 +34,7 @@ import "./types/ha-automation-condition-template";
|
|||||||
import "./types/ha-automation-condition-time";
|
import "./types/ha-automation-condition-time";
|
||||||
import "./types/ha-automation-condition-trigger";
|
import "./types/ha-automation-condition-trigger";
|
||||||
import "./types/ha-automation-condition-zone";
|
import "./types/ha-automation-condition-zone";
|
||||||
import { CONDITION_TYPES } from "../../../../data/condition";
|
import { sortableStyles } from "../../../../resources/ha-sortable-style";
|
||||||
import { stringCompare } from "../../../../common/string/compare";
|
|
||||||
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
|
||||||
import type { HaSelect } from "../../../../components/ha-select";
|
|
||||||
|
|
||||||
@customElement("ha-automation-condition")
|
@customElement("ha-automation-condition")
|
||||||
export default class HaAutomationCondition extends LitElement {
|
export default class HaAutomationCondition extends LitElement {
|
||||||
@@ -36,11 +42,23 @@ export default class HaAutomationCondition extends LitElement {
|
|||||||
|
|
||||||
@property() public conditions!: Condition[];
|
@property() public conditions!: Condition[];
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
private _focusLastConditionOnChange = false;
|
private _focusLastConditionOnChange = false;
|
||||||
|
|
||||||
private _conditionKeys = new WeakMap<Condition, string>();
|
private _conditionKeys = new WeakMap<Condition, string>();
|
||||||
|
|
||||||
|
private _sortable?: SortableInstance;
|
||||||
|
|
||||||
protected updated(changedProperties: PropertyValues) {
|
protected updated(changedProperties: PropertyValues) {
|
||||||
|
if (changedProperties.has("reOrderMode")) {
|
||||||
|
if (this.reOrderMode) {
|
||||||
|
this._createSortable();
|
||||||
|
} else {
|
||||||
|
this._destroySortable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!changedProperties.has("conditions")) {
|
if (!changedProperties.has("conditions")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -82,19 +100,53 @@ export default class HaAutomationCondition extends LitElement {
|
|||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
return html`
|
return html`
|
||||||
${repeat(
|
<div class="conditions">
|
||||||
this.conditions,
|
${repeat(
|
||||||
(condition) => this._getKey(condition),
|
this.conditions,
|
||||||
(cond, idx) => html`
|
(condition) => this._getKey(condition),
|
||||||
<ha-automation-condition-row
|
(cond, idx) => html`
|
||||||
.index=${idx}
|
<ha-automation-condition-row
|
||||||
.condition=${cond}
|
.index=${idx}
|
||||||
@duplicate=${this._duplicateCondition}
|
.totalConditions=${this.conditions.length}
|
||||||
@value-changed=${this._conditionChanged}
|
.condition=${cond}
|
||||||
.hass=${this.hass}
|
.hideMenu=${this.reOrderMode}
|
||||||
></ha-automation-condition-row>
|
.reOrderMode=${this.reOrderMode}
|
||||||
`
|
@duplicate=${this._duplicateCondition}
|
||||||
)}
|
@move-condition=${this._move}
|
||||||
|
@value-changed=${this._conditionChanged}
|
||||||
|
.hass=${this.hass}
|
||||||
|
>
|
||||||
|
${this.reOrderMode
|
||||||
|
? 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.conditions.length - 1}
|
||||||
|
></ha-icon-button>
|
||||||
|
<div class="handle" slot="icons">
|
||||||
|
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
</ha-automation-condition-row>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<ha-button-menu fixed @action=${this._addCondition}>
|
<ha-button-menu fixed @action=${this._addCondition}>
|
||||||
<mwc-button
|
<mwc-button
|
||||||
slot="trigger"
|
slot="trigger"
|
||||||
@@ -116,6 +168,36 @@ export default class HaAutomationCondition extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _createSortable() {
|
||||||
|
const Sortable = await loadSortable();
|
||||||
|
this._sortable = new Sortable(
|
||||||
|
this.shadowRoot!.querySelector(".conditions")!,
|
||||||
|
{
|
||||||
|
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(condition: Condition) {
|
private _getKey(condition: Condition) {
|
||||||
if (!this._conditionKeys.has(condition)) {
|
if (!this._conditionKeys.has(condition)) {
|
||||||
this._conditionKeys.set(condition, Math.random().toString());
|
this._conditionKeys.set(condition, Math.random().toString());
|
||||||
@@ -142,6 +224,30 @@ export default class HaAutomationCondition extends LitElement {
|
|||||||
fireEvent(this, "value-changed", { value: conditions });
|
fireEvent(this, "value-changed", { value: conditions });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _moveUp(ev) {
|
||||||
|
const index = (ev.target as any).index;
|
||||||
|
const newIndex = 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 conditions = this.conditions.concat();
|
||||||
|
const condition = conditions.splice(index, 1)[0];
|
||||||
|
conditions.splice(newIndex, 0, condition);
|
||||||
|
fireEvent(this, "value-changed", { value: conditions });
|
||||||
|
}
|
||||||
|
|
||||||
private _conditionChanged(ev: CustomEvent) {
|
private _conditionChanged(ev: CustomEvent) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const conditions = [...this.conditions];
|
const conditions = [...this.conditions];
|
||||||
@@ -186,16 +292,27 @@ export default class HaAutomationCondition extends LitElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return [
|
||||||
ha-automation-condition-row {
|
sortableStyles,
|
||||||
display: block;
|
css`
|
||||||
margin-bottom: 16px;
|
ha-automation-condition-row {
|
||||||
scroll-margin-top: 48px;
|
display: block;
|
||||||
}
|
margin-bottom: 16px;
|
||||||
ha-svg-icon {
|
scroll-margin-top: 48px;
|
||||||
height: 20px;
|
}
|
||||||
}
|
ha-svg-icon {
|
||||||
`;
|
height: 20px;
|
||||||
|
}
|
||||||
|
.handle {
|
||||||
|
cursor: move;
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
.handle ha-svg-icon {
|
||||||
|
pointer-events: none;
|
||||||
|
height: 24px;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ export class HaLogicalCondition extends LitElement implements ConditionElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public condition!: LogicalCondition;
|
@property({ attribute: false }) public condition!: LogicalCondition;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
return {
|
return {
|
||||||
conditions: [],
|
conditions: [],
|
||||||
@@ -24,6 +26,7 @@ export class HaLogicalCondition extends LitElement implements ConditionElement {
|
|||||||
.conditions=${this.condition.conditions || []}
|
.conditions=${this.condition.conditions || []}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
></ha-automation-condition>
|
></ha-automation-condition>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
|
import "@material/mwc-button";
|
||||||
import "@material/mwc-list/mwc-list-item";
|
import "@material/mwc-list/mwc-list-item";
|
||||||
import {
|
import {
|
||||||
mdiCheck,
|
mdiCheck,
|
||||||
mdiContentDuplicate,
|
mdiContentDuplicate,
|
||||||
mdiContentSave,
|
mdiContentSave,
|
||||||
|
mdiDebugStepOver,
|
||||||
mdiDelete,
|
mdiDelete,
|
||||||
mdiDotsVertical,
|
mdiDotsVertical,
|
||||||
mdiPencil,
|
mdiInformationOutline,
|
||||||
mdiPlay,
|
mdiPlay,
|
||||||
mdiPlayCircleOutline,
|
mdiPlayCircleOutline,
|
||||||
mdiRenameBox,
|
mdiRenameBox,
|
||||||
|
mdiSort,
|
||||||
mdiStopCircleOutline,
|
mdiStopCircleOutline,
|
||||||
mdiTransitConnection,
|
mdiTransitConnection,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
@@ -23,10 +26,12 @@ import {
|
|||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { property, state, query } from "lit/decorators";
|
import { property, query, state } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import { navigate } from "../../../common/navigate";
|
import { navigate } from "../../../common/navigate";
|
||||||
import { copyToClipboard } from "../../../common/util/copy-clipboard";
|
import { copyToClipboard } from "../../../common/util/copy-clipboard";
|
||||||
|
import { afterNextRender } from "../../../common/util/render-status";
|
||||||
import "../../../components/ha-button-menu";
|
import "../../../components/ha-button-menu";
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
import "../../../components/ha-fab";
|
import "../../../components/ha-fab";
|
||||||
@@ -40,24 +45,26 @@ import {
|
|||||||
deleteAutomation,
|
deleteAutomation,
|
||||||
getAutomationConfig,
|
getAutomationConfig,
|
||||||
getAutomationEditorInitData,
|
getAutomationEditorInitData,
|
||||||
|
saveAutomationConfig,
|
||||||
showAutomationEditor,
|
showAutomationEditor,
|
||||||
triggerAutomationActions,
|
triggerAutomationActions,
|
||||||
} from "../../../data/automation";
|
} from "../../../data/automation";
|
||||||
import {
|
import {
|
||||||
showAlertDialog,
|
showAlertDialog,
|
||||||
showConfirmationDialog,
|
showConfirmationDialog,
|
||||||
showPromptDialog,
|
|
||||||
} from "../../../dialogs/generic/show-dialog-box";
|
} from "../../../dialogs/generic/show-dialog-box";
|
||||||
import "../../../layouts/ha-app-layout";
|
import "../../../layouts/ha-app-layout";
|
||||||
import "../../../layouts/hass-tabs-subpage";
|
import "../../../layouts/hass-subpage";
|
||||||
import { KeyboardShortcutMixin } from "../../../mixins/keyboard-shortcut-mixin";
|
import { KeyboardShortcutMixin } from "../../../mixins/keyboard-shortcut-mixin";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import { HomeAssistant, Route } from "../../../types";
|
import { HomeAssistant, Route } from "../../../types";
|
||||||
import { showToast } from "../../../util/toast";
|
import { showToast } from "../../../util/toast";
|
||||||
import "../ha-config-section";
|
import "../ha-config-section";
|
||||||
import { configSections } from "../ha-panel-config";
|
import { showAutomationModeDialog } from "./automation-mode-dialog/show-dialog-automation-mode";
|
||||||
|
import { showAutomationRenameDialog } from "./automation-rename-dialog/show-dialog-automation-rename";
|
||||||
import "./blueprint-automation-editor";
|
import "./blueprint-automation-editor";
|
||||||
import "./manual-automation-editor";
|
import "./manual-automation-editor";
|
||||||
|
import type { HaManualAutomationEditor } from "./manual-automation-editor";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
@@ -97,7 +104,10 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _mode: "gui" | "yaml" = "gui";
|
@state() private _mode: "gui" | "yaml" = "gui";
|
||||||
|
|
||||||
@query("ha-yaml-editor", true) private _editor?: HaYamlEditor;
|
@query("ha-yaml-editor", true) private _yamlEditor?: HaYamlEditor;
|
||||||
|
|
||||||
|
@query("manual-automation-editor")
|
||||||
|
private _manualEditor?: HaManualAutomationEditor;
|
||||||
|
|
||||||
private _configSubscriptions: Record<
|
private _configSubscriptions: Record<
|
||||||
string,
|
string,
|
||||||
@@ -111,13 +121,27 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
? this.hass.states[this._entityId]
|
? this.hass.states[this._entityId]
|
||||||
: undefined;
|
: undefined;
|
||||||
return html`
|
return html`
|
||||||
<hass-tabs-subpage
|
<hass-subpage
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
.route=${this.route}
|
.route=${this.route}
|
||||||
.backCallback=${this._backTapped}
|
.backCallback=${this._backTapped}
|
||||||
.tabs=${configSections.automations}
|
.header=${!this._config
|
||||||
|
? ""
|
||||||
|
: this._config.alias ||
|
||||||
|
this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.default_name"
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
|
${this._config?.id && !this.narrow
|
||||||
|
? html`
|
||||||
|
<mwc-button @click=${this._showTrace} slot="toolbar-icon">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.show_trace"
|
||||||
|
)}
|
||||||
|
</mwc-button>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
<ha-button-menu corner="BOTTOM_START" slot="toolbar-icon">
|
<ha-button-menu corner="BOTTOM_START" slot="toolbar-icon">
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
slot="trigger"
|
slot="trigger"
|
||||||
@@ -125,6 +149,18 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
.path=${mdiDotsVertical}
|
.path=${mdiDotsVertical}
|
||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
|
|
||||||
|
<mwc-list-item
|
||||||
|
graphic="icon"
|
||||||
|
.disabled=${!stateObj}
|
||||||
|
@click=${this._showInfo}
|
||||||
|
>
|
||||||
|
${this.hass.localize("ui.panel.config.automation.editor.show_info")}
|
||||||
|
<ha-svg-icon
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiInformationOutline}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<mwc-list-item
|
<mwc-list-item
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
.disabled=${!stateObj}
|
.disabled=${!stateObj}
|
||||||
@@ -134,15 +170,9 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
<ha-svg-icon slot="graphic" .path=${mdiPlay}></ha-svg-icon>
|
<ha-svg-icon slot="graphic" .path=${mdiPlay}></ha-svg-icon>
|
||||||
</mwc-list-item>
|
</mwc-list-item>
|
||||||
|
|
||||||
${stateObj
|
${stateObj && this._config && this.narrow
|
||||||
? html`<a
|
? html`<a href="/config/automation/trace/${this._config.id}">
|
||||||
href="/config/automation/trace/${this._config
|
<mwc-list-item graphic="icon">
|
||||||
? this._config.id
|
|
||||||
: ""}"
|
|
||||||
target="_blank"
|
|
||||||
.disabled=${!stateObj}
|
|
||||||
>
|
|
||||||
<mwc-list-item graphic="icon" .disabled=${!stateObj}>
|
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.show_trace"
|
"ui.panel.config.automation.editor.show_trace"
|
||||||
)}
|
)}
|
||||||
@@ -154,11 +184,45 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
</a>`
|
</a>`
|
||||||
: ""}
|
: ""}
|
||||||
|
|
||||||
<mwc-list-item graphic="icon" @click=${this._promptAutomationAlias}>
|
<mwc-list-item
|
||||||
|
graphic="icon"
|
||||||
|
@click=${this._promptAutomationAlias}
|
||||||
|
.disabled=${!this.automationId || this._mode === "yaml"}
|
||||||
|
>
|
||||||
${this.hass.localize("ui.panel.config.automation.editor.rename")}
|
${this.hass.localize("ui.panel.config.automation.editor.rename")}
|
||||||
<ha-svg-icon slot="graphic" .path=${mdiRenameBox}></ha-svg-icon>
|
<ha-svg-icon slot="graphic" .path=${mdiRenameBox}></ha-svg-icon>
|
||||||
</mwc-list-item>
|
</mwc-list-item>
|
||||||
|
|
||||||
|
${this._config && !("use_blueprint" in this._config)
|
||||||
|
? html`
|
||||||
|
<mwc-list-item
|
||||||
|
graphic="icon"
|
||||||
|
@click=${this._promptAutomationMode}
|
||||||
|
.disabled=${this._mode === "yaml"}
|
||||||
|
>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.change_mode"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiDebugStepOver}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
${this._config && !("use_blueprint" in this._config)
|
||||||
|
? html`<mwc-list-item
|
||||||
|
graphic="icon"
|
||||||
|
@click=${this._toggleReOrderMode}
|
||||||
|
.disabled=${this._mode === "yaml"}
|
||||||
|
>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.re_order"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon slot="graphic" .path=${mdiSort}></ha-svg-icon>
|
||||||
|
</mwc-list-item>`
|
||||||
|
: ""}
|
||||||
|
|
||||||
<mwc-list-item
|
<mwc-list-item
|
||||||
.disabled=${!this.automationId}
|
.disabled=${!this.automationId}
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
@@ -201,12 +265,12 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
.disabled=${!stateObj}
|
.disabled=${!stateObj}
|
||||||
@click=${this._toggle}
|
@click=${this._toggle}
|
||||||
>
|
>
|
||||||
${!stateObj || stateObj.state === "off"
|
${stateObj?.state === "off"
|
||||||
? this.hass.localize("ui.panel.config.automation.editor.enable")
|
? this.hass.localize("ui.panel.config.automation.editor.enable")
|
||||||
: this.hass.localize("ui.panel.config.automation.editor.disable")}
|
: this.hass.localize("ui.panel.config.automation.editor.disable")}
|
||||||
<ha-svg-icon
|
<ha-svg-icon
|
||||||
slot="graphic"
|
slot="graphic"
|
||||||
.path=${!stateObj || stateObj.state === "off"
|
.path=${stateObj?.state === "off"
|
||||||
? mdiPlayCircleOutline
|
? mdiPlayCircleOutline
|
||||||
: mdiStopCircleOutline}
|
: mdiStopCircleOutline}
|
||||||
></ha-svg-icon>
|
></ha-svg-icon>
|
||||||
@@ -237,70 +301,48 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
@subscribe-automation-config=${this._subscribeAutomationConfig}
|
@subscribe-automation-config=${this._subscribeAutomationConfig}
|
||||||
>
|
>
|
||||||
${this._errors
|
${this._errors
|
||||||
? html`<div class="errors">${this._errors}</div>`
|
? html`<ha-alert alert-type="error">
|
||||||
|
${this._errors}
|
||||||
|
</ha-alert>`
|
||||||
: ""}
|
: ""}
|
||||||
${this._mode === "gui"
|
${this._mode === "gui"
|
||||||
? html`
|
? "use_blueprint" in this._config
|
||||||
${this.narrow
|
? html`
|
||||||
? html`<span slot="header"
|
<blueprint-automation-editor
|
||||||
>${this._config!.alias ||
|
.hass=${this.hass}
|
||||||
this.hass.localize(
|
.narrow=${this.narrow}
|
||||||
"ui.panel.config.automation.editor.default_name"
|
.isWide=${this.isWide}
|
||||||
)}</span
|
.stateObj=${stateObj}
|
||||||
>`
|
.config=${this._config}
|
||||||
: html`
|
@value-changed=${this._valueChanged}
|
||||||
<div class="header-name">
|
></blueprint-automation-editor>
|
||||||
<h1>
|
`
|
||||||
${this._config!.alias ||
|
: html`
|
||||||
this.hass.localize(
|
<manual-automation-editor
|
||||||
"ui.panel.config.automation.editor.default_name"
|
.hass=${this.hass}
|
||||||
)}
|
.narrow=${this.narrow}
|
||||||
</h1>
|
.isWide=${this.isWide}
|
||||||
<ha-icon-button
|
.stateObj=${stateObj}
|
||||||
.path=${mdiPencil}
|
.config=${this._config}
|
||||||
@click=${this._promptAutomationAlias}
|
@value-changed=${this._valueChanged}
|
||||||
.label=${this.hass.localize(
|
></manual-automation-editor>
|
||||||
"ui.panel.config.automation.editor.rename"
|
`
|
||||||
)}
|
|
||||||
></ha-icon-button>
|
|
||||||
</div>
|
|
||||||
`}
|
|
||||||
${"use_blueprint" in this._config
|
|
||||||
? html`
|
|
||||||
<blueprint-automation-editor
|
|
||||||
.hass=${this.hass}
|
|
||||||
.narrow=${this.narrow}
|
|
||||||
.isWide=${this.isWide}
|
|
||||||
.stateObj=${stateObj}
|
|
||||||
.config=${this._config}
|
|
||||||
@value-changed=${this._valueChanged}
|
|
||||||
></blueprint-automation-editor>
|
|
||||||
`
|
|
||||||
: html`
|
|
||||||
<manual-automation-editor
|
|
||||||
.hass=${this.hass}
|
|
||||||
.narrow=${this.narrow}
|
|
||||||
.isWide=${this.isWide}
|
|
||||||
.stateObj=${stateObj}
|
|
||||||
.config=${this._config}
|
|
||||||
@value-changed=${this._valueChanged}
|
|
||||||
></manual-automation-editor>
|
|
||||||
`}
|
|
||||||
`
|
|
||||||
: this._mode === "yaml"
|
: this._mode === "yaml"
|
||||||
? html`
|
? html`
|
||||||
${!this.narrow
|
${stateObj?.state === "off"
|
||||||
? html`
|
? html`
|
||||||
<ha-card outlined>
|
<ha-alert alert-type="info">
|
||||||
<div class="card-header">
|
${this.hass.localize(
|
||||||
${this._config.alias ||
|
"ui.panel.config.automation.editor.disabled"
|
||||||
this.hass.localize(
|
)}
|
||||||
"ui.panel.config.automation.editor.default_name"
|
<mwc-button slot="action" @click=${this._toggle}>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.enable"
|
||||||
)}
|
)}
|
||||||
</div>
|
</mwc-button>
|
||||||
</ha-card>
|
</ha-alert>
|
||||||
`
|
`
|
||||||
: ``}
|
: ""}
|
||||||
<ha-yaml-editor
|
<ha-yaml-editor
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.defaultValue=${this._preprocessYaml()}
|
.defaultValue=${this._preprocessYaml()}
|
||||||
@@ -329,7 +371,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
>
|
>
|
||||||
<ha-svg-icon slot="icon" .path=${mdiContentSave}></ha-svg-icon>
|
<ha-svg-icon slot="icon" .path=${mdiContentSave}></ha-svg-icon>
|
||||||
</ha-fab>
|
</ha-fab>
|
||||||
</hass-tabs-subpage>
|
</hass-subpage>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -408,7 +450,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
this._dirty = false;
|
this._dirty = false;
|
||||||
this._config = config;
|
this._config = config;
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
showAlertDialog(this, {
|
await showAlertDialog(this, {
|
||||||
text:
|
text:
|
||||||
err.status_code === 404
|
err.status_code === 404
|
||||||
? this.hass.localize(
|
? this.hass.localize(
|
||||||
@@ -419,7 +461,8 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
"err_no",
|
"err_no",
|
||||||
err.status_code
|
err.status_code
|
||||||
),
|
),
|
||||||
}).then(() => history.back());
|
});
|
||||||
|
history.back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -430,6 +473,22 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
this._errors = undefined;
|
this._errors = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _showInfo() {
|
||||||
|
if (!this.hass || !this._entityId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fireEvent(this, "hass-more-info", { entityId: this._entityId });
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _showTrace() {
|
||||||
|
if (this._config?.id) {
|
||||||
|
const result = await this.confirmUnsavedChanged();
|
||||||
|
if (result) {
|
||||||
|
navigate(`/config/automation/trace/${this._config.id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private _runActions() {
|
private _runActions() {
|
||||||
if (!this.hass || !this._entityId) {
|
if (!this.hass || !this._entityId) {
|
||||||
return;
|
return;
|
||||||
@@ -452,19 +511,17 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _preprocessYaml() {
|
private _preprocessYaml() {
|
||||||
const cleanConfig = this._config;
|
if (!this._config) {
|
||||||
if (!cleanConfig) {
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
const cleanConfig: AutomationConfig = { ...this._config };
|
||||||
delete cleanConfig.id;
|
delete cleanConfig.id;
|
||||||
|
|
||||||
return cleanConfig;
|
return cleanConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _copyYaml(): Promise<void> {
|
private async _copyYaml(): Promise<void> {
|
||||||
if (this._editor?.yaml) {
|
if (this._yamlEditor?.yaml) {
|
||||||
await copyToClipboard(this._editor.yaml);
|
await copyToClipboard(this._yamlEditor.yaml);
|
||||||
showToast(this, {
|
showToast(this, {
|
||||||
message: this.hass.localize("ui.common.copied_clipboard"),
|
message: this.hass.localize("ui.common.copied_clipboard"),
|
||||||
});
|
});
|
||||||
@@ -476,65 +533,67 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
if (!ev.detail.isValid) {
|
if (!ev.detail.isValid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._config = ev.detail.value;
|
this._config = { id: this._config?.id, ...ev.detail.value };
|
||||||
this._errors = undefined;
|
this._errors = undefined;
|
||||||
this._dirty = true;
|
this._dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _backTapped = (): void => {
|
private async confirmUnsavedChanged(): Promise<boolean> {
|
||||||
if (this._dirty) {
|
if (this._dirty) {
|
||||||
showConfirmationDialog(this, {
|
return showConfirmationDialog(this, {
|
||||||
|
title: this.hass!.localize(
|
||||||
|
"ui.panel.config.automation.editor.unsaved_confirm_title"
|
||||||
|
),
|
||||||
text: this.hass!.localize(
|
text: this.hass!.localize(
|
||||||
"ui.panel.config.automation.editor.unsaved_confirm"
|
"ui.panel.config.automation.editor.unsaved_confirm_text"
|
||||||
),
|
),
|
||||||
confirmText: this.hass!.localize("ui.common.leave"),
|
confirmText: this.hass!.localize("ui.common.leave"),
|
||||||
dismissText: this.hass!.localize("ui.common.stay"),
|
dismissText: this.hass!.localize("ui.common.stay"),
|
||||||
confirm: () => {
|
destructive: true,
|
||||||
setTimeout(() => history.back());
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
history.back();
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _backTapped = async () => {
|
||||||
|
const result = await this.confirmUnsavedChanged();
|
||||||
|
if (result) {
|
||||||
|
afterNextRender(() => history.back());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private async _duplicate() {
|
private async _duplicate() {
|
||||||
if (this._dirty) {
|
const result = await this.confirmUnsavedChanged();
|
||||||
if (
|
if (result) {
|
||||||
!(await showConfirmationDialog(this, {
|
showAutomationEditor({
|
||||||
text: this.hass!.localize(
|
...this._config,
|
||||||
"ui.panel.config.automation.editor.unsaved_confirm"
|
id: undefined,
|
||||||
),
|
alias: undefined,
|
||||||
confirmText: this.hass!.localize("ui.common.leave"),
|
});
|
||||||
dismissText: this.hass!.localize("ui.common.stay"),
|
|
||||||
}))
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Wait for dialog to complete closing
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
||||||
}
|
}
|
||||||
showAutomationEditor({
|
|
||||||
...this._config,
|
|
||||||
id: undefined,
|
|
||||||
alias: undefined,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _deleteConfirm() {
|
private async _deleteConfirm() {
|
||||||
showConfirmationDialog(this, {
|
showConfirmationDialog(this, {
|
||||||
|
title: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.picker.delete_confirm_title"
|
||||||
|
),
|
||||||
text: this.hass.localize(
|
text: this.hass.localize(
|
||||||
"ui.panel.config.automation.picker.delete_confirm"
|
"ui.panel.config.automation.picker.delete_confirm_text",
|
||||||
|
{ name: this._config?.alias }
|
||||||
),
|
),
|
||||||
confirmText: this.hass!.localize("ui.common.delete"),
|
confirmText: this.hass!.localize("ui.common.delete"),
|
||||||
|
destructive: true,
|
||||||
dismissText: this.hass!.localize("ui.common.cancel"),
|
dismissText: this.hass!.localize("ui.common.cancel"),
|
||||||
confirm: () => this._delete(),
|
confirm: () => this._delete(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _delete() {
|
private async _delete() {
|
||||||
await deleteAutomation(this.hass, this.automationId as string);
|
if (this.automationId) {
|
||||||
history.back();
|
await deleteAutomation(this.hass, this.automationId);
|
||||||
|
history.back();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _switchUiMode() {
|
private _switchUiMode() {
|
||||||
@@ -545,62 +604,63 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
this._mode = "yaml";
|
this._mode = "yaml";
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _promptAutomationAlias(): Promise<string | null> {
|
private _toggleReOrderMode() {
|
||||||
const result = await showPromptDialog(this, {
|
if (this._manualEditor) {
|
||||||
title: this.hass.localize(
|
this._manualEditor.reOrderMode = !this._manualEditor.reOrderMode;
|
||||||
"ui.panel.config.automation.editor.automation_alias"
|
|
||||||
),
|
|
||||||
inputLabel: this.hass.localize("ui.panel.config.automation.editor.alias"),
|
|
||||||
inputType: "string",
|
|
||||||
placeholder: this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.default_name"
|
|
||||||
),
|
|
||||||
defaultValue: this._config!.alias,
|
|
||||||
confirmText: this.hass.localize("ui.common.submit"),
|
|
||||||
});
|
|
||||||
if (result) {
|
|
||||||
this._config!.alias = result;
|
|
||||||
this._dirty = true;
|
|
||||||
this.requestUpdate();
|
|
||||||
}
|
}
|
||||||
return result;
|
}
|
||||||
|
|
||||||
|
private async _promptAutomationAlias(): Promise<void> {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
showAutomationRenameDialog(this, {
|
||||||
|
config: this._config!,
|
||||||
|
updateAutomation: (config) => {
|
||||||
|
this._config = config;
|
||||||
|
this._dirty = true;
|
||||||
|
this.requestUpdate();
|
||||||
|
resolve();
|
||||||
|
},
|
||||||
|
onClose: () => resolve(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _promptAutomationMode(): Promise<void> {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
showAutomationModeDialog(this, {
|
||||||
|
config: this._config!,
|
||||||
|
updateAutomation: (config) => {
|
||||||
|
this._config = config;
|
||||||
|
this._dirty = true;
|
||||||
|
this.requestUpdate();
|
||||||
|
resolve();
|
||||||
|
},
|
||||||
|
onClose: () => resolve(),
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _saveAutomation(): Promise<void> {
|
private async _saveAutomation(): Promise<void> {
|
||||||
const id = this.automationId || String(Date.now());
|
const id = this.automationId || String(Date.now());
|
||||||
if (!this._config!.alias) {
|
if (!this.automationId) {
|
||||||
const alias = await this._promptAutomationAlias();
|
await this._promptAutomationAlias();
|
||||||
if (!alias) {
|
|
||||||
showAlertDialog(this, {
|
|
||||||
text: this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.missing_name"
|
|
||||||
),
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._config!.alias = alias;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hass!.callApi(
|
try {
|
||||||
"POST",
|
await saveAutomationConfig(this.hass, id, this._config!);
|
||||||
"config/automation/config/" + id,
|
} catch (errors: any) {
|
||||||
this._config
|
this._errors = errors.body.message || errors.error || errors.body;
|
||||||
).then(
|
showToast(this, {
|
||||||
() => {
|
message: errors.body.message || errors.error || errors.body,
|
||||||
this._dirty = false;
|
});
|
||||||
|
throw errors;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.automationId) {
|
this._dirty = false;
|
||||||
navigate(`/config/automation/edit/${id}`, { replace: true });
|
|
||||||
}
|
if (!this.automationId) {
|
||||||
},
|
navigate(`/config/automation/edit/${id}`, { replace: true });
|
||||||
(errors) => {
|
}
|
||||||
this._errors = errors.body.message || errors.error || errors.body;
|
|
||||||
showToast(this, {
|
|
||||||
message: errors.body.message || errors.error || errors.body,
|
|
||||||
});
|
|
||||||
throw errors;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _subscribeAutomationConfig(ev) {
|
private _subscribeAutomationConfig(ev) {
|
||||||
@@ -623,11 +683,6 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
ha-card {
|
ha-card {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.errors {
|
|
||||||
padding: 20px;
|
|
||||||
font-weight: bold;
|
|
||||||
color: var(--error-color);
|
|
||||||
}
|
|
||||||
.content {
|
.content {
|
||||||
padding-bottom: 20px;
|
padding-bottom: 20px;
|
||||||
}
|
}
|
||||||
@@ -637,7 +692,8 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding-bottom: 0;
|
padding-bottom: 0;
|
||||||
}
|
}
|
||||||
manual-automation-editor {
|
manual-automation-editor,
|
||||||
|
blueprint-automation-editor {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
max-width: 1040px;
|
max-width: 1040px;
|
||||||
padding: 28px 20px 0;
|
padding: 28px 20px 0;
|
||||||
@@ -678,15 +734,6 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
h1 {
|
h1 {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-family: var(--paper-font-headline_-_font-family);
|
|
||||||
-webkit-font-smoothing: var(
|
|
||||||
--paper-font-headline_-_-webkit-font-smoothing
|
|
||||||
);
|
|
||||||
font-size: var(--paper-font-headline_-_font-size);
|
|
||||||
font-weight: var(--paper-font-headline_-_font-weight);
|
|
||||||
letter-spacing: var(--paper-font-headline_-_letter-spacing);
|
|
||||||
line-height: var(--paper-font-headline_-_line-height);
|
|
||||||
opacity: var(--dark-primary-opacity);
|
|
||||||
}
|
}
|
||||||
.header-name {
|
.header-name {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -1,4 +1,16 @@
|
|||||||
import { mdiHelpCircle, mdiInformationOutline, mdiPlus } from "@mdi/js";
|
import {
|
||||||
|
mdiCancel,
|
||||||
|
mdiContentDuplicate,
|
||||||
|
mdiDelete,
|
||||||
|
mdiHelpCircle,
|
||||||
|
mdiInformationOutline,
|
||||||
|
mdiPlay,
|
||||||
|
mdiPlayCircleOutline,
|
||||||
|
mdiPlus,
|
||||||
|
mdiStopCircleOutline,
|
||||||
|
mdiTransitConnection,
|
||||||
|
} from "@mdi/js";
|
||||||
|
import "@polymer/paper-tooltip/paper-tooltip";
|
||||||
import { CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
@@ -13,11 +25,22 @@ import type {
|
|||||||
RowClickedEvent,
|
RowClickedEvent,
|
||||||
} from "../../../components/data-table/ha-data-table";
|
} from "../../../components/data-table/ha-data-table";
|
||||||
import "../../../components/ha-button-related-filter-menu";
|
import "../../../components/ha-button-related-filter-menu";
|
||||||
|
import "../../../components/ha-chip";
|
||||||
import "../../../components/ha-fab";
|
import "../../../components/ha-fab";
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
|
import "../../../components/ha-icon-overflow-menu";
|
||||||
import "../../../components/ha-svg-icon";
|
import "../../../components/ha-svg-icon";
|
||||||
import type { AutomationEntity } from "../../../data/automation";
|
import {
|
||||||
import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
|
AutomationEntity,
|
||||||
|
deleteAutomation,
|
||||||
|
duplicateAutomation,
|
||||||
|
getAutomationConfig,
|
||||||
|
triggerAutomationActions,
|
||||||
|
} from "../../../data/automation";
|
||||||
|
import {
|
||||||
|
showAlertDialog,
|
||||||
|
showConfirmationDialog,
|
||||||
|
} from "../../../dialogs/generic/show-dialog-box";
|
||||||
import "../../../layouts/hass-tabs-subpage-data-table";
|
import "../../../layouts/hass-tabs-subpage-data-table";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import { HomeAssistant, Route } from "../../../types";
|
import { HomeAssistant, Route } from "../../../types";
|
||||||
@@ -63,6 +86,7 @@ class HaAutomationPicker extends LitElement {
|
|||||||
...automation,
|
...automation,
|
||||||
name: computeStateName(automation),
|
name: computeStateName(automation),
|
||||||
last_triggered: automation.attributes.last_triggered || undefined,
|
last_triggered: automation.attributes.last_triggered || undefined,
|
||||||
|
disabled: automation.state === "off",
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -123,22 +147,108 @@ class HaAutomationPicker extends LitElement {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
columns.disabled = this.narrow
|
||||||
|
? {
|
||||||
|
title: "",
|
||||||
|
template: (disabled: boolean) =>
|
||||||
|
disabled
|
||||||
|
? html`
|
||||||
|
<paper-tooltip animation-delay="0" position="left">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.picker.disabled"
|
||||||
|
)}
|
||||||
|
</paper-tooltip>
|
||||||
|
<ha-svg-icon
|
||||||
|
.path=${mdiCancel}
|
||||||
|
style="color: var(--secondary-text-color)"
|
||||||
|
></ha-svg-icon>
|
||||||
|
`
|
||||||
|
: "",
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
width: "20%",
|
||||||
|
title: "",
|
||||||
|
template: (disabled: boolean) =>
|
||||||
|
disabled
|
||||||
|
? html`
|
||||||
|
<ha-chip>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.picker.disabled"
|
||||||
|
)}
|
||||||
|
</ha-chip>
|
||||||
|
`
|
||||||
|
: "",
|
||||||
|
};
|
||||||
|
|
||||||
columns.actions = {
|
columns.actions = {
|
||||||
title: "",
|
title: "",
|
||||||
label: this.hass.localize(
|
width: this.narrow ? undefined : "10%",
|
||||||
"ui.panel.config.automation.picker.headers.actions"
|
type: "overflow-menu",
|
||||||
),
|
template: (_: string, automation: any) =>
|
||||||
type: "icon-button",
|
html`
|
||||||
template: (_info, automation: any) => html`
|
<ha-icon-overflow-menu
|
||||||
<ha-icon-button
|
.hass=${this.hass}
|
||||||
.automation=${automation}
|
narrow
|
||||||
.label=${this.hass.localize(
|
.items=${[
|
||||||
"ui.panel.config.automation.picker.headers.actions"
|
{
|
||||||
)}
|
path: mdiInformationOutline,
|
||||||
.path=${mdiInformationOutline}
|
label: this.hass.localize(
|
||||||
@click=${this._showInfo}
|
"ui.panel.config.automation.editor.show_info"
|
||||||
></ha-icon-button>
|
),
|
||||||
`,
|
action: () => this._showInfo(automation),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: mdiPlay,
|
||||||
|
label: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.run"
|
||||||
|
),
|
||||||
|
action: () => this._runActions(automation),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: mdiTransitConnection,
|
||||||
|
label: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.show_trace"
|
||||||
|
),
|
||||||
|
action: () => this._showTrace(automation),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
divider: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: mdiContentDuplicate,
|
||||||
|
label: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.picker.duplicate"
|
||||||
|
),
|
||||||
|
action: () => this.duplicate(automation),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path:
|
||||||
|
automation.state === "off"
|
||||||
|
? mdiPlayCircleOutline
|
||||||
|
: mdiStopCircleOutline,
|
||||||
|
label:
|
||||||
|
automation.state === "off"
|
||||||
|
? this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.enable"
|
||||||
|
)
|
||||||
|
: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.disable"
|
||||||
|
),
|
||||||
|
action: () => this._toggle(automation),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.picker.delete"
|
||||||
|
),
|
||||||
|
path: mdiDelete,
|
||||||
|
action: () => this._deleteConfirm(automation),
|
||||||
|
warning: true,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
</ha-icon-overflow-menu>
|
||||||
|
`,
|
||||||
};
|
};
|
||||||
return columns;
|
return columns;
|
||||||
}
|
}
|
||||||
@@ -210,12 +320,83 @@ class HaAutomationPicker extends LitElement {
|
|||||||
this._filterValue = undefined;
|
this._filterValue = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _showInfo(ev) {
|
private _showInfo(automation: any) {
|
||||||
ev.stopPropagation();
|
|
||||||
const automation = ev.currentTarget.automation;
|
|
||||||
fireEvent(this, "hass-more-info", { entityId: automation.entity_id });
|
fireEvent(this, "hass-more-info", { entityId: automation.entity_id });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _runActions(automation: any) {
|
||||||
|
triggerAutomationActions(this.hass, automation.entity_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _showTrace(automation: any) {
|
||||||
|
navigate(`/config/automation/trace/${automation.attributes.id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _toggle(automation): Promise<void> {
|
||||||
|
const service = automation.state === "off" ? "turn_on" : "turn_off";
|
||||||
|
await this.hass.callService("automation", service, {
|
||||||
|
entity_id: automation.entity_id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _deleteConfirm(automation) {
|
||||||
|
showConfirmationDialog(this, {
|
||||||
|
title: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.picker.delete_confirm_title"
|
||||||
|
),
|
||||||
|
text: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.picker.delete_confirm_text",
|
||||||
|
{ name: automation.name }
|
||||||
|
),
|
||||||
|
confirmText: this.hass!.localize("ui.common.delete"),
|
||||||
|
dismissText: this.hass!.localize("ui.common.cancel"),
|
||||||
|
confirm: () => this._delete(automation),
|
||||||
|
destructive: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _delete(automation) {
|
||||||
|
try {
|
||||||
|
await deleteAutomation(this.hass, automation.attributes.id);
|
||||||
|
} catch (err: any) {
|
||||||
|
await showAlertDialog(this, {
|
||||||
|
text:
|
||||||
|
err.status_code === 400
|
||||||
|
? this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.load_error_not_deletable"
|
||||||
|
)
|
||||||
|
: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.load_error_unknown",
|
||||||
|
"err_no",
|
||||||
|
err.status_code
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async duplicate(automation) {
|
||||||
|
try {
|
||||||
|
const config = await getAutomationConfig(
|
||||||
|
this.hass,
|
||||||
|
automation.attributes.id
|
||||||
|
);
|
||||||
|
duplicateAutomation(config);
|
||||||
|
} catch (err: any) {
|
||||||
|
await showAlertDialog(this, {
|
||||||
|
text:
|
||||||
|
err.status_code === 404
|
||||||
|
? this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.load_error_not_duplicable"
|
||||||
|
)
|
||||||
|
: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.load_error_unknown",
|
||||||
|
"err_no",
|
||||||
|
err.status_code
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private _showHelp() {
|
private _showHelp() {
|
||||||
showAlertDialog(this, {
|
showAlertDialog(this, {
|
||||||
title: this.hass.localize("ui.panel.config.automation.caption"),
|
title: this.hass.localize("ui.panel.config.automation.caption"),
|
||||||
@@ -242,7 +423,7 @@ class HaAutomationPicker extends LitElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (automation?.attributes.id) {
|
if (automation?.attributes.id) {
|
||||||
navigate(`/config/automation/edit/${automation?.attributes.id}`);
|
navigate(`/config/automation/edit/${automation.attributes.id}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
|
mdiDotsVertical,
|
||||||
mdiDownload,
|
mdiDownload,
|
||||||
|
mdiInformationOutline,
|
||||||
mdiPencil,
|
mdiPencil,
|
||||||
mdiRayEndArrow,
|
mdiRayEndArrow,
|
||||||
mdiRayStartArrow,
|
mdiRayStartArrow,
|
||||||
@@ -11,6 +13,8 @@ import { classMap } from "lit/directives/class-map";
|
|||||||
import { repeat } from "lit/directives/repeat";
|
import { repeat } from "lit/directives/repeat";
|
||||||
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
|
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
|
||||||
import { formatDateTimeWithSeconds } from "../../../common/datetime/format_date_time";
|
import { formatDateTimeWithSeconds } from "../../../common/datetime/format_date_time";
|
||||||
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
|
import "../../../components/ha-button-menu";
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
import "../../../components/trace/ha-trace-blueprint-config";
|
import "../../../components/trace/ha-trace-blueprint-config";
|
||||||
import "../../../components/trace/ha-trace-config";
|
import "../../../components/trace/ha-trace-config";
|
||||||
@@ -32,9 +36,9 @@ import {
|
|||||||
loadTraces,
|
loadTraces,
|
||||||
} from "../../../data/trace";
|
} from "../../../data/trace";
|
||||||
import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
|
import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
|
||||||
|
import "../../../layouts/hass-subpage";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import { HomeAssistant, Route } from "../../../types";
|
import { HomeAssistant, Route } from "../../../types";
|
||||||
import { configSections } from "../ha-panel-config";
|
|
||||||
|
|
||||||
@customElement("ha-automation-trace")
|
@customElement("ha-automation-trace")
|
||||||
export class HaAutomationTrace extends LitElement {
|
export class HaAutomationTrace extends LitElement {
|
||||||
@@ -90,89 +94,116 @@ export class HaAutomationTrace extends LitElement {
|
|||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const actionButtons = html`
|
|
||||||
<ha-icon-button
|
|
||||||
.label=${this.hass.localize("ui.panel.config.automation.trace.refresh")}
|
|
||||||
.path=${mdiRefresh}
|
|
||||||
@click=${this._refreshTraces}
|
|
||||||
></ha-icon-button>
|
|
||||||
<ha-icon-button
|
|
||||||
.label=${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.trace.download_trace"
|
|
||||||
)}
|
|
||||||
.path=${mdiDownload}
|
|
||||||
.disabled=${!this._trace}
|
|
||||||
@click=${this._downloadTrace}
|
|
||||||
></ha-icon-button>
|
|
||||||
`;
|
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
${devButtons}
|
${devButtons}
|
||||||
<hass-tabs-subpage
|
<hass-subpage .hass=${this.hass} .narrow=${this.narrow} .header=${title}>
|
||||||
.hass=${this.hass}
|
${!this.narrow && stateObj?.attributes.id
|
||||||
.narrow=${this.narrow}
|
? html`
|
||||||
.route=${this.route}
|
<a
|
||||||
.tabs=${configSections.automations}
|
class="trace-link"
|
||||||
>
|
href="/config/automation/edit/${stateObj.attributes.id}"
|
||||||
${this.narrow
|
slot="toolbar-icon"
|
||||||
? html`<span slot="header">${title}</span>
|
>
|
||||||
<div slot="toolbar-icon">${actionButtons}</div>`
|
<mwc-button>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.trace.edit_automation"
|
||||||
|
)}
|
||||||
|
</mwc-button>
|
||||||
|
</a>
|
||||||
|
`
|
||||||
: ""}
|
: ""}
|
||||||
<div class="toolbar">
|
<ha-button-menu corner="BOTTOM_START" slot="toolbar-icon">
|
||||||
${!this.narrow
|
<ha-icon-button
|
||||||
? html`<div>
|
slot="trigger"
|
||||||
${title}
|
.label=${this.hass.localize("ui.common.menu")}
|
||||||
|
.path=${mdiDotsVertical}
|
||||||
|
></ha-icon-button>
|
||||||
|
|
||||||
|
<mwc-list-item
|
||||||
|
graphic="icon"
|
||||||
|
.disabled=${!stateObj}
|
||||||
|
@click=${this._showInfo}
|
||||||
|
>
|
||||||
|
${this.hass.localize("ui.panel.config.automation.editor.show_info")}
|
||||||
|
<ha-svg-icon
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiInformationOutline}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
|
${stateObj?.attributes.id && this.narrow
|
||||||
|
? html`
|
||||||
<a
|
<a
|
||||||
class="linkButton"
|
class="trace-link"
|
||||||
href="/config/automation/edit/${this.automationId}"
|
href="/config/automation/edit/${stateObj.attributes.id}"
|
||||||
>
|
>
|
||||||
<ha-icon-button
|
<mwc-list-item graphic="icon">
|
||||||
.label=${this.hass!.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.trace.edit_automation"
|
"ui.panel.config.automation.trace.edit_automation"
|
||||||
)}
|
)}
|
||||||
.path=${mdiPencil}
|
<ha-svg-icon
|
||||||
tabindex="-1"
|
slot="graphic"
|
||||||
></ha-icon-button>
|
.path=${mdiPencil}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
</a>
|
</a>
|
||||||
</div>`
|
|
||||||
: ""}
|
|
||||||
${this._traces && this._traces.length > 0
|
|
||||||
? html`
|
|
||||||
<div>
|
|
||||||
<ha-icon-button
|
|
||||||
.label=${this.hass!.localize(
|
|
||||||
"ui.panel.config.automation.trace.older_trace"
|
|
||||||
)}
|
|
||||||
.path=${mdiRayEndArrow}
|
|
||||||
.disabled=${this._traces[this._traces.length - 1].run_id ===
|
|
||||||
this._runId}
|
|
||||||
@click=${this._pickOlderTrace}
|
|
||||||
></ha-icon-button>
|
|
||||||
<select .value=${this._runId} @change=${this._pickTrace}>
|
|
||||||
${repeat(
|
|
||||||
this._traces,
|
|
||||||
(trace) => trace.run_id,
|
|
||||||
(trace) =>
|
|
||||||
html`<option value=${trace.run_id}>
|
|
||||||
${formatDateTimeWithSeconds(
|
|
||||||
new Date(trace.timestamp.start),
|
|
||||||
this.hass.locale
|
|
||||||
)}
|
|
||||||
</option>`
|
|
||||||
)}
|
|
||||||
</select>
|
|
||||||
<ha-icon-button
|
|
||||||
.label=${this.hass!.localize(
|
|
||||||
"ui.panel.config.automation.trace.newer_trace"
|
|
||||||
)}
|
|
||||||
.path=${mdiRayStartArrow}
|
|
||||||
.disabled=${this._traces[0].run_id === this._runId}
|
|
||||||
@click=${this._pickNewerTrace}
|
|
||||||
></ha-icon-button>
|
|
||||||
</div>
|
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
${!this.narrow ? html`<div>${actionButtons}</div>` : ""}
|
|
||||||
|
<li divider role="separator"></li>
|
||||||
|
|
||||||
|
<mwc-list-item graphic="icon" @click=${this._refreshTraces}>
|
||||||
|
${this.hass.localize("ui.panel.config.automation.trace.refresh")}
|
||||||
|
<ha-svg-icon slot="graphic" .path=${mdiRefresh}></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
|
<mwc-list-item
|
||||||
|
graphic="icon"
|
||||||
|
.disabled=${!this._trace}
|
||||||
|
@click=${this._downloadTrace}
|
||||||
|
>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.trace.download_trace"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon slot="graphic" .path=${mdiDownload}></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
</ha-button-menu>
|
||||||
|
|
||||||
|
<div class="toolbar">
|
||||||
|
${this._traces && this._traces.length > 0
|
||||||
|
? html`
|
||||||
|
<ha-icon-button
|
||||||
|
.label=${this.hass!.localize(
|
||||||
|
"ui.panel.config.automation.trace.older_trace"
|
||||||
|
)}
|
||||||
|
.path=${mdiRayEndArrow}
|
||||||
|
.disabled=${this._traces[this._traces.length - 1].run_id ===
|
||||||
|
this._runId}
|
||||||
|
@click=${this._pickOlderTrace}
|
||||||
|
></ha-icon-button>
|
||||||
|
<select .value=${this._runId} @change=${this._pickTrace}>
|
||||||
|
${repeat(
|
||||||
|
this._traces,
|
||||||
|
(trace) => trace.run_id,
|
||||||
|
(trace) =>
|
||||||
|
html`<option value=${trace.run_id}>
|
||||||
|
${formatDateTimeWithSeconds(
|
||||||
|
new Date(trace.timestamp.start),
|
||||||
|
this.hass.locale
|
||||||
|
)}
|
||||||
|
</option>`
|
||||||
|
)}
|
||||||
|
</select>
|
||||||
|
<ha-icon-button
|
||||||
|
.label=${this.hass!.localize(
|
||||||
|
"ui.panel.config.automation.trace.newer_trace"
|
||||||
|
)}
|
||||||
|
.path=${mdiRayStartArrow}
|
||||||
|
.disabled=${this._traces[0].run_id === this._runId}
|
||||||
|
@click=${this._pickNewerTrace}
|
||||||
|
></ha-icon-button>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
${this._traces === undefined
|
${this._traces === undefined
|
||||||
@@ -276,7 +307,7 @@ export class HaAutomationTrace extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`}
|
`}
|
||||||
</hass-tabs-subpage>
|
</hass-subpage>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -457,6 +488,13 @@ export class HaAutomationTrace extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _showInfo() {
|
||||||
|
if (!this.hass || !this._entityId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fireEvent(this, "hass-more-info", { entityId: this._entityId });
|
||||||
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return [
|
||||||
haStyle,
|
haStyle,
|
||||||
@@ -465,7 +503,7 @@ export class HaAutomationTrace extends LitElement {
|
|||||||
.toolbar {
|
.toolbar {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: center;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
height: var(--header-height);
|
height: var(--header-height);
|
||||||
padding: 0 16px;
|
padding: 0 16px;
|
||||||
@@ -476,15 +514,6 @@ export class HaAutomationTrace extends LitElement {
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toolbar > * {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
:host([narrow]) .toolbar > * {
|
|
||||||
display: contents;
|
|
||||||
}
|
|
||||||
|
|
||||||
.main {
|
.main {
|
||||||
height: calc(100% - 56px);
|
height: calc(100% - 56px);
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -520,6 +549,9 @@ export class HaAutomationTrace extends LitElement {
|
|||||||
.linkButton {
|
.linkButton {
|
||||||
color: var(--primary-text-color);
|
color: var(--primary-text-color);
|
||||||
}
|
}
|
||||||
|
.trace-link {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,18 @@
|
|||||||
import "@material/mwc-button/mwc-button";
|
import "@material/mwc-button/mwc-button";
|
||||||
import { mdiHelpCircle, mdiRobot } from "@mdi/js";
|
import { mdiHelpCircle } from "@mdi/js";
|
||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { css, CSSResultGroup, html, LitElement } from "lit";
|
import { css, CSSResultGroup, html, LitElement } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import "../../../components/entity/ha-entity-toggle";
|
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
import "../../../components/ha-textarea";
|
|
||||||
import "../../../components/ha-textfield";
|
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
|
import "../../../components/ha-alert";
|
||||||
import {
|
import {
|
||||||
AUTOMATION_DEFAULT_MODE,
|
|
||||||
Condition,
|
Condition,
|
||||||
ManualAutomationConfig,
|
ManualAutomationConfig,
|
||||||
Trigger,
|
Trigger,
|
||||||
} from "../../../data/automation";
|
} from "../../../data/automation";
|
||||||
import { Action, isMaxMode, MODES } from "../../../data/script";
|
import { Action } from "../../../data/script";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } 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";
|
||||||
@@ -35,91 +32,53 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public stateObj?: HassEntity;
|
@property({ attribute: false }) public stateObj?: HassEntity;
|
||||||
|
|
||||||
|
@property({ type: Boolean, reflect: true, attribute: "re-order-mode" })
|
||||||
|
public reOrderMode = false;
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
<ha-card outlined>
|
${this.stateObj?.state === "off"
|
||||||
${this.stateObj && this.stateObj.state === "off"
|
? html`
|
||||||
? html`<div class="disabled-bar">
|
<ha-alert alert-type="info">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.disabled"
|
"ui.panel.config.automation.editor.disabled"
|
||||||
)}
|
)}
|
||||||
</div>`
|
<mwc-button slot="action" @click=${this._enable}>
|
||||||
: ""}
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.enable"
|
||||||
<ha-expansion-panel leftChevron>
|
)}
|
||||||
<div slot="header">
|
</mwc-button>
|
||||||
<ha-svg-icon class="settings-icon" .path=${mdiRobot}></ha-svg-icon>
|
</ha-alert>
|
||||||
${this.hass.localize(
|
`
|
||||||
"ui.panel.config.automation.editor.automation_settings"
|
: ""}
|
||||||
)}
|
${this.reOrderMode
|
||||||
</div>
|
? html`
|
||||||
<div class="card-content">
|
<ha-alert
|
||||||
<ha-textarea
|
alert-type="info"
|
||||||
.label=${this.hass.localize(
|
.title=${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.description.label"
|
"ui.panel.config.automation.editor.re_order_mode.title"
|
||||||
)}
|
)}
|
||||||
.placeholder=${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.description.placeholder"
|
|
||||||
)}
|
|
||||||
name="description"
|
|
||||||
autogrow
|
|
||||||
.value=${this.config.description || ""}
|
|
||||||
@change=${this._valueChanged}
|
|
||||||
></ha-textarea>
|
|
||||||
<ha-select
|
|
||||||
.label=${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.modes.label"
|
|
||||||
)}
|
|
||||||
.value=${this.config.mode || AUTOMATION_DEFAULT_MODE}
|
|
||||||
@selected=${this._modeChanged}
|
|
||||||
fixedMenuPosition
|
|
||||||
.helper=${html`
|
|
||||||
<a
|
|
||||||
style="color: var(--secondary-text-color)"
|
|
||||||
href=${documentationUrl(this.hass, "/docs/automation/modes/")}
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
>${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.modes.learn_more"
|
|
||||||
)}</a
|
|
||||||
>
|
|
||||||
`}
|
|
||||||
>
|
>
|
||||||
${MODES.map(
|
${this.hass.localize(
|
||||||
(mode) => html`
|
"ui.panel.config.automation.editor.re_order_mode.description"
|
||||||
<mwc-list-item .value=${mode}>
|
|
||||||
${this.hass.localize(
|
|
||||||
`ui.panel.config.automation.editor.modes.${mode}`
|
|
||||||
) || mode}
|
|
||||||
</mwc-list-item>
|
|
||||||
`
|
|
||||||
)}
|
)}
|
||||||
</ha-select>
|
<mwc-button slot="action" @click=${this._exitReOrderMode}>
|
||||||
${this.config.mode && isMaxMode(this.config.mode)
|
${this.hass.localize(
|
||||||
? html`
|
"ui.panel.config.automation.editor.re_order_mode.exit"
|
||||||
<br /><ha-textfield
|
)}
|
||||||
.label=${this.hass.localize(
|
</mwc-button>
|
||||||
`ui.panel.config.automation.editor.max.${this.config.mode}`
|
</ha-alert>
|
||||||
)}
|
`
|
||||||
type="number"
|
: ""}
|
||||||
name="max"
|
${this.config.description
|
||||||
.value=${this.config.max || "10"}
|
? html`<p class="description">${this.config.description}</p>`
|
||||||
@change=${this._valueChanged}
|
: ""}
|
||||||
class="max"
|
|
||||||
>
|
|
||||||
</ha-textfield>
|
|
||||||
`
|
|
||||||
: html``}
|
|
||||||
</div>
|
|
||||||
</ha-expansion-panel>
|
|
||||||
</ha-card>
|
|
||||||
|
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<div class="name">
|
<h2 id="triggers-heading" class="name">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.triggers.header"
|
"ui.panel.config.automation.editor.triggers.header"
|
||||||
)}
|
)}
|
||||||
</div>
|
</h2>
|
||||||
<a
|
<a
|
||||||
href=${documentationUrl(this.hass, "/docs/automation/trigger/")}
|
href=${documentationUrl(this.hass, "/docs/automation/trigger/")}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
@@ -135,17 +94,20 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ha-automation-trigger
|
<ha-automation-trigger
|
||||||
|
role="region"
|
||||||
|
aria-labelledby="triggers-heading"
|
||||||
.triggers=${this.config.trigger}
|
.triggers=${this.config.trigger}
|
||||||
@value-changed=${this._triggerChanged}
|
@value-changed=${this._triggerChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
></ha-automation-trigger>
|
></ha-automation-trigger>
|
||||||
|
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<div class="name">
|
<h2 id="conditions-heading" class="name">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.conditions.header"
|
"ui.panel.config.automation.editor.conditions.header"
|
||||||
)}
|
)}
|
||||||
</div>
|
</h2>
|
||||||
<a
|
<a
|
||||||
href=${documentationUrl(this.hass, "/docs/automation/condition/")}
|
href=${documentationUrl(this.hass, "/docs/automation/condition/")}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
@@ -161,80 +123,50 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ha-automation-condition
|
<ha-automation-condition
|
||||||
|
role="region"
|
||||||
|
aria-labelledby="conditions-heading"
|
||||||
.conditions=${this.config.condition || []}
|
.conditions=${this.config.condition || []}
|
||||||
@value-changed=${this._conditionChanged}
|
@value-changed=${this._conditionChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
></ha-automation-condition>
|
></ha-automation-condition>
|
||||||
|
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<div class="name">
|
<h2 id="actions-heading" class="name">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.actions.header"
|
"ui.panel.config.automation.editor.actions.header"
|
||||||
)}
|
)}
|
||||||
|
</h2>
|
||||||
|
<div>
|
||||||
|
<a
|
||||||
|
href=${documentationUrl(this.hass, "/docs/automation/action/")}
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
>
|
||||||
|
<ha-icon-button
|
||||||
|
.path=${mdiHelpCircle}
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.actions.learn_more"
|
||||||
|
)}
|
||||||
|
></ha-icon-button>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<a
|
|
||||||
href=${documentationUrl(this.hass, "/docs/automation/action/")}
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
>
|
|
||||||
<ha-icon-button
|
|
||||||
.path=${mdiHelpCircle}
|
|
||||||
.label=${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.actions.learn_more"
|
|
||||||
)}
|
|
||||||
></ha-icon-button>
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ha-automation-action
|
<ha-automation-action
|
||||||
|
role="region"
|
||||||
|
aria-labelledby="actions-heading"
|
||||||
.actions=${this.config.action}
|
.actions=${this.config.action}
|
||||||
@value-changed=${this._actionChanged}
|
@value-changed=${this._actionChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _valueChanged(ev: CustomEvent) {
|
private _exitReOrderMode() {
|
||||||
ev.stopPropagation();
|
this.reOrderMode = !this.reOrderMode;
|
||||||
const target = ev.target as any;
|
|
||||||
const name = target.name;
|
|
||||||
if (!name) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let newVal = target.value;
|
|
||||||
if (target.type === "number") {
|
|
||||||
newVal = Number(newVal);
|
|
||||||
}
|
|
||||||
if ((this.config![name] || "") === newVal) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fireEvent(this, "value-changed", {
|
|
||||||
value: { ...this.config!, [name]: newVal },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private _modeChanged(ev) {
|
|
||||||
const mode = ev.target.value;
|
|
||||||
|
|
||||||
if (
|
|
||||||
mode === this.config!.mode ||
|
|
||||||
(!this.config!.mode && mode === MODES[0])
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const value = {
|
|
||||||
...this.config!,
|
|
||||||
mode,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!isMaxMode(mode)) {
|
|
||||||
delete value.max;
|
|
||||||
}
|
|
||||||
|
|
||||||
fireEvent(this, "value-changed", {
|
|
||||||
value,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _triggerChanged(ev: CustomEvent): void {
|
private _triggerChanged(ev: CustomEvent): void {
|
||||||
@@ -261,6 +193,15 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _enable(): Promise<void> {
|
||||||
|
if (!this.hass || !this.stateObj) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await this.hass.callService("automation", "turn_on", {
|
||||||
|
entity_id: this.stateObj.entity_id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return [
|
||||||
haStyle,
|
haStyle,
|
||||||
@@ -271,30 +212,19 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
ha-card {
|
ha-card {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.link-button-row {
|
.description {
|
||||||
padding: 14px;
|
margin: 0;
|
||||||
}
|
}
|
||||||
ha-textarea,
|
|
||||||
ha-textfield {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
p {
|
p {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
ha-entity-toggle {
|
|
||||||
margin-right: 8px;
|
|
||||||
}
|
|
||||||
ha-select,
|
|
||||||
.max {
|
|
||||||
margin-top: 16px;
|
|
||||||
width: 200px;
|
|
||||||
}
|
|
||||||
.header {
|
.header {
|
||||||
display: flex;
|
display: flex;
|
||||||
margin: 16px 0;
|
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
.header:first-child {
|
||||||
|
margin-top: -16px;
|
||||||
|
}
|
||||||
.header .name {
|
.header .name {
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
@@ -303,32 +233,9 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
.header a {
|
.header a {
|
||||||
color: var(--secondary-text-color);
|
color: var(--secondary-text-color);
|
||||||
}
|
}
|
||||||
ha-expansion-panel {
|
ha-alert {
|
||||||
--expansion-panel-summary-padding: 0 0 0 8px;
|
display: block;
|
||||||
--expansion-panel-content-padding: 0;
|
margin-bottom: 16px;
|
||||||
}
|
|
||||||
.card-content {
|
|
||||||
padding: 16px;
|
|
||||||
}
|
|
||||||
.card-content ha-textarea:first-child {
|
|
||||||
margin-top: -16px;
|
|
||||||
}
|
|
||||||
.settings-icon {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
@media (min-width: 870px) {
|
|
||||||
.settings-icon {
|
|
||||||
display: inline-block;
|
|
||||||
color: var(--primary-color);
|
|
||||||
opacity: 0.9;
|
|
||||||
margin-right: 8px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.disabled-bar {
|
|
||||||
background: var(--divider-color, #e0e0e0);
|
|
||||||
text-align: center;
|
|
||||||
border-top-right-radius: var(--ha-card-border-radius);
|
|
||||||
border-top-left-radius: var(--ha-card-border-radius);
|
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ export default class HaAutomationTriggerRow extends LitElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public trigger!: Trigger;
|
@property({ attribute: false }) public trigger!: Trigger;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public hideMenu = false;
|
||||||
|
|
||||||
@state() private _warnings?: string[];
|
@state() private _warnings?: string[];
|
||||||
|
|
||||||
@state() private _yamlMode = false;
|
@state() private _yamlMode = false;
|
||||||
@@ -121,102 +123,117 @@ export default class HaAutomationTriggerRow extends LitElement {
|
|||||||
: ""}
|
: ""}
|
||||||
|
|
||||||
<ha-expansion-panel leftChevron>
|
<ha-expansion-panel leftChevron>
|
||||||
<div slot="header">
|
<h3 slot="header">
|
||||||
<ha-svg-icon
|
<ha-svg-icon
|
||||||
class="trigger-icon"
|
class="trigger-icon"
|
||||||
.path=${TRIGGER_TYPES[this.trigger.platform]}
|
.path=${TRIGGER_TYPES[this.trigger.platform]}
|
||||||
></ha-svg-icon>
|
></ha-svg-icon>
|
||||||
${capitalizeFirstLetter(describeTrigger(this.trigger, this.hass))}
|
${capitalizeFirstLetter(describeTrigger(this.trigger, this.hass))}
|
||||||
</div>
|
</h3>
|
||||||
<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">
|
<slot name="icons" slot="icons"></slot>
|
||||||
${this.hass.localize(
|
${this.hideMenu
|
||||||
"ui.panel.config.automation.editor.triggers.rename"
|
? ""
|
||||||
)}
|
: html`
|
||||||
<ha-svg-icon slot="graphic" .path=${mdiRenameBox}></ha-svg-icon>
|
<ha-button-menu
|
||||||
</mwc-list-item>
|
slot="icons"
|
||||||
<mwc-list-item graphic="icon">
|
fixed
|
||||||
${this.hass.localize(
|
corner="BOTTOM_START"
|
||||||
"ui.panel.config.automation.editor.actions.duplicate"
|
@action=${this._handleAction}
|
||||||
)}
|
@click=${preventDefault}
|
||||||
<ha-svg-icon
|
>
|
||||||
slot="graphic"
|
<ha-icon-button
|
||||||
.path=${mdiContentDuplicate}
|
slot="trigger"
|
||||||
></ha-svg-icon>
|
.label=${this.hass.localize("ui.common.menu")}
|
||||||
</mwc-list-item>
|
.path=${mdiDotsVertical}
|
||||||
|
></ha-icon-button>
|
||||||
|
|
||||||
<mwc-list-item graphic="icon">
|
<mwc-list-item graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.triggers.edit_id"
|
"ui.panel.config.automation.editor.triggers.rename"
|
||||||
)}
|
)}
|
||||||
<ha-svg-icon slot="graphic" .path=${mdiIdentifier}></ha-svg-icon>
|
<ha-svg-icon
|
||||||
</mwc-list-item>
|
slot="graphic"
|
||||||
|
.path=${mdiRenameBox}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
<mwc-list-item graphic="icon">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.actions.duplicate"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiContentDuplicate}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<li divider role="separator"></li>
|
<mwc-list-item graphic="icon">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.triggers.edit_id"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiIdentifier}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<mwc-list-item .disabled=${!supported} graphic="icon">
|
<li divider role="separator"></li>
|
||||||
${this.hass.localize("ui.panel.config.automation.editor.edit_ui")}
|
|
||||||
${!yamlMode
|
|
||||||
? html`<ha-svg-icon
|
|
||||||
slot="graphic"
|
|
||||||
.path=${mdiCheck}
|
|
||||||
></ha-svg-icon>`
|
|
||||||
: ``}
|
|
||||||
</mwc-list-item>
|
|
||||||
|
|
||||||
<mwc-list-item .disabled=${!supported} graphic="icon">
|
<mwc-list-item .disabled=${!supported} graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.edit_yaml"
|
"ui.panel.config.automation.editor.edit_ui"
|
||||||
)}
|
)}
|
||||||
${yamlMode
|
${!yamlMode
|
||||||
? html`<ha-svg-icon
|
? html`<ha-svg-icon
|
||||||
slot="graphic"
|
class="selected_menu_item"
|
||||||
.path=${mdiCheck}
|
slot="graphic"
|
||||||
></ha-svg-icon>`
|
.path=${mdiCheck}
|
||||||
: ``}
|
></ha-svg-icon>`
|
||||||
</mwc-list-item>
|
: ``}
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<li divider role="separator"></li>
|
<mwc-list-item .disabled=${!supported} graphic="icon">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.edit_yaml"
|
||||||
|
)}
|
||||||
|
${yamlMode
|
||||||
|
? html`<ha-svg-icon
|
||||||
|
class="selected_menu_item"
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiCheck}
|
||||||
|
></ha-svg-icon>`
|
||||||
|
: ``}
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<mwc-list-item graphic="icon">
|
<li divider role="separator"></li>
|
||||||
${this.trigger.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.trigger.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>
|
|
||||||
|
|
||||||
|
<mwc-list-item graphic="icon">
|
||||||
|
${this.trigger.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.trigger.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,
|
||||||
@@ -413,11 +430,15 @@ export default class HaAutomationTriggerRow extends LitElement {
|
|||||||
|
|
||||||
private _onDelete() {
|
private _onDelete() {
|
||||||
showConfirmationDialog(this, {
|
showConfirmationDialog(this, {
|
||||||
|
title: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.triggers.delete_confirm_title"
|
||||||
|
),
|
||||||
text: this.hass.localize(
|
text: this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.triggers.delete_confirm"
|
"ui.panel.config.automation.editor.triggers.delete_confirm_text"
|
||||||
),
|
),
|
||||||
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 });
|
||||||
},
|
},
|
||||||
@@ -532,13 +553,18 @@ export default class HaAutomationTriggerRow 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;
|
||||||
|
}
|
||||||
.trigger-icon {
|
.trigger-icon {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
@media (min-width: 870px) {
|
@media (min-width: 870px) {
|
||||||
.trigger-icon {
|
.trigger-icon {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
color: var(--primary-color);
|
color: var(--secondary-text-color);
|
||||||
opacity: 0.9;
|
opacity: 0.9;
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
@@ -587,6 +613,12 @@ export default class HaAutomationTriggerRow extends LitElement {
|
|||||||
display: block;
|
display: block;
|
||||||
margin-bottom: 24px;
|
margin-bottom: 24px;
|
||||||
}
|
}
|
||||||
|
.selected_menu_item {
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
li[role="separator"] {
|
||||||
|
border-bottom-color: var(--divider-color);
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,26 @@
|
|||||||
import { repeat } from "lit/directives/repeat";
|
|
||||||
import { mdiPlus } from "@mdi/js";
|
|
||||||
import deepClone from "deep-clone-simple";
|
|
||||||
import memoizeOne from "memoize-one";
|
|
||||||
import "@material/mwc-button";
|
import "@material/mwc-button";
|
||||||
|
import type { ActionDetail } from "@material/mwc-list";
|
||||||
|
import { mdiArrowDown, mdiArrowUp, mdiDrag, mdiPlus } from "@mdi/js";
|
||||||
|
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 type { ActionDetail } from "@material/mwc-list";
|
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 "../../../../components/ha-svg-icon";
|
import { stringCompare } from "../../../../common/string/compare";
|
||||||
|
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
||||||
import "../../../../components/ha-button-menu";
|
import "../../../../components/ha-button-menu";
|
||||||
|
import type { HaSelect } from "../../../../components/ha-select";
|
||||||
|
import "../../../../components/ha-svg-icon";
|
||||||
import { Trigger } from "../../../../data/automation";
|
import { Trigger } from "../../../../data/automation";
|
||||||
import { TRIGGER_TYPES } from "../../../../data/trigger";
|
import { TRIGGER_TYPES } from "../../../../data/trigger";
|
||||||
|
import { sortableStyles } from "../../../../resources/ha-sortable-style";
|
||||||
|
import { SortableInstance } from "../../../../resources/sortable";
|
||||||
|
import { loadSortable } from "../../../../resources/sortable.ondemand";
|
||||||
import { HomeAssistant } from "../../../../types";
|
import { HomeAssistant } from "../../../../types";
|
||||||
import "./ha-automation-trigger-row";
|
import "./ha-automation-trigger-row";
|
||||||
import type HaAutomationTriggerRow from "./ha-automation-trigger-row";
|
import type HaAutomationTriggerRow from "./ha-automation-trigger-row";
|
||||||
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
|
||||||
import { stringCompare } from "../../../../common/string/compare";
|
|
||||||
import type { HaSelect } from "../../../../components/ha-select";
|
|
||||||
import "./types/ha-automation-trigger-calendar";
|
import "./types/ha-automation-trigger-calendar";
|
||||||
import "./types/ha-automation-trigger-device";
|
import "./types/ha-automation-trigger-device";
|
||||||
import "./types/ha-automation-trigger-event";
|
import "./types/ha-automation-trigger-event";
|
||||||
@@ -39,49 +43,93 @@ export default class HaAutomationTrigger extends LitElement {
|
|||||||
|
|
||||||
@property() public triggers!: Trigger[];
|
@property() public triggers!: Trigger[];
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
private _focusLastTriggerOnChange = false;
|
private _focusLastTriggerOnChange = false;
|
||||||
|
|
||||||
private _triggerKeys = new WeakMap<Trigger, string>();
|
private _triggerKeys = new WeakMap<Trigger, string>();
|
||||||
|
|
||||||
|
private _sortable?: SortableInstance;
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
${repeat(
|
<div class="triggers">
|
||||||
this.triggers,
|
${repeat(
|
||||||
(trigger) => this._getKey(trigger),
|
this.triggers,
|
||||||
(trg, idx) => html`
|
(trigger) => this._getKey(trigger),
|
||||||
<ha-automation-trigger-row
|
(trg, idx) => html`
|
||||||
.index=${idx}
|
<ha-automation-trigger-row
|
||||||
.trigger=${trg}
|
.index=${idx}
|
||||||
@duplicate=${this._duplicateTrigger}
|
.trigger=${trg}
|
||||||
@value-changed=${this._triggerChanged}
|
.hideMenu=${this.reOrderMode}
|
||||||
.hass=${this.hass}
|
@duplicate=${this._duplicateTrigger}
|
||||||
></ha-automation-trigger-row>
|
@value-changed=${this._triggerChanged}
|
||||||
`
|
.hass=${this.hass}
|
||||||
)}
|
>
|
||||||
<ha-button-menu @action=${this._addTrigger}>
|
${this.reOrderMode
|
||||||
<mwc-button
|
? html`
|
||||||
slot="trigger"
|
<ha-icon-button
|
||||||
outlined
|
.index=${idx}
|
||||||
.label=${this.hass.localize(
|
slot="icons"
|
||||||
"ui.panel.config.automation.editor.triggers.add"
|
.label=${this.hass.localize(
|
||||||
)}
|
"ui.panel.config.automation.editor.move_up"
|
||||||
>
|
)}
|
||||||
<ha-svg-icon .path=${mdiPlus} slot="icon"></ha-svg-icon>
|
.path=${mdiArrowUp}
|
||||||
</mwc-button>
|
@click=${this._moveUp}
|
||||||
${this._processedTypes(this.hass.localize).map(
|
.disabled=${idx === 0}
|
||||||
([opt, label, icon]) => html`
|
></ha-icon-button>
|
||||||
<mwc-list-item .value=${opt} aria-label=${label} graphic="icon">
|
<ha-icon-button
|
||||||
${label}<ha-svg-icon slot="graphic" .path=${icon}></ha-svg-icon
|
.index=${idx}
|
||||||
></mwc-list-item>
|
slot="icons"
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.move_down"
|
||||||
|
)}
|
||||||
|
.path=${mdiArrowDown}
|
||||||
|
@click=${this._moveDown}
|
||||||
|
.disabled=${idx === this.triggers.length - 1}
|
||||||
|
></ha-icon-button>
|
||||||
|
<div class="handle" slot="icons">
|
||||||
|
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
</ha-automation-trigger-row>
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
</ha-button-menu>
|
</div>
|
||||||
|
<ha-button-menu @action=${this._addTrigger}>
|
||||||
|
<mwc-button
|
||||||
|
slot="trigger"
|
||||||
|
outlined
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.triggers.add"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<ha-svg-icon .path=${mdiPlus} slot="icon"></ha-svg-icon>
|
||||||
|
</mwc-button>
|
||||||
|
${this._processedTypes(this.hass.localize).map(
|
||||||
|
([opt, label, icon]) => html`
|
||||||
|
<mwc-list-item .value=${opt} aria-label=${label} graphic="icon">
|
||||||
|
${label}<ha-svg-icon slot="graphic" .path=${icon}></ha-svg-icon
|
||||||
|
></mwc-list-item>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</ha-button-menu>
|
||||||
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
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("triggers") && this._focusLastTriggerOnChange) {
|
if (changedProps.has("triggers") && this._focusLastTriggerOnChange) {
|
||||||
this._focusLastTriggerOnChange = false;
|
this._focusLastTriggerOnChange = false;
|
||||||
|
|
||||||
@@ -96,6 +144,36 @@ export default class HaAutomationTrigger extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _createSortable() {
|
||||||
|
const Sortable = await loadSortable();
|
||||||
|
this._sortable = new Sortable(
|
||||||
|
this.shadowRoot!.querySelector(".triggers")!,
|
||||||
|
{
|
||||||
|
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: Trigger) {
|
private _getKey(action: Trigger) {
|
||||||
if (!this._triggerKeys.has(action)) {
|
if (!this._triggerKeys.has(action)) {
|
||||||
this._triggerKeys.set(action, Math.random().toString());
|
this._triggerKeys.set(action, Math.random().toString());
|
||||||
@@ -122,6 +200,30 @@ export default class HaAutomationTrigger extends LitElement {
|
|||||||
fireEvent(this, "value-changed", { value: triggers });
|
fireEvent(this, "value-changed", { value: triggers });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _moveUp(ev) {
|
||||||
|
const index = (ev.target as any).index;
|
||||||
|
const newIndex = 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 triggers = this.triggers.concat();
|
||||||
|
const trigger = triggers.splice(index, 1)[0];
|
||||||
|
triggers.splice(newIndex, 0, trigger);
|
||||||
|
fireEvent(this, "value-changed", { value: triggers });
|
||||||
|
}
|
||||||
|
|
||||||
private _triggerChanged(ev: CustomEvent) {
|
private _triggerChanged(ev: CustomEvent) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const triggers = [...this.triggers];
|
const triggers = [...this.triggers];
|
||||||
@@ -166,16 +268,27 @@ export default class HaAutomationTrigger extends LitElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return [
|
||||||
ha-automation-trigger-row {
|
sortableStyles,
|
||||||
display: block;
|
css`
|
||||||
margin-bottom: 16px;
|
ha-automation-trigger-row {
|
||||||
scroll-margin-top: 48px;
|
display: block;
|
||||||
}
|
margin-bottom: 16px;
|
||||||
ha-svg-icon {
|
scroll-margin-top: 48px;
|
||||||
height: 20px;
|
}
|
||||||
}
|
ha-svg-icon {
|
||||||
`;
|
height: 20px;
|
||||||
|
}
|
||||||
|
.handle {
|
||||||
|
cursor: move;
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
.handle ha-svg-icon {
|
||||||
|
pointer-events: none;
|
||||||
|
height: 24px;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export class HaTagTrigger extends LitElement implements TriggerElement {
|
|||||||
|
|
||||||
@property() public trigger!: TagTrigger;
|
@property() public trigger!: TagTrigger;
|
||||||
|
|
||||||
@state() private _tags: Tag[] = [];
|
@state() private _tags?: Tag[];
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
return { tag_id: "" };
|
return { tag_id: "" };
|
||||||
@@ -27,14 +27,16 @@ export class HaTagTrigger extends LitElement implements TriggerElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
const { tag_id } = this.trigger;
|
if (!this._tags) {
|
||||||
|
return html``;
|
||||||
|
}
|
||||||
return html`
|
return html`
|
||||||
<ha-select
|
<ha-select
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.triggers.type.tag.label"
|
"ui.panel.config.automation.editor.triggers.type.tag.label"
|
||||||
)}
|
)}
|
||||||
.disabled=${this._tags.length === 0}
|
.disabled=${this._tags.length === 0}
|
||||||
.value=${tag_id}
|
.value=${this.trigger.tag_id}
|
||||||
@selected=${this._tagChanged}
|
@selected=${this._tagChanged}
|
||||||
>
|
>
|
||||||
${this._tags.map(
|
${this._tags.map(
|
||||||
@@ -49,13 +51,19 @@ export class HaTagTrigger extends LitElement implements TriggerElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _fetchTags() {
|
private async _fetchTags() {
|
||||||
this._tags = await fetchTags(this.hass);
|
this._tags = (await fetchTags(this.hass)).sort((a, b) =>
|
||||||
this._tags.sort((a, b) =>
|
|
||||||
caseInsensitiveStringCompare(a.name || a.id, b.name || b.id)
|
caseInsensitiveStringCompare(a.name || a.id, b.name || b.id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _tagChanged(ev) {
|
private _tagChanged(ev) {
|
||||||
|
if (
|
||||||
|
!ev.target.value ||
|
||||||
|
!this._tags ||
|
||||||
|
this.trigger.tag_id === ev.target.value
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
value: {
|
value: {
|
||||||
...this.trigger,
|
...this.trigger,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user