Compare commits

..

1 Commits

Author SHA1 Message Date
Paul Bottein
bd7b345fe2 Improve strategy edit mode 2025-08-18 13:43:18 +02:00
200 changed files with 5290 additions and 12551 deletions

View File

@@ -21,7 +21,7 @@ jobs:
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
steps:
- name: Check out files from GitHub
uses: actions/checkout@v5.0.0
uses: actions/checkout@v4.2.2
with:
ref: dev
@@ -56,7 +56,7 @@ jobs:
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
steps:
- name: Check out files from GitHub
uses: actions/checkout@v5.0.0
uses: actions/checkout@v4.2.2
with:
ref: master

View File

@@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out files from GitHub
uses: actions/checkout@v5.0.0
uses: actions/checkout@v4.2.2
- name: Setup Node
uses: actions/setup-node@v4.4.0
with:
@@ -58,7 +58,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out files from GitHub
uses: actions/checkout@v5.0.0
uses: actions/checkout@v4.2.2
- name: Setup Node
uses: actions/setup-node@v4.4.0
with:
@@ -76,7 +76,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out files from GitHub
uses: actions/checkout@v5.0.0
uses: actions/checkout@v4.2.2
- name: Setup Node
uses: actions/setup-node@v4.4.0
with:
@@ -100,7 +100,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out files from GitHub
uses: actions/checkout@v5.0.0
uses: actions/checkout@v4.2.2
- name: Setup Node
uses: actions/setup-node@v4.4.0
with:

View File

@@ -23,7 +23,7 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v5.0.0
uses: actions/checkout@v4.2.2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.

View File

@@ -22,7 +22,7 @@ jobs:
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
steps:
- name: Check out files from GitHub
uses: actions/checkout@v5.0.0
uses: actions/checkout@v4.2.2
with:
ref: dev
@@ -57,7 +57,7 @@ jobs:
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
steps:
- name: Check out files from GitHub
uses: actions/checkout@v5.0.0
uses: actions/checkout@v4.2.2
with:
ref: master

View File

@@ -16,7 +16,7 @@ jobs:
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
steps:
- name: Check out files from GitHub
uses: actions/checkout@v5.0.0
uses: actions/checkout@v4.2.2
- name: Setup Node
uses: actions/setup-node@v4.4.0

View File

@@ -21,7 +21,7 @@ jobs:
if: github.repository == 'home-assistant/frontend' && contains(github.event.pull_request.labels.*.name, 'needs design preview')
steps:
- name: Check out files from GitHub
uses: actions/checkout@v5.0.0
uses: actions/checkout@v4.2.2
- name: Setup Node
uses: actions/setup-node@v4.4.0

View File

@@ -20,7 +20,7 @@ jobs:
contents: write
steps:
- name: Checkout the repository
uses: actions/checkout@v5.0.0
uses: actions/checkout@v4.2.2
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5

View File

@@ -23,7 +23,7 @@ jobs:
contents: write # Required to upload release assets
steps:
- name: Checkout the repository
uses: actions/checkout@v5.0.0
uses: actions/checkout@v4.2.2
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
@@ -90,7 +90,7 @@ jobs:
contents: write # Required to upload release assets
steps:
- name: Checkout the repository
uses: actions/checkout@v5.0.0
uses: actions/checkout@v4.2.2
- name: Setup Node
uses: actions/setup-node@v4.4.0
with:
@@ -119,7 +119,7 @@ jobs:
contents: write # Required to upload release assets
steps:
- name: Checkout the repository
uses: actions/checkout@v5.0.0
uses: actions/checkout@v4.2.2
- name: Setup Node
uses: actions/setup-node@v4.4.0
with:

View File

@@ -9,7 +9,7 @@ jobs:
check-authorization:
runs-on: ubuntu-latest
# Only run if this is a Task issue type (from the issue form)
if: github.event.issue.type.name == 'Task'
if: github.event.issue.issue_type == 'Task'
steps:
- name: Check if user is authorized
uses: actions/github-script@v7

View File

@@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v5.0.0
uses: actions/checkout@v4.2.2
- name: Upload Translations
run: |

File diff suppressed because one or more lines are too long

View File

@@ -6,4 +6,4 @@ enableGlobalCache: false
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-4.9.4.cjs
yarnPath: .yarn/releases/yarn-4.9.2.cjs

View File

@@ -14,5 +14,5 @@
"name": "Home Assistant Cast",
"short_name": "HA Cast",
"start_url": "/?homescreen=1",
"theme_color": "#009ac7"
"theme_color": "#03A9F4"
}

View File

@@ -75,5 +75,5 @@
"name": "Home Assistant Demo",
"short_name": "HA Demo",
"start_url": "/?homescreen=1",
"theme_color": "#009ac7"
"theme_color": "#03A9F4"
}

View File

@@ -1106,7 +1106,7 @@ export default {
friendly_name: "Philips Hue",
entity_picture: null,
description:
"Press the button on the bridge to register Philips Hue with Home Assistant.",
"Press the button on the bridge to register Philips Hue with Home Assistant.\n\n![Description image](/static/images/config_philips_hue.jpg)",
submit_caption: "I have pressed the button",
},
last_changed: "2018-07-19T10:44:46.515160+00:00",

View File

@@ -18,6 +18,7 @@ import { HaDeviceAction } from "../../../../src/panels/config/automation/action/
import { HaEventAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-event";
import { HaIfAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-if";
import { HaParallelAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-parallel";
import { HaPlayMediaAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-play_media";
import { HaRepeatAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-repeat";
import { HaSequenceAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-sequence";
import { HaServiceAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-service";
@@ -31,6 +32,7 @@ const SCHEMAS: { name: string; actions: Action[] }[] = [
{ name: "Service", actions: [HaServiceAction.defaultConfig] },
{ name: "Condition", actions: [HaConditionAction.defaultConfig] },
{ name: "Delay", actions: [HaDelayAction.defaultConfig] },
{ name: "Play media", actions: [HaPlayMediaAction.defaultConfig] },
{ name: "Wait", actions: [HaWaitAction.defaultConfig] },
{ name: "WaitForTrigger", actions: [HaWaitForTriggerAction.defaultConfig] },
{ name: "Repeat", actions: [HaRepeatAction.defaultConfig] },

View File

@@ -101,14 +101,11 @@ const ENTITIES = [
ClimateEntityFeature.FAN_MODE +
ClimateEntityFeature.TARGET_TEMPERATURE_RANGE,
}),
getEntity("fan", "fan_demo", "on", {
getEntity("fan", "fan_direction", "on", {
friendly_name: "Ceiling fan",
device_class: "fan",
direction: "reverse",
supported_features:
FanEntityFeature.DIRECTION +
FanEntityFeature.SET_SPEED +
FanEntityFeature.OSCILLATE,
supported_features: [FanEntityFeature.DIRECTION],
}),
];
@@ -275,29 +272,11 @@ const CONFIGS = [
heading: "Fan direction feature",
config: `
- type: tile
entity: fan.fan_demo
entity: fan.fan_direction
features:
- type: fan-direction
`,
},
{
heading: "Fan speed feature",
config: `
- type: tile
entity: fan.fan_demo
features:
- type: fan-speed
`,
},
{
heading: "Fan oscillate feature",
config: `
- type: tile
entity: fan.fan_demo
features:
- type: fan-oscillate
`,
},
];
@customElement("demo-lovelace-tile-card")

View File

@@ -1,3 +0,0 @@
---
title: Fan
---

View File

@@ -1,50 +0,0 @@
import type { PropertyValues, TemplateResult } from "lit";
import { html, LitElement } 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 type { MockHomeAssistant } from "../../../../src/fake_data/provide_hass";
import { provideHass } from "../../../../src/fake_data/provide_hass";
import "../../components/demo-more-infos";
import { FanEntityFeature } from "../../../../src/data/fan";
const ENTITIES = [
getEntity("fan", "fan", "on", {
friendly_name: "Fan",
device_class: "fan",
supported_features:
FanEntityFeature.OSCILLATE +
FanEntityFeature.DIRECTION +
FanEntityFeature.SET_SPEED,
}),
];
@customElement("demo-more-info-fan")
class DemoMoreInfoFan extends LitElement {
@property({ attribute: false }) 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-fan": DemoMoreInfoFan;
}
}

View File

@@ -1,6 +1,6 @@
export default {
"*.?(c|m){js,ts}": [
"eslint --flag v10_config_lookup_from_file --cache --cache-strategy=content --cache-location=node_modules/.cache/eslint/.eslintcache --fix",
"eslint --flag unstable_config_lookup_from_file --cache --cache-strategy=content --cache-location=node_modules/.cache/eslint/.eslintcache --fix",
"prettier --cache --write",
"lit-analyzer --quiet",
],

View File

@@ -8,8 +8,8 @@
"version": "1.0.0",
"scripts": {
"build": "script/build_frontend",
"lint:eslint": "eslint --flag v10_config_lookup_from_file \"**/src/**/*.{js,ts,html}\" --cache --cache-strategy=content --cache-location=node_modules/.cache/eslint/.eslintcache --ignore-pattern=.gitignore --max-warnings=0",
"format:eslint": "eslint --flag v10_config_lookup_from_file \"**/src/**/*.{js,ts,html}\" --cache --cache-strategy=content --cache-location=node_modules/.cache/eslint/.eslintcache --ignore-pattern=.gitignore --fix",
"lint:eslint": "eslint --flag unstable_config_lookup_from_file \"**/src/**/*.{js,ts,html}\" --cache --cache-strategy=content --cache-location=node_modules/.cache/eslint/.eslintcache --ignore-pattern=.gitignore --max-warnings=0",
"format:eslint": "eslint --flag unstable_config_lookup_from_file \"**/src/**/*.{js,ts,html}\" --cache --cache-strategy=content --cache-location=node_modules/.cache/eslint/.eslintcache --ignore-pattern=.gitignore --fix",
"lint:prettier": "prettier . --cache --check",
"format:prettier": "prettier . --cache --write",
"lint:types": "tsc",
@@ -27,11 +27,11 @@
"type": "module",
"dependencies": {
"@awesome.me/webawesome": "3.0.0-beta.4",
"@babel/runtime": "7.28.3",
"@babel/runtime": "7.28.2",
"@braintree/sanitize-url": "7.1.1",
"@codemirror/autocomplete": "6.18.6",
"@codemirror/commands": "6.8.1",
"@codemirror/language": "6.11.3",
"@codemirror/language": "6.11.2",
"@codemirror/legacy-modes": "6.5.1",
"@codemirror/search": "6.5.11",
"@codemirror/state": "6.5.2",
@@ -80,7 +80,7 @@
"@material/mwc-top-app-bar": "0.27.0",
"@material/mwc-top-app-bar-fixed": "0.27.0",
"@material/top-app-bar": "=14.0.0-canary.53b3cad2f.0",
"@material/web": "2.4.0",
"@material/web": "2.3.0",
"@mdi/js": "7.4.47",
"@mdi/svg": "7.4.47",
"@replit/codemirror-indentation-markers": "6.5.3",
@@ -89,8 +89,8 @@
"@thomasloven/round-slider": "0.6.0",
"@tsparticles/engine": "3.9.1",
"@tsparticles/preset-links": "3.2.0",
"@vaadin/combo-box": "24.8.6",
"@vaadin/vaadin-themable-mixin": "24.8.6",
"@vaadin/combo-box": "24.8.5",
"@vaadin/vaadin-themable-mixin": "24.8.5",
"@vibrant/color": "4.0.0",
"@vue/web-component-wrapper": "1.3.0",
"@webcomponents/scoped-custom-element-registry": "0.0.10",
@@ -99,7 +99,7 @@
"barcode-detector": "3.0.5",
"color-name": "2.0.0",
"comlink": "4.4.2",
"core-js": "3.45.1",
"core-js": "3.45.0",
"cropperjs": "1.6.2",
"culori": "4.0.2",
"date-fns": "4.1.0",
@@ -112,7 +112,7 @@
"fuse.js": "7.1.0",
"google-timezones-json": "1.2.0",
"gulp-zopfli-green": "6.0.2",
"hls.js": "1.6.11",
"hls.js": "1.6.9",
"home-assistant-js-websocket": "9.5.0",
"idb-keyval": "6.2.2",
"intl-messageformat": "10.7.16",
@@ -123,7 +123,7 @@
"lit": "3.3.1",
"lit-html": "3.3.1",
"luxon": "3.7.1",
"marked": "16.2.1",
"marked": "16.1.2",
"memoize-one": "6.0.0",
"node-vibrant": "4.0.3",
"object-hash": "3.0.0",
@@ -149,18 +149,18 @@
"xss": "1.0.15"
},
"devDependencies": {
"@babel/core": "7.28.3",
"@babel/core": "7.28.0",
"@babel/helper-define-polyfill-provider": "0.6.5",
"@babel/plugin-transform-runtime": "7.28.3",
"@babel/preset-env": "7.28.3",
"@bundle-stats/plugin-webpack-filter": "4.21.3",
"@lokalise/node-api": "15.2.1",
"@babel/plugin-transform-runtime": "7.28.0",
"@babel/preset-env": "7.28.0",
"@bundle-stats/plugin-webpack-filter": "4.21.2",
"@lokalise/node-api": "15.0.0",
"@octokit/auth-oauth-device": "8.0.1",
"@octokit/plugin-retry": "8.0.1",
"@octokit/rest": "22.0.0",
"@rsdoctor/rspack-plugin": "1.2.3",
"@rspack/core": "1.5.1",
"@rspack/dev-server": "1.1.4",
"@rsdoctor/rspack-plugin": "1.2.1",
"@rspack/cli": "1.4.11",
"@rspack/core": "1.4.11",
"@types/babel__plugin-transform-runtime": "7.9.5",
"@types/chromecast-caf-receiver": "6.0.22",
"@types/chromecast-caf-sender": "1.0.11",
@@ -184,14 +184,14 @@
"babel-plugin-template-html-minifier": "4.1.0",
"browserslist-useragent-regexp": "4.1.3",
"del": "8.0.0",
"eslint": "9.34.0",
"eslint": "9.33.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-prettier": "10.1.8",
"eslint-import-resolver-webpack": "0.13.10",
"eslint-plugin-import": "2.32.0",
"eslint-plugin-lit": "2.1.1",
"eslint-plugin-lit-a11y": "5.1.1",
"eslint-plugin-unused-imports": "4.2.0",
"eslint-plugin-unused-imports": "4.1.4",
"eslint-plugin-wc": "3.0.1",
"fancy-log": "2.0.0",
"fs-extra": "11.3.1",
@@ -218,7 +218,7 @@
"terser-webpack-plugin": "5.3.14",
"ts-lit-plugin": "2.0.2",
"typescript": "5.9.2",
"typescript-eslint": "8.41.0",
"typescript-eslint": "8.39.0",
"vite-tsconfig-paths": "5.1.4",
"vitest": "3.2.4",
"webpack-stats-plugin": "1.1.3",
@@ -235,7 +235,7 @@
"globals": "16.3.0",
"tslib": "2.8.1",
"@material/mwc-list@^0.27.0": "patch:@material/mwc-list@npm%3A0.27.0#~/.yarn/patches/@material-mwc-list-npm-0.27.0-5344fc9de4.patch",
"@vaadin/vaadin-themable-mixin": "24.8.6"
"@vaadin/vaadin-themable-mixin": "24.8.5"
},
"packageManager": "yarn@4.9.4"
"packageManager": "yarn@4.9.2"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

@@ -1,76 +0,0 @@
<svg width="160" height="160" viewBox="0 0 160 160" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_4744_40067)">
<path d="M0 6C0 2.68629 2.68629 0 6 0H28C31.3137 0 34 2.68629 34 6C34 9.31371 31.3137 12 28 12H6C2.68629 12 0 9.31371 0 6Z" fill="white" fill-opacity="0.48"/>
<path d="M0 28C0 23.5817 3.58172 20 8 20H42.6667C47.0849 20 50.6667 23.5817 50.6667 28V36C50.6667 40.4183 47.0849 44 42.6667 44H8.00001C3.58173 44 0 40.4183 0 36V28Z" fill="#1C1C1C"/>
<path d="M8 20.5H42.667C46.809 20.5002 50.167 23.858 50.167 28V36C50.167 40.142 46.809 43.4998 42.667 43.5H8C3.85787 43.5 0.5 40.1421 0.5 36V28C0.5 23.8579 3.85786 20.5 8 20.5Z" stroke="white" stroke-opacity="0.24"/>
<path d="M6 32C6 28.6863 8.68629 26 12 26C15.3137 26 18 28.6863 18 32C18 35.3137 15.3137 38 12 38C8.68629 38 6 35.3137 6 32Z" fill="white" fill-opacity="0.24"/>
<path d="M24 31C24 29.3431 25.3431 28 27 28H39.6667C41.3235 28 42.6667 29.3431 42.6667 31V33C42.6667 34.6569 41.3235 36 39.6667 36H27C25.3431 36 24 34.6569 24 33V31Z" fill="white" fill-opacity="0.24"/>
<path d="M54.6666 28C54.6666 23.5817 58.2483 20 62.6666 20H97.3333C101.752 20 105.333 23.5817 105.333 28V36C105.333 40.4183 101.752 44 97.3333 44H62.6666C58.2484 44 54.6666 40.4183 54.6666 36V28Z" fill="#1C1C1C"/>
<path d="M62.6666 20.5H97.3336C101.476 20.5002 104.834 23.858 104.834 28V36C104.834 40.142 101.476 43.4998 97.3336 43.5H62.6666C58.5245 43.5 55.1666 40.1421 55.1666 36V28C55.1666 23.8579 58.5245 20.5 62.6666 20.5Z" stroke="white" stroke-opacity="0.24"/>
<path d="M60.6666 32C60.6666 28.6863 63.3529 26 66.6666 26C69.9803 26 72.6666 28.6863 72.6666 32C72.6666 35.3137 69.9803 38 66.6666 38C63.3529 38 60.6666 35.3137 60.6666 32Z" fill="white" fill-opacity="0.24"/>
<path d="M78.6666 31C78.6666 29.3431 80.0098 28 81.6666 28H94.3333C95.9901 28 97.3333 29.3431 97.3333 31V33C97.3333 34.6569 95.9901 36 94.3333 36H81.6666C80.0098 36 78.6666 34.6569 78.6666 33V31Z" fill="white" fill-opacity="0.24"/>
<path d="M109.333 28C109.333 23.5817 112.915 20 117.333 20H152C156.418 20 160 23.5817 160 28V36C160 40.4183 156.418 44 152 44H117.333C112.915 44 109.333 40.4183 109.333 36V28Z" fill="#1C1C1C"/>
<path d="M117.333 20.5H152C156.142 20.5002 159.5 23.858 159.5 28V36C159.5 40.142 156.142 43.4998 152 43.5H117.333C113.191 43.5 109.833 40.1421 109.833 36V28C109.833 23.8579 113.191 20.5 117.333 20.5Z" stroke="white" stroke-opacity="0.24"/>
<path d="M115.333 32C115.333 28.6863 118.02 26 121.333 26C124.647 26 127.333 28.6863 127.333 32C127.333 35.3137 124.647 38 121.333 38C118.02 38 115.333 35.3137 115.333 32Z" fill="white" fill-opacity="0.24"/>
<path d="M133.333 31C133.333 29.3431 134.677 28 136.333 28H149C150.657 28 152 29.3431 152 31V33C152 34.6569 150.657 36 149 36H136.333C134.677 36 133.333 34.6569 133.333 33V31Z" fill="white" fill-opacity="0.24"/>
<path d="M0 56C0 53.7909 1.79086 52 4 52H29C31.2091 52 33 53.7909 33 56C33 58.2091 31.2091 60 29 60H4C1.79086 60 0 58.2091 0 56Z" fill="white" fill-opacity="0.48"/>
<path d="M0 72C0 67.5817 3.58172 64 8 64H29C33.4183 64 37 67.5817 37 72V96C37 100.418 33.4183 104 29 104H8C3.58172 104 0 100.418 0 96V72Z" fill="#1C1C1C"/>
<path d="M8 64.5H29C33.1421 64.5 36.5 67.8579 36.5 72V96C36.5 100.142 33.1421 103.5 29 103.5H8C3.85786 103.5 0.5 100.142 0.5 96V72C0.5 67.8579 3.85786 64.5 8 64.5Z" stroke="white" stroke-opacity="0.24"/>
<mask id="mask0_4744_40067" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="6" y="72" width="25" height="24">
<path d="M18.5 74C16.6435 74 14.863 74.7375 13.5503 76.0503C12.2375 77.363 11.5 79.1435 11.5 81C11.5 83.38 12.69 85.47 14.5 86.74V89C14.5 89.2652 14.6054 89.5196 14.7929 89.7071C14.9804 89.8946 15.2348 90 15.5 90H21.5C21.7652 90 22.0196 89.8946 22.2071 89.7071C22.3946 89.5196 22.5 89.2652 22.5 89V86.74C24.31 85.47 25.5 83.38 25.5 81C25.5 79.1435 24.7625 77.363 23.4497 76.0503C22.137 74.7375 20.3565 74 18.5 74ZM15.5 93C15.5 93.2652 15.6054 93.5196 15.7929 93.7071C15.9804 93.8946 16.2348 94 16.5 94H20.5C20.7652 94 21.0196 93.8946 21.2071 93.7071C21.3946 93.5196 21.5 93.2652 21.5 93V92H15.5V93Z" fill="black"/>
</mask>
<g mask="url(#mask0_4744_40067)">
<rect x="6.5" y="72" width="24" height="24" fill="#03A9F4"/>
</g>
<path d="M41 72C41 67.5817 44.5817 64 49 64H70C74.4183 64 78 67.5817 78 72V96C78 100.418 74.4183 104 70 104H49C44.5817 104 41 100.418 41 96V72Z" fill="#1C1C1C"/>
<path d="M49 64.5H70C74.1421 64.5 77.5 67.8579 77.5 72V96C77.5 100.142 74.1421 103.5 70 103.5H49C44.8579 103.5 41.5 100.142 41.5 96V72C41.5 67.8579 44.8579 64.5 49 64.5Z" stroke="white" stroke-opacity="0.24"/>
<mask id="mask1_4744_40067" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="47" y="72" width="25" height="24">
<path d="M66.5 80C67.61 80 68.5 80.9 68.5 82V88.76C69.11 89.31 69.5 90.11 69.5 91C69.5 92.66 68.16 94 66.5 94C64.84 94 63.5 92.66 63.5 91C63.5 90.11 63.89 89.31 64.5 88.76V82C64.5 80.9 65.4 80 66.5 80ZM66.5 81C65.95 81 65.5 81.45 65.5 82V83H67.5V82C67.5 81.45 67.05 81 66.5 81ZM52.5 92V84H49.5L59.5 75L63.9 78.96C63.04 79.69 62.5 80.78 62.5 82V88C61.87 88.83 61.5 89.87 61.5 91L61.6 92H52.5Z" fill="black"/>
</mask>
<g mask="url(#mask1_4744_40067)">
<rect x="47.5" y="72" width="24" height="24" fill="#03A9F4"/>
</g>
<path d="M82 72C82 67.5817 85.5817 64 90 64H111C115.418 64 119 67.5817 119 72V96C119 100.418 115.418 104 111 104H90C85.5817 104 82 100.418 82 96V72Z" fill="#1C1C1C"/>
<path d="M90 64.5H111C115.142 64.5 118.5 67.8579 118.5 72V96C118.5 100.142 115.142 103.5 111 103.5H90C85.8579 103.5 82.5 100.142 82.5 96V72C82.5 67.8579 85.8579 64.5 90 64.5Z" stroke="white" stroke-opacity="0.24"/>
<mask id="mask2_4744_40067" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="88" y="72" width="25" height="24">
<path d="M100.5 84H107.5C106.97 88.11 104.22 91.78 100.5 92.92V84H93.5V78.3L100.5 75.19M100.5 73L91.5 77V83C91.5 88.55 95.34 93.73 100.5 95C105.66 93.73 109.5 88.55 109.5 83V77L100.5 73Z" fill="black"/>
</mask>
<g mask="url(#mask2_4744_40067)">
<rect x="88.5" y="72" width="24" height="24" fill="#03A9F4"/>
</g>
<path d="M123 72C123 67.5817 126.582 64 131 64H152C156.418 64 160 67.5817 160 72V96C160 100.418 156.418 104 152 104H131C126.582 104 123 100.418 123 96V72Z" fill="#1C1C1C"/>
<path d="M131 64.5H152C156.142 64.5 159.5 67.8579 159.5 72V96C159.5 100.142 156.142 103.5 152 103.5H131C126.858 103.5 123.5 100.142 123.5 96V72C123.5 67.8579 126.858 64.5 131 64.5Z" stroke="white" stroke-opacity="0.24"/>
<mask id="mask3_4744_40067" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="129" y="72" width="25" height="24">
<path d="M145.5 84C145.5 83.4696 145.711 82.9609 146.086 82.5858C146.461 82.2107 146.97 82 147.5 82C148.03 82 148.539 82.2107 148.914 82.5858C149.289 82.9609 149.5 83.4696 149.5 84C149.5 84.5304 149.289 85.0391 148.914 85.4142C148.539 85.7893 148.03 86 147.5 86C146.97 86 146.461 85.7893 146.086 85.4142C145.711 85.0391 145.5 84.5304 145.5 84ZM139.5 84C139.5 83.4696 139.711 82.9609 140.086 82.5858C140.461 82.2107 140.97 82 141.5 82C142.03 82 142.539 82.2107 142.914 82.5858C143.289 82.9609 143.5 83.4696 143.5 84C143.5 84.5304 143.289 85.0391 142.914 85.4142C142.539 85.7893 142.03 86 141.5 86C140.97 86 140.461 85.7893 140.086 85.4142C139.711 85.0391 139.5 84.5304 139.5 84ZM133.5 84C133.5 83.4696 133.711 82.9609 134.086 82.5858C134.461 82.2107 134.97 82 135.5 82C136.03 82 136.539 82.2107 136.914 82.5858C137.289 82.9609 137.5 83.4696 137.5 84C137.5 84.5304 137.289 85.0391 136.914 85.4142C136.539 85.7893 136.03 86 135.5 86C134.97 86 134.461 85.7893 134.086 85.4142C133.711 85.0391 133.5 84.5304 133.5 84Z" fill="black"/>
</mask>
<g mask="url(#mask3_4744_40067)">
<rect x="129.5" y="72" width="24" height="24" fill="#03A9F4"/>
</g>
<path d="M0 116C0 113.791 1.79086 112 4 112H29C31.2091 112 33 113.791 33 116C33 118.209 31.2091 120 29 120H4C1.79086 120 0 118.209 0 116Z" fill="white" fill-opacity="0.48"/>
<path d="M0 132C0 127.582 3.58172 124 8 124H70C74.4183 124 78 127.582 78 132V160H0V132Z" fill="url(#paint0_linear_4744_40067)"/>
<path d="M8 124.5H70C74.1421 124.5 77.5 127.858 77.5 132V159.5H0.5V132C0.5 127.858 3.85786 124.5 8 124.5Z" stroke="url(#paint1_linear_4744_40067)" stroke-opacity="0.12"/>
<path d="M82 132C82 127.582 85.5817 124 90 124H152C156.418 124 160 127.582 160 132V160H82V132Z" fill="url(#paint2_linear_4744_40067)"/>
<path d="M90 124.5H152C156.142 124.5 159.5 127.858 159.5 132V159.5H82.5V132C82.5 127.858 85.8579 124.5 90 124.5Z" stroke="url(#paint3_linear_4744_40067)" stroke-opacity="0.12"/>
</g>
<defs>
<linearGradient id="paint0_linear_4744_40067" x1="39" y1="124" x2="39" y2="160" gradientUnits="userSpaceOnUse">
<stop offset="0.5" stop-color="#1C1C1C"/>
<stop offset="1" stop-color="#1C1C1C" stop-opacity="0"/>
</linearGradient>
<linearGradient id="paint1_linear_4744_40067" x1="39" y1="124" x2="39" y2="160" gradientUnits="userSpaceOnUse">
<stop offset="0.5" stop-color="white" stop-opacity="0.24"/>
<stop offset="1" stop-opacity="0"/>
</linearGradient>
<linearGradient id="paint2_linear_4744_40067" x1="121" y1="124" x2="121" y2="160" gradientUnits="userSpaceOnUse">
<stop offset="0.5" stop-color="#1C1C1C"/>
<stop offset="1" stop-color="#1C1C1C" stop-opacity="0"/>
</linearGradient>
<linearGradient id="paint3_linear_4744_40067" x1="121" y1="124" x2="121" y2="160" gradientUnits="userSpaceOnUse">
<stop offset="0.5" stop-color="white" stop-opacity="0.24"/>
<stop offset="1" stop-opacity="0"/>
</linearGradient>
<clipPath id="clip0_4744_40067">
<rect width="160" height="160" fill="white"/>
</clipPath>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 9.3 KiB

View File

@@ -1,76 +0,0 @@
<svg width="160" height="160" viewBox="0 0 160 160" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_4744_39984)">
<path d="M0 6C0 2.68629 2.68629 0 6 0H28C31.3137 0 34 2.68629 34 6C34 9.31371 31.3137 12 28 12H6C2.68629 12 0 9.31371 0 6Z" fill="black" fill-opacity="0.32"/>
<path d="M0 28C0 23.5817 3.58172 20 8 20H42.6667C47.0849 20 50.6667 23.5817 50.6667 28V36C50.6667 40.4183 47.0849 44 42.6667 44H8.00001C3.58173 44 0 40.4183 0 36V28Z" fill="white"/>
<path d="M8 20.5H42.667C46.809 20.5002 50.167 23.858 50.167 28V36C50.167 40.142 46.809 43.4998 42.667 43.5H8C3.85787 43.5 0.5 40.1421 0.5 36V28C0.5 23.8579 3.85786 20.5 8 20.5Z" stroke="black" stroke-opacity="0.12"/>
<rect x="6" y="26" width="12" height="12" rx="6" fill="black" fill-opacity="0.12"/>
<path d="M24 31C24 29.3431 25.3431 28 27 28H39.6667C41.3235 28 42.6667 29.3431 42.6667 31V33C42.6667 34.6569 41.3235 36 39.6667 36H27C25.3431 36 24 34.6569 24 33V31Z" fill="black" fill-opacity="0.12"/>
<path d="M54.6667 28C54.6667 23.5817 58.2484 20 62.6667 20H97.3333C101.752 20 105.333 23.5817 105.333 28V36C105.333 40.4183 101.752 44 97.3334 44H62.6667C58.2484 44 54.6667 40.4183 54.6667 36V28Z" fill="white"/>
<path d="M62.6667 20.5H97.3337C101.476 20.5002 104.834 23.858 104.834 28V36C104.834 40.142 101.476 43.4998 97.3337 43.5H62.6667C58.5246 43.5 55.1667 40.1421 55.1667 36V28C55.1667 23.8579 58.5246 20.5 62.6667 20.5Z" stroke="black" stroke-opacity="0.12"/>
<rect x="60.6667" y="26" width="12" height="12" rx="6" fill="black" fill-opacity="0.12"/>
<path d="M78.6667 31C78.6667 29.3431 80.0098 28 81.6667 28H94.3334C95.9902 28 97.3334 29.3431 97.3334 31V33C97.3334 34.6569 95.9902 36 94.3334 36H81.6667C80.0098 36 78.6667 34.6569 78.6667 33V31Z" fill="black" fill-opacity="0.12"/>
<path d="M109.333 28C109.333 23.5817 112.915 20 117.333 20H152C156.418 20 160 23.5817 160 28V36C160 40.4183 156.418 44 152 44H117.333C112.915 44 109.333 40.4183 109.333 36V28Z" fill="white"/>
<path d="M117.333 20.5H152C156.142 20.5002 159.5 23.858 159.5 28V36C159.5 40.142 156.142 43.4998 152 43.5H117.333C113.191 43.5 109.833 40.1421 109.833 36V28C109.833 23.8579 113.191 20.5 117.333 20.5Z" stroke="black" stroke-opacity="0.12"/>
<rect x="115.333" y="26" width="12" height="12" rx="6" fill="black" fill-opacity="0.12"/>
<path d="M133.333 31C133.333 29.3431 134.676 28 136.333 28H149C150.657 28 152 29.3431 152 31V33C152 34.6569 150.657 36 149 36H136.333C134.676 36 133.333 34.6569 133.333 33V31Z" fill="black" fill-opacity="0.12"/>
<path d="M0 56C0 53.7909 1.79086 52 4 52H29C31.2091 52 33 53.7909 33 56C33 58.2091 31.2091 60 29 60H4C1.79086 60 0 58.2091 0 56Z" fill="black" fill-opacity="0.32"/>
<path d="M0 72C0 67.5817 3.58172 64 8 64H29C33.4183 64 37 67.5817 37 72V96C37 100.418 33.4183 104 29 104H8C3.58172 104 0 100.418 0 96V72Z" fill="white"/>
<path d="M8 64.5H29C33.1421 64.5 36.5 67.8579 36.5 72V96C36.5 100.142 33.1421 103.5 29 103.5H8C3.85786 103.5 0.5 100.142 0.5 96V72C0.5 67.8579 3.85786 64.5 8 64.5Z" stroke="black" stroke-opacity="0.12"/>
<mask id="mask0_4744_39984" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="6" y="72" width="25" height="24">
<path d="M18.5 74C16.6435 74 14.863 74.7375 13.5503 76.0503C12.2375 77.363 11.5 79.1435 11.5 81C11.5 83.38 12.69 85.47 14.5 86.74V89C14.5 89.2652 14.6054 89.5196 14.7929 89.7071C14.9804 89.8946 15.2348 90 15.5 90H21.5C21.7652 90 22.0196 89.8946 22.2071 89.7071C22.3946 89.5196 22.5 89.2652 22.5 89V86.74C24.31 85.47 25.5 83.38 25.5 81C25.5 79.1435 24.7625 77.363 23.4497 76.0503C22.137 74.7375 20.3565 74 18.5 74ZM15.5 93C15.5 93.2652 15.6054 93.5196 15.7929 93.7071C15.9804 93.8946 16.2348 94 16.5 94H20.5C20.7652 94 21.0196 93.8946 21.2071 93.7071C21.3946 93.5196 21.5 93.2652 21.5 93V92H15.5V93Z" fill="black"/>
</mask>
<g mask="url(#mask0_4744_39984)">
<rect x="6.5" y="72" width="24" height="24" fill="#03A9F4"/>
</g>
<path d="M41 72C41 67.5817 44.5817 64 49 64H70C74.4183 64 78 67.5817 78 72V96C78 100.418 74.4183 104 70 104H49C44.5817 104 41 100.418 41 96V72Z" fill="white"/>
<path d="M49 64.5H70C74.1421 64.5 77.5 67.8579 77.5 72V96C77.5 100.142 74.1421 103.5 70 103.5H49C44.8579 103.5 41.5 100.142 41.5 96V72C41.5 67.8579 44.8579 64.5 49 64.5Z" stroke="black" stroke-opacity="0.12"/>
<mask id="mask1_4744_39984" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="47" y="72" width="25" height="24">
<path d="M66.5 80C67.61 80 68.5 80.9 68.5 82V88.76C69.11 89.31 69.5 90.11 69.5 91C69.5 92.66 68.16 94 66.5 94C64.84 94 63.5 92.66 63.5 91C63.5 90.11 63.89 89.31 64.5 88.76V82C64.5 80.9 65.4 80 66.5 80ZM66.5 81C65.95 81 65.5 81.45 65.5 82V83H67.5V82C67.5 81.45 67.05 81 66.5 81ZM52.5 92V84H49.5L59.5 75L63.9 78.96C63.04 79.69 62.5 80.78 62.5 82V88C61.87 88.83 61.5 89.87 61.5 91L61.6 92H52.5Z" fill="black"/>
</mask>
<g mask="url(#mask1_4744_39984)">
<rect x="47.5" y="72" width="24" height="24" fill="#03A9F4"/>
</g>
<path d="M82 72C82 67.5817 85.5817 64 90 64H111C115.418 64 119 67.5817 119 72V96C119 100.418 115.418 104 111 104H90C85.5817 104 82 100.418 82 96V72Z" fill="white"/>
<path d="M90 64.5H111C115.142 64.5 118.5 67.8579 118.5 72V96C118.5 100.142 115.142 103.5 111 103.5H90C85.8579 103.5 82.5 100.142 82.5 96V72C82.5 67.8579 85.8579 64.5 90 64.5Z" stroke="black" stroke-opacity="0.12"/>
<mask id="mask2_4744_39984" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="88" y="72" width="25" height="24">
<path d="M100.5 84H107.5C106.97 88.11 104.22 91.78 100.5 92.92V84H93.5V78.3L100.5 75.19M100.5 73L91.5 77V83C91.5 88.55 95.34 93.73 100.5 95C105.66 93.73 109.5 88.55 109.5 83V77L100.5 73Z" fill="black"/>
</mask>
<g mask="url(#mask2_4744_39984)">
<rect x="88.5" y="72" width="24" height="24" fill="#03A9F4"/>
</g>
<path d="M123 72C123 67.5817 126.582 64 131 64H152C156.418 64 160 67.5817 160 72V96C160 100.418 156.418 104 152 104H131C126.582 104 123 100.418 123 96V72Z" fill="white"/>
<path d="M131 64.5H152C156.142 64.5 159.5 67.8579 159.5 72V96C159.5 100.142 156.142 103.5 152 103.5H131C126.858 103.5 123.5 100.142 123.5 96V72C123.5 67.8579 126.858 64.5 131 64.5Z" stroke="black" stroke-opacity="0.12"/>
<mask id="mask3_4744_39984" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="129" y="72" width="25" height="24">
<path d="M145.5 84C145.5 83.4696 145.711 82.9609 146.086 82.5858C146.461 82.2107 146.97 82 147.5 82C148.03 82 148.539 82.2107 148.914 82.5858C149.289 82.9609 149.5 83.4696 149.5 84C149.5 84.5304 149.289 85.0391 148.914 85.4142C148.539 85.7893 148.03 86 147.5 86C146.97 86 146.461 85.7893 146.086 85.4142C145.711 85.0391 145.5 84.5304 145.5 84ZM139.5 84C139.5 83.4696 139.711 82.9609 140.086 82.5858C140.461 82.2107 140.97 82 141.5 82C142.03 82 142.539 82.2107 142.914 82.5858C143.289 82.9609 143.5 83.4696 143.5 84C143.5 84.5304 143.289 85.0391 142.914 85.4142C142.539 85.7893 142.03 86 141.5 86C140.97 86 140.461 85.7893 140.086 85.4142C139.711 85.0391 139.5 84.5304 139.5 84ZM133.5 84C133.5 83.4696 133.711 82.9609 134.086 82.5858C134.461 82.2107 134.97 82 135.5 82C136.03 82 136.539 82.2107 136.914 82.5858C137.289 82.9609 137.5 83.4696 137.5 84C137.5 84.5304 137.289 85.0391 136.914 85.4142C136.539 85.7893 136.03 86 135.5 86C134.97 86 134.461 85.7893 134.086 85.4142C133.711 85.0391 133.5 84.5304 133.5 84Z" fill="black"/>
</mask>
<g mask="url(#mask3_4744_39984)">
<rect x="129.5" y="72" width="24" height="24" fill="#18BCF2"/>
</g>
<path d="M0 116C0 113.791 1.79086 112 4 112H29C31.2091 112 33 113.791 33 116C33 118.209 31.2091 120 29 120H4C1.79086 120 0 118.209 0 116Z" fill="black" fill-opacity="0.32"/>
<path d="M0 132C0 127.582 3.58172 124 8 124H70C74.4183 124 78 127.582 78 132V160H0V132Z" fill="url(#paint0_linear_4744_39984)"/>
<path d="M8 124.5H70C74.1421 124.5 77.5 127.858 77.5 132V159.5H0.5V132C0.5 127.858 3.85786 124.5 8 124.5Z" stroke="url(#paint1_linear_4744_39984)" stroke-opacity="0.12"/>
<path d="M82 132C82 127.582 85.5817 124 90 124H152C156.418 124 160 127.582 160 132V160H82V132Z" fill="url(#paint2_linear_4744_39984)"/>
<path d="M90 124.5H152C156.142 124.5 159.5 127.858 159.5 132V159.5H82.5V132C82.5 127.858 85.8579 124.5 90 124.5Z" stroke="url(#paint3_linear_4744_39984)" stroke-opacity="0.12"/>
</g>
<defs>
<linearGradient id="paint0_linear_4744_39984" x1="39" y1="124" x2="39" y2="160" gradientUnits="userSpaceOnUse">
<stop offset="0.5" stop-color="white"/>
<stop offset="1" stop-color="white" stop-opacity="0"/>
</linearGradient>
<linearGradient id="paint1_linear_4744_39984" x1="39" y1="124" x2="39" y2="160" gradientUnits="userSpaceOnUse">
<stop offset="0.5" stop-opacity="0.12"/>
<stop offset="1" stop-opacity="0"/>
</linearGradient>
<linearGradient id="paint2_linear_4744_39984" x1="121" y1="124" x2="121" y2="160" gradientUnits="userSpaceOnUse">
<stop offset="0.5" stop-color="white"/>
<stop offset="1" stop-color="white" stop-opacity="0"/>
</linearGradient>
<linearGradient id="paint3_linear_4744_39984" x1="121" y1="124" x2="121" y2="160" gradientUnits="userSpaceOnUse">
<stop offset="0.5" stop-opacity="0.12"/>
<stop offset="1" stop-opacity="0"/>
</linearGradient>
<clipPath id="clip0_4744_39984">
<rect width="160" height="160" fill="white"/>
</clipPath>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 8.9 KiB

View File

@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "home-assistant-frontend"
version = "20250827.0"
version = "20250730.0"
license = "Apache-2.0"
license-files = ["LICENSE*"]
description = "The Home Assistant frontend"

View File

@@ -28,10 +28,7 @@ export const computeEntityEntryName = (
hass: HomeAssistant
): string | undefined => {
const name =
entry.name ||
("original_name" in entry && entry.original_name != null
? String(entry.original_name)
: undefined);
entry.name || ("original_name" in entry ? entry.original_name : undefined);
const device = entry.device_id ? hass.devices[entry.device_id] : undefined;

View File

@@ -14,7 +14,6 @@ export type LocalizeKeys =
| `ui.card.weather.attributes.${string}`
| `ui.card.weather.cardinal_direction.${string}`
| `ui.card.lawn_mower.actions.${string}`
| `ui.common.${string}`
| `ui.components.calendar.event.rrule.${string}`
| `ui.components.selectors.file.${string}`
| `ui.components.logbook.messages.detected_device_classes.${string}`
@@ -27,7 +26,6 @@ export type LocalizeKeys =
| `ui.dialogs.unsupported.reasons.${string}`
| `ui.panel.config.${string}.${"caption" | "description"}`
| `ui.panel.config.dashboard.${string}`
| `ui.panel.config.storage.segments.${string}`
| `ui.panel.config.zha.${string}`
| `ui.panel.config.zwave_js.${string}`
| `ui.panel.lovelace.card.${string}`

View File

@@ -39,7 +39,6 @@ export type CustomLegendOption = ECOption["legend"] & {
type: "custom";
data?: {
id?: string;
secondaryIds?: string[]; // Other dataset IDs that should be controlled by this legend item.
name: string;
itemStyle?: Record<string, any>;
}[];
@@ -182,10 +181,6 @@ export class HaChartBase extends LitElement {
return;
}
let chartOptions: ECOption = {};
if (changedProps.has("options")) {
// Separate 'if' from below since this must updated before _getSeries()
this._updateHiddenStatsFromOptions(this.options);
}
if (changedProps.has("data") || changedProps.has("_hiddenDatasets")) {
chartOptions.series = this._getSeries();
}
@@ -456,7 +451,14 @@ export class HaChartBase extends LitElement {
});
}
this._updateHiddenStatsFromOptions(this.options);
const legend = ensureArray(this.options?.legend || [])[0] as
| LegendComponentOption
| undefined;
Object.entries(legend?.selected || {}).forEach(([stat, selected]) => {
if (selected === false) {
this._hiddenDatasets.add(stat);
}
});
this.chart.setOption({
...this._createOptions(),
@@ -467,42 +469,6 @@ export class HaChartBase extends LitElement {
}
}
// Return an array of all IDs associated with the legend item of the primaryId
private _getAllIdsFromLegend(
options: ECOption | undefined,
primaryId: string
): string[] {
if (!options) return [primaryId];
const legend = ensureArray(this.options?.legend || [])[0] as
| LegendComponentOption
| undefined;
let customLegendItem;
if (legend?.type === "custom") {
customLegendItem = (legend as CustomLegendOption).data?.find(
(li) => typeof li === "object" && li.id === primaryId
);
}
return [primaryId, ...(customLegendItem?.secondaryIds || [])];
}
// Parses the options structure and adds all ids of unselected legend items to hiddenDatasets.
// No known need to remove items at this time.
private _updateHiddenStatsFromOptions(options: ECOption | undefined) {
if (!options) return;
const legend = ensureArray(this.options?.legend || [])[0] as
| LegendComponentOption
| undefined;
Object.entries(legend?.selected || {}).forEach(([stat, selected]) => {
if (selected === false) {
this._getAllIdsFromLegend(options, stat).forEach((id) =>
this._hiddenDatasets.add(id)
);
}
});
}
private _getDataZoomConfig(): DataZoomComponentOption | undefined {
const xAxis = (this.options?.xAxis?.[0] ?? this.options?.xAxis) as
| XAXisOption
@@ -878,14 +844,10 @@ export class HaChartBase extends LitElement {
}
const id = ev.currentTarget?.id;
if (this._hiddenDatasets.has(id)) {
this._getAllIdsFromLegend(this.options, id).forEach((i) =>
this._hiddenDatasets.delete(i)
);
this._hiddenDatasets.delete(id);
fireEvent(this, "dataset-unhidden", { id });
} else {
this._getAllIdsFromLegend(this.options, id).forEach((i) =>
this._hiddenDatasets.add(i)
);
this._hiddenDatasets.add(id);
fireEvent(this, "dataset-hidden", { id });
}
this.requestUpdate("_hiddenDatasets");

View File

@@ -18,6 +18,7 @@ export interface Node {
value: number;
index: number; // like z-index but for x/y
label?: string;
tooltip?: string;
color?: string;
passThrough?: boolean;
}

View File

@@ -101,7 +101,7 @@ export class StateHistoryChartTimeline extends LitElement {
fill: api.value(4) as string,
},
};
const text = (api.value(3) as string).replaceAll("\n", " ");
const text = api.value(3) as string;
const textWidth = measureTextWidth(text, 12);
const LABEL_PADDING = 4;
if (textWidth < rectShape.width - LABEL_PADDING * 2) {

View File

@@ -97,6 +97,9 @@ class HaAlert extends LitElement {
content: "";
border-radius: 4px;
}
.icon {
z-index: 1;
}
.icon.no-title {
align-self: center;
}
@@ -119,11 +122,10 @@ class HaAlert extends LitElement {
.main-content {
overflow-wrap: anywhere;
word-break: break-word;
line-height: normal;
margin-left: 8px;
margin-right: 0;
margin-inline-start: 8px;
margin-inline-end: 8px;
margin-inline-end: 0;
}
.title {
margin-top: 2px;

View File

@@ -3,15 +3,11 @@ import type { CSSResultGroup, PropertyValues } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { computeAttributeNameDisplay } from "../common/entity/compute_attribute_display";
import {
STATE_ATTRIBUTES,
STATE_ATTRIBUTES_DOMAIN_CLASS,
} from "../data/entity_attributes";
import { STATE_ATTRIBUTES } from "../data/entity_attributes";
import { haStyle } from "../resources/styles";
import type { HomeAssistant } from "../types";
import "./ha-attribute-value";
import "./ha-expansion-panel";
import { computeStateDomain } from "../common/entity/compute_state_domain";
@customElement("ha-attributes")
class HaAttributes extends LitElement {
@@ -26,12 +22,7 @@ class HaAttributes extends LitElement {
private get _filteredAttributes() {
return this._computeDisplayAttributes(
STATE_ATTRIBUTES.concat(
this.extraFilters ? this.extraFilters.split(",") : [],
(this.stateObj &&
STATE_ATTRIBUTES_DOMAIN_CLASS[computeStateDomain(this.stateObj)]?.[
this.stateObj.attributes?.device_class
]) ||
[]
this.extraFilters ? this.extraFilters.split(",") : []
)
);
}

View File

@@ -1,7 +1,7 @@
import { mdiChevronUp } from "@mdi/js";
import type { TemplateResult } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, query } from "lit/decorators";
import { customElement, property } from "lit/decorators";
import { fireEvent } from "../common/dom/fire_event";
import "./ha-icon-button";
@@ -16,20 +16,12 @@ export class HaAutomationRow extends LitElement {
@property({ type: Boolean, reflect: true })
public selected = false;
@property({ type: Boolean, reflect: true, attribute: "sort-selected" })
public sortSelected = false;
@property({ type: Boolean, reflect: true })
public disabled = false;
@property({ type: Boolean, reflect: true, attribute: "building-block" })
public buildingBlock = false;
@property({ type: Boolean, reflect: true }) public highlight?: boolean;
@query(".row")
private _rowElement?: HTMLDivElement;
protected render(): TemplateResult {
return html`
<div
@@ -74,42 +66,15 @@ export class HaAutomationRow extends LitElement {
if (ev.defaultPrevented) {
return;
}
if (
ev.key !== "Enter" &&
ev.key !== " " &&
!(
(this.sortSelected || ev.altKey) &&
(ev.key === "ArrowUp" || ev.key === "ArrowDown")
)
) {
if (ev.key !== "Enter" && ev.key !== " ") {
return;
}
ev.preventDefault();
ev.stopPropagation();
if (ev.key === "ArrowUp" || ev.key === "ArrowDown") {
if (ev.key === "ArrowUp") {
fireEvent(this, "move-up");
return;
}
fireEvent(this, "move-down");
return;
}
if (this.sortSelected && (ev.key === "Enter" || ev.key === " ")) {
fireEvent(this, "stop-sort-selection");
return;
}
this.click();
}
public focus() {
requestAnimationFrame(() => {
this._rowElement?.focus();
});
}
static styles = css`
:host {
display: block;
@@ -169,22 +134,6 @@ export class HaAutomationRow extends LitElement {
overflow-wrap: anywhere;
margin: 0 12px;
}
:host([sort-selected]) .row {
outline: solid;
outline-color: rgba(var(--rgb-accent-color), 0.6);
outline-offset: -2px;
outline-width: 2px;
background-color: rgba(var(--rgb-accent-color), 0.08);
}
.row:hover {
background-color: rgba(var(--rgb-primary-text-color), 0.04);
}
:host([highlight]) .row {
background-color: rgba(var(--rgb-primary-color), 0.08);
}
:host([highlight]) .row:hover {
background-color: rgba(var(--rgb-primary-color), 0.16);
}
`;
}
@@ -195,6 +144,5 @@ declare global {
interface HASSDomEvents {
"toggle-collapsed": undefined;
"stop-sort-selection": undefined;
}
}

View File

@@ -1,269 +0,0 @@
import { css, html, LitElement } from "lit";
import { customElement, query, state } from "lit/decorators";
import { styleMap } from "lit/directives/style-map";
import { fireEvent } from "../common/dom/fire_event";
const ANIMATION_DURATION_MS = 300;
/**
* A bottom sheet component that slides up from the bottom of the screen.
*
* The bottom sheet provides a draggable interface that allows users to resize
* the sheet by dragging the handle at the top. It supports both mouse and touch
* interactions and automatically closes when dragged below a 20% of screen height.
*
* @fires bottom-sheet-closed - Fired when the bottom sheet is closed
*
* @cssprop --ha-bottom-sheet-border-width - Border width for the sheet
* @cssprop --ha-bottom-sheet-border-style - Border style for the sheet
* @cssprop --ha-bottom-sheet-border-color - Border color for the sheet
*/
@customElement("ha-bottom-sheet")
export class HaBottomSheet extends LitElement {
@query("dialog") private _dialog!: HTMLDialogElement;
private _dragging = false;
private _dragStartY = 0;
private _initialSize = 0;
@state() private _dialogMaxViewpointHeight = 70;
@state() private _dialogViewportHeight?: number;
render() {
return html`<dialog
open
@transitionend=${this._handleTransitionEnd}
style=${styleMap({
height: this._dialogViewportHeight
? `${this._dialogViewportHeight}vh`
: "auto",
maxHeight: `${this._dialogMaxViewpointHeight}vh`,
})}
>
<div class="handle-wrapper">
<div
@mousedown=${this._handleMouseDown}
@touchstart=${this._handleTouchStart}
class="handle"
></div>
</div>
<slot></slot>
</dialog>`;
}
protected firstUpdated(changedProperties) {
super.firstUpdated(changedProperties);
this._openSheet();
}
private _openSheet() {
requestAnimationFrame(() => {
// trigger opening animation
this._dialog.classList.add("show");
});
}
public closeSheet() {
requestAnimationFrame(() => {
this._dialog.classList.remove("show");
});
}
private _handleTransitionEnd() {
if (this._dialog.classList.contains("show")) {
// after show animation is done
// - set the height to the natural height, to prevent content shift when switch content
// - set max height to 90vh, so it opens at max 70vh but can be resized to 90vh
this._dialogViewportHeight =
(this._dialog.offsetHeight / window.innerHeight) * 100;
this._dialogMaxViewpointHeight = 90;
} else {
// after close animation is done close dialog element and fire closed event
this._dialog.close();
fireEvent(this, "bottom-sheet-closed");
}
}
connectedCallback() {
super.connectedCallback();
// register event listeners for drag handling
document.addEventListener("mousemove", this._handleMouseMove);
document.addEventListener("mouseup", this._handleMouseUp);
document.addEventListener("touchmove", this._handleTouchMove, {
passive: false,
});
document.addEventListener("touchend", this._handleTouchEnd);
document.addEventListener("touchcancel", this._handleTouchEnd);
}
disconnectedCallback() {
super.disconnectedCallback();
// unregister event listeners for drag handling
document.removeEventListener("mousemove", this._handleMouseMove);
document.removeEventListener("mouseup", this._handleMouseUp);
document.removeEventListener("touchmove", this._handleTouchMove);
document.removeEventListener("touchend", this._handleTouchEnd);
document.removeEventListener("touchcancel", this._handleTouchEnd);
}
private _handleMouseDown = (ev: MouseEvent) => {
this._startDrag(ev.clientY);
};
private _handleTouchStart = (ev: TouchEvent) => {
// Prevent the browser from interpreting this as a scroll/PTR gesture.
ev.preventDefault();
this._startDrag(ev.touches[0].clientY);
};
private _startDrag(clientY: number) {
this._dragging = true;
this._dragStartY = clientY;
this._initialSize = (this._dialog.offsetHeight / window.innerHeight) * 100;
document.body.style.setProperty("cursor", "grabbing");
}
private _handleMouseMove = (ev: MouseEvent) => {
if (!this._dragging) {
return;
}
this._updateSize(ev.clientY);
};
private _handleTouchMove = (ev: TouchEvent) => {
if (!this._dragging) {
return;
}
ev.preventDefault(); // Prevent scrolling
this._updateSize(ev.touches[0].clientY);
};
private _updateSize(clientY: number) {
const deltaY = this._dragStartY - clientY;
const viewportHeight = window.innerHeight;
const deltaVh = (deltaY / viewportHeight) * 100;
// Calculate new size and clamp between 10vh and 90vh
let newSize = this._initialSize + deltaVh;
newSize = Math.max(10, Math.min(90, newSize));
// on drag down and below 20vh
if (newSize < 20 && deltaY < 0) {
this._endDrag();
this.closeSheet();
return;
}
this._dialogViewportHeight = newSize;
}
private _handleMouseUp = () => {
this._endDrag();
};
private _handleTouchEnd = () => {
this._endDrag();
};
private _endDrag() {
if (!this._dragging) {
return;
}
this._dragging = false;
document.body.style.removeProperty("cursor");
}
static styles = css`
.handle-wrapper {
position: absolute;
top: 0;
width: 100%;
padding-bottom: 2px;
display: flex;
justify-content: center;
align-items: center;
cursor: grab;
touch-action: none;
}
.handle-wrapper .handle {
height: 20px;
width: 200px;
display: flex;
justify-content: center;
align-items: center;
z-index: 7;
padding-bottom: 76px;
}
.handle-wrapper .handle::after {
content: "";
border-radius: 8px;
height: 4px;
background: var(--divider-color, #e0e0e0);
width: 80px;
}
.handle-wrapper .handle:active::after {
cursor: grabbing;
}
dialog {
height: auto;
max-height: 70vh;
min-height: 30vh;
background-color: var(
--ha-dialog-surface-background,
var(--mdc-theme-surface, #fff)
);
display: flex;
flex-direction: column;
top: 0;
inset-inline-start: 0;
position: fixed;
width: calc(100% - 4px);
max-width: 100%;
border: none;
box-shadow: var(--wa-shadow-l);
padding: 0;
margin: 0;
top: auto;
inset-inline-end: auto;
bottom: 0;
inset-inline-start: 0;
box-shadow: 0px -8px 16px rgba(0, 0, 0, 0.2);
border-top-left-radius: var(
--ha-dialog-border-radius,
var(--ha-border-radius-2xl)
);
border-top-right-radius: var(
--ha-dialog-border-radius,
var(--ha-border-radius-2xl)
);
transform: translateY(100%);
transition: transform ${ANIMATION_DURATION_MS}ms ease;
border-top-width: var(--ha-bottom-sheet-border-width);
border-right-width: var(--ha-bottom-sheet-border-width);
border-left-width: var(--ha-bottom-sheet-border-width);
border-bottom-width: 0;
border-style: var(--ha-bottom-sheet-border-style);
border-color: var(--ha-bottom-sheet-border-color);
}
dialog.show {
transform: translateY(0);
}
`;
}
declare global {
interface HTMLElementTagNameMap {
"ha-bottom-sheet": HaBottomSheet;
}
interface HASSDomEvents {
"bottom-sheet-closed": undefined;
}
}

View File

@@ -148,10 +148,6 @@ export class HaDialog extends DialogBase {
white-space: nowrap;
display: block;
padding-left: 4px;
padding-right: 4px;
margin-right: 12px;
margin-inline-end: 12px;
margin-inline-start: initial;
}
.header_button {
text-decoration: none;

View File

@@ -1,8 +1,8 @@
import WaAnimation from "@awesome.me/webawesome/dist/components/animation/animation";
import SlAnimation from "@shoelace-style/shoelace/dist/components/animation/animation.component";
import { customElement, property } from "lit/decorators";
@customElement("ha-fade-in")
export class HaFadeIn extends WaAnimation {
export class HaFadeIn extends SlAnimation {
@property() public name = "fadeIn";
@property() public fill: FillMode = "both";

View File

@@ -329,8 +329,9 @@ export class HaFilterFloorAreas extends LitElement {
}
.subdir {
margin-inline-end: 8px;
opacity: 0.6;
opacity: .6;
}
.
`,
];
}

View File

@@ -6,9 +6,8 @@ import { repeat } from "lit/directives/repeat";
import memoizeOne from "memoize-one";
import { fireEvent } from "../common/dom/fire_event";
import { stringCompare } from "../common/string/compare";
import type { LocalizeFunc } from "../common/translations/localize";
import type { IntegrationManifest } from "../data/integration";
import { fetchIntegrationManifests, domainToName } from "../data/integration";
import { fetchIntegrationManifests } from "../data/integration";
import { haStyleScrollbar } from "../resources/styles";
import type { HomeAssistant } from "../types";
import "./ha-check-list-item";
@@ -64,12 +63,7 @@ export class HaFilterIntegrations extends LitElement {
multi
>
${repeat(
this._integrations(
this.hass.localize,
this._manifests,
this._filter,
this.value
),
this._integrations(this._manifests, this._filter, this.value),
(i) => i.domain,
(integration) =>
html`<ha-check-list-item
@@ -85,7 +79,7 @@ export class HaFilterIntegrations extends LitElement {
.domain=${integration.domain}
brand-fallback
></ha-domain-icon>
${integration.name}
${integration.name || integration.domain}
</ha-check-list-item>`
)}
</ha-list> `
@@ -114,21 +108,11 @@ export class HaFilterIntegrations extends LitElement {
protected async firstUpdated() {
this._manifests = await fetchIntegrationManifests(this.hass);
this.hass.loadBackendTranslation("title");
}
private _integrations = memoizeOne(
(
localize: LocalizeFunc,
manifest: IntegrationManifest[],
filter: string | undefined,
_value
) =>
(manifest: IntegrationManifest[], filter: string | undefined, _value) =>
manifest
.map((mnfst) => ({
...mnfst,
name: domainToName(localize, mnfst.domain, mnfst),
}))
.filter(
(mnfst) =>
(!mnfst.integration_type ||
@@ -140,7 +124,11 @@ export class HaFilterIntegrations extends LitElement {
mnfst.domain.toLowerCase().includes(filter))
)
.sort((a, b) =>
stringCompare(a.name, b.name, this.hass.locale.language)
stringCompare(
a.name || a.domain,
b.name || b.domain,
this.hass.locale.language
)
)
);

View File

@@ -393,13 +393,10 @@ export class HaItemDisplayEditor extends LitElement {
--md-list-item-one-line-container-height: 48px;
}
ha-md-list-item.drag-selected {
--md-focus-ring-color: rgba(var(--rgb-accent-color), 0.6);
box-shadow:
0px 0px 8px 4px rgba(var(--rgb-accent-color), 0.8),
inset 0px 2px 8px 4px rgba(var(--rgb-accent-color), 0.4);
border-radius: 8px;
outline: solid;
outline-color: rgba(var(--rgb-accent-color), 0.6);
outline-offset: -2px;
outline-width: 2px;
background-color: rgba(var(--rgb-accent-color), 0.08);
}
ha-md-list-item ha-icon-button {
margin-left: -12px;

View File

@@ -16,23 +16,9 @@ export class HaMdButtonMenu extends LitElement {
@property() public positioning?: "fixed" | "absolute" | "popover";
@property({ attribute: "anchor-corner" }) public anchorCorner:
| "start-start"
| "start-end"
| "end-start"
| "end-end" = "end-start";
@property({ attribute: "menu-corner" }) public menuCorner:
| "start-start"
| "start-end"
| "end-start"
| "end-end" = "start-start";
@property({ type: Boolean, attribute: "has-overflow" }) public hasOverflow =
false;
@property({ type: Boolean }) public quick = false;
@query("ha-md-menu", true) private _menu!: HaMdMenu;
public get items() {
@@ -53,11 +39,8 @@ export class HaMdButtonMenu extends LitElement {
<slot name="trigger" @slotchange=${this._setTriggerAria}></slot>
</div>
<ha-md-menu
.quick=${this.quick}
.positioning=${this.positioning}
.hasOverflow=${this.hasOverflow}
.anchorCorner=${this.anchorCorner}
.menuCorner=${this.menuCorner}
@opening=${this._handleOpening}
@closing=${this._handleClosing}
>

View File

@@ -1,4 +1,4 @@
import { mdiInformationOutline, mdiStar } from "@mdi/js";
import { mdiStar } from "@mdi/js";
import type { CSSResultGroup, TemplateResult } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -71,17 +71,6 @@ export class HaNetwork extends LitElement {
<span slot="description" data-for="auto_configure">
${this.hass.localize("ui.panel.config.network.adapter.detected")}:
${format_auto_detected_interfaces(this.networkConfig.adapters)}
${!configured_adapters.length
? html`<div class="info-text">
<ha-svg-icon
.path=${mdiInformationOutline}
class="info-icon"
></ha-svg-icon>
${this.hass.localize(
"ui.panel.config.network.adapter.auto_configure_manual_hint"
)}
</div>`
: nothing}
</span>
</ha-settings-row>
${configured_adapters.length || this._expanded
@@ -182,21 +171,6 @@ export class HaNetwork extends LitElement {
span[slot="description"] {
cursor: pointer;
}
.info-text {
display: flex;
align-items: center;
margin-top: 8px;
color: var(--secondary-text-color);
}
.info-icon {
width: 18px;
height: 18px;
color: var(--info-color, var(--primary-color));
margin-right: 8px;
flex-shrink: 0;
}
`,
];
}

View File

@@ -1,21 +1,12 @@
import ProgressRing from "@awesome.me/webawesome/dist/components/progress-ring/progress-ring";
import ProgressRing from "@shoelace-style/shoelace/dist/components/progress-ring/progress-ring.component";
import progressRingStyles from "@shoelace-style/shoelace/dist/components/progress-ring/progress-ring.styles";
import { css } from "lit";
import type { CSSResultGroup } from "lit";
import { customElement, property } from "lit/decorators";
import { StateSet } from "../resources/polyfills/stateset";
@customElement("ha-progress-ring")
export class HaProgressRing extends ProgressRing {
@property() public size?: "tiny" | "small" | "medium" | "large";
attachInternals() {
const internals = super.attachInternals();
Object.defineProperty(internals, "states", {
value: new StateSet(this, internals.states),
});
return internals;
}
public updated(changedProps) {
super.updated(changedProps);
@@ -40,26 +31,24 @@ export class HaProgressRing extends ProgressRing {
}
}
static get styles(): CSSResultGroup {
return [
ProgressRing.styles,
css`
:host {
--indicator-color: var(
--ha-progress-ring-indicator-color,
var(--primary-color)
);
--track-color: var(
--ha-progress-ring-divider-color,
var(--divider-color)
);
--track-width: 4px;
--speed: 3.5s;
--size: var(--ha-progress-ring-size, 48px);
}
`,
];
}
static override styles = [
progressRingStyles,
css`
:host {
--indicator-color: var(
--ha-progress-ring-indicator-color,
var(--primary-color)
);
--track-color: var(
--ha-progress-ring-divider-color,
var(--divider-color)
);
--track-width: 4px;
--speed: 3.5s;
--size: var(--ha-progress-ring-size, 48px);
}
`,
];
}
declare global {

View File

@@ -1,152 +0,0 @@
import type { TemplateResult } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import { styleMap } from "lit/directives/style-map";
import "./ha-tooltip";
export interface Segment {
value: number;
color: string;
label?: TemplateResult | string;
}
@customElement("ha-segmented-bar")
class HaSegmentedBar extends LitElement {
@property({ attribute: false }) public segments!: Segment[];
@property({ type: String }) public heading!: string;
@property({ type: String }) public description?: string;
@property({ type: Boolean, attribute: "hide-legend" })
public hideLegend = false;
@property({ type: Boolean, attribute: "hide-tooltip" })
public hideTooltip = false;
protected render(): TemplateResult {
const totalValue = this.segments.reduce(
(acc, segment) => acc + segment.value,
0
);
return html`
<div class="container">
<div class="heading">
<div class="title">
<span>${this.heading}</span>
<span>${this.description}</span>
</div>
<slot name="extra"></slot>
</div>
<div class="bar">
${this.segments.map((segment) => {
const bar = html`<div
style=${styleMap({
width: `${(segment.value / totalValue) * 100}%`,
backgroundColor: segment.color,
})}
></div>`;
return this.hideTooltip && !segment.label
? bar
: html`
<ha-tooltip>
<span slot="content">${segment.label}</span>
${bar}
</ha-tooltip>
`;
})}
</div>
${this.hideLegend
? nothing
: html`
<ul class="legend">
${this.segments.map((segment) =>
segment.label
? html`
<li>
<div
class="bullet"
style=${styleMap({
backgroundColor: segment.color,
})}
></div>
<span class="label">${segment.label}</span>
</li>
`
: nothing
)}
</ul>
`}
</div>
`;
}
static styles = css`
.container {
width: 100%;
}
.heading {
display: flex;
flex-direction: row;
gap: 8px;
}
.heading .title {
flex: 1;
}
.heading .title span {
color: var(--secondary-text-color);
line-height: var(--ha-line-height-expanded);
margin-right: 8px;
}
.heading .title span:first-child {
color: var(--primary-text-color);
}
.bar {
display: flex;
overflow: hidden;
border-radius: var(--ha-bar-border-radius, 4px);
width: 100%;
height: 12px;
margin: 2px 0;
background-color: var(
--ha-bar-background-color,
var(--secondary-background-color)
);
}
.bar div {
height: 100%;
}
.bar div:hover {
opacity: 0.8;
}
.legend {
display: flex;
flex-direction: row;
flex-wrap: wrap;
gap: 12px;
margin: 12px 0;
padding: 0;
list-style: none;
}
.legend li {
display: flex;
align-items: center;
gap: 4px;
font-size: var(--ha-font-size-s);
}
.legend li .bullet {
width: 12px;
height: 12px;
border-radius: 50%;
}
.spacer {
flex: 1;
}
`;
}
declare global {
interface HTMLElementTagNameMap {
"ha-segmented-bar": HaSegmentedBar;
}
}

View File

@@ -1,7 +1,7 @@
import { consume, ContextProvider } from "@lit/context";
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
import { fullEntitiesContext } from "../../data/context";
import {
@@ -13,7 +13,6 @@ import { migrateAutomationAction } from "../../data/script";
import type { ActionSelector } from "../../data/selector";
import { SubscribeMixin } from "../../mixins/subscribe-mixin";
import "../../panels/config/automation/action/ha-automation-action";
import type HaAutomationAction from "../../panels/config/automation/action/ha-automation-action";
import type { HomeAssistant } from "../../types";
@customElement("ha-selector-action")
@@ -36,9 +35,6 @@ export class HaActionSelector extends SubscribeMixin(LitElement) {
@state() private _entitiesContext;
@query("ha-automation-action")
private _actionElement?: HaAutomationAction;
protected hassSubscribeRequiredHostProps = ["_entitiesContext"];
private _actions = memoizeOne((action: Action | undefined) => {
@@ -65,14 +61,6 @@ export class HaActionSelector extends SubscribeMixin(LitElement) {
];
}
public expandAll() {
this._actionElement?.expandAll();
}
public collapseAll() {
this._actionElement?.collapseAll();
}
protected render() {
return html`
${this.label ? html`<label>${this.label}</label>` : nothing}
@@ -89,12 +77,12 @@ export class HaActionSelector extends SubscribeMixin(LitElement) {
static styles = css`
ha-automation-action {
display: block;
margin-bottom: 16px;
}
label {
display: block;
margin-bottom: 4px;
font-weight: var(--ha-font-weight-medium);
color: var(--secondary-text-color);
}
`;
}

View File

@@ -1,9 +1,8 @@
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, query } from "lit/decorators";
import { customElement, property } from "lit/decorators";
import type { Condition } from "../../data/automation";
import type { ConditionSelector } from "../../data/selector";
import "../../panels/config/automation/condition/ha-automation-condition";
import type HaAutomationCondition from "../../panels/config/automation/condition/ha-automation-condition";
import type { HomeAssistant } from "../../types";
@customElement("ha-selector-condition")
@@ -20,9 +19,6 @@ export class HaConditionSelector extends LitElement {
@property({ type: Boolean, reflect: true }) public disabled = false;
@query("ha-automation-condition")
private _conditionElement?: HaAutomationCondition;
protected render() {
return html`
${this.label ? html`<label>${this.label}</label>` : nothing}
@@ -36,14 +32,6 @@ export class HaConditionSelector extends LitElement {
`;
}
public expandAll() {
this._conditionElement?.expandAll();
}
public collapseAll() {
this._conditionElement?.collapseAll();
}
static styles = css`
ha-automation-condition {
display: block;
@@ -53,7 +41,6 @@ export class HaConditionSelector extends LitElement {
display: block;
margin-bottom: 4px;
font-weight: var(--ha-font-weight-medium);
color: var(--secondary-text-color);
}
`;
}

View File

@@ -18,7 +18,6 @@ import "../ha-alert";
import "../ha-form/ha-form";
import type { SchemaUnion } from "../ha-form/types";
import { showMediaBrowserDialog } from "../media-player/show-media-browser-dialog";
import { ensureArray } from "../../common/array/ensure-array";
const MANUAL_SCHEMA = [
{ name: "media_content_id", required: false, selector: { text: {} } },
@@ -45,25 +44,9 @@ export class HaMediaSelector extends LitElement {
@property({ type: Boolean, reflect: true }) public required = true;
@property({ attribute: false }) public context?: {
filter_entity?: string | string[];
};
@state() private _thumbnailUrl?: string | null;
private _contextEntities: string[] | undefined;
private get _hasAccept(): boolean {
return !!this.selector?.media?.accept?.length;
}
willUpdate(changedProps: PropertyValues<this>) {
if (changedProps.has("context")) {
if (!this._hasAccept) {
this._contextEntities = ensureArray(this.context?.filter_entity);
}
}
if (changedProps.has("value")) {
const thumbnail = this.value?.metadata?.thumbnail;
const oldThumbnail = (changedProps.get("value") as this["value"])
@@ -96,23 +79,24 @@ export class HaMediaSelector extends LitElement {
}
protected render() {
const entityId = this._getActiveEntityId();
const stateObj = entityId ? this.hass.states[entityId] : undefined;
const stateObj = this.value?.entity_id
? this.hass.states[this.value.entity_id]
: undefined;
const supportsBrowse =
!entityId ||
!this.value?.entity_id ||
(stateObj &&
supportsFeature(stateObj, MediaPlayerEntityFeature.BROWSE_MEDIA));
const hasAccept = this.selector?.media?.accept?.length;
return html`
${this._hasAccept ||
(this._contextEntities && this._contextEntities.length <= 1)
${hasAccept
? nothing
: html`
<ha-entity-picker
.hass=${this.hass}
.value=${entityId}
.value=${this.value?.entity_id}
.label=${this.label ||
this.hass.localize(
"ui.components.selectors.media.pick_media_player"
@@ -120,10 +104,8 @@ export class HaMediaSelector extends LitElement {
.disabled=${this.disabled}
.helper=${this.helper}
.required=${this.required}
.hideClearIcon=${!!this._contextEntities}
.includeDomains=${INCLUDE_DOMAINS}
.includeEntities=${this._contextEntities}
.allowCustomEntity=${!this._contextEntities}
allow-custom-entity
@value-changed=${this._entityChanged}
></ha-entity-picker>
`}
@@ -139,7 +121,6 @@ export class HaMediaSelector extends LitElement {
.data=${this.value || EMPTY_FORM}
.schema=${MANUAL_SCHEMA}
.computeLabel=${this._computeLabelCallback}
.computeHelper=${this._computeHelperCallback}
></ha-form>
`
: html`
@@ -152,7 +133,7 @@ export class HaMediaSelector extends LitElement {
: this.value.metadata?.title || this.value.media_content_id}
@click=${this._pickMedia}
@keydown=${this._handleKeyDown}
class=${this.disabled || (!entityId && !this._hasAccept)
class=${this.disabled || (!this.value?.entity_id && !hasAccept)
? "disabled"
: ""}
>
@@ -212,38 +193,21 @@ export class HaMediaSelector extends LitElement {
): string =>
this.hass.localize(`ui.components.selectors.media.${schema.name}`);
private _computeHelperCallback = (
schema: SchemaUnion<typeof MANUAL_SCHEMA>
): string =>
this.hass.localize(`ui.components.selectors.media.${schema.name}_detail`);
private _entityChanged(ev: CustomEvent) {
ev.stopPropagation();
if (!this._hasAccept && this.context?.filter_entity) {
fireEvent(this, "value-changed", {
value: {
media_content_id: "",
media_content_type: "",
metadata: {
browse_entity_id: ev.detail.value,
},
},
});
} else {
fireEvent(this, "value-changed", {
value: {
entity_id: ev.detail.value,
media_content_id: "",
media_content_type: "",
},
});
}
fireEvent(this, "value-changed", {
value: {
entity_id: ev.detail.value,
media_content_id: "",
media_content_type: "",
},
});
}
private _pickMedia() {
showMediaBrowserDialog(this, {
action: "pick",
entityId: this._getActiveEntityId(),
entityId: this.value?.entity_id,
navigateIds: this.value?.metadata?.navigateIds,
accept: this.selector.media?.accept,
mediaPickedCallback: (pickedMedia: MediaPickedEvent) => {
@@ -261,9 +225,6 @@ export class HaMediaSelector extends LitElement {
media_content_type: id.media_content_type,
media_content_id: id.media_content_id,
})),
...(!this._hasAccept && this.context?.filter_entity
? { browse_entity_id: this._getActiveEntityId() }
: {}),
},
},
});
@@ -271,15 +232,6 @@ export class HaMediaSelector extends LitElement {
});
}
private _getActiveEntityId(): string | undefined {
const metaId = this.value?.metadata?.browse_entity_id;
return (
this.value?.entity_id ||
(metaId && this._contextEntities?.includes(metaId) && metaId) ||
this._contextEntities?.[0]
);
}
private _handleKeyDown(ev: KeyboardEvent) {
if (ev.key === "Enter" || ev.key === " ") {
ev.preventDefault();

View File

@@ -8,6 +8,7 @@ import type {
LocalizeKeys,
} from "../../common/translations/localize";
import type { HomeAssistant } from "../../types";
import "../ha-alert";
import "../ha-form/ha-form";
const SELECTOR_DEFAULTS = {
@@ -155,8 +156,6 @@ export class HaSelectorSelector extends LitElement {
@property({ type: Boolean, reflect: true }) public disabled = false;
@property({ type: Boolean }) public narrow = false;
@property({ type: Boolean, reflect: true }) public required = true;
private _yamlMode = false;
@@ -173,10 +172,10 @@ export class HaSelectorSelector extends LitElement {
[
{
name: "type",
required: true,
selector: {
select: {
mode: "dropdown",
required: true,
options: Object.keys(SELECTOR_SCHEMAS)
.concat("manual")
.map((key) => ({
@@ -229,17 +228,17 @@ export class HaSelectorSelector extends LitElement {
const schema = this._schema(type, this.hass.localize);
return html`<div>
<p>${this.label ? this.label : ""}</p>
<ha-form
.hass=${this.hass}
.data=${data}
.schema=${schema}
.computeLabel=${this._computeLabelCallback}
@value-changed=${this._valueChanged}
.narrow=${this.narrow}
></ha-form>
</div>`;
return html`<ha-card>
<div class="card-content">
<p>${this.label ? this.label : ""}</p>
<ha-form
.hass=${this.hass}
.data=${data}
.schema=${schema}
.computeLabel=${this._computeLabelCallback}
@value-changed=${this._valueChanged}
></ha-form></div
></ha-card>`;
}
private _valueChanged(ev: CustomEvent) {
@@ -286,6 +285,23 @@ export class HaSelectorSelector extends LitElement {
) || schema.name;
static styles = css`
:host {
--expansion-panel-summary-padding: 0 16px;
}
ha-alert {
display: block;
margin-bottom: 16px;
}
ha-card {
margin: 0 0 16px 0;
}
ha-card.disabled {
pointer-events: none;
color: var(--disabled-text-color);
}
.card-content {
padding: 0px 16px 16px 16px;
}
.title {
font-size: var(--ha-font-size-l);
padding-top: 16px;

View File

@@ -21,15 +21,9 @@ declare global {
};
"drag-start": undefined;
"drag-end": undefined;
"item-cloned": HaSortableClonedEventData;
}
}
export interface HaSortableClonedEventData {
item: any;
clone: any;
}
export type HaSortableOptions = Omit<
SortableInstance.SortableOptions,
"onStart" | "onChoose" | "onEnd" | "onUpdate" | "onAdd" | "onRemove"
@@ -154,7 +148,6 @@ export class HaSortable extends LitElement {
onUpdate: this._handleUpdate,
onAdd: this._handleAdd,
onRemove: this._handleRemove,
onClone: this._handleClone,
};
if (this.draggableSelector) {
@@ -194,10 +187,6 @@ export class HaSortable extends LitElement {
fireEvent(this, "item-removed", { index: evt.oldIndex });
};
private _handleClone = (evt) => {
fireEvent(this, "item-cloned", evt);
};
private _handleEnd = async (evt) => {
fireEvent(this, "drag-end");
// put back in original location

View File

@@ -38,7 +38,7 @@ class MediaManageButton extends LitElement {
return nothing;
}
return html`
<ha-button appearance="filled" size="small" @click=${this._manage}>
<ha-button appearance="plain" size="small" @click=${this._manage}>
<ha-svg-icon .path=${mdiFolderEdit} slot="start"></ha-svg-icon>
${this.hass.localize(
"ui.components.media-browser.file_management.manage"

View File

@@ -91,15 +91,6 @@ export const isService = (key: string | undefined): boolean | undefined =>
export const getService = (key: string): string =>
key.substring(SERVICE_PREFIX.length);
export const COLLAPSIBLE_ACTION_ELEMENTS = [
"ha-automation-action-choose",
"ha-automation-action-condition",
"ha-automation-action-if",
"ha-automation-action-parallel",
"ha-automation-action-repeat",
"ha-automation-action-sequence",
];
export const ACTION_BUILDING_BLOCKS = [
"choose",
"if",

View File

@@ -7,10 +7,10 @@ import { navigate } from "../common/navigate";
import { createSearchParam } from "../common/url/search-params";
import type { Context, HomeAssistant } from "../types";
import type { BlueprintInput } from "./blueprint";
import { CONDITION_BUILDING_BLOCKS } from "./condition";
import type { DeviceCondition, DeviceTrigger } from "./device_automation";
import type { Action, Field, MODES } from "./script";
import type { Action, MODES } from "./script";
import { migrateAutomationAction } from "./script";
import { CONDITION_BUILDING_BLOCKS } from "./condition";
export const AUTOMATION_DEFAULT_MODE: (typeof MODES)[number] = "single";
export const AUTOMATION_DEFAULT_MAX = 10;
@@ -513,14 +513,6 @@ export const isCondition = (config: unknown): boolean => {
return "condition" in condition && typeof condition.condition === "string";
};
export const isScriptField = (config: unknown): boolean => {
if (!config || typeof config !== "object") {
return false;
}
const field = config as Record<string, unknown>;
return "field" in field && typeof field.field === "object";
};
export const subscribeTrigger = (
hass: HomeAssistant,
onChange: (result: {
@@ -554,81 +546,3 @@ export interface AutomationClipboard {
condition?: Condition;
action?: Action;
}
export interface BaseSidebarConfig {
delete: () => void;
close: (focus?: boolean) => void;
}
export interface TriggerSidebarConfig extends BaseSidebarConfig {
save: (value: Trigger) => void;
rename: () => void;
disable: () => void;
duplicate: () => void;
cut: () => void;
copy: () => void;
toggleYamlMode: () => void;
config: Trigger;
yamlMode: boolean;
uiSupported: boolean;
}
export interface ConditionSidebarConfig extends BaseSidebarConfig {
save: (value: Condition) => void;
rename: () => void;
disable: () => void;
test: () => void;
duplicate: () => void;
cut: () => void;
copy: () => void;
toggleYamlMode: () => void;
config: Condition;
yamlMode: boolean;
uiSupported: boolean;
}
export interface ActionSidebarConfig extends BaseSidebarConfig {
save: (value: Action) => void;
rename: () => void;
disable: () => void;
duplicate: () => void;
cut: () => void;
copy: () => void;
run: () => void;
toggleYamlMode: () => void;
config: {
action: Action;
};
yamlMode: boolean;
uiSupported: boolean;
}
export interface OptionSidebarConfig extends BaseSidebarConfig {
rename: () => void;
duplicate: () => void;
defaultOption?: boolean;
}
export interface ScriptFieldSidebarConfig extends BaseSidebarConfig {
save: (value: Field) => void;
config: {
field: Field;
selector: boolean;
key: string;
excludeKeys: string[];
};
toggleYamlMode: () => void;
yamlMode: boolean;
}
export type SidebarConfig =
| TriggerSidebarConfig
| ConditionSidebarConfig
| ActionSidebarConfig
| OptionSidebarConfig
| ScriptFieldSidebarConfig;
export interface ShowAutomationEditorParams {
data?: Partial<AutomationConfig>;
expanded?: boolean;
}

View File

@@ -378,17 +378,7 @@ const tryDescribeTrigger = (
// Tag Trigger
if (trigger.trigger === "tag") {
const entity = Object.values(hass.states).find(
(state) =>
state.entity_id.startsWith("tag.") &&
state.attributes.tag_id === trigger.tag_id
);
return entity
? hass.localize(
`${triggerTranslationBaseKey}.tag.description.known_tag`,
{ tag_name: computeStateName(entity) }
)
: hass.localize(`${triggerTranslationBaseKey}.tag.description.full`);
return hass.localize(`${triggerTranslationBaseKey}.tag.description.full`);
}
// Time Trigger

View File

@@ -52,9 +52,3 @@ export const CONDITION_GROUPS: AutomationElementGroup = {
} as const;
export const CONDITION_BUILDING_BLOCKS = ["and", "or", "not"];
export const COLLAPSIBLE_CONDITION_ELEMENTS = [
"ha-automation-condition-and",
"ha-automation-condition-not",
"ha-automation-condition-or",
];

View File

@@ -42,19 +42,6 @@ export const getSubEntries = (hass: HomeAssistant, entry_id: string) =>
entry_id,
});
export const updateSubEntry = (
hass: HomeAssistant,
entry_id: string,
subentry_id: string,
updatedValues: SubEntryMutableParams
) =>
hass.callWS({
type: "config_entries/subentries/update",
entry_id,
subentry_id,
...updatedValues,
});
export const deleteSubEntry = (
hass: HomeAssistant,
entry_id: string,
@@ -73,8 +60,6 @@ export type ConfigEntryMutableParams = Partial<
>
>;
export type SubEntryMutableParams = Partial<Pick<SubEntry, "title">>;
// https://github.com/home-assistant/core/blob/2286dea636fda001f03433ba14d7adbda43979e5/homeassistant/config_entries.py#L81
export const ERROR_STATES: ConfigEntry["state"][] = [
"migration_error",

View File

@@ -1,7 +1,6 @@
import { formatDurationDigital } from "../common/datetime/format_duration";
import type { FrontendLocaleData } from "./translation";
// These attributes are hidden from the more-info window for all entities.
export const STATE_ATTRIBUTES = [
"entity_id",
"assumed_state",
@@ -27,14 +26,6 @@ export const STATE_ATTRIBUTES = [
"available_tones",
];
// These attributes are hidden from the more-info window for entities of the
// matching domain and device_class.
export const STATE_ATTRIBUTES_DOMAIN_CLASS = {
sensor: {
enum: ["options"],
},
};
export const TEMPERATURE_ATTRIBUTES = new Set([
"temperature",
"current_temperature",

View File

@@ -44,14 +44,6 @@ export interface DatadiskList {
disks: Datadisk[];
}
export interface HostDisksUsage {
total_bytes?: number;
used_bytes: number;
id: string;
label: string;
children?: HostDisksUsage[];
}
export const fetchHassioHostInfo = async (
hass: HomeAssistant
): Promise<HassioHostInfo> => {
@@ -188,21 +180,3 @@ export const listDatadisks = async (
await hass.callApi<HassioResponse<DatadiskList>>("GET", "/os/datadisk/list")
);
};
export const fetchHostDisksUsage = async (hass: HomeAssistant) => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
return hass.callWS<HostDisksUsage>({
type: "supervisor/api",
endpoint: "/host/disks/default/usage",
method: "get",
timeout: 3600, // seconds. This can take a while
});
}
return hassioApiResultExtractor(
await hass.callApi<HassioResponse<HostDisksUsage>>(
"GET",
"hassio/host/disks/default/usage"
)
);
};

View File

@@ -23,6 +23,7 @@ export interface LovelaceViewElement extends HTMLElement {
badges?: HuiBadge[];
sections?: HuiSection[];
isStrategy: boolean;
allowEdit: boolean;
setConfig(config: LovelaceViewConfig): void;
}
@@ -35,6 +36,7 @@ export interface LovelaceSectionElement extends HTMLElement {
cards?: HuiCard[];
isStrategy: boolean;
importOnly?: boolean;
allowEdit: boolean;
setConfig(config: LovelaceSectionConfig): void;
}

View File

@@ -1,7 +1,6 @@
import type { HASSDomEvent } from "../../common/dom/fire_event";
export interface ActionHandlerOptions {
hasTap?: boolean;
hasHold?: boolean;
hasDoubleClick?: boolean;
disabled?: boolean;

View File

@@ -11,6 +11,8 @@ import {
union,
array,
assign,
literal,
is,
boolean,
refine,
} from "superstruct";
@@ -66,6 +68,17 @@ export const serviceActionStruct: Describe<ServiceActionWithTemplate> = assign(
})
);
const playMediaActionStruct: Describe<PlayMediaAction> = assign(
baseActionStruct,
object({
action: literal("media_player.play_media"),
target: optional(object({ entity_id: optional(string()) })),
entity_id: optional(string()),
data: object({ media_content_id: string(), media_content_type: string() }),
metadata: object(),
})
);
export interface ScriptEntity extends HassEntityBase {
attributes: HassEntityAttributeBase & {
last_triggered: string;
@@ -169,6 +182,14 @@ export interface WaitForTriggerAction extends BaseAction {
continue_on_timeout?: boolean;
}
export interface PlayMediaAction extends BaseAction {
action: "media_player.play_media";
target?: { entity_id?: string };
entity_id?: string;
data: { media_content_id: string; media_content_type: string };
metadata: Record<string, unknown>;
}
export interface RepeatAction extends BaseAction {
repeat: CountRepeat | WhileRepeat | UntilRepeat | ForEachRepeat;
}
@@ -245,6 +266,7 @@ export type NonConditionAction =
| ChooseAction
| IfAction
| VariablesAction
| PlayMediaAction
| StopAction
| SequenceAction
| ParallelAction
@@ -269,6 +291,7 @@ export interface ActionTypes {
wait_for_trigger: WaitForTriggerAction;
variables: VariablesAction;
service: ServiceAction;
play_media: PlayMediaAction;
stop: StopAction;
sequence: SequenceAction;
parallel: ParallelAction;
@@ -375,6 +398,11 @@ export const getActionType = (action: Action): ActionType => {
return "set_conversation_response";
}
if ("action" in action || "service" in action) {
if ("metadata" in action) {
if (is(action, playMediaActionStruct)) {
return "play_media";
}
}
return "service";
}
return "unknown";
@@ -415,31 +443,6 @@ export const migrateAutomationAction = (
delete action.scene;
}
// legacy play media
if (
typeof action === "object" &&
action !== null &&
"action" in action &&
action.action === "media_player.play_media" &&
"data" in action &&
((action.data as any)?.media_content_id ||
(action.data as any)?.media_content_type)
) {
const oldData = { ...(action.data as any) };
const media = {
media_content_id: oldData.media_content_id,
media_content_type: oldData.media_content_type,
metadata: { ...(action.metadata || {}) },
};
delete action.metadata;
delete oldData.media_content_id;
delete oldData.media_content_type;
action.data = {
...oldData,
media,
};
}
if (typeof action === "object" && action !== null && "sequence" in action) {
for (const sequenceAction of (action as SequenceAction).sequence) {
migrateAutomationAction(sequenceAction);

View File

@@ -26,6 +26,7 @@ import type {
EventAction,
IfAction,
ParallelAction,
PlayMediaAction,
RepeatAction,
SequenceAction,
SetConversationResponseAction,
@@ -302,6 +303,27 @@ const tryDescribeAction = <T extends ActionType>(
});
}
if (actionType === "play_media") {
const config = action as PlayMediaAction;
const entityId = config.target?.entity_id || config.entity_id;
const mediaStateObj = entityId ? hass.states[entityId] : undefined;
return hass.localize(
`${actionTranslationBaseKey}.play_media.description.full`,
{
hasMedia:
config.metadata.title || config.data.media_content_id
? "true"
: "false",
media:
(config.metadata.title as string | undefined) ||
config.data.media_content_id,
hasMediaPlayer:
mediaStateObj || entityId !== undefined ? "true" : "false",
mediaPlayer: mediaStateObj ? computeStateName(mediaStateObj) : entityId,
}
);
}
if (actionType === "wait_for_trigger") {
const config = action as WaitForTriggerAction;
const triggers = ensureArray(config.wait_for_trigger);

View File

@@ -323,7 +323,6 @@ export interface MediaSelectorValue {
media_class?: string;
children_media_class?: string | null;
navigateIds?: { media_content_type: string; media_content_id: string }[];
browse_entity_id?: string;
};
}

View File

@@ -1 +0,0 @@
export const SELECTOR_SELECTOR_BUILDING_BLOCKS = ["condition", "action"];

View File

@@ -12,7 +12,6 @@ export interface Zone {
}
export interface HomeZoneMutableParams {
name?: string;
latitude: number;
longitude: number;
radius: number;

View File

@@ -1,106 +0,0 @@
import { css, html, LitElement, nothing } 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-icon";
import "../../components/ha-md-list";
import "../../components/ha-md-list-item";
import "../../components/ha-svg-icon";
import type { HomeAssistant } from "../../types";
import type { HassDialog } from "../make-dialog-manager";
import type { ListItemsDialogParams } from "./show-list-items-dialog";
@customElement("dialog-list-items")
export class ListItemsDialog
extends LitElement
implements HassDialog<ListItemsDialogParams>
{
@property({ attribute: false }) public hass?: HomeAssistant;
@state() private _params?: ListItemsDialogParams;
public async showDialog(params: ListItemsDialogParams): Promise<void> {
this._params = params;
}
private _dialogClosed(): void {
this._params = undefined;
fireEvent(this, "dialog-closed", { dialog: this.localName });
}
private _itemClicked(ev: CustomEvent): void {
const item = (ev.currentTarget as any).item;
if (!item) return;
item.action();
this._dialogClosed();
}
protected render() {
if (!this._params || !this.hass) {
return nothing;
}
return html`
<ha-dialog
open
.heading=${createCloseHeading(this.hass, this._params.title ?? " ")}
@closed=${this._dialogClosed}
hideActions
>
<div class="container">
<ha-md-list>
${this._params.items.map(
(item) => html`
<ha-md-list-item
type="button"
@click=${this._itemClicked}
.item=${item}
>
${item.iconPath
? html`
<ha-svg-icon
.path=${item.iconPath}
slot="start"
class="item-icon"
></ha-svg-icon>
`
: item.icon
? html`
<ha-icon
icon=${item.icon}
slot="start"
class="item-icon"
></ha-icon>
`
: nothing}
<span class="headline">${item.label}</span>
${item.description
? html`
<span class="supporting-text">${item.description}</span>
`
: nothing}
</ha-md-list-item>
`
)}
</ha-md-list>
</div>
</ha-dialog>
`;
}
static styles = css`
ha-dialog {
/* Place above other dialogs */
--dialog-z-index: 104;
--dialog-content-padding: 0;
--md-list-item-leading-space: 24px;
--md-list-item-trailing-space: 24px;
}
`;
}
declare global {
interface HTMLElementTagNameMap {
"dialog-list-items": ListItemsDialog;
}
}

View File

@@ -1,24 +0,0 @@
import { fireEvent } from "../../common/dom/fire_event";
interface ListItem {
icon?: string;
iconPath?: string;
label: string;
description?: string;
action: () => any;
}
export interface ListItemsDialogParams {
title?: string;
items: ListItem[];
}
export const showListItemsDialog = (
element: HTMLElement,
params: ListItemsDialogParams
) =>
fireEvent(element, "show-dialog", {
dialogTag: "dialog-list-items",
dialogImport: () => import("./dialog-list-items"),
dialogParams: params,
});

View File

@@ -840,9 +840,7 @@ export class QuickBar extends LitElement {
const additionalItems = [
{
path: "",
primaryText: this.hass.localize(
"ui.dialogs.quick-bar.commands.navigation.shortcuts"
),
primaryText: this.hass.localize("ui.panel.config.info.shortcuts"),
action: () => showShortcutsDialog(this),
iconPath: mdiKeyboard,
},
@@ -858,9 +856,7 @@ export class QuickBar extends LitElement {
private _generateNavigationPanelCommands(): BaseNavigationCommand[] {
return Object.keys(this.hass.panels)
.filter(
(panelKey) => panelKey !== "_my_redirect" && panelKey !== "hassio"
)
.filter((panelKey) => panelKey !== "_my_redirect")
.map((panelKey) => {
const panel = this.hass.panels[panelKey];
const translationKey = getPanelNameTranslationKey(panel);

View File

@@ -112,9 +112,7 @@ export class HaVoiceAssistantSetupStepSuccess extends LitElement {
this.assistConfiguration.available_wake_words.length > 1
? html`<div class="row">
<ha-select
.label=${this.hass.localize(
"ui.panel.config.voice_assistants.assistants.pipeline.detail.form.wake_word_id"
)}
.label=${"Wake word"}
@closed=${stopPropagation}
fixedMenuPosition
naturalMenuWidth
@@ -146,9 +144,7 @@ export class HaVoiceAssistantSetupStepSuccess extends LitElement {
${pipelineEntity
? html`<div class="row">
<ha-select
.label=${this.hass.localize(
"ui.panel.config.voice_assistants.assistants.pipeline.devices.pipeline"
)}
.label=${"Assistant"}
@closed=${stopPropagation}
.value=${pipelineEntity?.state}
fixedMenuPosition

View File

@@ -441,35 +441,6 @@ class WaterHeaterEntity extends Entity {
}
}
class FanEntity extends Entity {
static CAPABILITY_ATTRIBUTES = new Set([
...CAPABILITY_ATTRIBUTES,
"direction",
"oscillating",
"percentage",
]);
public async handleService(domain, service, data) {
if (domain !== this.domain) {
return;
}
if (["turn_on", "turn_off"].includes(service)) {
this.update(service === "turn_on" ? "on" : "off");
} else if (
["set_direction", "oscillate", "set_percentage"].includes(service)
) {
const { entity_id, ...toSet } = data;
this.update(this.state, {
...this.attributes,
...toSet,
});
} else {
super.handleService(domain, service, data);
}
}
}
class GroupEntity extends Entity {
public async handleService(domain, service, data) {
if (!["homeassistant", this.domain].includes(domain)) {
@@ -492,7 +463,6 @@ const TYPES = {
alarm_control_panel: AlarmControlPanelEntity,
climate: ClimateEntity,
cover: CoverEntity,
fan: FanEntity,
group: GroupEntity,
input_boolean: ToggleEntity,
input_number: InputNumberEntity,

View File

@@ -5,15 +5,11 @@ import { dynamicElement } from "../../../../common/dom/dynamic-element-directive
import { fireEvent } from "../../../../common/dom/fire_event";
import "../../../../components/ha-yaml-editor";
import type { HaYamlEditor } from "../../../../components/ha-yaml-editor";
import { COLLAPSIBLE_ACTION_ELEMENTS } from "../../../../data/action";
import { migrateAutomationAction, type Action } from "../../../../data/script";
import type { HomeAssistant } from "../../../../types";
import "../ha-automation-editor-warning";
import { editorStyles, indentStyle } from "../styles";
import {
getAutomationActionType,
type ActionElement,
} from "./ha-automation-action-row";
import { editorStyles } from "../styles";
import { getAutomationActionType } from "./ha-automation-action-row";
@customElement("ha-automation-action-editor")
export default class HaAutomationActionEditor extends LitElement {
@@ -38,9 +34,6 @@ export default class HaAutomationActionEditor extends LitElement {
@query("ha-yaml-editor") public yamlEditor?: HaYamlEditor;
@query(COLLAPSIBLE_ACTION_ELEMENTS.join(", "))
private _collapsibleElement?: ActionElement;
protected render() {
const yamlMode = this.yamlMode || !this.uiSupported;
const type = getAutomationActionType(this.action);
@@ -53,7 +46,6 @@ export default class HaAutomationActionEditor extends LitElement {
this.disabled || (this.action.enabled === false && !this.yamlMode),
yaml: yamlMode,
indent: this.indent,
card: !this.inSidebar,
})}
>
${yamlMode
@@ -97,7 +89,7 @@ export default class HaAutomationActionEditor extends LitElement {
if (!ev.detail.isValid) {
return;
}
fireEvent(this, "yaml-changed", {
fireEvent(this, "value-changed", {
value: migrateAutomationAction(ev.detail.value),
});
}
@@ -111,15 +103,7 @@ export default class HaAutomationActionEditor extends LitElement {
fireEvent(this, "value-changed", { value });
}
public expandAll() {
this._collapsibleElement?.expandAll?.();
}
public collapseAll() {
this._collapsibleElement?.collapseAll?.();
}
static styles = [editorStyles, indentStyle];
static styles = editorStyles;
}
declare global {

View File

@@ -26,7 +26,6 @@ import { stopPropagation } from "../../../../common/dom/stop_propagation";
import { capitalizeFirstLetter } from "../../../../common/string/capitalize-first-letter";
import { handleStructError } from "../../../../common/structs/handle-errors";
import "../../../../components/ha-automation-row";
import type { HaAutomationRow } from "../../../../components/ha-automation-row";
import "../../../../components/ha-card";
import "../../../../components/ha-expansion-panel";
import "../../../../components/ha-icon-button";
@@ -42,11 +41,9 @@ import {
YAML_ONLY_ACTION_TYPES,
} from "../../../../data/action";
import type {
ActionSidebarConfig,
AutomationClipboard,
Condition,
} from "../../../../data/automation";
import { CONDITION_BUILDING_BLOCKS } from "../../../../data/condition";
import { validateConfig } from "../../../../data/config";
import {
floorsContext,
@@ -82,6 +79,7 @@ import "./types/ha-automation-action-device_id";
import "./types/ha-automation-action-event";
import "./types/ha-automation-action-if";
import "./types/ha-automation-action-parallel";
import "./types/ha-automation-action-play_media";
import { getRepeatType } from "./types/ha-automation-action-repeat";
import "./types/ha-automation-action-sequence";
import "./types/ha-automation-action-service";
@@ -89,6 +87,7 @@ import "./types/ha-automation-action-set_conversation_response";
import "./types/ha-automation-action-stop";
import "./types/ha-automation-action-wait_for_trigger";
import "./types/ha-automation-action-wait_template";
import { CONDITION_BUILDING_BLOCKS } from "../../../../data/condition";
export const getAutomationActionType = memoizeOne(
(action: Action | undefined) => {
@@ -96,7 +95,7 @@ export const getAutomationActionType = memoizeOne(
return undefined;
}
if ("action" in action) {
return getActionType(action) as "action";
return getActionType(action) as "action" | "play_media";
}
if (CONDITION_BUILDING_BLOCKS.some((key) => key in action)) {
return "condition" as const;
@@ -109,8 +108,6 @@ export const getAutomationActionType = memoizeOne(
export interface ActionElement extends LitElement {
action: Action;
expandAll?: () => void;
collapseAll?: () => void;
}
export const handleChangeEvent = (element: ActionElement, ev: CustomEvent) => {
@@ -145,20 +142,13 @@ export default class HaAutomationActionRow extends LitElement {
@property({ type: Boolean }) public disabled = false;
@property({ type: Boolean }) public root = false;
@property({ type: Boolean }) public first?: boolean;
@property({ type: Boolean }) public last?: boolean;
@property({ type: Boolean }) public highlight?: boolean;
@property({ type: Boolean, attribute: "sidebar" })
public optionsInSidebar = false;
@property({ type: Boolean, attribute: "sort-selected" })
public sortSelected = false;
@storage({
key: "automationClipboard",
state: false,
@@ -185,23 +175,12 @@ export default class HaAutomationActionRow extends LitElement {
@state() private _selected = false;
@state() private _collapsed = true;
@state() private _collapsed = false;
@state() private _warnings?: string[];
@query("ha-automation-action-editor")
private _actionEditor?: HaAutomationActionEditor;
@query("ha-automation-row")
private _automationRowElement?: HaAutomationRow;
protected firstUpdated(changedProperties: PropertyValues): void {
super.firstUpdated(changedProperties);
if (this.root) {
this._collapsed = false;
}
}
private actionEditor?: HaAutomationActionEditor;
protected willUpdate(changedProperties: PropertyValues) {
if (changedProperties.has("yamlMode")) {
@@ -263,30 +242,26 @@ export default class HaAutomationActionRow extends LitElement {
<ha-svg-icon .path=${mdiAlertCircleCheck}></ha-svg-icon>
</ha-tooltip>`
: nothing}
${!this.optionsInSidebar
? html`<ha-md-button-menu
quick
slot="icons"
@click=${preventDefaultStopPropagation}
@keydown=${stopPropagation}
@closed=${stopPropagation}
positioning="fixed"
anchor-corner="end-end"
menu-corner="start-end"
>
<ha-icon-button
slot="trigger"
.label=${this.hass.localize("ui.common.menu")}
.path=${mdiDotsVertical}
></ha-icon-button>
<ha-md-menu-item .clickAction=${this._runAction}>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.run"
)}
<ha-svg-icon slot="start" .path=${mdiPlay}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
<ha-md-button-menu
slot="icons"
@click=${preventDefaultStopPropagation}
@keydown=${stopPropagation}
@closed=${stopPropagation}
positioning="fixed"
>
<ha-icon-button
slot="trigger"
.label=${this.hass.localize("ui.common.menu")}
.path=${mdiDotsVertical}
></ha-icon-button>
<ha-md-menu-item .clickAction=${this._runAction}>
${this.hass.localize("ui.panel.config.automation.editor.actions.run")}
<ha-svg-icon slot="start" .path=${mdiPlay}></ha-svg-icon>
</ha-md-menu-item>
${!this.optionsInSidebar
? html` <ha-md-menu-item
.clickAction=${this._renameAction}
.disabled=${this.disabled}
>
@@ -294,60 +269,59 @@ export default class HaAutomationActionRow extends LitElement {
"ui.panel.config.automation.editor.actions.rename"
)}
<ha-svg-icon slot="start" .path=${mdiRenameBox}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-divider role="separator" tabindex="-1"></ha-md-divider>
<ha-md-menu-item
.clickAction=${this._duplicateAction}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.duplicate"
)}
<ha-svg-icon
slot="start"
.path=${mdiContentDuplicate}
></ha-svg-icon>
</ha-md-menu-item>
</ha-md-menu-item>`
: nothing}
<ha-md-menu-item
.clickAction=${this._copyAction}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.copy"
)}
<ha-svg-icon slot="start" .path=${mdiContentCopy}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-divider role="separator" tabindex="-1"></ha-md-divider>
<ha-md-menu-item
.clickAction=${this._cutAction}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.cut"
)}
<ha-svg-icon slot="start" .path=${mdiContentCut}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
.clickAction=${this._duplicateAction}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.duplicate"
)}
<ha-svg-icon slot="start" .path=${mdiContentDuplicate}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
.clickAction=${this._moveUp}
.disabled=${this.disabled || !!this.first}
>
${this.hass.localize("ui.panel.config.automation.editor.move_up")}
<ha-svg-icon slot="start" .path=${mdiArrowUp}></ha-svg-icon
></ha-md-menu-item>
<ha-md-menu-item
.clickAction=${this._copyAction}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.copy"
)}
<ha-svg-icon slot="start" .path=${mdiContentCopy}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
.clickAction=${this._moveDown}
.disabled=${this.disabled || !!this.last}
>
${this.hass.localize(
"ui.panel.config.automation.editor.move_down"
)}
<ha-svg-icon slot="start" .path=${mdiArrowDown}></ha-svg-icon
></ha-md-menu-item>
<ha-md-menu-item
.clickAction=${this._cutAction}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.cut"
)}
<ha-svg-icon slot="start" .path=${mdiContentCut}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
<ha-md-menu-item
.clickAction=${this._moveUp}
.disabled=${this.disabled || !!this.first}
>
${this.hass.localize("ui.panel.config.automation.editor.move_up")}
<ha-svg-icon slot="start" .path=${mdiArrowUp}></ha-svg-icon
></ha-md-menu-item>
<ha-md-menu-item
.clickAction=${this._moveDown}
.disabled=${this.disabled || !!this.last}
>
${this.hass.localize("ui.panel.config.automation.editor.move_down")}
<ha-svg-icon slot="start" .path=${mdiArrowDown}></ha-svg-icon
></ha-md-menu-item>
${!this.optionsInSidebar
? html`<ha-md-menu-item
.clickAction=${this._toggleYamlMode}
.disabled=${!this._uiModeAvailable || !!this._warnings}
>
@@ -355,44 +329,45 @@ export default class HaAutomationActionRow extends LitElement {
`ui.panel.config.automation.editor.edit_${!this._yamlMode ? "yaml" : "ui"}`
)}
<ha-svg-icon slot="start" .path=${mdiPlaylistEdit}></ha-svg-icon>
</ha-md-menu-item>
</ha-md-menu-item>`
: nothing}
<ha-md-divider role="separator" tabindex="-1"></ha-md-divider>
<ha-md-divider role="separator" tabindex="-1"></ha-md-divider>
<ha-md-menu-item
.clickAction=${this._onDisable}
.disabled=${this.disabled}
>
${this.action.enabled === false
? this.hass.localize(
"ui.panel.config.automation.editor.actions.enable"
)
: this.hass.localize(
"ui.panel.config.automation.editor.actions.disable"
)}
<ha-svg-icon
slot="start"
.path=${this.action.enabled === false
? mdiPlayCircleOutline
: mdiStopCircleOutline}
></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
class="warning"
.clickAction=${this._onDelete}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.delete"
<ha-md-menu-item
.clickAction=${this._onDisable}
.disabled=${this.disabled}
>
${this.action.enabled === false
? this.hass.localize(
"ui.panel.config.automation.editor.actions.enable"
)
: this.hass.localize(
"ui.panel.config.automation.editor.actions.disable"
)}
<ha-svg-icon
class="warning"
slot="start"
.path=${mdiDelete}
></ha-svg-icon>
</ha-md-menu-item>
</ha-md-button-menu>`
: nothing}
<ha-svg-icon
slot="start"
.path=${this.action.enabled === false
? mdiPlayCircleOutline
: mdiStopCircleOutline}
></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
class="warning"
.clickAction=${this._onDelete}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.delete"
)}
<ha-svg-icon
class="warning"
slot="start"
.path=${mdiDelete}
></ha-svg-icon>
</ha-md-menu-item>
</ha-md-button-menu>
${!this.optionsInSidebar
? html`${this._warnings
? html`<ha-automation-editor-warning
@@ -442,20 +417,14 @@ export default class HaAutomationActionRow extends LitElement {
.leftChevron=${[
...ACTION_BUILDING_BLOCKS,
...ACTION_COMBINED_BLOCKS,
].includes(blockType!) ||
(blockType === "condition" &&
CONDITION_BUILDING_BLOCKS.includes(
(this.action as Condition).condition
))}
].includes(blockType!)}
.collapsed=${this._collapsed}
.selected=${this._selected}
.highlight=${this.highlight}
@toggle-collapsed=${this._toggleCollapse}
.buildingBlock=${[
...ACTION_BUILDING_BLOCKS,
...ACTION_COMBINED_BLOCKS,
].includes(blockType!)}
.sortSelected=${this.sortSelected}
>${this._renderRow()}</ha-automation-row
>`
: html`
@@ -472,9 +441,9 @@ export default class HaAutomationActionRow extends LitElement {
(blockType === "condition" &&
CONDITION_BUILDING_BLOCKS.includes(
(this.action as Condition).condition
)))
))) &&
!this._collapsed
? html`<ha-automation-action-editor
class=${this._collapsed ? "hidden" : ""}
.hass=${this.hass}
.action=${this.action}
.narrow=${this.narrow}
@@ -509,7 +478,7 @@ export default class HaAutomationActionRow extends LitElement {
this.openSidebar(value); // refresh sidebar
if (this._yamlMode && !this.optionsInSidebar) {
this._actionEditor?.yamlEditor?.setValue(value);
this.actionEditor?.yamlEditor?.setValue(value);
}
};
@@ -612,7 +581,7 @@ export default class HaAutomationActionRow extends LitElement {
if (this._selected && this.optionsInSidebar) {
this.openSidebar(value); // refresh sidebar
} else if (this._yamlMode) {
this._actionEditor?.yamlEditor?.setValue(value);
this.actionEditor?.yamlEditor?.setValue(value);
}
}
};
@@ -672,6 +641,9 @@ export default class HaAutomationActionRow extends LitElement {
}
public openSidebar(action?: Action): void {
if (this.narrow) {
this.scrollIntoView();
}
const sidebarAction = action ?? this.action;
const actionType = getAutomationActionType(sidebarAction);
@@ -679,79 +651,33 @@ export default class HaAutomationActionRow extends LitElement {
save: (value) => {
fireEvent(this, "value-changed", { value });
},
close: (focus?: boolean) => {
close: () => {
this._selected = false;
fireEvent(this, "close-sidebar");
if (focus) {
this.focus();
}
},
rename: () => {
this._renameAction();
},
toggleYamlMode: () => {
this._toggleYamlMode();
this.openSidebar();
return this._yamlMode;
},
disable: this._onDisable,
delete: this._onDelete,
copy: this._copyAction,
cut: this._cutAction,
duplicate: this._duplicateAction,
run: this._runAction,
config: {
action: sidebarAction,
},
config: sidebarAction,
type: "action",
uiSupported: actionType ? this._uiSupported(actionType) : false,
yamlMode: this._yamlMode,
} satisfies ActionSidebarConfig);
});
this._selected = true;
this._collapsed = false;
if (this.narrow) {
requestAnimationFrame(() => {
this.scrollIntoView({
block: "start",
behavior: "smooth",
});
});
}
}
public expand() {
if (this.optionsInSidebar) {
this._collapsed = false;
return;
}
this.updateComplete.then(() => {
this.shadowRoot!.querySelector("ha-expansion-panel")!.expanded = true;
});
}
public collapse() {
if (this.optionsInSidebar) {
this._collapsed = true;
return;
}
this.updateComplete.then(() => {
this.shadowRoot!.querySelector("ha-expansion-panel")!.expanded = false;
});
}
public expandAll() {
this.expand();
this._actionEditor?.expandAll();
}
public collapseAll() {
this.collapse();
this._actionEditor?.collapseAll();
}
private _uiSupported = memoizeOne(
(type: string) =>
customElements.get(`ha-automation-action-${type}`) !== undefined
@@ -761,14 +687,6 @@ export default class HaAutomationActionRow extends LitElement {
this._collapsed = !this._collapsed;
}
public isSelected() {
return this._selected;
}
public focus() {
this._automationRowElement?.focus();
}
static styles = rowStyles;
}

View File

@@ -1,15 +1,15 @@
import { mdiDrag, mdiPlus } from "@mdi/js";
import deepClone from "deep-clone-simple";
import type { PropertyValues } from "lit";
import { LitElement, html, nothing } from "lit";
import { customElement, property, queryAll, state } from "lit/decorators";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { repeat } from "lit/directives/repeat";
import { storage } from "../../../../common/decorators/storage";
import { fireEvent } from "../../../../common/dom/fire_event";
import { listenMediaQuery } from "../../../../common/dom/media_query";
import { nextRender } from "../../../../common/util/render-status";
import "../../../../components/ha-button";
import "../../../../components/ha-sortable";
import type { HaSortableClonedEventData } from "../../../../components/ha-sortable";
import "../../../../components/ha-svg-icon";
import {
ACTION_BUILDING_BLOCKS,
@@ -24,7 +24,6 @@ import {
VIRTUAL_ACTIONS,
showAddAutomationElementDialog,
} from "../show-add-automation-element-dialog";
import { automationRowsStyles } from "../styles";
import type HaAutomationActionRow from "./ha-automation-action-row";
import { getAutomationActionType } from "./ha-automation-action-row";
@@ -45,7 +44,7 @@ export default class HaAutomationAction extends LitElement {
@property({ type: Boolean, attribute: "sidebar" }) public optionsInSidebar =
false;
@state() private _rowSortSelected?: number;
@state() private _showReorder = false;
@state()
@storage({
@@ -56,35 +55,43 @@ export default class HaAutomationAction extends LitElement {
})
public _clipboard?: AutomationClipboard;
@queryAll("ha-automation-action-row")
private _actionRowElements?: HaAutomationActionRow[];
private _focusLastActionOnChange = false;
private _focusActionIndexOnChange?: number;
private _actionKeys = new WeakMap<Action, string>();
private _unsubMql?: () => void;
public connectedCallback() {
super.connectedCallback();
this._unsubMql = listenMediaQuery("(min-width: 600px)", (matches) => {
this._showReorder = matches;
});
}
public disconnectedCallback() {
super.disconnectedCallback();
this._unsubMql?.();
this._unsubMql = undefined;
}
protected render() {
return html`
<ha-sortable
handle-selector=".handle"
draggable-selector="ha-automation-action-row"
.disabled=${this.disabled}
.disabled=${!this._showReorder || this.disabled}
group="actions"
invert-swap
@item-moved=${this._actionMoved}
@item-added=${this._actionAdded}
@item-removed=${this._actionRemoved}
@item-cloned=${this._actionCloned}
>
<div class="rows ${!this.optionsInSidebar ? "no-sidebar" : ""}">
<div class="actions">
${repeat(
this.actions,
(action) => this._getKey(action),
(action, idx) => html`
<ha-automation-action-row
.root=${this.root}
.sortableData=${action}
.index=${idx}
.first=${idx === 0}
@@ -97,22 +104,12 @@ export default class HaAutomationAction extends LitElement {
@move-up=${this._moveUp}
@value-changed=${this._actionChanged}
.hass=${this.hass}
.highlight=${this.highlightedActions?.includes(action)}
?highlight=${this.highlightedActions?.includes(action)}
.optionsInSidebar=${this.optionsInSidebar}
.sortSelected=${this._rowSortSelected === idx}
@stop-sort-selection=${this._stopSortSelection}
>
${!this.disabled
${this._showReorder && !this.disabled
? html`
<div
tabindex="0"
class="handle ${this._rowSortSelected === idx
? "active"
: ""}"
slot="icons"
@keydown=${this._handleDragKeydown}
.index=${idx}
>
<div class="handle" slot="icons">
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
</div>
`
@@ -152,65 +149,40 @@ export default class HaAutomationAction extends LitElement {
protected updated(changedProps: PropertyValues) {
super.updated(changedProps);
if (
changedProps.has("actions") &&
(this._focusLastActionOnChange ||
this._focusActionIndexOnChange !== undefined)
) {
const mode = this._focusLastActionOnChange ? "new" : "moved";
if (changedProps.has("actions") && this._focusLastActionOnChange) {
this._focusLastActionOnChange = false;
const row = this.shadowRoot!.querySelector<HaAutomationActionRow>(
`ha-automation-action-row:${mode === "new" ? "last-of-type" : `nth-of-type(${this._focusActionIndexOnChange! + 1})`}`
"ha-automation-action-row:last-of-type"
)!;
this._focusLastActionOnChange = false;
this._focusActionIndexOnChange = undefined;
row.updateComplete.then(() => {
// on new condition open the settings in the sidebar, except for building blocks
const type = getAutomationActionType(row.action);
if (
type &&
this.optionsInSidebar &&
(!ACTION_BUILDING_BLOCKS.includes(type) || mode === "moved")
!ACTION_BUILDING_BLOCKS.includes(type)
) {
row.openSidebar();
if (this.narrow) {
row.scrollIntoView({
block: "start",
behavior: "smooth",
});
}
}
if (mode === "new") {
} else if (!this.optionsInSidebar) {
row.expand();
}
if (!this.optionsInSidebar) {
row.focus();
}
row.scrollIntoView();
row.focus();
});
}
}
public expandAll() {
this._actionRowElements?.forEach((row) => {
row.expandAll();
});
}
public collapseAll() {
this._actionRowElements?.forEach((row) => {
row.collapseAll();
const rows = this.shadowRoot!.querySelectorAll<HaAutomationActionRow>(
"ha-automation-action-row"
)!;
rows.forEach((row) => {
row.expand();
});
}
private _addActionDialog() {
if (this.narrow) {
fireEvent(this, "request-close-sidebar");
}
showAddAutomationElementDialog(this, {
type: "action",
add: this._addAction,
@@ -258,30 +230,18 @@ export default class HaAutomationAction extends LitElement {
return this._actionKeys.get(action)!;
}
private async _moveUp(ev) {
private _moveUp(ev) {
ev.stopPropagation();
const index = (ev.target as any).index;
if (!(ev.target as HaAutomationActionRow).first) {
const newIndex = index - 1;
this._move(index, newIndex);
if (this._rowSortSelected === index) {
this._rowSortSelected = newIndex;
}
ev.target.focus();
}
const newIndex = index - 1;
this._move(index, newIndex);
}
private async _moveDown(ev) {
private _moveDown(ev) {
ev.stopPropagation();
const index = (ev.target as any).index;
if (!(ev.target as HaAutomationActionRow).last) {
const newIndex = index + 1;
this._move(index, newIndex);
if (this._rowSortSelected === index) {
this._rowSortSelected = newIndex;
}
ev.target.focus();
}
const newIndex = index + 1;
this._move(index, newIndex);
}
private _move(oldIndex: number, newIndex: number) {
@@ -301,12 +261,6 @@ export default class HaAutomationAction extends LitElement {
private async _actionAdded(ev: CustomEvent): Promise<void> {
ev.stopPropagation();
const { index, data } = ev.detail;
let selected = false;
if (data?.["ha-automation-row-selected"]) {
selected = true;
delete data["ha-automation-row-selected"];
}
let actions = [
...this.actions.slice(0, index),
data,
@@ -314,9 +268,6 @@ export default class HaAutomationAction extends LitElement {
];
// Add action locally to avoid UI jump
this.actions = actions;
if (selected) {
this._focusActionIndexOnChange = actions.length === 1 ? 0 : index;
}
await nextRender();
if (this.actions !== actions) {
// Ensure action is added even after update
@@ -325,9 +276,6 @@ export default class HaAutomationAction extends LitElement {
data,
...this.actions.slice(index),
];
if (selected) {
this._focusActionIndexOnChange = actions.length === 1 ? 0 : index;
}
}
fireEvent(this, "value-changed", { value: actions });
}
@@ -342,6 +290,7 @@ export default class HaAutomationAction extends LitElement {
// Ensure action is removed even after update
const actions = this.actions.filter((a) => a !== action);
fireEvent(this, "value-changed", { value: actions });
fireEvent(this, "close-sidebar");
}
private _actionChanged(ev: CustomEvent) {
@@ -363,12 +312,6 @@ export default class HaAutomationAction extends LitElement {
fireEvent(this, "value-changed", { value: actions });
}
private _actionCloned(ev: CustomEvent<HaSortableClonedEventData>) {
if (ev.detail.item.action && ev.detail.item.isSelected()) {
ev.detail.item.action["ha-automation-row-selected"] = true;
}
}
private _duplicateAction(ev: CustomEvent) {
ev.stopPropagation();
const index = (ev.target as any).index;
@@ -377,21 +320,44 @@ export default class HaAutomationAction extends LitElement {
});
}
private _handleDragKeydown(ev: KeyboardEvent) {
if (ev.key === "Enter" || ev.key === " ") {
ev.stopPropagation();
this._rowSortSelected =
this._rowSortSelected === undefined
? (ev.target as any).index
: undefined;
static styles = css`
.actions {
padding: 16px 0 16px 16px;
margin: -16px;
display: flex;
flex-direction: column;
gap: 16px;
}
}
private _stopSortSelection() {
this._rowSortSelected = undefined;
}
static styles = automationRowsStyles;
:host([root]) .actions {
padding-right: 8px;
}
.sortable-ghost {
background: none;
border-radius: var(--ha-card-border-radius, var(--ha-border-radius-lg));
}
.sortable-drag {
background: none;
}
ha-automation-action-row {
display: block;
scroll-margin-top: 48px;
}
.handle {
padding: 12px;
cursor: move; /* fallback if grab cursor is unsupported */
cursor: grab;
}
.handle ha-svg-icon {
pointer-events: none;
height: 24px;
}
.buttons {
display: flex;
flex-wrap: wrap;
gap: 8px;
order: 1;
}
`;
}
declare global {

View File

@@ -1,15 +1,12 @@
import { type CSSResultGroup, LitElement, css, html, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { type CSSResultGroup, LitElement, css, html } from "lit";
import { customElement, property, state } from "lit/decorators";
import { ensureArray } from "../../../../../common/array/ensure-array";
import { fireEvent } from "../../../../../common/dom/fire_event";
import "../../../../../components/ha-button";
import type { Action, ChooseAction, Option } from "../../../../../data/script";
import { haStyle } from "../../../../../resources/styles";
import type { HomeAssistant } from "../../../../../types";
import "../../option/ha-automation-option";
import type HaAutomationOption from "../../option/ha-automation-option";
import "../../option/ha-automation-option-row";
import type HaAutomationOptionRow from "../../option/ha-automation-option-row";
import { indentStyle } from "../../styles";
import "../ha-automation-action";
import type { ActionElement } from "../ha-automation-action-row";
@@ -27,11 +24,6 @@ export class HaChooseAction extends LitElement implements ActionElement {
@state() private _showDefault = false;
@query("ha-automation-option") private _optionElement?: HaAutomationOption;
@query("ha-automation-option-row")
private _defaultOptionRowElement?: HaAutomationOptionRow;
public static get defaultConfig(): ChooseAction {
return { choose: [{ conditions: [], sequence: [] }] };
}
@@ -49,29 +41,42 @@ export class HaChooseAction extends LitElement implements ActionElement {
.hass=${this.hass}
.narrow=${this.narrow}
.optionsInSidebar=${this.indent}
.showDefaultActions=${this._showDefault || !!action.default}
@show-default-actions=${this._addDefault}
></ha-automation-option>
${this._showDefault || action.default
? html`
<ha-automation-option-row
.defaultActions=${(ensureArray(action.default) || []) as Action[]}
.narrow=${this.narrow}
<h2>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.type.choose.default"
)}:
</h2>
<ha-automation-action
.actions=${ensureArray(action.default) || []}
.disabled=${this.disabled}
.hass=${this.hass}
.optionsInSidebar=${this.indent}
@value-changed=${this._defaultChanged}
></ha-automation-option-row>
.hass=${this.hass}
.narrow=${this.narrow}
.optionsInSidebar=${this.indent}
></ha-automation-action>
`
: nothing}
: html`
<div class="link-button-row">
<button
class="link"
@click=${this._addDefault}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.type.choose.add_default"
)}
</button>
</div>
`}
`;
}
private async _addDefault() {
private _addDefault() {
this._showDefault = true;
await this._defaultOptionRowElement?.updateComplete;
this._defaultOptionRowElement?.expand();
}
private _optionsChanged(ev: CustomEvent) {
@@ -99,28 +104,12 @@ export class HaChooseAction extends LitElement implements ActionElement {
fireEvent(this, "value-changed", { value: newValue });
}
public expandAll() {
this._optionElement?.expandAll();
this._defaultOptionRowElement?.expandAll();
}
public collapseAll() {
this._optionElement?.collapseAll();
this._defaultOptionRowElement?.collapseAll();
}
static get styles(): CSSResultGroup {
return [
haStyle,
indentStyle,
css`
ha-automation-option-row {
display: block;
margin-top: 24px;
}
h3 {
font-size: inherit;
font-weight: inherit;
.link-button-row {
padding: 14px 14px 0 14px;
}
`,
];

View File

@@ -1,5 +1,5 @@
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, query } from "lit/decorators";
import { customElement, property } from "lit/decorators";
import memoizeOne from "memoize-one";
import { fireEvent } from "../../../../../common/dom/fire_event";
import { stringCompare } from "../../../../../common/string/compare";
@@ -14,7 +14,7 @@ import {
} from "../../../../../data/condition";
import type { Entries, HomeAssistant } from "../../../../../types";
import "../../condition/ha-automation-condition-editor";
import type HaAutomationConditionEditor from "../../condition/ha-automation-condition-editor";
import type { ActionElement } from "../ha-automation-action-row";
import "../../condition/types/ha-automation-condition-and";
import "../../condition/types/ha-automation-condition-device";
import "../../condition/types/ha-automation-condition-not";
@@ -26,7 +26,6 @@ import "../../condition/types/ha-automation-condition-template";
import "../../condition/types/ha-automation-condition-time";
import "../../condition/types/ha-automation-condition-trigger";
import "../../condition/types/ha-automation-condition-zone";
import type { ActionElement } from "../ha-automation-action-row";
@customElement("ha-automation-action-condition")
export class HaConditionAction extends LitElement implements ActionElement {
@@ -42,9 +41,6 @@ export class HaConditionAction extends LitElement implements ActionElement {
@property({ type: Boolean, attribute: "indent" }) public indent = false;
@query("ha-automation-condition-editor")
private _conditionEditor?: HaAutomationConditionEditor;
public static get defaultConfig(): Omit<Condition, "state" | "entity_id"> {
return { condition: "state" };
}
@@ -150,14 +146,6 @@ export class HaConditionAction extends LitElement implements ActionElement {
customElements.get(`ha-automation-condition-${type}`) !== undefined
);
public expandAll() {
this._conditionEditor?.expandAll();
}
public collapseAll() {
this._conditionEditor?.collapseAll();
}
static styles = css`
ha-select {
margin-bottom: 24px;

View File

@@ -1,15 +1,13 @@
import type { CSSResultGroup } from "lit";
import { css, html, LitElement } from "lit";
import { customElement, property, query, queryAll } from "lit/decorators";
import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../../../../../common/dom/fire_event";
import "../../../../../components/ha-textfield";
import type { Action, IfAction } from "../../../../../data/script";
import { haStyle } from "../../../../../resources/styles";
import type { HomeAssistant } from "../../../../../types";
import type { Condition } from "../../../../lovelace/common/validate-condition";
import type HaAutomationCondition from "../../condition/ha-automation-condition";
import "../ha-automation-action";
import type HaAutomationAction from "../ha-automation-action";
import type { ActionElement } from "../ha-automation-action-row";
@customElement("ha-automation-action-if")
@@ -24,11 +22,7 @@ export class HaIfAction extends LitElement implements ActionElement {
@property({ type: Boolean }) public indent = false;
@query("ha-automation-condition")
private _conditionElement?: HaAutomationCondition;
@queryAll("ha-automation-action")
private _actionElements?: HaAutomationAction[];
@state() private _showElse = false;
public static get defaultConfig(): IfAction {
return {
@@ -41,11 +35,11 @@ export class HaIfAction extends LitElement implements ActionElement {
const action = this.action;
return html`
<h4>
<h3>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.type.if.if"
)}:
</h4>
)}*:
</h3>
<ha-automation-condition
.conditions=${action.if ?? []}
.disabled=${this.disabled}
@@ -55,11 +49,11 @@ export class HaIfAction extends LitElement implements ActionElement {
.optionsInSidebar=${this.indent}
></ha-automation-condition>
<h4>
<h3>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.type.if.then"
)}:
</h4>
)}*:
</h3>
<ha-automation-action
.actions=${action.then ?? []}
.disabled=${this.disabled}
@@ -68,22 +62,40 @@ export class HaIfAction extends LitElement implements ActionElement {
.narrow=${this.narrow}
.optionsInSidebar=${this.indent}
></ha-automation-action>
<h4>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.type.if.else"
)}:
</h4>
<ha-automation-action
.actions=${action.else || []}
.disabled=${this.disabled}
@value-changed=${this._elseChanged}
.hass=${this.hass}
.narrow=${this.narrow}
.optionsInSidebar=${this.indent}
></ha-automation-action>
${this._showElse || action.else
? html`
<h3>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.type.if.else"
)}:
</h3>
<ha-automation-action
.actions=${action.else || []}
.disabled=${this.disabled}
@value-changed=${this._elseChanged}
.hass=${this.hass}
.narrow=${this.narrow}
.optionsInSidebar=${this.indent}
></ha-automation-action>
`
: html`<div class="link-button-row">
<button
class="link"
@click=${this._addElse}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.type.if.add_else"
)}
</button>
</div>`}
`;
}
private _addElse() {
this._showElse = true;
}
private _ifChanged(ev: CustomEvent) {
ev.stopPropagation();
const value = ev.detail.value as Condition[];
@@ -108,6 +120,7 @@ export class HaIfAction extends LitElement implements ActionElement {
private _elseChanged(ev: CustomEvent) {
ev.stopPropagation();
this._showElse = true;
const elseAction = ev.detail.value as Action[];
const newValue: IfAction = {
...this.action,
@@ -119,26 +132,12 @@ export class HaIfAction extends LitElement implements ActionElement {
fireEvent(this, "value-changed", { value: newValue });
}
public expandAll() {
this._conditionElement?.expandAll();
this._actionElements?.forEach((element) => element.expandAll?.());
}
public collapseAll() {
this._conditionElement?.collapseAll();
this._actionElements?.forEach((element) => element.collapseAll?.());
}
static get styles(): CSSResultGroup {
return [
haStyle,
css`
h4 {
color: var(--secondary-text-color);
margin-bottom: 8px;
}
h4:first-child {
margin-top: 0;
.link-button-row {
padding: 14px;
}
`,
];

View File

@@ -1,13 +1,12 @@
import type { CSSResultGroup } from "lit";
import { html, LitElement } from "lit";
import { customElement, property, query } from "lit/decorators";
import { customElement, property } from "lit/decorators";
import { fireEvent } from "../../../../../common/dom/fire_event";
import "../../../../../components/ha-textfield";
import type { Action, ParallelAction } from "../../../../../data/script";
import { haStyle } from "../../../../../resources/styles";
import type { HomeAssistant } from "../../../../../types";
import "../ha-automation-action";
import type HaAutomationAction from "../ha-automation-action";
import type { ActionElement } from "../ha-automation-action-row";
@customElement("ha-automation-action-parallel")
@@ -22,9 +21,6 @@ export class HaParallelAction extends LitElement implements ActionElement {
@property({ type: Boolean }) public indent = false;
@query("ha-automation-action")
private _actionElement?: HaAutomationAction;
public static get defaultConfig(): ParallelAction {
return {
parallel: [],
@@ -57,14 +53,6 @@ export class HaParallelAction extends LitElement implements ActionElement {
});
}
public expandAll() {
this._actionElement?.expandAll();
}
public collapseAll() {
this._actionElement?.collapseAll();
}
static get styles(): CSSResultGroup {
return haStyle;
}

View File

@@ -0,0 +1,79 @@
import { html, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
import memoizeOne from "memoize-one";
import { fireEvent } from "../../../../../common/dom/fire_event";
import "../../../../../components/ha-selector/ha-selector";
import type { PlayMediaAction } from "../../../../../data/script";
import type {
MediaSelectorValue,
Selector,
} from "../../../../../data/selector";
import type { HomeAssistant } from "../../../../../types";
import type { ActionElement } from "../ha-automation-action-row";
const MEDIA_SELECTOR_SCHEMA: Selector = {
media: {},
};
@customElement("ha-automation-action-play_media")
export class HaPlayMediaAction extends LitElement implements ActionElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ type: Boolean }) public disabled = false;
@property({ attribute: false }) public action!: PlayMediaAction;
@property({ type: Boolean }) public narrow = false;
public static get defaultConfig(): PlayMediaAction {
return {
action: "media_player.play_media",
target: { entity_id: "" },
data: { media_content_id: "", media_content_type: "" },
metadata: {},
};
}
private _getSelectorValue = memoizeOne(
(action: PlayMediaAction): MediaSelectorValue => ({
entity_id: action.target?.entity_id || action.entity_id,
media_content_id: action.data?.media_content_id,
media_content_type: action.data?.media_content_type,
metadata: action.metadata,
})
);
protected render() {
return html`
<ha-selector
.selector=${MEDIA_SELECTOR_SCHEMA}
.hass=${this.hass}
.disabled=${this.disabled}
.value=${this._getSelectorValue(this.action)}
@value-changed=${this._valueChanged}
></ha-selector>
`;
}
private _valueChanged(ev: CustomEvent<{ value: MediaSelectorValue }>) {
ev.stopPropagation();
fireEvent(this, "value-changed", {
value: {
...this.action,
action: "media_player.play_media",
target: { entity_id: ev.detail.value.entity_id },
data: {
media_content_id: ev.detail.value.media_content_id,
media_content_type: ev.detail.value.media_content_type,
},
metadata: ev.detail.value.metadata || {},
} as PlayMediaAction,
});
}
}
declare global {
interface HTMLElementTagNameMap {
"ha-automation-action-play_media": HaPlayMediaAction;
}
}

View File

@@ -1,6 +1,6 @@
import type { CSSResultGroup } from "lit";
import { css, html, LitElement } from "lit";
import { customElement, property, query } from "lit/decorators";
import { customElement, property } from "lit/decorators";
import memoizeOne from "memoize-one";
import { fireEvent } from "../../../../../common/dom/fire_event";
import "../../../../../components/ha-textfield";
@@ -12,14 +12,10 @@ import type { ActionElement } from "../ha-automation-action-row";
import { isTemplate } from "../../../../../common/string/has-template";
import "../../../../../components/ha-form/ha-form";
import type { HaForm } from "../../../../../components/ha-form/ha-form";
import type {
HaFormSchema,
SchemaUnion,
} from "../../../../../components/ha-form/types";
import type { HaSelector } from "../../../../../components/ha-selector/ha-selector";
import type { HaActionSelector } from "../../../../../components/ha-selector/ha-selector-action";
import type { HaConditionSelector } from "../../../../../components/ha-selector/ha-selector-condition";
const OPTIONS = ["count", "while", "until", "for_each"] as const;
type RepeatType = (typeof OPTIONS)[number];
@@ -41,9 +37,6 @@ export class HaRepeatAction extends LitElement implements ActionElement {
@property({ type: Boolean, attribute: "indent" }) public indent = false;
@query("ha-form")
private _formElement?: HaForm;
public static get defaultConfig(): RepeatAction {
return { repeat: { count: 2, sequence: [] } };
}
@@ -182,41 +175,6 @@ export class HaRepeatAction extends LitElement implements ActionElement {
];
}
private _getSelectorElements() {
if (this._formElement) {
const selectors =
this._formElement.shadowRoot?.querySelectorAll<HaSelector>(
"ha-selector"
);
const selectorElements: (HaConditionSelector | HaActionSelector)[] = [];
selectors?.forEach((selector) => {
selectorElements.push(
...Array.from(
selector.shadowRoot?.querySelectorAll<
HaConditionSelector | HaActionSelector
>("ha-selector-condition, ha-selector-action") || []
)
);
});
return selectorElements;
}
return [];
}
public expandAll() {
this._getSelectorElements().forEach((element) => {
element.expandAll?.();
});
}
public collapseAll() {
this._getSelectorElements().forEach((element) => {
element.collapseAll?.();
});
}
private _computeLabelCallback = (
schema: SchemaUnion<ReturnType<typeof this._schema>>
): string => {

View File

@@ -1,6 +1,6 @@
import type { CSSResultGroup } from "lit";
import { html, LitElement } from "lit";
import { query, customElement, property } from "lit/decorators";
import { customElement, property } from "lit/decorators";
import { fireEvent } from "../../../../../common/dom/fire_event";
import "../../../../../components/ha-textfield";
import type { Action, SequenceAction } from "../../../../../data/script";
@@ -8,7 +8,6 @@ import { haStyle } from "../../../../../resources/styles";
import type { HomeAssistant } from "../../../../../types";
import "../ha-automation-action";
import type { ActionElement } from "../ha-automation-action-row";
import type HaAutomationAction from "../ha-automation-action";
@customElement("ha-automation-action-sequence")
export class HaSequenceAction extends LitElement implements ActionElement {
@@ -22,9 +21,6 @@ export class HaSequenceAction extends LitElement implements ActionElement {
@property({ type: Boolean }) public indent = false;
@query("ha-automation-action")
private _actionElement?: HaAutomationAction;
public static get defaultConfig(): SequenceAction {
return {
sequence: [],
@@ -57,14 +53,6 @@ export class HaSequenceAction extends LitElement implements ActionElement {
});
}
public expandAll() {
this._actionElement?.expandAll();
}
public collapseAll() {
this._actionElement?.collapseAll();
}
static get styles(): CSSResultGroup {
return haStyle;
}

View File

@@ -244,7 +244,14 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
manifests?: DomainManifestLookup
): ListItem[] => {
if (type === "action" && isService(group)) {
return this._services(localize, services, manifests, group);
let result = this._services(localize, services, manifests, group);
if (group === `${SERVICE_PREFIX}media_player`) {
result = [
this._convertToItem("play_media", {}, type, localize),
...result,
];
}
return result;
}
const groups = this._getGroups(type, group);

View File

@@ -1,31 +1,24 @@
import { mdiClose, mdiPlus } from "@mdi/js";
import { dump } from "js-yaml";
import type { CSSResultGroup } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { mdiClose, mdiPlus } from "@mdi/js";
import { dump } from "js-yaml";
import { fireEvent } from "../../../../common/dom/fire_event";
import "../../../../components/chips/ha-assist-chip";
import "../../../../components/chips/ha-chip-set";
import "../../../../components/ha-alert";
import "../../../../components/ha-area-picker";
import "../../../../components/ha-domain-icon";
import "../../../../components/ha-expansion-panel";
import "../../../../components/ha-icon-picker";
import "../../../../components/ha-labels-picker";
import "../../../../components/ha-suggest-with-ai-button";
import type { SuggestWithAIGenerateTask } from "../../../../components/ha-suggest-with-ai-button";
import "../../../../components/ha-svg-icon";
import "../../../../components/ha-textarea";
import "../../../../components/ha-textfield";
import "../../../../components/ha-labels-picker";
import "../../../../components/ha-suggest-with-ai-button";
import type { SuggestWithAIGenerateTask } from "../../../../components/ha-suggest-with-ai-button";
import "../../category/ha-category-picker";
import "../../../../components/ha-expansion-panel";
import "../../../../components/chips/ha-chip-set";
import "../../../../components/chips/ha-assist-chip";
import "../../../../components/ha-area-picker";
import { computeStateDomain } from "../../../../common/entity/compute_state_domain";
import { supportsMarkdownHelper } from "../../../../common/translations/markdown_support";
import { subscribeOne } from "../../../../common/util/subscribe-one";
import type { GenDataTaskResult } from "../../../../data/ai_task";
import { fetchCategoryRegistry } from "../../../../data/category_registry";
import { subscribeEntityRegistry } from "../../../../data/entity_registry";
import { subscribeLabelRegistry } from "../../../../data/label_registry";
import type { HassDialog } from "../../../../dialogs/make-dialog-manager";
import { haStyle, haStyleDialog } from "../../../../resources/styles";
import type { HomeAssistant } from "../../../../types";
@@ -33,6 +26,13 @@ import type {
EntityRegistryUpdate,
SaveDialogParams,
} from "./show-dialog-automation-save";
import { supportsMarkdownHelper } from "../../../../common/translations/markdown_support";
import type { GenDataTaskResult } from "../../../../data/ai_task";
import { computeStateDomain } from "../../../../common/entity/compute_state_domain";
import { subscribeOne } from "../../../../common/util/subscribe-one";
import { subscribeLabelRegistry } from "../../../../data/label_registry";
import { subscribeEntityRegistry } from "../../../../data/entity_registry";
import { fetchCategoryRegistry } from "../../../../data/category_registry";
@customElement("ha-dialog-automation-save")
class DialogAutomationSave extends LitElement implements HassDialog {
@@ -242,7 +242,7 @@ class DialogAutomationSave extends LitElement implements HassDialog {
const title = this.hass.localize(
this._params.config.alias
? "ui.panel.config.automation.editor.rename"
: "ui.common.save"
: "ui.panel.config.automation.editor.save"
);
return html`
@@ -289,7 +289,7 @@ class DialogAutomationSave extends LitElement implements HassDialog {
${this.hass.localize(
this._params.config.alias && !this._params.onDiscard
? "ui.panel.config.automation.editor.rename"
: "ui.common.save"
: "ui.panel.config.automation.editor.save"
)}
</ha-button>
</div>

View File

@@ -6,7 +6,6 @@ import { fireEvent } from "../../../common/dom/fire_event";
import "../../../components/ha-alert";
import "../../../components/ha-button";
import "../../../components/ha-markdown";
import "../../../components/ha-fab";
import type { BlueprintAutomationConfig } from "../../../data/automation";
import { fetchBlueprints } from "../../../data/blueprint";
import { HaBlueprintGenericEditor } from "../blueprint/blueprint-generic-editor";
@@ -59,7 +58,7 @@ export class HaBlueprintAutomationEditor extends HaBlueprintGenericEditor {
<ha-fab
slot="fab"
class=${this.dirty ? "dirty" : ""}
.label=${this.hass.localize("ui.common.save")}
.label=${this.hass.localize("ui.panel.config.automation.editor.save")}
.disabled=${this.saving}
extended
@click=${this._saveAutomation}

View File

@@ -8,11 +8,9 @@ import "../../../../components/ha-yaml-editor";
import type { HaYamlEditor } from "../../../../components/ha-yaml-editor";
import type { Condition } from "../../../../data/automation";
import { expandConditionWithShorthand } from "../../../../data/automation";
import { COLLAPSIBLE_CONDITION_ELEMENTS } from "../../../../data/condition";
import type { HomeAssistant } from "../../../../types";
import "../ha-automation-editor-warning";
import { editorStyles, indentStyle } from "../styles";
import type { ConditionElement } from "./ha-automation-condition-row";
import { editorStyles } from "../styles";
@customElement("ha-automation-condition-editor")
export default class HaAutomationConditionEditor extends LitElement {
@@ -28,8 +26,6 @@ export default class HaAutomationConditionEditor extends LitElement {
@property({ type: Boolean }) public narrow = false;
@property({ type: Boolean, attribute: "sidebar" }) public inSidebar = false;
@property({ type: Boolean, reflect: true }) public selected = false;
@property({ type: Boolean, attribute: "supported" }) public uiSupported =
@@ -37,9 +33,6 @@ export default class HaAutomationConditionEditor extends LitElement {
@query("ha-yaml-editor") public yamlEditor?: HaYamlEditor;
@query(COLLAPSIBLE_CONDITION_ELEMENTS.join(", "))
private _collapsibleElement?: ConditionElement;
private _processedCondition = memoizeOne((condition) =>
expandConditionWithShorthand(condition)
);
@@ -57,7 +50,6 @@ export default class HaAutomationConditionEditor extends LitElement {
(this.condition.enabled === false && !this.yamlMode),
yaml: yamlMode,
indent: this.indent,
card: !this.inSidebar,
})}
>
${yamlMode
@@ -103,7 +95,8 @@ export default class HaAutomationConditionEditor extends LitElement {
if (!ev.detail.isValid) {
return;
}
fireEvent(this, "yaml-changed", { value: ev.detail.value });
// @ts-ignore
fireEvent(this, "value-changed", { value: ev.detail.value, yaml: true });
}
private _onUiChanged(ev: CustomEvent) {
@@ -115,17 +108,8 @@ export default class HaAutomationConditionEditor extends LitElement {
fireEvent(this, "value-changed", { value });
}
public expandAll() {
this._collapsibleElement?.expandAll?.();
}
public collapseAll() {
this._collapsibleElement?.collapseAll?.();
}
static styles = [
editorStyles,
indentStyle,
css`
:host([action]) .card-content {
padding: 0;
@@ -135,7 +119,6 @@ export default class HaAutomationConditionEditor extends LitElement {
margin-right: 0;
padding: 0;
border-left: none;
border-bottom: none;
}
`,
];

View File

@@ -14,7 +14,7 @@ import {
mdiStopCircleOutline,
} from "@mdi/js";
import deepClone from "deep-clone-simple";
import type { CSSResultGroup, PropertyValues } from "lit";
import type { CSSResultGroup } from "lit";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
@@ -26,7 +26,6 @@ import { stopPropagation } from "../../../../common/dom/stop_propagation";
import { capitalizeFirstLetter } from "../../../../common/string/capitalize-first-letter";
import { handleStructError } from "../../../../common/structs/handle-errors";
import "../../../../components/ha-automation-row";
import type { HaAutomationRow } from "../../../../components/ha-automation-row";
import "../../../../components/ha-card";
import "../../../../components/ha-expansion-panel";
import "../../../../components/ha-icon-button";
@@ -36,7 +35,6 @@ import "../../../../components/ha-md-menu-item";
import type {
AutomationClipboard,
Condition,
ConditionSidebarConfig,
} from "../../../../data/automation";
import { testCondition } from "../../../../data/automation";
import { describeCondition } from "../../../../data/automation_i18n";
@@ -71,8 +69,6 @@ import "./types/ha-automation-condition-zone";
export interface ConditionElement extends LitElement {
condition: Condition;
expandAll?: () => void;
collapseAll?: () => void;
}
export const handleChangeEvent = (
@@ -108,20 +104,13 @@ export default class HaAutomationConditionRow extends LitElement {
@property({ type: Boolean }) public disabled = false;
@property({ type: Boolean }) public root = false;
@property({ type: Boolean }) public first?: boolean;
@property({ type: Boolean }) public last?: boolean;
@property({ type: Boolean }) public narrow = false;
@property({ type: Boolean }) public highlight?: boolean;
@property({ type: Boolean, attribute: "sort-selected" })
public sortSelected = false;
@state() private _collapsed = true;
@state() private _collapsed = false;
@state() private _warnings?: string[];
@@ -151,9 +140,6 @@ export default class HaAutomationConditionRow extends LitElement {
@query("ha-automation-condition-editor")
public conditionEditor?: HaAutomationConditionEditor;
@query("ha-automation-row")
private _automationRowElement?: HaAutomationRow;
private _renderRow() {
return html`
<ha-svg-icon
@@ -169,94 +155,90 @@ export default class HaAutomationConditionRow extends LitElement {
<slot name="icons" slot="icons"></slot>
${!this.optionsInSidebar
? html`<ha-md-button-menu
quick
slot="icons"
@click=${preventDefaultStopPropagation}
@keydown=${stopPropagation}
@closed=${stopPropagation}
positioning="fixed"
anchor-corner="end-end"
menu-corner="start-end"
>
<ha-icon-button
slot="trigger"
.label=${this.hass.localize("ui.common.menu")}
.path=${mdiDotsVertical}
>
</ha-icon-button>
<ha-md-button-menu
slot="icons"
@click=${preventDefaultStopPropagation}
@keydown=${stopPropagation}
@closed=${stopPropagation}
positioning="fixed"
>
<ha-icon-button
slot="trigger"
.label=${this.hass.localize("ui.common.menu")}
.path=${mdiDotsVertical}
>
</ha-icon-button>
<ha-md-menu-item .clickAction=${this._testCondition}>
${this.hass.localize(
"ui.panel.config.automation.editor.conditions.test"
)}
<ha-svg-icon slot="start" .path=${mdiFlask}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
.clickAction=${this._renameCondition}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.conditions.rename"
)}
<ha-svg-icon slot="start" .path=${mdiRenameBox}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item .clickAction=${this._testCondition}>
${this.hass.localize(
"ui.panel.config.automation.editor.conditions.test"
)}
<ha-svg-icon slot="start" .path=${mdiFlask}></ha-svg-icon>
</ha-md-menu-item>
${!this.optionsInSidebar
? html`
<ha-md-menu-item
.clickAction=${this._renameCondition}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.conditions.rename"
)}
<ha-svg-icon slot="start" .path=${mdiRenameBox}></ha-svg-icon>
</ha-md-menu-item>
`
: nothing}
<ha-md-divider role="separator" tabindex="-1"></ha-md-divider>
<ha-md-divider role="separator" tabindex="-1"></ha-md-divider>
<ha-md-menu-item
.clickAction=${this._duplicateCondition}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.duplicate"
)}
<ha-svg-icon
slot="start"
.path=${mdiContentDuplicate}
></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
.clickAction=${this._duplicateCondition}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.duplicate"
)}
<ha-svg-icon slot="start" .path=${mdiContentDuplicate}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
.clickAction=${this._copyCondition}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.copy"
)}
<ha-svg-icon slot="start" .path=${mdiContentCopy}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
.clickAction=${this._copyCondition}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.copy"
)}
<ha-svg-icon slot="start" .path=${mdiContentCopy}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
.clickAction=${this._cutCondition}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.cut"
)}
<ha-svg-icon slot="start" .path=${mdiContentCut}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
.clickAction=${this._cutCondition}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.cut"
)}
<ha-svg-icon slot="start" .path=${mdiContentCut}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
.clickAction=${this._moveUp}
.disabled=${this.disabled || this.first}
>
${this.hass.localize("ui.panel.config.automation.editor.move_up")}
<ha-svg-icon slot="start" .path=${mdiArrowUp}></ha-svg-icon
></ha-md-menu-item>
<ha-md-menu-item
.clickAction=${this._moveUp}
.disabled=${this.disabled || this.first}
>
${this.hass.localize("ui.panel.config.automation.editor.move_up")}
<ha-svg-icon slot="start" .path=${mdiArrowUp}></ha-svg-icon
></ha-md-menu-item>
<ha-md-menu-item
.clickAction=${this._moveDown}
.disabled=${this.disabled || this.last}
>
${this.hass.localize(
"ui.panel.config.automation.editor.move_down"
)}
<ha-svg-icon slot="start" .path=${mdiArrowDown}></ha-svg-icon
></ha-md-menu-item>
<ha-md-menu-item
.clickAction=${this._moveDown}
.disabled=${this.disabled || this.last}
>
${this.hass.localize("ui.panel.config.automation.editor.move_down")}
<ha-svg-icon slot="start" .path=${mdiArrowDown}></ha-svg-icon
></ha-md-menu-item>
<ha-md-menu-item
${!this.optionsInSidebar
? html`<ha-md-menu-item
.clickAction=${this._toggleYamlMode}
.disabled=${this._uiSupported(this.condition.condition) ||
!!this._warnings}
@@ -265,44 +247,45 @@ export default class HaAutomationConditionRow extends LitElement {
`ui.panel.config.automation.editor.edit_${!this._yamlMode ? "yaml" : "ui"}`
)}
<ha-svg-icon slot="start" .path=${mdiPlaylistEdit}></ha-svg-icon>
</ha-md-menu-item>
</ha-md-menu-item>`
: nothing}
<ha-md-divider role="separator" tabindex="-1"></ha-md-divider>
<ha-md-divider role="separator" tabindex="-1"></ha-md-divider>
<ha-md-menu-item
.clickAction=${this._onDisable}
.disabled=${this.disabled}
>
${this.condition.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="start"
.path=${this.condition.enabled === false
? mdiPlayCircleOutline
: mdiStopCircleOutline}
></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
class="warning"
.clickAction=${this._onDelete}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.delete"
<ha-md-menu-item
.clickAction=${this._onDisable}
.disabled=${this.disabled}
>
${this.condition.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
class="warning"
slot="start"
.path=${mdiDelete}
></ha-svg-icon>
</ha-md-menu-item>
</ha-md-button-menu>`
: nothing}
<ha-svg-icon
slot="start"
.path=${this.condition.enabled === false
? mdiPlayCircleOutline
: mdiStopCircleOutline}
></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
class="warning"
.clickAction=${this._onDelete}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.delete"
)}
<ha-svg-icon
class="warning"
slot="start"
.path=${mdiDelete}
></ha-svg-icon>
</ha-md-menu-item>
</ha-md-button-menu>
${!this.optionsInSidebar
? html`${this._warnings
? html`<ha-automation-editor-warning
@@ -357,13 +340,11 @@ export default class HaAutomationConditionRow extends LitElement {
)}
.collapsed=${this._collapsed}
.selected=${this._selected}
.highlight=${this.highlight}
@click=${this._toggleSidebar}
@toggle-collapsed=${this._toggleCollapse}
.buildingBlock=${CONDITION_BUILDING_BLOCKS.includes(
this.condition.condition
)}
.sortSelected=${this.sortSelected}
>${this._renderRow()}</ha-automation-row
>`
: html`
@@ -389,9 +370,9 @@ export default class HaAutomationConditionRow extends LitElement {
</ha-card>
${this.optionsInSidebar &&
CONDITION_BUILDING_BLOCKS.includes(this.condition.condition)
CONDITION_BUILDING_BLOCKS.includes(this.condition.condition) &&
!this._collapsed
? html`<ha-automation-condition-editor
class=${this._collapsed ? "hidden" : ""}
.hass=${this.hass}
.condition=${this.condition}
.disabled=${this.disabled}
@@ -405,14 +386,6 @@ export default class HaAutomationConditionRow extends LitElement {
`;
}
protected firstUpdated(changedProperties: PropertyValues): void {
super.firstUpdated(changedProperties);
if (this.root) {
this._collapsed = false;
}
}
protected willUpdate(changedProperties) {
// on yaml toggle --> clear warnings
if (changedProperties.has("yamlMode")) {
@@ -601,32 +574,11 @@ export default class HaAutomationConditionRow extends LitElement {
};
public expand() {
if (this.optionsInSidebar) {
this._collapsed = false;
return;
}
this.updateComplete.then(() => {
this.shadowRoot!.querySelector("ha-expansion-panel")!.expanded = true;
});
}
public collapse() {
this._collapsed = true;
}
public expandAll() {
this.expand();
this.conditionEditor?.expandAll();
}
public collapseAll() {
this.collapse();
this.conditionEditor?.collapseAll();
}
private _handleUiModeNotAvailable(ev: CustomEvent) {
this._warnings = handleStructError(this.hass, ev.detail).warnings;
if (!this._yamlMode) {
@@ -646,46 +598,34 @@ export default class HaAutomationConditionRow extends LitElement {
}
public openSidebar(condition?: Condition): void {
if (this.narrow) {
this.scrollIntoView();
}
const sidebarCondition = condition || this.condition;
fireEvent(this, "open-sidebar", {
save: (value) => {
fireEvent(this, "value-changed", { value });
},
close: (focus?: boolean) => {
close: () => {
this._selected = false;
fireEvent(this, "close-sidebar");
if (focus) {
this.focus();
}
},
rename: () => {
this._renameCondition();
},
toggleYamlMode: () => {
this._toggleYamlMode();
this.openSidebar();
return this._yamlMode;
},
disable: this._onDisable,
delete: this._onDelete,
duplicate: this._duplicateCondition,
copy: this._copyCondition,
cut: this._cutCondition,
test: this._testCondition,
config: sidebarCondition,
type: "condition",
uiSupported: this._uiSupported(sidebarCondition.condition),
yamlMode: this._yamlMode,
} satisfies ConditionSidebarConfig);
});
this._selected = true;
this._collapsed = false;
if (this.narrow) {
requestAnimationFrame(() => {
this.scrollIntoView({
block: "start",
behavior: "smooth",
});
});
}
}
private _uiSupported = memoizeOne(
@@ -697,14 +637,6 @@ export default class HaAutomationConditionRow extends LitElement {
this._collapsed = !this._collapsed;
}
public isSelected() {
return this._selected;
}
public focus() {
this._automationRowElement?.focus();
}
static get styles(): CSSResultGroup {
return [
rowStyles,
@@ -723,13 +655,8 @@ export default class HaAutomationConditionRow extends LitElement {
overflow: hidden;
transition: max-height 0.3s;
text-align: center;
border-top-right-radius: var(
--ha-card-border-radius,
var(--ha-border-radius-lg)
);
border-top-left-radius: var(
--ha-card-border-radius,
var(--ha-border-radius-lg)
border-top-right-radius: var(--ha-card-border-radius, var(--ha-border-radius-lg));
border-top-left-radius: var(--ha-card-border-radius, var(--ha-border-radius-lg));
);
}
.testing.active {

View File

@@ -1,30 +1,29 @@
import { mdiDrag, mdiPlus } from "@mdi/js";
import deepClone from "deep-clone-simple";
import type { PropertyValues } from "lit";
import { html, LitElement, nothing } from "lit";
import { customElement, property, queryAll, state } from "lit/decorators";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { repeat } from "lit/directives/repeat";
import { storage } from "../../../../common/decorators/storage";
import { fireEvent } from "../../../../common/dom/fire_event";
import { listenMediaQuery } from "../../../../common/dom/media_query";
import { nextRender } from "../../../../common/util/render-status";
import "../../../../components/ha-button";
import "../../../../components/ha-button-menu";
import "../../../../components/ha-sortable";
import type { HaSortableClonedEventData } from "../../../../components/ha-sortable";
import "../../../../components/ha-svg-icon";
import type {
AutomationClipboard,
Condition,
} from "../../../../data/automation";
import { CONDITION_BUILDING_BLOCKS } from "../../../../data/condition";
import type { HomeAssistant } from "../../../../types";
import {
PASTE_VALUE,
showAddAutomationElementDialog,
} from "../show-add-automation-element-dialog";
import { automationRowsStyles } from "../styles";
import "./ha-automation-condition-row";
import type HaAutomationConditionRow from "./ha-automation-condition-row";
import { CONDITION_BUILDING_BLOCKS } from "../../../../data/condition";
@customElement("ha-automation-condition")
export default class HaAutomationCondition extends LitElement {
@@ -43,7 +42,7 @@ export default class HaAutomationCondition extends LitElement {
@property({ type: Boolean, attribute: "sidebar" }) public optionsInSidebar =
false;
@state() private _rowSortSelected?: number;
@state() private _showReorder = false;
@state()
@storage({
@@ -54,15 +53,25 @@ export default class HaAutomationCondition extends LitElement {
})
public _clipboard?: AutomationClipboard;
@queryAll("ha-automation-condition-row")
private _conditionRowElements?: HaAutomationConditionRow[];
private _focusLastConditionOnChange = false;
private _focusConditionIndexOnChange?: number;
private _conditionKeys = new WeakMap<Condition, string>();
private _unsubMql?: () => void;
public connectedCallback() {
super.connectedCallback();
this._unsubMql = listenMediaQuery("(min-width: 600px)", (matches) => {
this._showReorder = matches;
});
}
public disconnectedCallback() {
super.disconnectedCallback();
this._unsubMql?.();
this._unsubMql = undefined;
}
protected updated(changedProperties: PropertyValues) {
if (!changedProperties.has("conditions")) {
return;
@@ -87,55 +96,33 @@ export default class HaAutomationCondition extends LitElement {
fireEvent(this, "value-changed", {
value: updatedConditions,
});
} else if (
this._focusLastConditionOnChange ||
this._focusConditionIndexOnChange !== undefined
) {
const mode = this._focusLastConditionOnChange ? "new" : "moved";
const row = this.shadowRoot!.querySelector<HaAutomationConditionRow>(
`ha-automation-condition-row:${mode === "new" ? "last-of-type" : `nth-of-type(${this._focusConditionIndexOnChange! + 1})`}`
)!;
} else if (this._focusLastConditionOnChange) {
this._focusLastConditionOnChange = false;
this._focusConditionIndexOnChange = undefined;
const row = this.shadowRoot!.querySelector<HaAutomationConditionRow>(
"ha-automation-condition-row:last-of-type"
)!;
row.updateComplete.then(() => {
// on new condition open the settings in the sidebar, except for building blocks
if (
this.optionsInSidebar &&
(!CONDITION_BUILDING_BLOCKS.includes(row.condition.condition) ||
mode === "moved")
!CONDITION_BUILDING_BLOCKS.includes(row.condition.condition)
) {
row.openSidebar();
if (this.narrow) {
row.scrollIntoView({
block: "start",
behavior: "smooth",
});
}
}
if (mode === "new") {
} else if (!this.optionsInSidebar) {
row.expand();
}
if (!this.optionsInSidebar) {
row.focus();
}
row.scrollIntoView();
row.focus();
});
}
}
public expandAll() {
this._conditionRowElements?.forEach((row) => {
row.expandAll();
});
}
public collapseAll() {
this._conditionRowElements?.forEach((row) => {
row.collapseAll();
const rows = this.shadowRoot!.querySelectorAll<HaAutomationConditionRow>(
"ha-automation-condition-row"
)!;
rows.forEach((row) => {
row.expand();
});
}
@@ -147,21 +134,19 @@ export default class HaAutomationCondition extends LitElement {
<ha-sortable
handle-selector=".handle"
draggable-selector="ha-automation-condition-row"
.disabled=${this.disabled}
.disabled=${!this._showReorder || this.disabled}
group="conditions"
invert-swap
@item-moved=${this._conditionMoved}
@item-added=${this._conditionAdded}
@item-removed=${this._conditionRemoved}
@item-cloned=${this._conditionCloned}
>
<div class="rows ${!this.optionsInSidebar ? "no-sidebar" : ""}">
<div class="conditions">
${repeat(
this.conditions.filter((c) => typeof c === "object"),
(condition) => this._getKey(condition),
(cond, idx) => html`
<ha-automation-condition-row
.root=${this.root}
.sortableData=${cond}
.index=${idx}
.first=${idx === 0}
@@ -175,22 +160,12 @@ export default class HaAutomationCondition extends LitElement {
@move-up=${this._moveUp}
@value-changed=${this._conditionChanged}
.hass=${this.hass}
.highlight=${this.highlightedConditions?.includes(cond)}
?highlight=${this.highlightedConditions?.includes(cond)}
.optionsInSidebar=${this.optionsInSidebar}
.sortSelected=${this._rowSortSelected === idx}
@stop-sort-selection=${this._stopSortSelection}
>
${!this.disabled
${this._showReorder && !this.disabled
? html`
<div
tabindex="0"
class="handle ${this._rowSortSelected === idx
? "active"
: ""}"
slot="icons"
@keydown=${this._handleDragKeydown}
.index=${idx}
>
<div class="handle" slot="icons">
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
</div>
`
@@ -228,9 +203,6 @@ export default class HaAutomationCondition extends LitElement {
}
private _addConditionDialog() {
if (this.narrow) {
fireEvent(this, "request-close-sidebar");
}
showAddAutomationElementDialog(this, {
type: "condition",
add: this._addCondition,
@@ -279,27 +251,15 @@ export default class HaAutomationCondition extends LitElement {
private _moveUp(ev) {
ev.stopPropagation();
const index = (ev.target as any).index;
if (!(ev.target as HaAutomationConditionRow).first) {
const newIndex = index - 1;
this._move(index, newIndex);
if (this._rowSortSelected === index) {
this._rowSortSelected = newIndex;
}
ev.target.focus();
}
const newIndex = index - 1;
this._move(index, newIndex);
}
private _moveDown(ev) {
ev.stopPropagation();
const index = (ev.target as any).index;
if (!(ev.target as HaAutomationConditionRow).last) {
const newIndex = index + 1;
this._move(index, newIndex);
if (this._rowSortSelected === index) {
this._rowSortSelected = newIndex;
}
ev.target.focus();
}
const newIndex = index + 1;
this._move(index, newIndex);
}
private _move(oldIndex: number, newIndex: number) {
@@ -319,11 +279,6 @@ export default class HaAutomationCondition extends LitElement {
private async _conditionAdded(ev: CustomEvent): Promise<void> {
ev.stopPropagation();
const { index, data } = ev.detail;
let selected = false;
if (data?.["ha-automation-row-selected"]) {
selected = true;
delete data["ha-automation-row-selected"];
}
let conditions = [
...this.conditions.slice(0, index),
data,
@@ -331,9 +286,6 @@ export default class HaAutomationCondition extends LitElement {
];
// Add condition locally to avoid UI jump
this.conditions = conditions;
if (selected) {
this._focusConditionIndexOnChange = conditions.length === 1 ? 0 : index;
}
await nextRender();
if (this.conditions !== conditions) {
// Ensure condition is added even after update
@@ -342,9 +294,6 @@ export default class HaAutomationCondition extends LitElement {
data,
...this.conditions.slice(index),
];
if (selected) {
this._focusConditionIndexOnChange = conditions.length === 1 ? 0 : index;
}
}
fireEvent(this, "value-changed", { value: conditions });
}
@@ -359,12 +308,7 @@ export default class HaAutomationCondition extends LitElement {
// Ensure condition is removed even after update
const conditions = this.conditions.filter((c) => c !== condition);
fireEvent(this, "value-changed", { value: conditions });
}
private _conditionCloned(ev: CustomEvent<HaSortableClonedEventData>) {
if (ev.detail.item.isSelected()) {
ev.detail.item.condition["ha-automation-row-selected"] = true;
}
fireEvent(this, "close-sidebar");
}
private _conditionChanged(ev: CustomEvent) {
@@ -396,21 +340,44 @@ export default class HaAutomationCondition extends LitElement {
});
}
private _handleDragKeydown(ev: KeyboardEvent) {
if (ev.key === "Enter" || ev.key === " ") {
ev.stopPropagation();
this._rowSortSelected =
this._rowSortSelected === undefined
? (ev.target as any).index
: undefined;
static styles = css`
.conditions {
padding: 16px 0 16px 16px;
margin: -16px;
display: flex;
flex-direction: column;
gap: 16px;
}
}
private _stopSortSelection() {
this._rowSortSelected = undefined;
}
static styles = automationRowsStyles;
:host([root]) .conditions {
padding-right: 8px;
}
.sortable-ghost {
background: none;
border-radius: var(--ha-card-border-radius, var(--ha-border-radius-lg));
}
.sortable-drag {
background: none;
}
ha-automation-condition-row {
display: block;
scroll-margin-top: 48px;
}
.handle {
padding: 12px;
cursor: move; /* fallback if grab cursor is unsupported */
cursor: grab;
}
.handle ha-svg-icon {
pointer-events: none;
height: 24px;
}
.buttons {
display: flex;
flex-wrap: wrap;
gap: 8px;
order: 1;
}
`;
}
declare global {

View File

@@ -1,10 +1,9 @@
import { html, LitElement } from "lit";
import { customElement, property, query } from "lit/decorators";
import { customElement, property } from "lit/decorators";
import { fireEvent } from "../../../../../common/dom/fire_event";
import type { LogicalCondition } from "../../../../../data/automation";
import type { HomeAssistant } from "../../../../../types";
import "../ha-automation-condition";
import type HaAutomationCondition from "../ha-automation-condition";
import type { ConditionElement } from "../ha-automation-condition-row";
@customElement("ha-automation-condition-logical")
@@ -23,9 +22,6 @@ export abstract class HaLogicalCondition
@property({ type: Boolean, attribute: "sidebar" }) public optionsInSidebar =
false;
@query("ha-automation-condition")
private _conditionElement?: HaAutomationCondition;
protected render() {
return html`
<ha-automation-condition
@@ -39,14 +35,6 @@ export abstract class HaLogicalCondition
`;
}
public expandAll() {
this._conditionElement?.expandAll?.();
}
public collapseAll() {
this._conditionElement?.collapseAll?.();
}
private _valueChanged(ev: CustomEvent): void {
ev.stopPropagation();
fireEvent(this, "value-changed", {

View File

@@ -16,8 +16,6 @@ import {
mdiStopCircleOutline,
mdiTag,
mdiTransitConnection,
mdiUnfoldLessHorizontal,
mdiUnfoldMoreHorizontal,
} from "@mdi/js";
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
@@ -27,6 +25,7 @@ import { classMap } from "lit/directives/class-map";
import { transform } from "../../../common/decorators/transform";
import { fireEvent } from "../../../common/dom/fire_event";
import { navigate } from "../../../common/navigate";
import { computeRTL } from "../../../common/util/compute_rtl";
import { promiseTimeout } from "../../../common/util/promise-timeout";
import { afterNextRender } from "../../../common/util/render-status";
import "../../../components/ha-button";
@@ -371,30 +370,6 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
<ha-svg-icon slot="graphic" .path=${mdiPlaylistEdit}></ha-svg-icon>
</ha-list-item>
${!useBlueprint
? html`
<ha-list-item graphic="icon" @click=${this._collapseAll}>
<ha-svg-icon
slot="graphic"
.path=${mdiUnfoldLessHorizontal}
></ha-svg-icon>
${this.hass.localize(
"ui.panel.config.automation.editor.collapse_all"
)}
</ha-list-item>
<ha-list-item graphic="icon" @click=${this._expandAll}>
<ha-svg-icon
slot="graphic"
.path=${mdiUnfoldMoreHorizontal}
></ha-svg-icon>
${this.hass.localize(
"ui.panel.config.automation.editor.expand_all"
)}
</ha-list-item>
`
: nothing}
<li divider role="separator"></li>
<ha-list-item
@@ -432,9 +407,69 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
class=${this._mode === "yaml" ? "yaml-mode" : ""}
@subscribe-automation-config=${this._subscribeAutomationConfig}
>
<div class="error-wrapper">
${this._errors || stateObj?.state === UNAVAILABLE
? html`<ha-alert
alert-type="error"
.title=${stateObj?.state === UNAVAILABLE
? this.hass.localize(
"ui.panel.config.automation.editor.unavailable"
)
: undefined}
>
${this._errors || this._validationErrors}
${stateObj?.state === UNAVAILABLE
? html`<ha-svg-icon
slot="icon"
.path=${mdiRobotConfused}
></ha-svg-icon>`
: nothing}
</ha-alert>`
: ""}
${this._blueprintConfig
? html`<ha-alert alert-type="info">
${this.hass.localize(
"ui.panel.config.automation.editor.confirm_take_control"
)}
<div slot="action" style="display: flex;">
<ha-button
appearance="plain"
@click=${this._takeControlSave}
>${this.hass.localize("ui.common.yes")}</ha-button
>
<ha-button
appearance="plain"
@click=${this._revertBlueprint}
>${this.hass.localize("ui.common.no")}</ha-button
>
</div>
</ha-alert>`
: this._readOnly
? html`<ha-alert alert-type="warning" dismissable
>${this.hass.localize(
"ui.panel.config.automation.editor.read_only"
)}
<ha-button
appearance="filled"
size="small"
variant="warning"
slot="action"
@click=${this._duplicate}
>
${this.hass.localize(
"ui.panel.config.automation.editor.migrate"
)}
</ha-button>
</ha-alert>`
: nothing}
</div>
${this._mode === "gui"
? html`
<div>
<div
class=${classMap({
rtl: computeRTL(this.hass),
})}
>
${useBlueprint
? html`
<blueprint-automation-editor
@@ -443,7 +478,7 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
.isWide=${this.isWide}
.stateObj=${stateObj}
.config=${this._config}
.disabled=${this._readOnly}
.disabled=${Boolean(this._readOnly)}
.saving=${this._saving}
.dirty=${this._dirty}
@value-changed=${this._valueChanged}
@@ -457,94 +492,13 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
.isWide=${this.isWide}
.stateObj=${stateObj}
.config=${this._config}
.disabled=${this._readOnly}
.disabled=${Boolean(this._readOnly)}
.dirty=${this._dirty}
.saving=${this._saving}
@value-changed=${this._valueChanged}
@save-automation=${this._handleSaveAutomation}
@editor-save=${this._handleSaveAutomation}
>
<div class="alert-wrapper" slot="alerts">
${this._errors || stateObj?.state === UNAVAILABLE
? html`<ha-alert
alert-type="error"
.title=${stateObj?.state === UNAVAILABLE
? this.hass.localize(
"ui.panel.config.automation.editor.unavailable"
)
: undefined}
>
${this._errors || this._validationErrors}
${stateObj?.state === UNAVAILABLE
? html`<ha-svg-icon
slot="icon"
.path=${mdiRobotConfused}
></ha-svg-icon>`
: nothing}
</ha-alert>`
: nothing}
${this._blueprintConfig
? html`<ha-alert alert-type="info">
${this.hass.localize(
"ui.panel.config.automation.editor.confirm_take_control"
)}
<div slot="action" style="display: flex;">
<ha-button
appearance="plain"
@click=${this._takeControlSave}
>${this.hass.localize(
"ui.common.yes"
)}</ha-button
>
<ha-button
appearance="plain"
@click=${this._revertBlueprint}
>${this.hass.localize(
"ui.common.no"
)}</ha-button
>
</div>
</ha-alert>`
: this._readOnly
? html`<ha-alert
alert-type="warning"
dismissable
>${this.hass.localize(
"ui.panel.config.automation.editor.read_only"
)}
<ha-button
appearance="filled"
size="small"
variant="warning"
slot="action"
@click=${this._duplicate}
>
${this.hass.localize(
"ui.panel.config.automation.editor.migrate"
)}
</ha-button>
</ha-alert>`
: nothing}
${stateObj?.state === "off"
? html`
<ha-alert alert-type="info">
${this.hass.localize(
"ui.panel.config.automation.editor.disabled"
)}
<ha-button
size="small"
slot="action"
@click=${this._toggle}
>
${this.hass.localize(
"ui.panel.config.automation.editor.enable"
)}
</ha-button>
</ha-alert>
`
: nothing}
</div>
</manual-automation-editor>
></manual-automation-editor>
`}
</div>
`
@@ -567,7 +521,7 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
</ha-button>
</ha-alert>
`
: nothing}
: ""}
<ha-yaml-editor
copy-clipboard
.hass=${this.hass}
@@ -581,10 +535,12 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
<ha-fab
slot="fab"
class=${this._dirty ? "dirty" : ""}
.label=${this.hass.localize("ui.common.save")}
.label=${this.hass.localize(
"ui.panel.config.automation.editor.save"
)}
.disabled=${this._saving}
extended
@click=${this._handleSaveAutomation}
@click=${this._saveAutomation}
>
<ha-svg-icon
slot="icon"
@@ -1149,14 +1105,6 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
return this._confirmUnsavedChanged();
}
private _collapseAll() {
this._manualEditor?.collapseAll();
}
private _expandAll() {
this._manualEditor?.expandAll();
}
static get styles(): CSSResultGroup {
return [
haStyle,
@@ -1181,6 +1129,22 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
display: block;
}
:not(.yaml-mode) > .error-wrapper {
position: absolute;
top: 4px;
z-index: 3;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
:not(.yaml-mode) > .error-wrapper ha-alert {
background-color: var(--card-background-color);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
border-radius: var(--ha-border-radius-sm);
}
manual-automation-editor {
max-width: 1540px;
padding: 0 12px;

View File

@@ -1,143 +1,84 @@
import {
mdiClose,
mdiDelete,
mdiDotsVertical,
mdiIdentifier,
mdiPlayCircleOutline,
mdiPlaylistEdit,
mdiRenameBox,
mdiStopCircleOutline,
} from "@mdi/js";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import "../../../components/ha-bottom-sheet";
import type { HaBottomSheet } from "../../../components/ha-bottom-sheet";
import {
isCondition,
isScriptField,
isTrigger,
type ActionSidebarConfig,
type ConditionSidebarConfig,
type ScriptFieldSidebarConfig,
type SidebarConfig,
type TriggerSidebarConfig,
} from "../../../data/automation";
import { classMap } from "lit/directives/class-map";
import { fireEvent } from "../../../common/dom/fire_event";
import { stopPropagation } from "../../../common/dom/stop_propagation";
import { handleStructError } from "../../../common/structs/handle-errors";
import type { LocalizeKeys } from "../../../common/translations/localize";
import "../../../components/ha-card";
import "../../../components/ha-dialog-header";
import "../../../components/ha-icon-button";
import "../../../components/ha-md-button-menu";
import "../../../components/ha-md-divider";
import "../../../components/ha-md-menu-item";
import type { Condition, Trigger } from "../../../data/automation";
import type { Action, RepeatAction } from "../../../data/script";
import { isTriggerList } from "../../../data/trigger";
import type { HomeAssistant } from "../../../types";
import "./sidebar/ha-automation-sidebar-action";
import "./sidebar/ha-automation-sidebar-condition";
import "./sidebar/ha-automation-sidebar-option";
import "./sidebar/ha-automation-sidebar-script-field";
import "./sidebar/ha-automation-sidebar-script-field-selector";
import "./sidebar/ha-automation-sidebar-trigger";
import "./action/ha-automation-action-editor";
import { getAutomationActionType } from "./action/ha-automation-action-row";
import { getRepeatType } from "./action/types/ha-automation-action-repeat";
import "./condition/ha-automation-condition-editor";
import type HaAutomationConditionEditor from "./condition/ha-automation-condition-editor";
import "./ha-automation-editor-warning";
import "./trigger/ha-automation-trigger-editor";
import type HaAutomationTriggerEditor from "./trigger/ha-automation-trigger-editor";
import { ACTION_BUILDING_BLOCKS } from "../../../data/action";
import { CONDITION_BUILDING_BLOCKS } from "../../../data/condition";
export interface OpenSidebarConfig {
save: (config: Trigger | Condition | Action) => void;
close: () => void;
rename: () => void;
toggleYamlMode: () => boolean;
disable: () => void;
delete: () => void;
config: Trigger | Condition | Action;
type: "trigger" | "condition" | "action" | "option";
uiSupported: boolean;
yamlMode: boolean;
}
@customElement("ha-automation-sidebar")
export default class HaAutomationSidebar extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public config?: SidebarConfig;
@property({ attribute: false }) public config?: OpenSidebarConfig;
@property({ type: Boolean, attribute: "wide" }) public isWide = false;
@property({ type: Boolean }) public disabled = false;
@property({ type: Boolean }) public narrow = false;
@property({ attribute: "sidebar-key" }) public sidebarKey?: string;
@state() private _yamlMode = false;
@query("ha-bottom-sheet") private _bottomSheetElement?: HaBottomSheet;
@state() private _requestShowId = false;
private _renderContent() {
// get config type
const type = this._getType();
@state() private _warnings?: string[];
if (type === "trigger") {
return html`
<ha-automation-sidebar-trigger
class="sidebar-content"
.hass=${this.hass}
.config=${this.config}
.isWide=${this.isWide}
.narrow=${this.narrow}
.disabled=${this.disabled}
.yamlMode=${this._yamlMode}
.sidebarKey=${this.sidebarKey}
@toggle-yaml-mode=${this._toggleYamlMode}
@close-sidebar=${this._handleCloseSidebar}
></ha-automation-sidebar-trigger>
`;
}
if (type === "condition") {
return html`
<ha-automation-sidebar-condition
class="sidebar-content"
.hass=${this.hass}
.config=${this.config}
.isWide=${this.isWide}
.narrow=${this.narrow}
.disabled=${this.disabled}
.yamlMode=${this._yamlMode}
.sidebarKey=${this.sidebarKey}
@toggle-yaml-mode=${this._toggleYamlMode}
@close-sidebar=${this._handleCloseSidebar}
></ha-automation-sidebar-condition>
`;
}
if (type === "action") {
return html`
<ha-automation-sidebar-action
class="sidebar-content"
.hass=${this.hass}
.config=${this.config}
.isWide=${this.isWide}
.narrow=${this.narrow}
.disabled=${this.disabled}
.yamlMode=${this._yamlMode}
.sidebarKey=${this.sidebarKey}
@toggle-yaml-mode=${this._toggleYamlMode}
@close-sidebar=${this._handleCloseSidebar}
></ha-automation-sidebar-action>
`;
}
if (type === "option") {
return html`
<ha-automation-sidebar-option
class="sidebar-content"
.hass=${this.hass}
.config=${this.config}
.isWide=${this.isWide}
.narrow=${this.narrow}
.disabled=${this.disabled}
@close-sidebar=${this._handleCloseSidebar}
></ha-automation-sidebar-option>
`;
}
if (type === "script-field-selector") {
return html`
<ha-automation-sidebar-script-field-selector
class="sidebar-content"
.hass=${this.hass}
.config=${this.config}
.isWide=${this.isWide}
.narrow=${this.narrow}
.disabled=${this.disabled}
.yamlMode=${this._yamlMode}
.sidebarKey=${this.sidebarKey}
@toggle-yaml-mode=${this._toggleYamlMode}
@close-sidebar=${this._handleCloseSidebar}
></ha-automation-sidebar-script-field-selector>
`;
}
if (type === "script-field") {
return html`
<ha-automation-sidebar-script-field
class="sidebar-content"
.hass=${this.hass}
.config=${this.config}
.isWide=${this.isWide}
.narrow=${this.narrow}
.disabled=${this.disabled}
.yamlMode=${this._yamlMode}
.sidebarKey=${this.sidebarKey}
@toggle-yaml-mode=${this._toggleYamlMode}
@close-sidebar=${this._handleCloseSidebar}
></ha-automation-sidebar-script-field>
`;
}
@query(".sidebar-editor")
public editor?: HaAutomationTriggerEditor | HaAutomationConditionEditor;
return nothing;
protected willUpdate(changedProperties) {
if (changedProperties.has("config")) {
this._requestShowId = false;
this._warnings = undefined;
if (this.config) {
this._yamlMode = this.config.yamlMode;
if (this._yamlMode) {
this.editor?.yamlEditor?.setValue(this.config.config);
}
}
}
}
protected render() {
@@ -145,84 +86,320 @@ export default class HaAutomationSidebar extends LitElement {
return nothing;
}
if (this.narrow) {
return html`
<ha-bottom-sheet @bottom-sheet-closed=${this._closeSidebar}>
${this._renderContent()}
</ha-bottom-sheet>
`;
const disabled =
this.disabled ||
("enabled" in this.config.config && this.config.config.enabled === false);
let type = isTriggerList(this.config.config as Trigger)
? "list"
: this.config.type === "action"
? getAutomationActionType(this.config.config as Action)
: this.config.config[this.config.type];
if (this.config.type === "action" && type === "repeat") {
type = `repeat_${getRepeatType((this.config.config as RepeatAction).repeat)}`;
}
return this._renderContent();
const isBuildingBlock = [
...CONDITION_BUILDING_BLOCKS,
...ACTION_BUILDING_BLOCKS,
].includes(type);
const subtitle = this.hass.localize(
(this.config.type === "option"
? "ui.panel.config.automation.editor.actions.type.choose.label"
: `ui.panel.config.automation.editor.${this.config.type}s.${this.config.type}`) as LocalizeKeys
);
const title =
this.hass.localize(
(this.config.type === "option"
? "ui.panel.config.automation.editor.actions.type.choose.option_label"
: `ui.panel.config.automation.editor.${this.config.type}s.type.${type}.label`) as LocalizeKeys
) || type;
const description =
isBuildingBlock || this.config.type === "option"
? this.hass.localize(
(this.config.type === "option"
? "ui.panel.config.automation.editor.actions.type.choose.option_description"
: `ui.panel.config.automation.editor.${this.config.type}s.type.${type}.description.picker`) as LocalizeKeys
)
: "";
return html`
<ha-card
outlined
class=${classMap({
mobile: !this.isWide,
yaml: this._yamlMode,
})}
>
<ha-dialog-header>
<ha-icon-button
slot="navigationIcon"
.label=${this.hass.localize("ui.common.close")}
.path=${mdiClose}
@click=${this._closeSidebar}
></ha-icon-button>
<span slot="title">${title}</span>
<span slot="subtitle">${subtitle}</span>
<ha-md-button-menu
slot="actionItems"
@click=${this._openOverflowMenu}
@keydown=${stopPropagation}
@closed=${stopPropagation}
positioning="fixed"
>
<ha-icon-button
slot="trigger"
.label=${this.hass.localize("ui.common.menu")}
.path=${mdiDotsVertical}
></ha-icon-button>
<ha-md-menu-item
.clickAction=${this.config.rename}
.disabled=${disabled || type === "list"}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.rename"
)}
<ha-svg-icon slot="start" .path=${mdiRenameBox}></ha-svg-icon>
</ha-md-menu-item>
${this.config.type === "trigger" &&
!this._yamlMode &&
!("id" in this.config.config) &&
!this._requestShowId
? html`<ha-md-menu-item
.clickAction=${this._showTriggerId}
.disabled=${disabled || type === "list"}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.edit_id"
)}
<ha-svg-icon
slot="start"
.path=${mdiIdentifier}
></ha-svg-icon>
</ha-md-menu-item>`
: nothing}
${this.config.type !== "option"
? html`
<ha-md-menu-item
.clickAction=${this._toggleYamlMode}
.disabled=${!this.config.uiSupported || !!this._warnings}
>
${this.hass.localize(
`ui.panel.config.automation.editor.edit_${!this._yamlMode ? "yaml" : "ui"}`
)}
<ha-svg-icon
slot="start"
.path=${mdiPlaylistEdit}
></ha-svg-icon>
</ha-md-menu-item>
`
: nothing}
<ha-md-divider role="separator" tabindex="-1"></ha-md-divider>
${this.config.type !== "option"
? html`
<ha-md-menu-item
.clickAction=${this.config.disable}
.disabled=${this.disabled || type === "list"}
>
${disabled
? this.hass.localize(
"ui.panel.config.automation.editor.actions.enable"
)
: this.hass.localize(
"ui.panel.config.automation.editor.actions.disable"
)}
<ha-svg-icon
slot="start"
.path=${disabled
? mdiPlayCircleOutline
: mdiStopCircleOutline}
></ha-svg-icon>
</ha-md-menu-item>
`
: nothing}
<ha-md-menu-item
.clickAction=${this.config.delete}
class="warning"
.disabled=${this.disabled}
>
${this.hass.localize(
`ui.panel.config.automation.editor.actions.${this.config.type !== "option" ? "delete" : "type.choose.remove_option"}`
)}
<ha-svg-icon
class="warning"
slot="start"
.path=${mdiDelete}
></ha-svg-icon>
</ha-md-menu-item>
</ha-md-button-menu>
</ha-dialog-header>
${this._warnings
? html`<ha-automation-editor-warning
.localize=${this.hass.localize}
.warnings=${this._warnings}
>
</ha-automation-editor-warning>`
: nothing}
<div class="card-content">
${this.config.type === "trigger"
? html`<ha-automation-trigger-editor
class="sidebar-editor"
.hass=${this.hass}
.trigger=${this.config.config as Trigger}
@value-changed=${this._valueChangedSidebar}
.uiSupported=${this.config.uiSupported}
.showId=${this._requestShowId}
.yamlMode=${this._yamlMode}
.disabled=${this.disabled}
@ui-mode-not-available=${this._handleUiModeNotAvailable}
></ha-automation-trigger-editor>`
: this.config.type === "condition" &&
(this._yamlMode || !CONDITION_BUILDING_BLOCKS.includes(type))
? html`
<ha-automation-condition-editor
class="sidebar-editor"
.hass=${this.hass}
.condition=${this.config.config as Condition}
.yamlMode=${this._yamlMode}
.uiSupported=${this.config.uiSupported}
@value-changed=${this._valueChangedSidebar}
.disabled=${this.disabled}
@ui-mode-not-available=${this._handleUiModeNotAvailable}
></ha-automation-condition-editor>
`
: this.config.type === "action" &&
(this._yamlMode || !ACTION_BUILDING_BLOCKS.includes(type))
? html`
<ha-automation-action-editor
class="sidebar-editor"
.hass=${this.hass}
.action=${this.config.config as Action}
.yamlMode=${this._yamlMode}
.uiSupported=${this.config.uiSupported}
@value-changed=${this._valueChangedSidebar}
sidebar
narrow
.disabled=${this.disabled}
@ui-mode-not-available=${this._handleUiModeNotAvailable}
></ha-automation-action-editor>
`
: description || nothing}
</div>
</ha-card>
`;
}
private _getType() {
if (
(this.config as TriggerSidebarConfig)?.config &&
(isTrigger((this.config as TriggerSidebarConfig)?.config) ||
isTriggerList((this.config as TriggerSidebarConfig)?.config))
) {
return "trigger";
private _handleUiModeNotAvailable(ev: CustomEvent) {
this._warnings = handleStructError(this.hass, ev.detail).warnings;
if (!this._yamlMode) {
this._yamlMode = true;
}
if (isCondition((this.config as ConditionSidebarConfig)?.config)) {
return "condition";
}
if (
(this.config as ScriptFieldSidebarConfig)?.config &&
isScriptField((this.config as ScriptFieldSidebarConfig)?.config)
) {
return (this.config as ScriptFieldSidebarConfig)?.config.selector
? "script-field-selector"
: "script-field";
}
// option is always a building block and doesn't have a config
if (this.config && !(this.config as any)?.config) {
return "option";
}
if ((this.config as ActionSidebarConfig)?.config.action) {
return "action";
}
return undefined;
}
private _handleCloseSidebar(ev: CustomEvent) {
private _valueChangedSidebar(ev: CustomEvent) {
ev.stopPropagation();
if (this.narrow) {
this._bottomSheetElement?.closeSheet();
return;
}
this._closeSidebar();
this.config?.save(ev.detail.value);
if (this.config) {
fireEvent(this, "value-changed", {
value: {
...this.config,
config: ev.detail.value,
},
});
}
}
private _closeSidebar() {
this.config?.close(true);
this.config?.close();
}
private _openOverflowMenu(ev: MouseEvent) {
ev.stopPropagation();
ev.preventDefault();
}
private _toggleYamlMode = () => {
(this.config as ActionSidebarConfig)?.toggleYamlMode();
this._yamlMode = this.config!.toggleYamlMode();
fireEvent(this, "value-changed", {
value: {
...this.config,
yamlMode: this._yamlMode,
},
});
};
private _showTriggerId = () => {
this._requestShowId = true;
};
static styles = css`
:host {
outline: none;
height: 100%;
--ha-card-border-radius: var(
--ha-dialog-border-radius,
var(--ha-border-radius-2xl)
);
border-radius: var(--ha-card-border-radius);
--ha-bottom-sheet-border-width: 2px;
--ha-bottom-sheet-border-style: solid;
--ha-bottom-sheet-border-color: var(--primary-color);
}
ha-card {
height: 100%;
width: 100%;
border-color: var(--primary-color);
border-width: 2px;
display: block;
}
ha-card.mobile {
border-bottom-right-radius: var(--ha-border-radius-square);
border-bottom-left-radius: var(--ha-border-radius-square);
}
@media all and (max-width: 870px) {
.sidebar-content {
max-height: 100%;
ha-card.mobile {
max-height: 70vh;
max-height: 70dvh;
border-width: 2px 2px 0;
}
ha-card.mobile.yaml {
height: 70vh;
height: 70dvh;
}
}
ha-dialog-header {
border-radius: var(--ha-card-border-radius);
}
.sidebar-editor {
padding-top: 64px;
}
.card-content {
max-height: calc(100% - 80px);
overflow: auto;
}
@media (min-width: 450px) and (min-height: 500px) {
.card-content {
max-height: calc(100% - 104px);
overflow: auto;
}
}
@media all and (max-width: 870px) {
ha-card.mobile .card-content {
max-height: calc(
70vh - 88px - max(var(--safe-area-inset-bottom), 16px)
);
max-height: calc(
70dvh - 88px - max(var(--safe-area-inset-bottom), 16px)
);
}
}
`;
@@ -232,11 +409,4 @@ declare global {
interface HTMLElementTagNameMap {
"ha-automation-sidebar": HaAutomationSidebar;
}
interface HASSDomEvents {
"toggle-yaml-mode": undefined;
"yaml-changed": {
value: unknown;
};
}
}

View File

@@ -3,7 +3,7 @@ import type { HassEntity } from "home-assistant-js-websocket";
import { load } from "js-yaml";
import type { CSSResultGroup, PropertyValues } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import {
any,
@@ -31,7 +31,6 @@ import type {
AutomationConfig,
Condition,
ManualAutomationConfig,
SidebarConfig,
Trigger,
} from "../../../data/automation";
import {
@@ -48,10 +47,11 @@ import type HaAutomationAction from "./action/ha-automation-action";
import "./condition/ha-automation-condition";
import type HaAutomationCondition from "./condition/ha-automation-condition";
import "./ha-automation-sidebar";
import type HaAutomationSidebar from "./ha-automation-sidebar";
import type { OpenSidebarConfig } from "./ha-automation-sidebar";
import { showPasteReplaceDialog } from "./paste-replace-dialog/show-dialog-paste-replace";
import { manualEditorStyles, saveFabStyles } from "./styles";
import { saveFabStyles } from "./styles";
import "./trigger/ha-automation-trigger";
import type HaAutomationTrigger from "./trigger/ha-automation-trigger";
const baseConfigStruct = object({
alias: optional(string()),
@@ -90,11 +90,7 @@ export class HaManualAutomationEditor extends LitElement {
@state() private _pastedConfig?: ManualAutomationConfig;
@state() private _sidebarConfig?: SidebarConfig;
@state() private _sidebarKey?: string;
@query("ha-automation-sidebar") private _sidebarElement?: HaAutomationSidebar;
@state() private _sidebarConfig?: OpenSidebarConfig;
private _previousConfig?: ManualAutomationConfig;
@@ -108,8 +104,47 @@ export class HaManualAutomationEditor extends LitElement {
super.disconnectedCallback();
}
protected firstUpdated(changedProps: PropertyValues): void {
super.firstUpdated(changedProps);
const expanded = extractSearchParam("expanded");
if (expanded === "1") {
this._clearParam("expanded");
const items = this.shadowRoot!.querySelectorAll<
HaAutomationTrigger | HaAutomationCondition | HaAutomationAction
>("ha-automation-trigger, ha-automation-condition, ha-automation-action");
items.forEach((el) => {
el.updateComplete.then(() => {
el.expandAll();
});
});
}
}
private _clearParam(param: string) {
window.history.replaceState(
null,
"",
constructUrlCurrentPath(removeSearchParam(param))
);
}
private _renderContent() {
return html`
${this.stateObj?.state === "off"
? html`
<ha-alert alert-type="info">
${this.hass.localize(
"ui.panel.config.automation.editor.disabled"
)}
<ha-button size="small" slot="action" @click=${this._enable}>
${this.hass.localize(
"ui.panel.config.automation.editor.enable"
)}
</ha-button>
</ha-alert>
`
: nothing}
${this.config.description
? html`<ha-markdown
class="description"
@@ -154,7 +189,6 @@ export class HaManualAutomationEditor extends LitElement {
.disabled=${this.disabled || this.saving}
.narrow=${this.narrow}
@open-sidebar=${this._openSidebar}
@request-close-sidebar=${this._closeSidebar}
@close-sidebar=${this._handleCloseSidebar}
root
sidebar
@@ -201,7 +235,6 @@ export class HaManualAutomationEditor extends LitElement {
.disabled=${this.disabled || this.saving}
.narrow=${this.narrow}
@open-sidebar=${this._openSidebar}
@request-close-sidebar=${this._closeSidebar}
@close-sidebar=${this._handleCloseSidebar}
root
sidebar
@@ -243,7 +276,6 @@ export class HaManualAutomationEditor extends LitElement {
.highlightedActions=${this._pastedConfig?.actions || []}
@value-changed=${this._actionChanged}
@open-sidebar=${this._openSidebar}
@request-close-sidebar=${this._closeSidebar}
@close-sidebar=${this._handleCloseSidebar}
.hass=${this.hass}
.narrow=${this.narrow}
@@ -256,74 +288,45 @@ export class HaManualAutomationEditor extends LitElement {
protected render() {
return html`
<div
class=${classMap({
"has-sidebar": this._sidebarConfig && !this.narrow,
})}
>
<div class="split-view">
<div class="content-wrapper">
<div class="content">
<slot name="alerts"></slot>
${this._renderContent()}
</div>
<div class="fab-positioner">
<ha-fab
slot="fab"
class=${this.dirty ? "dirty" : ""}
.label=${this.hass.localize("ui.common.save")}
.disabled=${this.saving}
extended
@click=${this._saveAutomation}
>
<ha-svg-icon slot="icon" .path=${mdiContentSave}></ha-svg-icon>
</ha-fab>
</div>
</div>
<div class="sidebar-positioner">
<ha-automation-sidebar
tabindex="-1"
class=${classMap({ hidden: !this._sidebarConfig })}
.isWide=${this.isWide}
.hass=${this.hass}
.narrow=${this.narrow}
.config=${this._sidebarConfig}
@value-changed=${this._sidebarConfigChanged}
.disabled=${this.disabled}
.sidebarKey=${this._sidebarKey}
></ha-automation-sidebar>
<div class="content">${this._renderContent()}</div>
<ha-fab
slot="fab"
class=${this.dirty ? "dirty" : ""}
.label=${this.hass.localize(
"ui.panel.config.automation.editor.save"
)}
.disabled=${this.saving}
extended
@click=${this._saveAutomation}
>
<ha-svg-icon slot="icon" .path=${mdiContentSave}></ha-svg-icon>
</ha-fab>
</div>
<ha-automation-sidebar
class=${classMap({
sidebar: true,
hidden: !this._sidebarConfig,
overlay: !this.isWide,
})}
.isWide=${this.isWide}
.hass=${this.hass}
.config=${this._sidebarConfig}
@value-changed=${this._sidebarConfigChanged}
.disabled=${this.disabled}
></ha-automation-sidebar>
</div>
`;
}
protected firstUpdated(changedProps: PropertyValues): void {
super.firstUpdated(changedProps);
const expanded = extractSearchParam("expanded");
if (expanded === "1") {
this._clearParam("expanded");
this.expandAll();
}
}
private _clearParam(param: string) {
window.history.replaceState(
null,
"",
constructUrlCurrentPath(removeSearchParam(param))
);
}
private async _openSidebar(ev: CustomEvent<SidebarConfig>) {
private _openSidebar(ev: CustomEvent<OpenSidebarConfig>) {
// deselect previous selected row
this._sidebarConfig?.close?.();
this._sidebarConfig = ev.detail;
this._sidebarKey = JSON.stringify(this._sidebarConfig);
await this._sidebarElement?.updateComplete;
this._sidebarElement?.focus();
}
private _sidebarConfigChanged(ev: CustomEvent<{ value: SidebarConfig }>) {
private _sidebarConfigChanged(ev: CustomEvent<{ value: OpenSidebarConfig }>) {
ev.stopPropagation();
if (!this._sidebarConfig) {
return;
@@ -337,7 +340,9 @@ export class HaManualAutomationEditor extends LitElement {
private _closeSidebar() {
if (this._sidebarConfig) {
this._sidebarConfig?.close();
const closeRow = this._sidebarConfig?.close;
this._sidebarConfig = undefined;
closeRow?.();
}
}
@@ -372,6 +377,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,
});
}
private _saveAutomation() {
this._closeSidebar();
fireEvent(this, "save-automation");
@@ -587,29 +601,82 @@ export class HaManualAutomationEditor extends LitElement {
});
}
private _getCollapsableElements() {
return this.shadowRoot!.querySelectorAll<
HaAutomationAction | HaAutomationCondition
>("ha-automation-action, ha-automation-condition");
}
public expandAll() {
this._getCollapsableElements().forEach((element) => {
element.expandAll();
});
}
public collapseAll() {
this._getCollapsableElements().forEach((element) => {
element.collapseAll();
});
}
static get styles(): CSSResultGroup {
return [
saveFabStyles,
manualEditorStyles,
css`
:host {
display: block;
}
.split-view {
display: flex;
flex-direction: row;
height: 100%;
position: relative;
gap: 16px;
}
.content-wrapper {
position: relative;
flex: 6;
}
.content {
padding: 32px 16px 64px 0;
height: calc(100vh - 153px);
height: calc(100dvh - 153px);
overflow-y: auto;
overflow-x: hidden;
}
.sidebar {
padding: 12px 0;
flex: 4;
height: calc(100vh - 81px);
height: calc(100dvh - 81px);
width: 40%;
}
.sidebar.hidden {
border-color: transparent;
border-width: 0;
overflow: hidden;
flex: 0;
visibility: hidden;
}
.sidebar.overlay {
position: fixed;
bottom: 0;
right: 0;
height: calc(100% - 64px);
padding: 0;
z-index: 5;
}
@media all and (max-width: 870px) {
.sidebar.overlay {
max-height: 70vh;
max-height: 70dvh;
height: auto;
width: 100%;
box-shadow: 0px -8px 16px rgba(0, 0, 0, 0.2);
}
}
@media all and (max-width: 870px) {
.sidebar.overlay.hidden {
height: 0;
}
}
.sidebar.overlay.hidden {
width: 0;
}
.description {
margin: 0;
}
p {
margin-top: 0;
}
@@ -625,7 +692,10 @@ export class HaManualAutomationEditor extends LitElement {
.header .name {
font-weight: var(--ha-font-weight-normal);
flex: 1;
margin-bottom: 8px;
margin-bottom: 16px;
}
.header a {
color: var(--secondary-text-color);
}
.header .small {
font-size: small;
@@ -633,8 +703,9 @@ export class HaManualAutomationEditor extends LitElement {
line-height: 0;
}
.description {
margin-top: 16px;
ha-alert {
display: block;
margin-bottom: 16px;
}
`,
];
@@ -647,8 +718,7 @@ declare global {
}
interface HASSDomEvents {
"open-sidebar": SidebarConfig;
"request-close-sidebar": undefined;
"open-sidebar": OpenSidebarConfig;
"close-sidebar": undefined;
}
}

View File

@@ -9,7 +9,7 @@ import {
} from "@mdi/js";
import type { CSSResultGroup } from "lit";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { ensureArray } from "../../../../common/array/ensure-array";
import { fireEvent } from "../../../../common/dom/fire_event";
@@ -17,17 +17,13 @@ import { preventDefaultStopPropagation } from "../../../../common/dom/prevent_de
import { stopPropagation } from "../../../../common/dom/stop_propagation";
import { capitalizeFirstLetter } from "../../../../common/string/capitalize-first-letter";
import "../../../../components/ha-automation-row";
import type { HaAutomationRow } from "../../../../components/ha-automation-row";
import "../../../../components/ha-card";
import "../../../../components/ha-expansion-panel";
import "../../../../components/ha-icon-button";
import "../../../../components/ha-md-button-menu";
import "../../../../components/ha-md-menu-item";
import "../../../../components/ha-svg-icon";
import type {
Condition,
OptionSidebarConfig,
} from "../../../../data/automation";
import type { Condition } from "../../../../data/automation";
import { describeCondition } from "../../../../data/automation_i18n";
import { fullEntitiesContext } from "../../../../data/context";
import type { EntityRegistryEntry } from "../../../../data/entity_registry";
@@ -38,18 +34,14 @@ import {
} from "../../../../dialogs/generic/show-dialog-box";
import type { HomeAssistant } from "../../../../types";
import "../action/ha-automation-action";
import type HaAutomationAction from "../action/ha-automation-action";
import "../condition/ha-automation-condition";
import type HaAutomationCondition from "../condition/ha-automation-condition";
import { editorStyles, indentStyle, rowStyles } from "../styles";
import { editorStyles, rowStyles } from "../styles";
@customElement("ha-automation-option-row")
export default class HaAutomationOptionRow extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public option?: Option;
@property({ attribute: false }) public defaultActions?: Action[];
@property({ attribute: false }) public option!: Option;
@property({ type: Boolean }) public narrow = false;
@@ -64,28 +56,16 @@ export default class HaAutomationOptionRow extends LitElement {
@property({ type: Boolean, attribute: "sidebar" })
public optionsInSidebar = false;
@property({ type: Boolean, attribute: "sort-selected" })
public sortSelected = false;
@state() private _expanded = false;
@state() private _selected = false;
@state() private _collapsed = true;
@state() private _collapsed = false;
@state()
@consume({ context: fullEntitiesContext, subscribe: true })
_entityReg!: EntityRegistryEntry[];
@query("ha-automation-condition")
private _conditionElement?: HaAutomationCondition;
@query("ha-automation-action")
private _actionElement?: HaAutomationAction;
@query("ha-automation-row")
private _automationRowElement?: HaAutomationRow;
private _expandedChanged(ev) {
if (ev.currentTarget.id !== "option") {
return;
@@ -94,7 +74,7 @@ export default class HaAutomationOptionRow extends LitElement {
}
private _getDescription() {
const conditions = ensureArray<Condition | string>(this.option!.conditions);
const conditions = ensureArray<Condition | string>(this.option.conditions);
if (!conditions || conditions.length === 0) {
return this.hass.localize(
"ui.panel.config.automation.editor.actions.type.choose.no_conditions"
@@ -118,36 +98,30 @@ export default class HaAutomationOptionRow extends LitElement {
private _renderRow() {
return html`
<h3 slot="header">
${this.option
? `${this.hass.localize(
"ui.panel.config.automation.editor.actions.type.choose.option",
{ number: this.index + 1 }
)}: ${this.option.alias || (this._expanded ? "" : this._getDescription())}`
: this.hass.localize(
"ui.panel.config.automation.editor.actions.type.choose.default"
)}
${this.hass.localize(
"ui.panel.config.automation.editor.actions.type.choose.option",
{ number: this.index + 1 }
)}:
${this.option.alias || (this._expanded ? "" : this._getDescription())}
</h3>
<slot name="icons" slot="icons"></slot>
${this.option && !this.optionsInSidebar
? html`
<ha-md-button-menu
quick
slot="icons"
@click=${preventDefaultStopPropagation}
@closed=${stopPropagation}
@keydown=${stopPropagation}
positioning="fixed"
anchor-corner="end-end"
menu-corner="start-end"
>
<ha-icon-button
slot="trigger"
.label=${this.hass.localize("ui.common.menu")}
.path=${mdiDotsVertical}
></ha-icon-button>
<ha-md-button-menu
slot="icons"
@click=${preventDefaultStopPropagation}
@closed=${stopPropagation}
@keydown=${stopPropagation}
positioning="fixed"
>
<ha-icon-button
slot="trigger"
.label=${this.hass.localize("ui.common.menu")}
.path=${mdiDotsVertical}
></ha-icon-button>
${!this.optionsInSidebar
? html`
<ha-md-menu-item
@click=${this._renameOption}
.disabled=${this.disabled}
@@ -155,59 +129,56 @@ export default class HaAutomationOptionRow extends LitElement {
${this.hass.localize(
"ui.panel.config.automation.editor.actions.rename"
)}
<ha-svg-icon slot="start" .path=${mdiRenameBox}></ha-svg-icon>
<ha-svg-icon slot="graphic" .path=${mdiRenameBox}></ha-svg-icon>
</ha-md-menu-item>
`
: nothing}
<ha-md-menu-item
@click=${this._duplicateOption}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.duplicate"
)}
<ha-svg-icon
slot="start"
.path=${mdiContentDuplicate}
></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
@click=${this._duplicateOption}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.duplicate"
)}
<ha-svg-icon
slot="graphic"
.path=${mdiContentDuplicate}
></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
@click=${this._moveUp}
.disabled=${this.disabled || this.first}
>
${this.hass.localize(
"ui.panel.config.automation.editor.move_up"
)}
<ha-svg-icon slot="start" .path=${mdiArrowUp}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
@click=${this._moveUp}
.disabled=${this.disabled || this.first}
>
${this.hass.localize("ui.panel.config.automation.editor.move_up")}
<ha-svg-icon slot="graphic" .path=${mdiArrowUp}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
@click=${this._moveDown}
.disabled=${this.disabled || this.last}
>
${this.hass.localize(
"ui.panel.config.automation.editor.move_down"
)}
<ha-svg-icon slot="start" .path=${mdiArrowDown}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
@click=${this._moveDown}
.disabled=${this.disabled || this.last}
>
${this.hass.localize("ui.panel.config.automation.editor.move_down")}
<ha-svg-icon slot="graphic" .path=${mdiArrowDown}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
@click=${this._removeOption}
class="warning"
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.type.choose.remove_option"
)}
<ha-svg-icon
class="warning"
slot="graphic"
.path=${mdiDelete}
></ha-svg-icon>
</ha-md-menu-item>
</ha-md-button-menu>
<ha-md-menu-item
@click=${this._removeOption}
class="warning"
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.type.choose.remove_option"
)}
<ha-svg-icon
class="warning"
slot="start"
.path=${mdiDelete}
></ha-svg-icon>
</ha-md-menu-item>
</ha-md-button-menu>
`
: nothing}
${!this.optionsInSidebar ? this._renderContent() : nothing}
`;
}
@@ -216,42 +187,30 @@ export default class HaAutomationOptionRow extends LitElement {
return html`<div
class=${classMap({
"card-content": true,
card: !this.optionsInSidebar,
indent: this.optionsInSidebar,
selected: this._selected,
hidden: this.optionsInSidebar && this._collapsed,
})}
>
${this.option
? html`
<h4 class="top">
${this.hass.localize(
"ui.panel.config.automation.editor.actions.type.choose.conditions"
)}:
</h4>
<ha-automation-condition
.conditions=${ensureArray<string | Condition>(
this.option.conditions
)}
.disabled=${this.disabled}
.hass=${this.hass}
.narrow=${this.narrow}
@value-changed=${this._conditionChanged}
.optionsInSidebar=${this.optionsInSidebar}
></ha-automation-condition>
`
: nothing}
<h4 class=${this.option ? "" : "top"}>
<h4>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.type.choose.conditions"
)}:
</h4>
<ha-automation-condition
.conditions=${ensureArray<string | Condition>(this.option.conditions)}
.disabled=${this.disabled}
.hass=${this.hass}
.narrow=${this.narrow}
@value-changed=${this._conditionChanged}
.optionsInSidebar=${this.optionsInSidebar}
></ha-automation-condition>
<h4>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.type.choose.sequence"
)}:
</h4>
<ha-automation-action
.actions=${(this.option
? ensureArray(this.option.sequence) || []
: this.defaultActions
? ensureArray(this.defaultActions) || []
: []) as Action[]}
.actions=${ensureArray(this.option.sequence) || []}
.disabled=${this.disabled}
.hass=${this.hass}
.narrow=${this.narrow}
@@ -262,7 +221,7 @@ export default class HaAutomationOptionRow extends LitElement {
}
protected render() {
if (!this.option && !this.defaultActions) return nothing;
if (!this.option) return nothing;
return html`
<ha-card outlined class=${this._selected ? "selected" : ""}>
@@ -273,7 +232,6 @@ export default class HaAutomationOptionRow extends LitElement {
.selected=${this._selected}
@click=${this._toggleSidebar}
@toggle-collapsed=${this._toggleCollapse}
.sortSelected=${this.sortSelected}
>${this._renderRow()}</ha-automation-row
>`
: html`
@@ -287,13 +245,15 @@ export default class HaAutomationOptionRow extends LitElement {
`}
</ha-card>
${this.optionsInSidebar ? this._renderContent() : nothing}
${this.optionsInSidebar && !this._collapsed
? this._renderContent()
: nothing}
`;
}
private _duplicateOption = () => {
private _duplicateOption() {
fireEvent(this, "duplicate");
};
}
private _moveUp() {
fireEvent(this, "move-up");
@@ -335,7 +295,7 @@ export default class HaAutomationOptionRow extends LitElement {
),
inputType: "string",
placeholder: capitalizeFirstLetter(this._getDescription()),
defaultValue: this.option!.alias,
defaultValue: this.option.alias,
confirmText: this.hass.localize("ui.common.submit"),
});
if (alias !== null) {
@@ -361,9 +321,6 @@ export default class HaAutomationOptionRow extends LitElement {
}
private _actionChanged(ev: CustomEvent) {
if (this.defaultActions) {
return;
}
ev.stopPropagation();
const actions = ev.detail.value as Action[];
const value = { ...this.option, sequence: actions };
@@ -384,93 +341,52 @@ export default class HaAutomationOptionRow extends LitElement {
}
public openSidebar(): void {
if (this.narrow) {
this.scrollIntoView();
}
fireEvent(this, "open-sidebar", {
close: (focus?: boolean) => {
save: () => {
// nothing to save for an option in the sidebar
},
close: () => {
this._selected = false;
fireEvent(this, "close-sidebar");
if (focus) {
this.focus();
}
},
rename: () => {
this._renameOption();
},
toggleYamlMode: () => false, // no yaml mode for options
disable: () => {
// option cannot be disabled
},
delete: this._removeOption,
duplicate: this._duplicateOption,
defaultOption: !!this.defaultActions,
} satisfies OptionSidebarConfig);
config: {},
type: "option",
uiSupported: true,
yamlMode: false,
});
this._selected = true;
this._collapsed = false;
if (this.narrow) {
requestAnimationFrame(() => {
this.scrollIntoView({
block: "start",
behavior: "smooth",
});
});
}
}
public expand() {
if (this.optionsInSidebar) {
this._collapsed = false;
return;
}
this.updateComplete.then(() => {
this.shadowRoot!.querySelector("ha-expansion-panel")!.expanded = true;
});
}
public collapse() {
this._collapsed = true;
}
public expandAll() {
this.expand();
this._conditionElement?.expandAll();
this._actionElement?.expandAll();
}
public collapseAll() {
this.collapse();
this._conditionElement?.collapseAll();
this._actionElement?.collapseAll();
}
private _toggleCollapse() {
this._collapsed = !this._collapsed;
}
public isSelected() {
return this._selected;
}
public focus() {
this._automationRowElement?.focus();
}
static get styles(): CSSResultGroup {
return [
rowStyles,
editorStyles,
indentStyle,
css`
li[role="separator"] {
border-bottom-color: var(--divider-color);
}
h4 {
color: var(--ha-color-text-secondary);
}
h4 {
margin-bottom: 8px;
}
h4.top {
margin-top: 0;
}
`,
];
}

View File

@@ -2,19 +2,18 @@ import { mdiDrag, mdiPlus } from "@mdi/js";
import deepClone from "deep-clone-simple";
import type { PropertyValues } from "lit";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property, queryAll, state } from "lit/decorators";
import { customElement, property, state } from "lit/decorators";
import { repeat } from "lit/directives/repeat";
import { storage } from "../../../../common/decorators/storage";
import { fireEvent } from "../../../../common/dom/fire_event";
import { listenMediaQuery } from "../../../../common/dom/media_query";
import { nextRender } from "../../../../common/util/render-status";
import "../../../../components/ha-button";
import "../../../../components/ha-sortable";
import type { HaSortableClonedEventData } from "../../../../components/ha-sortable";
import "../../../../components/ha-svg-icon";
import type { AutomationClipboard } from "../../../../data/automation";
import type { Option } from "../../../../data/script";
import type { HomeAssistant } from "../../../../types";
import { automationRowsStyles } from "../styles";
import "./ha-automation-option-row";
import type HaAutomationOptionRow from "./ha-automation-option-row";
@@ -31,10 +30,7 @@ export default class HaAutomationOption extends LitElement {
@property({ type: Boolean, attribute: "sidebar" }) public optionsInSidebar =
false;
@property({ type: Boolean, attribute: "show-default" })
public showDefaultActions = false;
@state() private _rowSortSelected?: number;
@state() private _showReorder = false;
@state()
@storage({
@@ -45,29 +41,38 @@ export default class HaAutomationOption extends LitElement {
})
public _clipboard?: AutomationClipboard;
@queryAll("ha-automation-option-row")
private _optionRowElements?: HaAutomationOptionRow[];
private _focusLastOptionOnChange = false;
private _focusOptionIndexOnChange?: number;
private _optionsKeys = new WeakMap<Option, string>();
private _unsubMql?: () => void;
public connectedCallback() {
super.connectedCallback();
this._unsubMql = listenMediaQuery("(min-width: 600px)", (matches) => {
this._showReorder = matches;
});
}
public disconnectedCallback() {
super.disconnectedCallback();
this._unsubMql?.();
this._unsubMql = undefined;
}
protected render() {
return html`
<ha-sortable
handle-selector=".handle"
draggable-selector="ha-automation-option-row"
.disabled=${this.disabled}
.disabled=${!this._showReorder || this.disabled}
group="options"
invert-swap
@item-moved=${this._optionMoved}
@item-added=${this._optionAdded}
@item-removed=${this._optionRemoved}
@item-cloned=${this._optionCloned}
>
<div class="rows ${!this.optionsInSidebar ? "no-sidebar" : ""}">
<div class="options">
${repeat(
this.options,
(option) => this._getKey(option),
@@ -86,20 +91,10 @@ export default class HaAutomationOption extends LitElement {
@value-changed=${this._optionChanged}
.hass=${this.hass}
.optionsInSidebar=${this.optionsInSidebar}
.sortSelected=${this._rowSortSelected === idx}
@stop-sort-selection=${this._stopSortSelection}
>
${!this.disabled
${this._showReorder && !this.disabled
? html`
<div
tabindex="0"
class="handle ${this._rowSortSelected === idx
? "active"
: ""}"
slot="icons"
@keydown=${this._handleDragKeydown}
.index=${idx}
>
<div class="handle" slot="icons">
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
</div>
`
@@ -119,19 +114,6 @@ export default class HaAutomationOption extends LitElement {
"ui.panel.config.automation.editor.actions.type.choose.add_option"
)}
</ha-button>
${!this.showDefaultActions
? html`<ha-button
appearance="plain"
size="small"
.disabled=${this.disabled}
@click=${this._showDefaultActions}
>
<ha-svg-icon .path=${mdiPlus} slot="start"></ha-svg-icon>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.type.choose.add_default"
)}
</ha-button>`
: nothing}
</div>
</div>
</ha-sortable>
@@ -141,47 +123,29 @@ export default class HaAutomationOption extends LitElement {
protected updated(changedProps: PropertyValues) {
super.updated(changedProps);
if (
changedProps.has("options") &&
(this._focusLastOptionOnChange ||
this._focusOptionIndexOnChange !== undefined)
) {
const mode = this._focusLastOptionOnChange ? "new" : "moved";
if (changedProps.has("options") && this._focusLastOptionOnChange) {
this._focusLastOptionOnChange = false;
const row = this.shadowRoot!.querySelector<HaAutomationOptionRow>(
`ha-automation-option-row:${mode === "new" ? "last-of-type" : `nth-of-type(${this._focusOptionIndexOnChange! + 1})`}`
"ha-automation-option-row:last-of-type"
)!;
this._focusLastOptionOnChange = false;
this._focusOptionIndexOnChange = undefined;
row.updateComplete.then(() => {
if (this.narrow) {
row.scrollIntoView({
block: "start",
behavior: "smooth",
});
}
if (mode === "new") {
if (!this.optionsInSidebar) {
row.expand();
}
if (this.optionsInSidebar) {
row.openSidebar();
} else {
row.focus();
}
row.scrollIntoView();
row.focus();
});
}
}
public expandAll() {
this._optionRowElements?.forEach((row) => row.expandAll());
}
public collapseAll() {
this._optionRowElements?.forEach((row) => row.collapseAll());
const rows = this.shadowRoot!.querySelectorAll<HaAutomationOptionRow>(
"ha-automation-option-row"
)!;
rows.forEach((row) => {
row.expand();
});
}
private _addOption = () => {
@@ -201,27 +165,15 @@ export default class HaAutomationOption extends LitElement {
private _moveUp(ev) {
ev.stopPropagation();
const index = (ev.target as any).index;
if (!(ev.target as HaAutomationOptionRow).first) {
const newIndex = index - 1;
this._move(index, newIndex);
if (this._rowSortSelected === index) {
this._rowSortSelected = newIndex;
}
ev.target.focus();
}
const newIndex = index - 1;
this._move(index, newIndex);
}
private _moveDown(ev) {
ev.stopPropagation();
const index = (ev.target as any).index;
if (!(ev.target as HaAutomationOptionRow).last) {
const newIndex = index + 1;
this._move(index, newIndex);
if (this._rowSortSelected === index) {
this._rowSortSelected = newIndex;
}
ev.target.focus();
}
const newIndex = index + 1;
this._move(index, newIndex);
}
private _move(oldIndex: number, newIndex: number) {
@@ -241,12 +193,6 @@ export default class HaAutomationOption extends LitElement {
private async _optionAdded(ev: CustomEvent): Promise<void> {
ev.stopPropagation();
const { index, data } = ev.detail;
let selected = false;
if (data?.["ha-automation-row-selected"]) {
selected = true;
delete data["ha-automation-row-selected"];
}
const options = [
...this.options.slice(0, index),
data,
@@ -254,9 +200,6 @@ export default class HaAutomationOption extends LitElement {
];
// Add option locally to avoid UI jump
this.options = options;
if (selected) {
this._focusOptionIndexOnChange = options.length === 1 ? 0 : index;
}
await nextRender();
fireEvent(this, "value-changed", { value: this.options });
}
@@ -273,12 +216,6 @@ export default class HaAutomationOption extends LitElement {
fireEvent(this, "value-changed", { value: options });
}
private _optionCloned(ev: CustomEvent<HaSortableClonedEventData>) {
if (ev.detail.item.isSelected()) {
ev.detail.item.option["ha-automation-row-selected"] = true;
}
}
private _optionChanged(ev: CustomEvent) {
ev.stopPropagation();
const options = [...this.options];
@@ -306,40 +243,45 @@ export default class HaAutomationOption extends LitElement {
});
}
private _showDefaultActions = () => {
fireEvent(this, "show-default-actions");
};
private _handleDragKeydown(ev: KeyboardEvent) {
if (ev.key === "Enter" || ev.key === " ") {
ev.stopPropagation();
this._rowSortSelected =
this._rowSortSelected === undefined
? (ev.target as any).index
: undefined;
static styles = css`
.options {
padding: 16px 0 16px 16px;
margin: -16px;
display: flex;
flex-direction: column;
gap: 16px;
}
}
private _stopSortSelection() {
this._rowSortSelected = undefined;
}
static styles = [
automationRowsStyles,
css`
:host([root]) .rows {
padding-right: 8px;
}
`,
];
.sortable-ghost {
background: none;
border-radius: var(--ha-card-border-radius, var(--ha-border-radius-lg));
}
.sortable-drag {
background: none;
}
ha-automation-option-row {
display: block;
scroll-margin-top: 48px;
}
.handle {
padding: 12px;
cursor: move; /* fallback if grab cursor is unsupported */
cursor: grab;
}
.handle ha-svg-icon {
pointer-events: none;
height: 24px;
}
.buttons {
display: flex;
flex-wrap: wrap;
gap: 8px;
order: 1;
}
`;
}
declare global {
interface HTMLElementTagNameMap {
"ha-automation-option": HaAutomationOption;
}
interface HASSDomEvents {
"show-default-actions": undefined;
}
}

View File

@@ -1,12 +1,11 @@
import { css, type CSSResultGroup, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../../../../common/dom/fire_event";
import "../../../../components/ha-button";
import { createCloseHeading } from "../../../../components/ha-dialog";
import "../../../../components/ha-yaml-editor";
import { css, type CSSResultGroup, html, LitElement, nothing } from "lit";
import type { HassDialog } from "../../../../dialogs/make-dialog-manager";
import { haStyle, haStyleDialog } from "../../../../resources/styles";
import type { HomeAssistant } from "../../../../types";
import { fireEvent } from "../../../../common/dom/fire_event";
import { haStyle, haStyleDialog } from "../../../../resources/styles";
import { createCloseHeading } from "../../../../components/ha-dialog";
import "../trigger/ha-automation-trigger-row";
import type { PasteReplaceDialogParams } from "./show-dialog-paste-replace";
@customElement("ha-dialog-paste-replace")

View File

@@ -1,247 +0,0 @@
import {
mdiContentCopy,
mdiContentCut,
mdiContentDuplicate,
mdiDelete,
mdiPlay,
mdiPlayCircleOutline,
mdiPlaylistEdit,
mdiRenameBox,
mdiStopCircleOutline,
} from "@mdi/js";
import { html, LitElement } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { keyed } from "lit/directives/keyed";
import { fireEvent } from "../../../../common/dom/fire_event";
import { handleStructError } from "../../../../common/structs/handle-errors";
import type { LocalizeKeys } from "../../../../common/translations/localize";
import "../../../../components/ha-md-divider";
import "../../../../components/ha-md-menu-item";
import { ACTION_BUILDING_BLOCKS } from "../../../../data/action";
import type { ActionSidebarConfig } from "../../../../data/automation";
import type { RepeatAction } from "../../../../data/script";
import type { HomeAssistant } from "../../../../types";
import type HaAutomationConditionEditor from "../action/ha-automation-action-editor";
import { getAutomationActionType } from "../action/ha-automation-action-row";
import { getRepeatType } from "../action/types/ha-automation-action-repeat";
import { sidebarEditorStyles } from "../styles";
import "../trigger/ha-automation-trigger-editor";
import "./ha-automation-sidebar-card";
@customElement("ha-automation-sidebar-action")
export default class HaAutomationSidebarAction extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public config!: ActionSidebarConfig;
@property({ type: Boolean, attribute: "wide" }) public isWide = false;
@property({ type: Boolean }) public disabled = false;
@property({ type: Boolean, attribute: "yaml-mode" }) public yamlMode = false;
@property({ type: Boolean }) public narrow = false;
@property({ attribute: "sidebar-key" }) public sidebarKey?: string;
@state() private _warnings?: string[];
@query(".sidebar-editor")
public editor?: HaAutomationConditionEditor;
protected willUpdate(changedProperties) {
if (changedProperties.has("config")) {
this._warnings = undefined;
if (this.config) {
this.yamlMode = this.config.yamlMode;
if (this.yamlMode) {
this.editor?.yamlEditor?.setValue(this.config.config.action);
}
}
}
}
protected render() {
const actionConfig = this.config.config.action;
const disabled =
this.disabled ||
("enabled" in actionConfig && actionConfig.enabled === false);
const actionType = getAutomationActionType(actionConfig);
const type =
actionType !== "repeat"
? actionType
: `repeat_${getRepeatType((actionConfig as RepeatAction).repeat)}`;
const isBuildingBlock = ACTION_BUILDING_BLOCKS.includes(type || "");
const subtitle = this.hass.localize(
"ui.panel.config.automation.editor.actions.action"
);
const title =
this.hass.localize(
`ui.panel.config.automation.editor.actions.type.${type}.label` as LocalizeKeys
) || type;
const description = isBuildingBlock
? this.hass.localize(
`ui.panel.config.automation.editor.actions.type.${type}.description.picker` as LocalizeKeys
)
: "";
return html`<ha-automation-sidebar-card
.hass=${this.hass}
.isWide=${this.isWide}
.yamlMode=${this.yamlMode}
.warnings=${this._warnings}
.narrow=${this.narrow}
>
<span slot="title">${title}</span>
<span slot="subtitle">${subtitle}</span>
<ha-md-menu-item slot="menu-items" .clickAction=${this.config.run}>
${this.hass.localize("ui.panel.config.automation.editor.actions.run")}
<ha-svg-icon slot="start" .path=${mdiPlay}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.rename}
.disabled=${!!disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.rename"
)}
<ha-svg-icon slot="start" .path=${mdiRenameBox}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-divider
slot="menu-items"
role="separator"
tabindex="-1"
></ha-md-divider>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.duplicate}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.duplicate"
)}
<ha-svg-icon slot="start" .path=${mdiContentDuplicate}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.copy}
.disabled=${this.disabled}
>
${this.hass.localize("ui.panel.config.automation.editor.triggers.copy")}
<ha-svg-icon slot="start" .path=${mdiContentCopy}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.cut}
.disabled=${this.disabled}
>
${this.hass.localize("ui.panel.config.automation.editor.triggers.cut")}
<ha-svg-icon slot="start" .path=${mdiContentCut}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this._toggleYamlMode}
.disabled=${!this.config.uiSupported || !!this._warnings}
>
${this.hass.localize(
`ui.panel.config.automation.editor.edit_${!this.yamlMode ? "yaml" : "ui"}`
)}
<ha-svg-icon slot="start" .path=${mdiPlaylistEdit}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-divider
slot="menu-items"
role="separator"
tabindex="-1"
></ha-md-divider>
<ha-md-menu-item slot="menu-items" .clickAction=${this.config.disable}>
${this.hass.localize(
`ui.panel.config.automation.editor.actions.${disabled ? "enable" : "disable"}`
)}
<ha-svg-icon
slot="start"
.path=${this.disabled ? mdiPlayCircleOutline : mdiStopCircleOutline}
></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.delete}
.disabled=${this.disabled}
class="warning"
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.delete"
)}
<ha-svg-icon slot="start" .path=${mdiDelete}></ha-svg-icon>
</ha-md-menu-item>
${description && !this.yamlMode
? html`<div class="description">${description}</div>`
: keyed(
this.sidebarKey,
html`<ha-automation-action-editor
class="sidebar-editor"
.hass=${this.hass}
.action=${actionConfig}
.yamlMode=${this.yamlMode}
.uiSupported=${this.config.uiSupported}
@value-changed=${this._valueChangedSidebar}
@yaml-changed=${this._yamlChangedSidebar}
sidebar
narrow
.disabled=${this.disabled}
@ui-mode-not-available=${this._handleUiModeNotAvailable}
></ha-automation-action-editor>`
)}
</ha-automation-sidebar-card>`;
}
private _handleUiModeNotAvailable(ev: CustomEvent) {
this._warnings = handleStructError(this.hass, ev.detail).warnings;
if (!this.yamlMode) {
this.yamlMode = true;
}
}
private _valueChangedSidebar(ev: CustomEvent) {
ev.stopPropagation();
this.config?.save?.(ev.detail.value);
if (this.config) {
fireEvent(this, "value-changed", {
value: {
...this.config,
config: {
action: ev.detail.value,
},
},
});
}
}
private _yamlChangedSidebar(ev: CustomEvent) {
ev.stopPropagation();
this.config?.save?.(ev.detail.value);
}
private _toggleYamlMode = () => {
fireEvent(this, "toggle-yaml-mode");
};
static styles = sidebarEditorStyles;
}
declare global {
interface HTMLElementTagNameMap {
"ha-automation-sidebar-action": HaAutomationSidebarAction;
}
}

View File

@@ -1,171 +0,0 @@
import { mdiClose, mdiDotsVertical } from "@mdi/js";
import { css, html, LitElement, nothing } from "lit";
import {
customElement,
eventOptions,
property,
query,
state,
} from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { fireEvent } from "../../../../common/dom/fire_event";
import { stopPropagation } from "../../../../common/dom/stop_propagation";
import "../../../../components/ha-card";
import "../../../../components/ha-dialog-header";
import "../../../../components/ha-icon-button";
import "../../../../components/ha-md-button-menu";
import "../../../../components/ha-md-divider";
import "../../../../components/ha-md-menu-item";
import type { HomeAssistant } from "../../../../types";
import "../ha-automation-editor-warning";
export interface SidebarOverflowMenuEntry {
clickAction: () => void;
disabled?: boolean;
label: string;
icon?: string;
danger?: boolean;
}
export type SidebarOverflowMenu = (SidebarOverflowMenuEntry | "separator")[];
@customElement("ha-automation-sidebar-card")
export default class HaAutomationSidebarCard extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ type: Boolean, attribute: "wide" }) public isWide = false;
@property({ type: Boolean, attribute: "yaml-mode" }) public yamlMode = false;
@property({ attribute: false }) public warnings?: string[];
@property({ type: Boolean }) public narrow = false;
@state() private _contentScrolled = false;
@query(".card-content") private _contentElement?: HTMLDivElement;
protected render() {
return html`
<ha-card
outlined
class=${classMap({
mobile: !this.isWide,
yaml: this.yamlMode,
})}
>
<ha-dialog-header
class=${classMap({ scrolled: this._contentScrolled })}
>
<ha-icon-button
slot="navigationIcon"
.label=${this.hass.localize("ui.common.close")}
.path=${mdiClose}
@click=${this._closeSidebar}
></ha-icon-button>
<slot slot="title" name="title"></slot>
<slot slot="subtitle" name="subtitle"></slot>
<slot name="overflow-menu" slot="actionItems">
<ha-md-button-menu
quick
@click=${this._openOverflowMenu}
@keydown=${stopPropagation}
@closed=${stopPropagation}
.positioning=${this.narrow ? "absolute" : "fixed"}
anchor-corner="end-end"
menu-corner="start-end"
>
<ha-icon-button
slot="trigger"
.label=${this.hass.localize("ui.common.menu")}
.path=${mdiDotsVertical}
></ha-icon-button>
<slot name="menu-items"></slot>
</ha-md-button-menu>
</slot>
</ha-dialog-header>
${this.warnings
? html`<ha-automation-editor-warning
.localize=${this.hass.localize}
.warnings=${this.warnings}
>
</ha-automation-editor-warning>`
: nothing}
<div class="card-content" @scroll=${this._onScroll}>
<slot></slot>
</div>
</ha-card>
`;
}
@eventOptions({ passive: true })
private _onScroll() {
const top = this._contentElement?.scrollTop ?? 0;
this._contentScrolled = top > 0;
}
private _closeSidebar() {
fireEvent(this, "close-sidebar");
}
private _openOverflowMenu(ev: MouseEvent) {
ev.stopPropagation();
ev.preventDefault();
}
static styles = css`
ha-card {
height: 100%;
width: 100%;
border-color: var(--primary-color);
border-width: 2px;
display: block;
}
@media all and (max-width: 870px) {
ha-card.mobile {
border: none;
}
ha-card.mobile {
border-bottom-right-radius: var(--ha-border-radius-square);
border-bottom-left-radius: var(--ha-border-radius-square);
}
}
ha-dialog-header {
border-radius: var(--ha-card-border-radius);
box-shadow: none;
transition: box-shadow 180ms ease-in-out;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
z-index: 6;
position: relative;
background-color: var(
--ha-dialog-surface-background,
var(--mdc-theme-surface, #fff)
);
}
ha-dialog-header.scrolled {
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
.card-content {
max-height: calc(100% - 80px);
overflow: auto;
}
@media (min-width: 450px) and (min-height: 500px) {
.card-content {
max-height: calc(100% - 104px);
overflow: auto;
}
}
`;
}
declare global {
interface HTMLElementTagNameMap {
"ha-automation-sidebar-card": HaAutomationSidebarCard;
}
}

View File

@@ -1,236 +0,0 @@
import {
mdiContentCopy,
mdiContentCut,
mdiContentDuplicate,
mdiDelete,
mdiFlask,
mdiPlayCircleOutline,
mdiPlaylistEdit,
mdiRenameBox,
mdiStopCircleOutline,
} from "@mdi/js";
import { html, LitElement } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { keyed } from "lit/directives/keyed";
import { fireEvent } from "../../../../common/dom/fire_event";
import { handleStructError } from "../../../../common/structs/handle-errors";
import type { ConditionSidebarConfig } from "../../../../data/automation";
import { CONDITION_BUILDING_BLOCKS } from "../../../../data/condition";
import type { HomeAssistant } from "../../../../types";
import "../condition/ha-automation-condition-editor";
import type HaAutomationConditionEditor from "../condition/ha-automation-condition-editor";
import { sidebarEditorStyles } from "../styles";
import "./ha-automation-sidebar-card";
@customElement("ha-automation-sidebar-condition")
export default class HaAutomationSidebarCondition extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public config!: ConditionSidebarConfig;
@property({ type: Boolean, attribute: "wide" }) public isWide = false;
@property({ type: Boolean }) public disabled = false;
@property({ type: Boolean, attribute: "yaml-mode" }) public yamlMode = false;
@property({ type: Boolean }) public narrow = false;
@property({ attribute: "sidebar-key" }) public sidebarKey?: string;
@state() private _warnings?: string[];
@query(".sidebar-editor")
public editor?: HaAutomationConditionEditor;
protected willUpdate(changedProperties) {
if (changedProperties.has("config")) {
this._warnings = undefined;
if (this.config) {
this.yamlMode = this.config.yamlMode;
if (this.yamlMode) {
this.editor?.yamlEditor?.setValue(this.config.config);
}
}
}
}
protected render() {
const disabled =
this.disabled ||
("enabled" in this.config.config && this.config.config.enabled === false);
const type = this.config.config.condition;
const isBuildingBlock = CONDITION_BUILDING_BLOCKS.includes(type);
const subtitle = this.hass.localize(
"ui.panel.config.automation.editor.conditions.condition"
);
const title =
this.hass.localize(
`ui.panel.config.automation.editor.conditions.type.${type}.label`
) || type;
const description = isBuildingBlock
? this.hass.localize(
`ui.panel.config.automation.editor.conditions.type.${type}.description.picker`
)
: "";
return html`<ha-automation-sidebar-card
.hass=${this.hass}
.isWide=${this.isWide}
.yamlMode=${this.yamlMode}
.warnings=${this._warnings}
.narrow=${this.narrow}
>
<span slot="title">${title}</span>
<span slot="subtitle">${subtitle}</span>
<ha-md-menu-item slot="menu-items" .clickAction=${this.config.test}>
${this.hass.localize(
"ui.panel.config.automation.editor.conditions.test"
)}
<ha-svg-icon slot="start" .path=${mdiFlask}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.rename}
.disabled=${!!disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.rename"
)}
<ha-svg-icon slot="start" .path=${mdiRenameBox}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-divider
slot="menu-items"
role="separator"
tabindex="-1"
></ha-md-divider>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.duplicate}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.duplicate"
)}
<ha-svg-icon slot="start" .path=${mdiContentDuplicate}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.copy}
.disabled=${this.disabled}
>
${this.hass.localize("ui.panel.config.automation.editor.triggers.copy")}
<ha-svg-icon slot="start" .path=${mdiContentCopy}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.cut}
.disabled=${this.disabled}
>
${this.hass.localize("ui.panel.config.automation.editor.triggers.cut")}
<ha-svg-icon slot="start" .path=${mdiContentCut}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this._toggleYamlMode}
.disabled=${!this.config.uiSupported || !!this._warnings}
>
${this.hass.localize(
`ui.panel.config.automation.editor.edit_${!this.yamlMode ? "yaml" : "ui"}`
)}
<ha-svg-icon slot="start" .path=${mdiPlaylistEdit}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-divider
slot="menu-items"
role="separator"
tabindex="-1"
></ha-md-divider>
<ha-md-menu-item slot="menu-items" .clickAction=${this.config.disable}>
${this.hass.localize(
`ui.panel.config.automation.editor.actions.${disabled ? "enable" : "disable"}`
)}
<ha-svg-icon
slot="start"
.path=${this.disabled ? mdiPlayCircleOutline : mdiStopCircleOutline}
></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.delete}
.disabled=${this.disabled}
class="warning"
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.delete"
)}
<ha-svg-icon slot="start" .path=${mdiDelete}></ha-svg-icon>
</ha-md-menu-item>
${description && !this.yamlMode
? html`<div class="description">${description}</div>`
: keyed(
this.sidebarKey,
html`<ha-automation-condition-editor
class="sidebar-editor"
.hass=${this.hass}
.condition=${this.config.config}
.yamlMode=${this.yamlMode}
.uiSupported=${this.config.uiSupported}
@value-changed=${this._valueChangedSidebar}
@yaml-changed=${this._yamlChangedSidebar}
.disabled=${this.disabled}
@ui-mode-not-available=${this._handleUiModeNotAvailable}
sidebar
></ha-automation-condition-editor>`
)}
</ha-automation-sidebar-card>`;
}
private _handleUiModeNotAvailable(ev: CustomEvent) {
this._warnings = handleStructError(this.hass, ev.detail).warnings;
if (!this.yamlMode) {
this.yamlMode = true;
}
}
private _valueChangedSidebar(ev: CustomEvent) {
ev.stopPropagation();
this.config?.save?.(ev.detail.value);
if (this.config) {
fireEvent(this, "value-changed", {
value: {
...this.config,
config: ev.detail.value,
},
});
}
}
private _yamlChangedSidebar(ev: CustomEvent) {
ev.stopPropagation();
this.config?.save?.(ev.detail.value);
}
private _toggleYamlMode = () => {
fireEvent(this, "toggle-yaml-mode");
};
static styles = sidebarEditorStyles;
}
declare global {
interface HTMLElementTagNameMap {
"ha-automation-sidebar-condition": HaAutomationSidebarCondition;
}
}

View File

@@ -1,103 +0,0 @@
import { mdiContentDuplicate, mdiDelete, mdiRenameBox } from "@mdi/js";
import { html, LitElement } from "lit";
import { customElement, property, query } from "lit/decorators";
import type { OptionSidebarConfig } from "../../../../data/automation";
import type { HomeAssistant } from "../../../../types";
import type HaAutomationConditionEditor from "../action/ha-automation-action-editor";
import { sidebarEditorStyles } from "../styles";
import "./ha-automation-sidebar-card";
@customElement("ha-automation-sidebar-option")
export default class HaAutomationSidebarOption extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public config!: OptionSidebarConfig;
@property({ type: Boolean, attribute: "wide" }) public isWide = false;
@property({ type: Boolean }) public disabled = false;
@property({ type: Boolean }) public narrow = false;
@query(".sidebar-editor")
public editor?: HaAutomationConditionEditor;
protected render() {
const disabled = this.disabled;
const subtitle = this.hass.localize(
"ui.panel.config.automation.editor.actions.type.choose.label"
);
const title = this.hass.localize(
`ui.panel.config.automation.editor.actions.type.choose.${this.config.defaultOption ? "default_" : ""}option_label`
);
const description = this.hass.localize(
`ui.panel.config.automation.editor.actions.type.choose.${this.config.defaultOption ? "default_" : ""}option_description`
);
return html`<ha-automation-sidebar-card
.hass=${this.hass}
.isWide=${this.isWide}
.narrow=${this.narrow}
>
<span slot="title">${title}</span>
<span slot="subtitle">${subtitle}</span>
${this.config.defaultOption
? html`<span slot="overflow-menu"></span>`
: html`
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.rename}
.disabled=${!!disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.rename"
)}
<ha-svg-icon slot="start" .path=${mdiRenameBox}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
slot="menu-items"
@click=${this.config.duplicate}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.duplicate"
)}
<ha-svg-icon
slot="start"
.path=${mdiContentDuplicate}
></ha-svg-icon>
</ha-md-menu-item>
<ha-md-divider
slot="menu-items"
role="separator"
tabindex="-1"
></ha-md-divider>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.delete}
.disabled=${this.disabled}
class="warning"
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.type.choose.remove_option"
)}
<ha-svg-icon slot="start" .path=${mdiDelete}></ha-svg-icon>
</ha-md-menu-item>
`}
<div class="description">${description}</div>
</ha-automation-sidebar-card>`;
}
static styles = sidebarEditorStyles;
}
declare global {
interface HTMLElementTagNameMap {
"ha-automation-sidebar-option": HaAutomationSidebarOption;
}
}

View File

@@ -1,143 +0,0 @@
import { mdiDelete, mdiPlaylistEdit } from "@mdi/js";
import { html, LitElement } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { keyed } from "lit/directives/keyed";
import { fireEvent } from "../../../../common/dom/fire_event";
import type { LocalizeKeys } from "../../../../common/translations/localize";
import type { ScriptFieldSidebarConfig } from "../../../../data/automation";
import type { HomeAssistant } from "../../../../types";
import "../../script/ha-script-field-selector-editor";
import type HaAutomationConditionEditor from "../action/ha-automation-action-editor";
import { sidebarEditorStyles } from "../styles";
import "./ha-automation-sidebar-card";
@customElement("ha-automation-sidebar-script-field-selector")
export default class HaAutomationSidebarScriptFieldSelector extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public config!: ScriptFieldSidebarConfig;
@property({ type: Boolean, attribute: "wide" }) public isWide = false;
@property({ type: Boolean }) public disabled = false;
@property({ type: Boolean, attribute: "yaml-mode" }) public yamlMode = false;
@property({ type: Boolean }) public narrow = false;
@property({ attribute: "sidebar-key" }) public sidebarKey?: string;
@state() private _warnings?: string[];
@query(".sidebar-editor")
public editor?: HaAutomationConditionEditor;
protected willUpdate(changedProperties) {
if (changedProperties.has("config")) {
this._warnings = undefined;
if (this.config) {
this.yamlMode = this.config.yamlMode;
if (this.yamlMode) {
this.editor?.yamlEditor?.setValue(this.config.config);
}
}
}
}
protected render() {
const subtitle = this.hass.localize(
"ui.panel.config.script.editor.field.field_selector"
);
const title =
this.hass.localize(
`ui.components.selectors.selector.types.${Object.keys(this.config.config.field.selector)[0]}` as LocalizeKeys
) || Object.keys(this.config.config.field.selector)[0];
return html`<ha-automation-sidebar-card
.hass=${this.hass}
.isWide=${this.isWide}
.yamlMode=${this.yamlMode}
.warnings=${this._warnings}
.narrow=${this.narrow}
>
<span slot="title">${title}</span>
<span slot="subtitle">${subtitle}</span>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this._toggleYamlMode}
.disabled=${!!this._warnings}
>
${this.hass.localize(
`ui.panel.config.automation.editor.edit_${!this.yamlMode ? "yaml" : "ui"}`
)}
<ha-svg-icon slot="start" .path=${mdiPlaylistEdit}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.delete}
.disabled=${this.disabled}
class="warning"
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.delete"
)}
<ha-svg-icon slot="start" .path=${mdiDelete}></ha-svg-icon>
</ha-md-menu-item>
${keyed(
this.sidebarKey,
html`<ha-script-field-selector-editor
class="sidebar-editor"
.hass=${this.hass}
.field=${this.config.config.field}
.disabled=${this.disabled}
@value-changed=${this._valueChangedSidebar}
@yaml-changed=${this._yamlChangedSidebar}
.yamlMode=${this.yamlMode}
></ha-script-field-selector-editor>`
)}
</ha-automation-sidebar-card>`;
}
private _valueChangedSidebar(ev: CustomEvent) {
ev.stopPropagation();
this.config?.save?.({
...this.config.config.field,
key: this.config.config.key,
...ev.detail.value,
});
if (this.config) {
fireEvent(this, "value-changed", {
value: {
...this.config,
config: {
field: ev.detail.value,
key: this.config.config.key,
excludeKeys: this.config.config.excludeKeys,
selector: true,
},
},
});
}
}
private _yamlChangedSidebar(ev: CustomEvent) {
ev.stopPropagation();
this.config?.save?.(ev.detail.value);
}
private _toggleYamlMode = () => {
fireEvent(this, "toggle-yaml-mode");
};
static styles = sidebarEditorStyles;
}
declare global {
interface HTMLElementTagNameMap {
"ha-automation-sidebar-script-field-selector": HaAutomationSidebarScriptFieldSelector;
}
}

View File

@@ -1,137 +0,0 @@
import { mdiDelete, mdiPlaylistEdit } from "@mdi/js";
import { html, LitElement } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { keyed } from "lit/directives/keyed";
import { fireEvent } from "../../../../common/dom/fire_event";
import type { ScriptFieldSidebarConfig } from "../../../../data/automation";
import type { HomeAssistant } from "../../../../types";
import "../../script/ha-script-field-editor";
import type HaAutomationConditionEditor from "../action/ha-automation-action-editor";
import { sidebarEditorStyles } from "../styles";
import "./ha-automation-sidebar-card";
@customElement("ha-automation-sidebar-script-field")
export default class HaAutomationSidebarScriptField extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public config!: ScriptFieldSidebarConfig;
@property({ type: Boolean, attribute: "wide" }) public isWide = false;
@property({ type: Boolean }) public disabled = false;
@property({ type: Boolean, attribute: "yaml-mode" }) public yamlMode = false;
@property({ type: Boolean }) public narrow = false;
@property({ attribute: "sidebar-key" }) public sidebarKey?: string;
@state() private _warnings?: string[];
@query(".sidebar-editor")
public editor?: HaAutomationConditionEditor;
protected willUpdate(changedProperties) {
if (changedProperties.has("config")) {
this._warnings = undefined;
if (this.config) {
this.yamlMode = this.config.yamlMode;
if (this.yamlMode) {
this.editor?.yamlEditor?.setValue(this.config.config);
}
}
}
}
protected render() {
const title = this.hass.localize(
"ui.panel.config.script.editor.field.label"
);
return html`<ha-automation-sidebar-card
.hass=${this.hass}
.isWide=${this.isWide}
.yamlMode=${this.yamlMode}
.warnings=${this._warnings}
.narrow=${this.narrow}
>
<span slot="title">${title}</span>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this._toggleYamlMode}
.disabled=${!!this._warnings}
>
${this.hass.localize(
`ui.panel.config.automation.editor.edit_${!this.yamlMode ? "yaml" : "ui"}`
)}
<ha-svg-icon slot="start" .path=${mdiPlaylistEdit}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.delete}
.disabled=${this.disabled}
class="warning"
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.delete"
)}
<ha-svg-icon slot="start" .path=${mdiDelete}></ha-svg-icon>
</ha-md-menu-item>
${keyed(
this.sidebarKey,
html`<ha-script-field-editor
class="sidebar-editor"
.hass=${this.hass}
.field=${this.config.config.field}
.key=${this.config.config.key}
.excludeKeys=${this.config.config.excludeKeys}
.disabled=${this.disabled}
.yamlMode=${this.yamlMode}
@value-changed=${this._valueChangedSidebar}
@yaml-changed=${this._yamlChangedSidebar}
></ha-script-field-editor>`
)}
</ha-automation-sidebar-card>`;
}
private _valueChangedSidebar(ev: CustomEvent) {
ev.stopPropagation();
this.config?.save?.({
...this.config.config.field,
key: ev.detail.value.key ?? this.config.config.key,
...ev.detail.value,
});
if (this.config) {
fireEvent(this, "value-changed", {
value: {
...this.config,
config: {
field: ev.detail.value,
key: ev.detail.value.key ?? this.config.config.key,
excludeKeys: this.config.config.excludeKeys,
},
},
});
}
}
private _yamlChangedSidebar(ev: CustomEvent) {
ev.stopPropagation();
this.config?.save?.(ev.detail.value);
}
private _toggleYamlMode = () => {
fireEvent(this, "toggle-yaml-mode");
};
static styles = sidebarEditorStyles;
}
declare global {
interface HTMLElementTagNameMap {
"ha-automation-sidebar-script-field": HaAutomationSidebarScriptField;
}
}

View File

@@ -1,252 +0,0 @@
import {
mdiContentCopy,
mdiContentCut,
mdiContentDuplicate,
mdiDelete,
mdiIdentifier,
mdiPlayCircleOutline,
mdiPlaylistEdit,
mdiRenameBox,
mdiStopCircleOutline,
} from "@mdi/js";
import { html, LitElement, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { keyed } from "lit/directives/keyed";
import { fireEvent } from "../../../../common/dom/fire_event";
import { handleStructError } from "../../../../common/structs/handle-errors";
import type { TriggerSidebarConfig } from "../../../../data/automation";
import { isTriggerList } from "../../../../data/trigger";
import type { HomeAssistant } from "../../../../types";
import { sidebarEditorStyles } from "../styles";
import "../trigger/ha-automation-trigger-editor";
import type HaAutomationTriggerEditor from "../trigger/ha-automation-trigger-editor";
import "./ha-automation-sidebar-card";
@customElement("ha-automation-sidebar-trigger")
export default class HaAutomationSidebarTrigger extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public config!: TriggerSidebarConfig;
@property({ type: Boolean, attribute: "wide" }) public isWide = false;
@property({ type: Boolean }) public disabled = false;
@property({ type: Boolean, attribute: "yaml-mode" }) public yamlMode = false;
@property({ type: Boolean }) public narrow = false;
@property({ attribute: "sidebar-key" }) public sidebarKey?: string;
@state() private _requestShowId = false;
@state() private _warnings?: string[];
@query(".sidebar-editor")
public editor?: HaAutomationTriggerEditor;
protected willUpdate(changedProperties) {
if (changedProperties.has("config")) {
this._requestShowId = false;
this._warnings = undefined;
if (this.config) {
this.yamlMode = this.config.yamlMode;
if (this.yamlMode) {
this.editor?.yamlEditor?.setValue(this.config.config);
}
}
}
}
protected render() {
const disabled =
this.disabled ||
("enabled" in this.config.config && this.config.config.enabled === false);
const type = isTriggerList(this.config.config)
? "list"
: this.config.config.trigger;
const subtitle = this.hass.localize(
"ui.panel.config.automation.editor.triggers.trigger"
);
const title = this.hass.localize(
`ui.panel.config.automation.editor.triggers.type.${type}.label`
);
return html`
<ha-automation-sidebar-card
.hass=${this.hass}
.isWide=${this.isWide}
.yamlMode=${this.yamlMode}
.warnings=${this._warnings}
.narrow=${this.narrow}
>
<span slot="title">${title}</span>
<span slot="subtitle">${subtitle}</span>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.rename}
.disabled=${disabled || type === "list"}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.rename"
)}
<ha-svg-icon slot="start" .path=${mdiRenameBox}></ha-svg-icon>
</ha-md-menu-item>
${!this.yamlMode &&
!("id" in this.config.config) &&
!this._requestShowId
? html`<ha-md-menu-item
slot="menu-items"
.clickAction=${this._showTriggerId}
.disabled=${disabled || type === "list"}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.edit_id"
)}
<ha-svg-icon slot="start" .path=${mdiIdentifier}></ha-svg-icon>
</ha-md-menu-item>`
: nothing}
<ha-md-divider
slot="menu-items"
role="separator"
tabindex="-1"
></ha-md-divider>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.duplicate}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.duplicate"
)}
<ha-svg-icon slot="start" .path=${mdiContentDuplicate}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.copy}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.copy"
)}
<ha-svg-icon slot="start" .path=${mdiContentCopy}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.cut}
.disabled=${this.disabled}
>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.cut"
)}
<ha-svg-icon slot="start" .path=${mdiContentCut}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this._toggleYamlMode}
.disabled=${!this.config.uiSupported || !!this._warnings}
>
${this.hass.localize(
`ui.panel.config.automation.editor.edit_${!this.yamlMode ? "yaml" : "ui"}`
)}
<ha-svg-icon slot="start" .path=${mdiPlaylistEdit}></ha-svg-icon>
</ha-md-menu-item>
<ha-md-divider
slot="menu-items"
role="separator"
tabindex="-1"
></ha-md-divider>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.disable}
.disabled=${type === "list"}
>
${this.hass.localize(
`ui.panel.config.automation.editor.actions.${disabled ? "enable" : "disable"}`
)}
<ha-svg-icon
slot="start"
.path=${this.disabled ? mdiPlayCircleOutline : mdiStopCircleOutline}
></ha-svg-icon>
</ha-md-menu-item>
<ha-md-menu-item
slot="menu-items"
.clickAction=${this.config.delete}
.disabled=${this.disabled}
class="warning"
>
${this.hass.localize(
"ui.panel.config.automation.editor.actions.delete"
)}
<ha-svg-icon slot="start" .path=${mdiDelete}></ha-svg-icon>
</ha-md-menu-item>
${keyed(
this.sidebarKey,
html`<ha-automation-trigger-editor
class="sidebar-editor"
.hass=${this.hass}
.trigger=${this.config.config}
@value-changed=${this._valueChangedSidebar}
@yaml-changed=${this._yamlChangedSidebar}
.uiSupported=${this.config.uiSupported}
.showId=${this._requestShowId}
.yamlMode=${this.yamlMode}
.disabled=${this.disabled}
@ui-mode-not-available=${this._handleUiModeNotAvailable}
sidebar
></ha-automation-trigger-editor>`
)}
</ha-automation-sidebar-card>
`;
}
private _handleUiModeNotAvailable(ev: CustomEvent) {
this._warnings = handleStructError(this.hass, ev.detail).warnings;
if (!this.yamlMode) {
this.yamlMode = true;
}
}
private _valueChangedSidebar(ev: CustomEvent) {
ev.stopPropagation();
this.config?.save?.(ev.detail.value);
if (this.config) {
fireEvent(this, "value-changed", {
value: {
...this.config,
config: ev.detail.value,
},
});
}
}
private _yamlChangedSidebar(ev: CustomEvent) {
ev.stopPropagation();
this.config?.save?.(ev.detail.value);
}
private _toggleYamlMode = () => {
fireEvent(this, "toggle-yaml-mode");
};
private _showTriggerId = () => {
this._requestShowId = true;
};
static styles = sidebarEditorStyles;
}
declare global {
interface HTMLElementTagNameMap {
"ha-automation-sidebar-trigger": HaAutomationSidebarTrigger;
}
}

Some files were not shown because too many files have changed in this diff Show More