mirror of
https://github.com/home-assistant/frontend.git
synced 2026-05-27 11:37:06 +00:00
Compare commits
92 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 88b36ec314 | |||
| f31a7c3af0 | |||
| 44d91eaa4f | |||
| 3cc1cb7893 | |||
| e7354ed5a2 | |||
| e3ac2c149d | |||
| afcd45a780 | |||
| fe87466351 | |||
| bdef924426 | |||
| 86ea3082f7 | |||
| 0374330676 | |||
| d8a68326fb | |||
| 4901d50918 | |||
| a16e41a7ac | |||
| f1d644ac51 | |||
| a9378abe31 | |||
| 5c2fcd7f9b | |||
| 0015559e24 | |||
| 2fbe6809c1 | |||
| e926091e54 | |||
| 1198f983aa | |||
| 6a15216104 | |||
| b99a139f51 | |||
| 0e9a013549 | |||
| 1d1ff410b2 | |||
| d4d3a1cb65 | |||
| 81e3652446 | |||
| adb61ab99b | |||
| 1c139d0bc7 | |||
| 419f23879a | |||
| e175c7ba3c | |||
| 2575d35f2c | |||
| 5eb45209e8 | |||
| 0e70b866ae | |||
| c6aa2886ed | |||
| 77e01812d1 | |||
| a5863a9a67 | |||
| 526c34993c | |||
| 3199319830 | |||
| 6bb350b5ec | |||
| f41330a29b | |||
| 7780ae8f76 | |||
| 40cf15c1f3 | |||
| 9be6a47d88 | |||
| 5933c2eb8e | |||
| a8b7937d75 | |||
| 4919341871 | |||
| 36e99c3c0f | |||
| 825008e24a | |||
| ae04a5457e | |||
| a7c3774c29 | |||
| 9c24dbe333 | |||
| 50f089fd4f | |||
| 019ef4ba8f | |||
| b31a9d590e | |||
| 43ea175a1a | |||
| b2f0b6a814 | |||
| 614496d65c | |||
| d121c1cd18 | |||
| b18160d987 | |||
| 5b17c59a56 | |||
| 139cbb363c | |||
| e8e4733fc9 | |||
| b4d6fc3c20 | |||
| 25a5bd568a | |||
| 77b8152c55 | |||
| ebcbfda92d | |||
| 01a4b55ed8 | |||
| 311d11f2da | |||
| c400e771cb | |||
| 7611a99f55 | |||
| 1044b3c399 | |||
| 239d3ca00c | |||
| 00c2cb731b | |||
| ef7d839c0f | |||
| 66a22ae102 | |||
| d48853fcdd | |||
| 175a388822 | |||
| 872395bec5 | |||
| 5faf7cf0af | |||
| e768c78dce | |||
| 50cc8594be | |||
| 363092ff03 | |||
| 1bce5efc9e | |||
| 14513e5905 | |||
| b168f8d027 | |||
| e151520d74 | |||
| 02b763e8f3 | |||
| 498102ddd9 | |||
| 6aba5c1017 | |||
| 2176d4dcea | |||
| 9fdef3df6d |
@@ -6,3 +6,9 @@ updates:
|
||||
interval: weekly
|
||||
time: "06:00"
|
||||
open-pull-requests-limit: 10
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
time: "06:00"
|
||||
open-pull-requests-limit: 5
|
||||
|
||||
@@ -22,12 +22,12 @@ jobs:
|
||||
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v3.2.0
|
||||
with:
|
||||
ref: dev
|
||||
|
||||
- name: Set up Node ${{ env.NODE_VERSION }}
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v3.5.1
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: yarn
|
||||
@@ -60,12 +60,12 @@ jobs:
|
||||
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v3.2.0
|
||||
with:
|
||||
ref: master
|
||||
|
||||
- name: Set up Node ${{ env.NODE_VERSION }}
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v3.5.1
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: yarn
|
||||
|
||||
@@ -20,9 +20,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v3.2.0
|
||||
- name: Set up Node ${{ env.NODE_VERSION }}
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v3.5.1
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: yarn
|
||||
@@ -44,9 +44,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v3.2.0
|
||||
- name: Set up Node ${{ env.NODE_VERSION }}
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v3.5.1
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: yarn
|
||||
@@ -63,9 +63,9 @@ jobs:
|
||||
needs: [lint, test]
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v3.2.0
|
||||
- name: Set up Node ${{ env.NODE_VERSION }}
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v3.5.1
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: yarn
|
||||
@@ -82,9 +82,9 @@ jobs:
|
||||
needs: [lint, test]
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v3.2.0
|
||||
- name: Set up Node ${{ env.NODE_VERSION }}
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v3.5.1
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: yarn
|
||||
|
||||
@@ -23,7 +23,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v3.2.0
|
||||
with:
|
||||
# We must fetch at least the immediate parents so that if this is
|
||||
# a pull request then we can checkout the head.
|
||||
|
||||
@@ -7,23 +7,28 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- dev
|
||||
- master
|
||||
|
||||
env:
|
||||
NODE_VERSION: 16
|
||||
NODE_OPTIONS: --max_old_space_size=6144
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
deploy_dev:
|
||||
runs-on: ubuntu-latest
|
||||
name: Demo Development
|
||||
if: github.event_name != 'push' || github.ref != 'master'
|
||||
environment:
|
||||
name: Demo
|
||||
name: Demo Development
|
||||
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v3.2.0
|
||||
with:
|
||||
ref: dev
|
||||
|
||||
- name: Set up Node ${{ env.NODE_VERSION }}
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v3.5.1
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: yarn
|
||||
@@ -46,3 +51,41 @@ jobs:
|
||||
env:
|
||||
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
||||
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEMO_DEV_SITE_ID }}
|
||||
|
||||
deploy_master:
|
||||
runs-on: ubuntu-latest
|
||||
name: Demo Production
|
||||
if: github.event_name == 'push' && github.ref == 'master'
|
||||
environment:
|
||||
name: Demo Production
|
||||
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3.2.0
|
||||
with:
|
||||
ref: master
|
||||
|
||||
- name: Set up Node ${{ env.NODE_VERSION }}
|
||||
uses: actions/setup-node@v3.5.1
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: yarn
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn install
|
||||
env:
|
||||
CI: true
|
||||
|
||||
- name: Build Demo
|
||||
run: ./node_modules/.bin/gulp build-demo
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Deploy to Netlify
|
||||
id: deploy
|
||||
uses: netlify/actions/cli@master
|
||||
with:
|
||||
args: deploy --dir=demo/dist --prod
|
||||
env:
|
||||
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
||||
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEMO_SITE_ID }}
|
||||
@@ -17,10 +17,10 @@ jobs:
|
||||
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v3.2.0
|
||||
|
||||
- name: Set up Node ${{ env.NODE_VERSION }}
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v3.5.1
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: yarn
|
||||
|
||||
@@ -22,10 +22,10 @@ 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@v3
|
||||
uses: actions/checkout@v3.2.0
|
||||
|
||||
- name: Set up Node ${{ env.NODE_VERSION }}
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v3.5.1
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: yarn
|
||||
|
||||
@@ -21,7 +21,7 @@ jobs:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Checkout the repository
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v3.2.0
|
||||
|
||||
- name: Set up Python ${{ env.PYTHON_VERSION }}
|
||||
uses: actions/setup-python@v4
|
||||
@@ -29,7 +29,7 @@ jobs:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
|
||||
- name: Set up Node ${{ env.NODE_VERSION }}
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v3.5.1
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: yarn
|
||||
|
||||
@@ -24,7 +24,7 @@ jobs:
|
||||
contents: write # Required to upload release assets
|
||||
steps:
|
||||
- name: Checkout the repository
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v3.2.0
|
||||
|
||||
- name: Verify version
|
||||
uses: home-assistant/actions/helpers/verify-version@master
|
||||
@@ -35,7 +35,7 @@ jobs:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
|
||||
- name: Set up Node ${{ env.NODE_VERSION }}
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v3.5.1
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: yarn
|
||||
|
||||
@@ -10,7 +10,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 90 days stale policy
|
||||
uses: actions/stale@v6.0.1
|
||||
uses: actions/stale@v7.0.0
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
days-before-stale: 90
|
||||
|
||||
@@ -16,7 +16,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout the repository
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v3.2.0
|
||||
|
||||
- name: Upload Translations
|
||||
run: |
|
||||
|
||||
@@ -98,7 +98,9 @@ const alerts: {
|
||||
description: "Alert with slotted image",
|
||||
type: "warning",
|
||||
iconSlot: html`<span slot="icon" class="image"
|
||||
><img src="https://www.home-assistant.io/images/home-assistant-logo.svg"
|
||||
><img
|
||||
alt="Home Assistant logo"
|
||||
src="https://www.home-assistant.io/images/home-assistant-logo.svg"
|
||||
/></span>`,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -142,7 +142,8 @@ export class DemoHaBarSlider extends LitElement {
|
||||
}
|
||||
.custom {
|
||||
--slider-bar-color: #ffcf4c;
|
||||
--slider-bar-background: #ffcf4c64;
|
||||
--slider-bar-background: #ffcf4c;
|
||||
--slider-bar-background-opacity: 0.2;
|
||||
--slider-bar-thickness: 100px;
|
||||
--slider-bar-border-radius: 24px;
|
||||
}
|
||||
|
||||
@@ -115,8 +115,8 @@ export class DemoHaBarSwitch extends LitElement {
|
||||
font-weight: 600;
|
||||
}
|
||||
.custom {
|
||||
--switch-bar-color-on: var(--rgb-green-color);
|
||||
--switch-bar-color-off: var(--rgb-red-color);
|
||||
--switch-bar-on-color: rgb(var(--rgb-green-color));
|
||||
--switch-bar-off-color: rgb(var(--rgb-red-color));
|
||||
--switch-bar-thickness: 100px;
|
||||
--switch-bar-border-radius: 24px;
|
||||
--switch-bar-padding: 6px;
|
||||
|
||||
@@ -106,6 +106,7 @@ const ENTITIES: HassEntity[] = [
|
||||
// Alert
|
||||
createEntity("alert.off", "off"),
|
||||
createEntity("alert.on", "on"),
|
||||
createEntity("alert.idle", "idle"),
|
||||
// Automation
|
||||
createEntity("automation.off", "off"),
|
||||
createEntity("automation.on", "on"),
|
||||
@@ -219,6 +220,11 @@ const ENTITIES: HassEntity[] = [
|
||||
// Siren
|
||||
createEntity("siren.off", "off"),
|
||||
createEntity("siren.on", "on"),
|
||||
// Sun
|
||||
createEntity("sun.below", "below_horizon"),
|
||||
createEntity("sun.above", "above_horizon"),
|
||||
createEntity("sun.unknown", "unknown"),
|
||||
createEntity("sun.unavailable", "unavailable"),
|
||||
// Switch
|
||||
createEntity("switch.off", "off"),
|
||||
createEntity("switch.on", "on"),
|
||||
@@ -322,7 +328,7 @@ export class DemoEntityState extends LitElement {
|
||||
`,
|
||||
},
|
||||
entity_id: {
|
||||
title: "Entity id",
|
||||
title: "Entity ID",
|
||||
width: "30%",
|
||||
filterable: true,
|
||||
sortable: true,
|
||||
|
||||
@@ -29,7 +29,9 @@ class HassioAddonRepositoryEl extends LitElement {
|
||||
if (filter) {
|
||||
return filterAndSort(addons, filter);
|
||||
}
|
||||
return addons.sort((a, b) => caseInsensitiveStringCompare(a.name, b.name));
|
||||
return addons.sort((a, b) =>
|
||||
caseInsensitiveStringCompare(a.name, b.name, this.hass.locale.language)
|
||||
);
|
||||
});
|
||||
|
||||
protected render(): TemplateResult {
|
||||
|
||||
@@ -404,6 +404,7 @@ class HassioAddonInfo extends LitElement {
|
||||
? html`
|
||||
<img
|
||||
class="logo"
|
||||
alt=""
|
||||
src="/api/hassio/addons/${this.addon.slug}/logo"
|
||||
/>
|
||||
`
|
||||
|
||||
@@ -35,7 +35,13 @@ class HassioAddons extends LitElement {
|
||||
</ha-card>
|
||||
`
|
||||
: this.supervisor.addon.addons
|
||||
.sort((a, b) => caseInsensitiveStringCompare(a.name, b.name))
|
||||
.sort((a, b) =>
|
||||
caseInsensitiveStringCompare(
|
||||
a.name,
|
||||
b.name,
|
||||
this.hass.locale.language
|
||||
)
|
||||
)
|
||||
.map(
|
||||
(addon) => html`
|
||||
<ha-card
|
||||
|
||||
@@ -15,7 +15,12 @@ import { HomeAssistant } from "../../../../src/types";
|
||||
import { HassioHardwareDialogParams } from "./show-dialog-hassio-hardware";
|
||||
|
||||
const _filterDevices = memoizeOne(
|
||||
(showAdvanced: boolean, hardware: HassioHardwareInfo, filter: string) =>
|
||||
(
|
||||
showAdvanced: boolean,
|
||||
hardware: HassioHardwareInfo,
|
||||
filter: string,
|
||||
language: string
|
||||
) =>
|
||||
hardware.devices
|
||||
.filter(
|
||||
(device) =>
|
||||
@@ -28,7 +33,7 @@ const _filterDevices = memoizeOne(
|
||||
.toLocaleLowerCase()
|
||||
.includes(filter))
|
||||
)
|
||||
.sort((a, b) => stringCompare(a.name, b.name))
|
||||
.sort((a, b) => stringCompare(a.name, b.name, language))
|
||||
);
|
||||
|
||||
@customElement("dialog-hassio-hardware")
|
||||
@@ -56,7 +61,8 @@ class HassioHardwareDialog extends LitElement {
|
||||
const devices = _filterDevices(
|
||||
this.hass.userData?.showAdvanced || false,
|
||||
this._dialogParams.hardware,
|
||||
(this._filter || "").toLowerCase()
|
||||
(this._filter || "").toLowerCase(),
|
||||
this.hass.locale.language
|
||||
);
|
||||
|
||||
return html`
|
||||
|
||||
@@ -68,7 +68,9 @@ class HassioRepositoriesDialog extends LitElement {
|
||||
repo.slug !== "a0d7b954" && // Home Assistant Community Add-ons
|
||||
repo.slug !== "5c53de3b" // The ESPHome repository
|
||||
)
|
||||
.sort((a, b) => caseInsensitiveStringCompare(a.name, b.name))
|
||||
.sort((a, b) =>
|
||||
caseInsensitiveStringCompare(a.name, b.name, this.hass.locale.language)
|
||||
)
|
||||
);
|
||||
|
||||
private _filteredUsedRepositories = memoizeOne(
|
||||
|
||||
@@ -59,7 +59,11 @@ class HassioIngressView extends LitElement {
|
||||
return html` <hass-loading-screen></hass-loading-screen> `;
|
||||
}
|
||||
|
||||
const iframe = html`<iframe src=${this._addon.ingress_url!}></iframe>`;
|
||||
const iframe = html`<iframe
|
||||
.title=${this._addon.name}
|
||||
.src=${this._addon.ingress_url!}
|
||||
>
|
||||
</iframe>`;
|
||||
|
||||
if (!this.ingressPanel) {
|
||||
return html`<hass-subpage
|
||||
|
||||
@@ -5,4 +5,5 @@ module.exports = {
|
||||
'printf "%s\n" "Translation files should not be added or modified here. Instead, make the necessary modifications in src/translations/en.json. Other languages are managed externally. Please see https://developers.home-assistant.io/docs/translations/ for details." ' +
|
||||
files.join(" ") +
|
||||
" >&2 && exit 1",
|
||||
"/yarn.lock": () => "yarn dedupe",
|
||||
};
|
||||
|
||||
+3
-2
@@ -106,6 +106,7 @@
|
||||
"core-js": "^3.15.2",
|
||||
"cropperjs": "^1.5.12",
|
||||
"date-fns": "^2.23.0",
|
||||
"date-fns-tz": "^1.3.7",
|
||||
"deep-clone-simple": "^1.1.1",
|
||||
"deep-freeze": "^0.0.1",
|
||||
"fuse.js": "^6.0.0",
|
||||
@@ -183,7 +184,7 @@
|
||||
"@types/sortablejs": "^1",
|
||||
"@types/tar": "^6",
|
||||
"@types/webspeechapi": "^0.0.29",
|
||||
"@typescript-eslint/eslint-plugin": "^5.44.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.46.1",
|
||||
"@typescript-eslint/parser": "^5.44.0",
|
||||
"@web/dev-server": "^0.0.24",
|
||||
"@web/dev-server-rollup": "^0.2.11",
|
||||
@@ -200,7 +201,7 @@
|
||||
"eslint-plugin-lit": "^1.6.1",
|
||||
"eslint-plugin-unused-imports": "^1.1.5",
|
||||
"eslint-plugin-wc": "^1.3.2",
|
||||
"fancy-log": "^1.3.3",
|
||||
"fancy-log": "^2.0.0",
|
||||
"fs-extra": "^7.0.1",
|
||||
"glob": "^7.2.0",
|
||||
"gulp": "^4.0.2",
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "home-assistant-frontend"
|
||||
version = "20221213.0"
|
||||
version = "20230102.0"
|
||||
license = {text = "Apache-2.0"}
|
||||
description = "The Home Assistant frontend"
|
||||
readme = "README.md"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { hex2rgb } from "./convert-color";
|
||||
|
||||
export const THEME_COLORS = new Set([
|
||||
"primary",
|
||||
"accent",
|
||||
@@ -27,16 +25,9 @@ export const THEME_COLORS = new Set([
|
||||
"white",
|
||||
]);
|
||||
|
||||
export function computeRgbColor(color: string): string {
|
||||
export function computeCssColor(color: string): string {
|
||||
if (THEME_COLORS.has(color)) {
|
||||
return `var(--rgb-${color}-color)`;
|
||||
}
|
||||
if (color.startsWith("#")) {
|
||||
try {
|
||||
return hex2rgb(color).join(", ");
|
||||
} catch (err) {
|
||||
return "";
|
||||
}
|
||||
return `rgb(var(--rgb-${color}-color))`;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ import {
|
||||
mdiCommentAlert,
|
||||
mdiCounter,
|
||||
mdiCurrentAc,
|
||||
mdiDatabase,
|
||||
mdiEarHearing,
|
||||
mdiEye,
|
||||
mdiFan,
|
||||
mdiFlash,
|
||||
@@ -57,6 +59,7 @@ import {
|
||||
mdiThermometerLines,
|
||||
mdiThermostat,
|
||||
mdiTimerOutline,
|
||||
mdiTransmissionTower,
|
||||
mdiVideo,
|
||||
mdiWater,
|
||||
mdiWaterPercent,
|
||||
@@ -133,6 +136,8 @@ export const FIXED_DEVICE_CLASS_ICONS = {
|
||||
carbon_dioxide: mdiMoleculeCo2,
|
||||
carbon_monoxide: mdiMoleculeCo,
|
||||
current: mdiCurrentAc,
|
||||
data_rate: mdiTransmissionTower,
|
||||
data_size: mdiDatabase,
|
||||
date: mdiCalendar,
|
||||
distance: mdiArrowLeftRight,
|
||||
duration: mdiProgressClock,
|
||||
@@ -158,6 +163,7 @@ export const FIXED_DEVICE_CLASS_ICONS = {
|
||||
pressure: mdiGauge,
|
||||
reactive_power: mdiFlash,
|
||||
signal_strength: mdiWifi,
|
||||
sound_pressure: mdiEarHearing,
|
||||
speed: mdiSpeedometer,
|
||||
sulphur_dioxide: mdiMolecule,
|
||||
temperature: mdiThermometer,
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
export const alertColor = (state?: string): string | undefined => {
|
||||
switch (state) {
|
||||
case "on":
|
||||
return "alert";
|
||||
case "off":
|
||||
return "alert-off";
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
@@ -6,6 +6,7 @@ const ALERTING_DEVICE_CLASSES = new Set([
|
||||
"carbon_monoxide",
|
||||
"gas",
|
||||
"heat",
|
||||
"lock",
|
||||
"moisture",
|
||||
"problem",
|
||||
"safety",
|
||||
|
||||
@@ -3,6 +3,7 @@ import { HvacAction } from "../../../data/climate";
|
||||
export const CLIMATE_HVAC_ACTION_COLORS: Record<HvacAction, string> = {
|
||||
cooling: "var(--rgb-state-climate-cool-color)",
|
||||
drying: "var(--rgb-state-climate-dry-color)",
|
||||
fan: "var(--rgb-state-climate-fan-only-color)",
|
||||
heating: "var(--rgb-state-climate-heat-color)",
|
||||
idle: "var(--rgb-state-climate-idle-color)",
|
||||
off: "var(--rgb-state-climate-off-color)",
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { HassEntity } from "home-assistant-js-websocket";
|
||||
import { EntityRegistryEntry } from "../../data/entity_registry";
|
||||
import { HomeAssistant } from "../../types";
|
||||
import { LocalizeFunc } from "../translations/localize";
|
||||
import { computeDomain } from "./compute_domain";
|
||||
|
||||
export const computeAttributeValueDisplay = (
|
||||
localize: LocalizeFunc,
|
||||
stateObj: HassEntity,
|
||||
entities: HomeAssistant["entities"],
|
||||
attribute: string,
|
||||
value?: any
|
||||
): string => {
|
||||
const entityId = stateObj.entity_id;
|
||||
const attributeValue =
|
||||
value !== undefined ? value : stateObj.attributes[attribute];
|
||||
const domain = computeDomain(entityId);
|
||||
const entity = entities[entityId] as EntityRegistryEntry | undefined;
|
||||
const translationKey = entity?.translation_key;
|
||||
|
||||
return (
|
||||
(translationKey &&
|
||||
localize(
|
||||
`component.${entity.platform}.entity.${domain}.${translationKey}.state_attributes.${attribute}.state.${attributeValue}`
|
||||
)) ||
|
||||
localize(
|
||||
`component.${domain}.state_attributes._.${attribute}.state.${attributeValue}`
|
||||
) ||
|
||||
attributeValue
|
||||
);
|
||||
};
|
||||
|
||||
export const computeAttributeNameDisplay = (
|
||||
localize: LocalizeFunc,
|
||||
stateObj: HassEntity,
|
||||
entities: HomeAssistant["entities"],
|
||||
attribute: string
|
||||
): string => {
|
||||
const entityId = stateObj.entity_id;
|
||||
const domain = computeDomain(entityId);
|
||||
const entity = entities[entityId] as EntityRegistryEntry | undefined;
|
||||
const translationKey = entity?.translation_key;
|
||||
|
||||
return (
|
||||
(translationKey &&
|
||||
localize(
|
||||
`component.${entity.platform}.entity.${domain}.${translationKey}.state_attributes.${attribute}.name`
|
||||
)) ||
|
||||
localize(`component.${domain}.state_attributes._.${attribute}.name`) ||
|
||||
attribute
|
||||
);
|
||||
};
|
||||
@@ -2,7 +2,7 @@ import { HassEntity } from "home-assistant-js-websocket";
|
||||
import { computeStateDomain } from "./compute_state_domain";
|
||||
import { UNAVAILABLE_STATES } from "../../data/entity";
|
||||
|
||||
const FIXED_DOMAIN_STATES = {
|
||||
export const FIXED_DOMAIN_STATES = {
|
||||
alarm_control_panel: [
|
||||
"armed_away",
|
||||
"armed_custom_bypass",
|
||||
@@ -57,7 +57,7 @@ const FIXED_DOMAIN_STATES = {
|
||||
"windy-variant",
|
||||
"windy",
|
||||
],
|
||||
};
|
||||
} as const;
|
||||
|
||||
const FIXED_DOMAIN_ATTRIBUTE_STATES = {
|
||||
alarm_control_panel: {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { HassEntity } from "home-assistant-js-websocket";
|
||||
import { OFF_STATES, UNAVAILABLE } from "../../data/entity";
|
||||
import { isUnavailableState, OFF, UNAVAILABLE } from "../../data/entity";
|
||||
import { computeDomain } from "./compute_domain";
|
||||
|
||||
export function stateActive(stateObj: HassEntity, state?: string): boolean {
|
||||
@@ -10,7 +10,15 @@ export function stateActive(stateObj: HassEntity, state?: string): boolean {
|
||||
return compareState !== UNAVAILABLE;
|
||||
}
|
||||
|
||||
if (OFF_STATES.includes(compareState)) {
|
||||
if (isUnavailableState(compareState)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The "off" check is relevant for most domains, but there are exceptions
|
||||
// such as "alert" where "off" is still a somewhat active state and
|
||||
// therefore gets a custom color and "idle" is instead the state that
|
||||
// matches what most other domains consider inactive.
|
||||
if (compareState === OFF && domain !== "alert") {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,8 +26,11 @@ export function stateActive(stateObj: HassEntity, state?: string): boolean {
|
||||
switch (domain) {
|
||||
case "alarm_control_panel":
|
||||
return compareState !== "disarmed";
|
||||
case "alert":
|
||||
// "on" and "off" are active, as "off" just means alert was acknowledged but is still active
|
||||
return compareState !== "idle";
|
||||
case "cover":
|
||||
return !["closed", "closing"].includes(compareState);
|
||||
return compareState !== "closed";
|
||||
case "device_tracker":
|
||||
case "person":
|
||||
return compareState !== "not_home";
|
||||
@@ -37,7 +48,7 @@ export function stateActive(stateObj: HassEntity, state?: string): boolean {
|
||||
return compareState === "active";
|
||||
case "camera":
|
||||
return compareState === "streaming";
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { HassEntity } from "home-assistant-js-websocket";
|
||||
import { UNAVAILABLE } from "../../data/entity";
|
||||
import { alarmControlPanelColor } from "./color/alarm_control_panel_color";
|
||||
import { alertColor } from "./color/alert_color";
|
||||
import { binarySensorColor } from "./color/binary_sensor_color";
|
||||
import { climateColor } from "./color/climate_color";
|
||||
import { lockColor } from "./color/lock_color";
|
||||
@@ -12,7 +13,6 @@ import { computeDomain } from "./compute_domain";
|
||||
import { stateActive } from "./state_active";
|
||||
|
||||
const STATIC_ACTIVE_COLORED_DOMAIN = new Set([
|
||||
"alert",
|
||||
"automation",
|
||||
"calendar",
|
||||
"camera",
|
||||
@@ -65,6 +65,9 @@ export const stateColor = (stateObj: HassEntity, state?: string) => {
|
||||
case "alarm_control_panel":
|
||||
return alarmControlPanelColor(compareState);
|
||||
|
||||
case "alert":
|
||||
return alertColor(compareState);
|
||||
|
||||
case "binary_sensor":
|
||||
return binarySensorColor(stateObj, compareState);
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ export const protocolIntegrationPicked = async (
|
||||
"ui.panel.config.integrations.config_flow.missing_zwave_zigbee",
|
||||
{
|
||||
integration: "Zigbee",
|
||||
brand: options?.brand || options?.domain || "Z-Wave",
|
||||
brand: options?.brand || options?.domain || "Zigbee",
|
||||
supported_hardware_link: html`<a
|
||||
href=${documentationUrl(
|
||||
hass,
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
export const stringCompare = (a: string, b: string) => {
|
||||
import memoizeOne from "memoize-one";
|
||||
|
||||
const collator = memoizeOne(
|
||||
(language: string | undefined) => new Intl.Collator(language)
|
||||
);
|
||||
|
||||
const caseInsensitiveCollator = memoizeOne(
|
||||
(language: string | undefined) =>
|
||||
new Intl.Collator(language, { sensitivity: "accent" })
|
||||
);
|
||||
|
||||
const fallbackStringCompare = (a: string, b: string) => {
|
||||
if (a < b) {
|
||||
return -1;
|
||||
}
|
||||
@@ -9,5 +20,28 @@ export const stringCompare = (a: string, b: string) => {
|
||||
return 0;
|
||||
};
|
||||
|
||||
export const caseInsensitiveStringCompare = (a: string, b: string) =>
|
||||
stringCompare(a.toLowerCase(), b.toLowerCase());
|
||||
export const stringCompare = (
|
||||
a: string,
|
||||
b: string,
|
||||
language: string | undefined = undefined
|
||||
) => {
|
||||
// @ts-ignore
|
||||
if (Intl?.Collator) {
|
||||
return collator(language).compare(a, b);
|
||||
}
|
||||
|
||||
return fallbackStringCompare(a, b);
|
||||
};
|
||||
|
||||
export const caseInsensitiveStringCompare = (
|
||||
a: string,
|
||||
b: string,
|
||||
language: string | undefined = undefined
|
||||
) => {
|
||||
// @ts-ignore
|
||||
if (Intl?.Collator) {
|
||||
return caseInsensitiveCollator(language).compare(a, b);
|
||||
}
|
||||
|
||||
return fallbackStringCompare(a.toLowerCase(), b.toLowerCase());
|
||||
};
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { css } from "lit";
|
||||
|
||||
export const iconColorCSS = css`
|
||||
ha-state-icon[data-active][data-domain="alarm_control_panel"][data-state="pending"],
|
||||
ha-state-icon[data-active][data-domain="alarm_control_panel"][data-state="arming"],
|
||||
ha-state-icon[data-active][data-domain="alarm_control_panel"][data-state="triggered"] {
|
||||
ha-state-icon[data-domain="alarm_control_panel"][data-state="pending"],
|
||||
ha-state-icon[data-domain="alarm_control_panel"][data-state="arming"],
|
||||
ha-state-icon[data-domain="alarm_control_panel"][data-state="triggered"],
|
||||
ha-state-icon[data-domain="lock"][data-state="jammed"] {
|
||||
animation: pulse 1s infinite;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,6 @@ import { getLocalLanguage } from "../../util/common-translation";
|
||||
export type LocalizeKeys =
|
||||
| FlattenObjectKeys<Omit<TranslationDict, "supervisor">>
|
||||
| `panel.${string}`
|
||||
| `state.${string}`
|
||||
| `state_attributes.${string}`
|
||||
| `state_badge.${string}`
|
||||
| `ui.card.alarm_control_panel.${string}`
|
||||
| `ui.card.weather.attributes.${string}`
|
||||
| `ui.card.weather.cardinal_direction.${string}`
|
||||
|
||||
@@ -266,14 +266,16 @@ export const getCountryOptions = memoizeOne((language?: string) => {
|
||||
value: country,
|
||||
label: countryDisplayNames ? countryDisplayNames.of(country)! : country,
|
||||
}));
|
||||
options.sort((a, b) => caseInsensitiveStringCompare(a.label, b.label));
|
||||
options.sort((a, b) =>
|
||||
caseInsensitiveStringCompare(a.label, b.label, language)
|
||||
);
|
||||
return options;
|
||||
});
|
||||
|
||||
export const createCountryListEl = () => {
|
||||
export const createCountryListEl = (language?: string) => {
|
||||
const list = document.createElement("datalist");
|
||||
list.id = "countries";
|
||||
const options = getCountryOptions();
|
||||
const options = getCountryOptions(language);
|
||||
for (const country of options) {
|
||||
const option = document.createElement("option");
|
||||
option.value = country.value;
|
||||
|
||||
@@ -173,14 +173,16 @@ export const getCurrencyOptions = memoizeOne((language?: string) => {
|
||||
value: currency,
|
||||
label: currencyDisplayNames ? currencyDisplayNames.of(currency)! : currency,
|
||||
}));
|
||||
options.sort((a, b) => caseInsensitiveStringCompare(a.label, b.label));
|
||||
options.sort((a, b) =>
|
||||
caseInsensitiveStringCompare(a.label, b.label, language)
|
||||
);
|
||||
return options;
|
||||
});
|
||||
|
||||
export const createCurrencyListEl = () => {
|
||||
export const createCurrencyListEl = (language: string) => {
|
||||
const list = document.createElement("datalist");
|
||||
list.id = "currencies";
|
||||
for (const currency of getCurrencyOptions()) {
|
||||
for (const currency of getCurrencyOptions(language)) {
|
||||
const option = document.createElement("option");
|
||||
option.value = currency.value;
|
||||
option.innerText = currency.label;
|
||||
|
||||
@@ -1,26 +1,15 @@
|
||||
import "@material/mwc-button/mwc-button";
|
||||
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
||||
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
||||
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { fireEvent } from "../../common/dom/fire_event";
|
||||
import { computeDomain } from "../../common/entity/compute_domain";
|
||||
import { stringCompare } from "../../common/string/compare";
|
||||
import {
|
||||
AreaRegistryEntry,
|
||||
subscribeAreaRegistry,
|
||||
} from "../../data/area_registry";
|
||||
import {
|
||||
DeviceEntityLookup,
|
||||
DeviceRegistryEntry,
|
||||
subscribeDeviceRegistry,
|
||||
} from "../../data/device_registry";
|
||||
import {
|
||||
EntityRegistryEntry,
|
||||
subscribeEntityRegistry,
|
||||
} from "../../data/entity_registry";
|
||||
import { SubscribeMixin } from "../../mixins/subscribe-mixin";
|
||||
import { PolymerChangedEvent } from "../../polymer-types";
|
||||
import { HomeAssistant } from "../../types";
|
||||
import "../ha-icon-button";
|
||||
@@ -45,7 +34,7 @@ const rowRenderer: ComboBoxLitRenderer<AreaDevices> = (
|
||||
</mwc-list-item>`;
|
||||
|
||||
@customElement("ha-area-devices-picker")
|
||||
export class HaAreaDevicesPicker extends SubscribeMixin(LitElement) {
|
||||
export class HaAreaDevicesPicker extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property() public label?: string;
|
||||
@@ -82,25 +71,22 @@ export class HaAreaDevicesPicker extends SubscribeMixin(LitElement) {
|
||||
|
||||
@state() private _areaPicker = true;
|
||||
|
||||
@state() private _devices?: DeviceRegistryEntry[];
|
||||
|
||||
@state() private _areas?: AreaRegistryEntry[];
|
||||
|
||||
@state() private _entities?: EntityRegistryEntry[];
|
||||
|
||||
private _selectedDevices: string[] = [];
|
||||
|
||||
private _filteredDevices: DeviceRegistryEntry[] = [];
|
||||
|
||||
private _getAreasWithDevices = memoizeOne(
|
||||
(
|
||||
devices: DeviceRegistryEntry[],
|
||||
areas: AreaRegistryEntry[],
|
||||
entities: EntityRegistryEntry[],
|
||||
deviceReg: HomeAssistant["devices"],
|
||||
areas: HomeAssistant["areas"],
|
||||
entityReg: HomeAssistant["entities"],
|
||||
includeDomains: this["includeDomains"],
|
||||
excludeDomains: this["excludeDomains"],
|
||||
includeDeviceClasses: this["includeDeviceClasses"]
|
||||
): AreaDevices[] => {
|
||||
const devices = Object.values(deviceReg);
|
||||
const entities = Object.values(entityReg);
|
||||
|
||||
if (!devices.length) {
|
||||
return [];
|
||||
}
|
||||
@@ -164,11 +150,6 @@ export class HaAreaDevicesPicker extends SubscribeMixin(LitElement) {
|
||||
|
||||
this._filteredDevices = inputDevices;
|
||||
|
||||
const areaLookup: { [areaId: string]: AreaRegistryEntry } = {};
|
||||
for (const area of areas) {
|
||||
areaLookup[area.area_id] = area;
|
||||
}
|
||||
|
||||
const devicesByArea: DevicesByArea = {};
|
||||
|
||||
for (const device of inputDevices) {
|
||||
@@ -177,7 +158,7 @@ export class HaAreaDevicesPicker extends SubscribeMixin(LitElement) {
|
||||
if (!(areaId in devicesByArea)) {
|
||||
devicesByArea[areaId] = {
|
||||
id: areaId,
|
||||
name: areaLookup[areaId].name,
|
||||
name: areas[areaId].name,
|
||||
devices: [],
|
||||
};
|
||||
}
|
||||
@@ -189,7 +170,8 @@ export class HaAreaDevicesPicker extends SubscribeMixin(LitElement) {
|
||||
.sort((a, b) =>
|
||||
stringCompare(
|
||||
devicesByArea[a].name || "",
|
||||
devicesByArea[b].name || ""
|
||||
devicesByArea[b].name || "",
|
||||
this.hass.locale.language
|
||||
)
|
||||
)
|
||||
.map((key) => devicesByArea[key]);
|
||||
@@ -198,20 +180,6 @@ export class HaAreaDevicesPicker extends SubscribeMixin(LitElement) {
|
||||
}
|
||||
);
|
||||
|
||||
public hassSubscribe(): UnsubscribeFunc[] {
|
||||
return [
|
||||
subscribeDeviceRegistry(this.hass.connection!, (devices) => {
|
||||
this._devices = devices;
|
||||
}),
|
||||
subscribeAreaRegistry(this.hass.connection!, (areas) => {
|
||||
this._areas = areas;
|
||||
}),
|
||||
subscribeEntityRegistry(this.hass.connection!, (entities) => {
|
||||
this._entities = entities;
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
protected updated(changedProps: PropertyValues) {
|
||||
super.updated(changedProps);
|
||||
if (changedProps.has("area") && this.area) {
|
||||
@@ -230,13 +198,10 @@ export class HaAreaDevicesPicker extends SubscribeMixin(LitElement) {
|
||||
}
|
||||
|
||||
protected render(): TemplateResult {
|
||||
if (!this._devices || !this._areas || !this._entities) {
|
||||
return html``;
|
||||
}
|
||||
const areas = this._getAreasWithDevices(
|
||||
this._devices,
|
||||
this._areas,
|
||||
this._entities,
|
||||
this.hass.devices,
|
||||
this.hass.areas,
|
||||
this.hass.entities,
|
||||
this.includeDomains,
|
||||
this.excludeDomains,
|
||||
this.includeDeviceClasses
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import "@material/mwc-list/mwc-list-item";
|
||||
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
||||
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
@@ -7,21 +6,15 @@ import memoizeOne from "memoize-one";
|
||||
import { fireEvent } from "../../common/dom/fire_event";
|
||||
import { computeDomain } from "../../common/entity/compute_domain";
|
||||
import { stringCompare } from "../../common/string/compare";
|
||||
import {
|
||||
AreaRegistryEntry,
|
||||
subscribeAreaRegistry,
|
||||
} from "../../data/area_registry";
|
||||
|
||||
|
||||
import {
|
||||
computeDeviceName,
|
||||
DeviceEntityLookup,
|
||||
DeviceRegistryEntry,
|
||||
subscribeDeviceRegistry,
|
||||
} from "../../data/device_registry";
|
||||
import {
|
||||
EntityRegistryEntry,
|
||||
subscribeEntityRegistry,
|
||||
} from "../../data/entity_registry";
|
||||
import { SubscribeMixin } from "../../mixins/subscribe-mixin";
|
||||
|
||||
|
||||
import { PolymerChangedEvent } from "../../polymer-types";
|
||||
import { HomeAssistant } from "../../types";
|
||||
import "../ha-combo-box";
|
||||
@@ -45,7 +38,7 @@ const rowRenderer: ComboBoxLitRenderer<Device> = (item) => html`<mwc-list-item
|
||||
</mwc-list-item>`;
|
||||
|
||||
@customElement("ha-device-picker")
|
||||
export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
||||
export class HaDevicePicker extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property() public label?: string;
|
||||
@@ -54,12 +47,6 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
||||
|
||||
@property() public helper?: string;
|
||||
|
||||
@property() public devices?: DeviceRegistryEntry[];
|
||||
|
||||
@property() public areas?: AreaRegistryEntry[];
|
||||
|
||||
@property() public entities?: EntityRegistryEntry[];
|
||||
|
||||
/**
|
||||
* Show only devices with entities from specific domains.
|
||||
* @type {Array}
|
||||
@@ -84,6 +71,14 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
||||
@property({ type: Array, attribute: "include-device-classes" })
|
||||
public includeDeviceClasses?: string[];
|
||||
|
||||
/**
|
||||
* List of devices to be excluded.
|
||||
* @type {Array}
|
||||
* @attr exclude-devices
|
||||
*/
|
||||
@property({ type: Array, attribute: "exclude-devices" })
|
||||
public excludeDevices?: string[];
|
||||
|
||||
@property() public deviceFilter?: HaDevicePickerDeviceFilterFunc;
|
||||
|
||||
@property({ type: Boolean }) public disabled?: boolean;
|
||||
@@ -98,14 +93,18 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
||||
|
||||
private _getDevices = memoizeOne(
|
||||
(
|
||||
devices: DeviceRegistryEntry[],
|
||||
areas: AreaRegistryEntry[],
|
||||
entities: EntityRegistryEntry[],
|
||||
deviceReg: HomeAssistant["devices"],
|
||||
areas: HomeAssistant["areas"],
|
||||
entityReg: HomeAssistant["entities"],
|
||||
includeDomains: this["includeDomains"],
|
||||
excludeDomains: this["excludeDomains"],
|
||||
includeDeviceClasses: this["includeDeviceClasses"],
|
||||
deviceFilter: this["deviceFilter"]
|
||||
deviceFilter: this["deviceFilter"],
|
||||
excludeDevices: this["excludeDevices"]
|
||||
): Device[] => {
|
||||
const devices = Object.values(deviceReg);
|
||||
const entities = Object.values(entityReg);
|
||||
|
||||
if (!devices.length) {
|
||||
return [
|
||||
{
|
||||
@@ -129,12 +128,6 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
||||
deviceEntityLookup[entity.device_id].push(entity);
|
||||
}
|
||||
}
|
||||
|
||||
const areaLookup: { [areaId: string]: AreaRegistryEntry } = {};
|
||||
for (const area of areas) {
|
||||
areaLookup[area.area_id] = area;
|
||||
}
|
||||
|
||||
let inputDevices = devices.filter(
|
||||
(device) => device.id === this.value || !device.disabled_by
|
||||
);
|
||||
@@ -164,6 +157,12 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
||||
});
|
||||
}
|
||||
|
||||
if (excludeDevices) {
|
||||
inputDevices = inputDevices.filter(
|
||||
(device) => !excludeDevices!.includes(device.id)
|
||||
);
|
||||
}
|
||||
|
||||
if (includeDeviceClasses) {
|
||||
inputDevices = inputDevices.filter((device) => {
|
||||
const devEntities = deviceEntityLookup[device.id];
|
||||
@@ -199,8 +198,8 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
||||
deviceEntityLookup[device.id]
|
||||
),
|
||||
area:
|
||||
device.area_id && areaLookup[device.area_id]
|
||||
? areaLookup[device.area_id].name
|
||||
device.area_id && device.area_id in areas
|
||||
? areas[device.area_id].name
|
||||
: this.hass.localize("ui.components.device-picker.no_area"),
|
||||
}));
|
||||
if (!outputDevices.length) {
|
||||
@@ -216,7 +215,7 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
||||
return outputDevices;
|
||||
}
|
||||
return outputDevices.sort((a, b) =>
|
||||
stringCompare(a.name || "", b.name || "")
|
||||
stringCompare(a.name || "", b.name || "", this.hass.locale.language)
|
||||
);
|
||||
}
|
||||
);
|
||||
@@ -231,34 +230,21 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
||||
await this.comboBox?.focus();
|
||||
}
|
||||
|
||||
public hassSubscribe(): UnsubscribeFunc[] {
|
||||
return [
|
||||
subscribeDeviceRegistry(this.hass.connection!, (devices) => {
|
||||
this.devices = devices;
|
||||
}),
|
||||
subscribeAreaRegistry(this.hass.connection!, (areas) => {
|
||||
this.areas = areas;
|
||||
}),
|
||||
subscribeEntityRegistry(this.hass.connection!, (entities) => {
|
||||
this.entities = entities;
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
protected updated(changedProps: PropertyValues) {
|
||||
if (
|
||||
(!this._init && this.devices && this.areas && this.entities) ||
|
||||
!this._init ||
|
||||
(this._init && changedProps.has("_opened") && this._opened)
|
||||
) {
|
||||
this._init = true;
|
||||
(this.comboBox as any).items = this._getDevices(
|
||||
this.devices!,
|
||||
this.areas!,
|
||||
this.entities!,
|
||||
this.hass.devices,
|
||||
this.hass.areas,
|
||||
this.hass.entities,
|
||||
this.includeDomains,
|
||||
this.excludeDomains,
|
||||
this.includeDeviceClasses,
|
||||
this.deviceFilter
|
||||
this.deviceFilter,
|
||||
this.excludeDevices
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +174,8 @@ export class HaEntityPicker extends LitElement {
|
||||
.sort((entityA, entityB) =>
|
||||
caseInsensitiveStringCompare(
|
||||
entityA.friendly_name,
|
||||
entityB.friendly_name
|
||||
entityB.friendly_name,
|
||||
this.hass.locale.language
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -205,7 +206,8 @@ export class HaEntityPicker extends LitElement {
|
||||
.sort((entityA, entityB) =>
|
||||
caseInsensitiveStringCompare(
|
||||
entityA.friendly_name,
|
||||
entityB.friendly_name
|
||||
entityB.friendly_name,
|
||||
this.hass.locale.language
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import { property, state } from "lit/decorators";
|
||||
import { STATES_OFF } from "../../common/const";
|
||||
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
||||
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||
import { UNAVAILABLE, UNAVAILABLE_STATES, UNKNOWN } from "../../data/entity";
|
||||
import { isUnavailableState, UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
||||
import { forwardHaptic } from "../../data/haptics";
|
||||
import { HomeAssistant } from "../../types";
|
||||
import "../ha-formfield";
|
||||
@@ -22,7 +22,7 @@ import "../ha-switch";
|
||||
const isOn = (stateObj?: HassEntity) =>
|
||||
stateObj !== undefined &&
|
||||
!STATES_OFF.includes(stateObj.state) &&
|
||||
!UNAVAILABLE_STATES.includes(stateObj.state);
|
||||
!isUnavailableState(stateObj.state);
|
||||
|
||||
export class HaEntityToggle extends LitElement {
|
||||
// hass is not a property so that we only re-render on stateObj changes
|
||||
|
||||
@@ -10,21 +10,45 @@ import {
|
||||
} from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { arrayLiteralIncludes } from "../../common/array/literal-includes";
|
||||
import secondsToDuration from "../../common/datetime/seconds_to_duration";
|
||||
import { computeStateDisplay } from "../../common/entity/compute_state_display";
|
||||
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
||||
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||
import { FIXED_DOMAIN_STATES } from "../../common/entity/get_states";
|
||||
import {
|
||||
formatNumber,
|
||||
getNumberFormatOptions,
|
||||
isNumericState,
|
||||
} from "../../common/number/format_number";
|
||||
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
||||
import { isUnavailableState, UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
||||
import { timerTimeRemaining } from "../../data/timer";
|
||||
import { HomeAssistant } from "../../types";
|
||||
import "../ha-label-badge";
|
||||
import "../ha-state-icon";
|
||||
|
||||
// Define the domains whose states have special truncated strings
|
||||
const TRUNCATED_DOMAINS = [
|
||||
"alarm_control_panel",
|
||||
"device_tracker",
|
||||
"person",
|
||||
] as const satisfies ReadonlyArray<keyof typeof FIXED_DOMAIN_STATES>;
|
||||
|
||||
type TruncatedDomain = typeof TRUNCATED_DOMAINS[number];
|
||||
type TruncatedKey = {
|
||||
[T in TruncatedDomain]: `${T}.${typeof FIXED_DOMAIN_STATES[T][number]}`;
|
||||
}[TruncatedDomain];
|
||||
|
||||
const getTruncatedKey = (domainKey: string, stateKey: string) => {
|
||||
if (
|
||||
arrayLiteralIncludes(TRUNCATED_DOMAINS)(domainKey) &&
|
||||
arrayLiteralIncludes(FIXED_DOMAIN_STATES[domainKey])(stateKey)
|
||||
) {
|
||||
return `${domainKey}.${stateKey}` as TruncatedKey;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
@customElement("ha-state-label-badge")
|
||||
export class HaStateLabelBadge extends LitElement {
|
||||
@property({ attribute: false }) public hass?: HomeAssistant;
|
||||
@@ -186,19 +210,18 @@ export class HaStateLabelBadge extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private _computeLabel(domain, entityState, _timerTimeRemaining) {
|
||||
if (
|
||||
entityState.state === UNAVAILABLE ||
|
||||
["device_tracker", "alarm_control_panel", "person"].includes(domain)
|
||||
) {
|
||||
// Localize the state with a special state_badge namespace, which has variations of
|
||||
// the state translations that are truncated to fit within the badge label. Translations
|
||||
// are only added for device_tracker, alarm_control_panel and person.
|
||||
return (
|
||||
this.hass!.localize(`state_badge.${domain}.${entityState.state}`) ||
|
||||
this.hass!.localize(`state_badge.default.${entityState.state}`) ||
|
||||
entityState.state
|
||||
);
|
||||
private _computeLabel(
|
||||
domain: string,
|
||||
entityState: HassEntity,
|
||||
_timerTimeRemaining = 0
|
||||
) {
|
||||
// For unavailable states or certain domains, use a special translation that is truncated to fit within the badge label
|
||||
if (isUnavailableState(entityState.state)) {
|
||||
return this.hass!.localize(`state_badge.default.${entityState.state}`);
|
||||
}
|
||||
const domainStateKey = getTruncatedKey(domain, entityState.state);
|
||||
if (domainStateKey) {
|
||||
return this.hass!.localize(`state_badge.${domainStateKey}`);
|
||||
}
|
||||
if (domain === "timer") {
|
||||
return secondsToDuration(_timerTimeRemaining);
|
||||
|
||||
@@ -177,7 +177,9 @@ export class HaStatisticPicker extends LitElement {
|
||||
}
|
||||
|
||||
if (output.length > 1) {
|
||||
output.sort((a, b) => stringCompare(a.name || "", b.name || ""));
|
||||
output.sort((a, b) =>
|
||||
stringCompare(a.name || "", b.name || "", this.hass.locale.language)
|
||||
);
|
||||
}
|
||||
|
||||
output.push({
|
||||
|
||||
@@ -32,6 +32,8 @@ export class StateBadge extends LitElement {
|
||||
|
||||
@property({ type: Boolean }) public stateColor?: boolean;
|
||||
|
||||
@property() public color?: string;
|
||||
|
||||
@property({ type: Boolean, reflect: true, attribute: "icon" })
|
||||
private _showIcon = true;
|
||||
|
||||
@@ -59,11 +61,9 @@ export class StateBadge extends LitElement {
|
||||
}
|
||||
|
||||
const domain = stateObj ? computeStateDomain(stateObj) : undefined;
|
||||
const active = this._stateColor && stateObj ? stateActive(stateObj) : false;
|
||||
|
||||
return html`<ha-state-icon
|
||||
style=${styleMap(this._iconStyle)}
|
||||
?data-active=${active}
|
||||
data-domain=${ifDefined(domain)}
|
||||
data-state=${ifDefined(stateObj?.state)}
|
||||
.icon=${this.overrideIcon}
|
||||
@@ -77,7 +77,8 @@ export class StateBadge extends LitElement {
|
||||
!changedProps.has("stateObj") &&
|
||||
!changedProps.has("overrideImage") &&
|
||||
!changedProps.has("overrideIcon") &&
|
||||
!changedProps.has("stateColor")
|
||||
!changedProps.has("stateColor") &&
|
||||
!changedProps.has("color")
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@@ -108,6 +109,9 @@ export class StateBadge extends LitElement {
|
||||
}
|
||||
hostStyle.backgroundImage = `url(${imageUrl})`;
|
||||
this._showIcon = false;
|
||||
} else if (this.color) {
|
||||
// Externally provided overriding color wins over state color
|
||||
iconStyle.color = this.color;
|
||||
} else if (this._stateColor && stateActive(stateObj)) {
|
||||
const color = stateColorCss(stateObj);
|
||||
if (color) {
|
||||
|
||||
@@ -19,6 +19,8 @@ class StateInfo extends LitElement {
|
||||
// property used only in CSS
|
||||
@property({ type: Boolean, reflect: true }) public rtl = false;
|
||||
|
||||
@property() public color?: string;
|
||||
|
||||
protected render(): TemplateResult {
|
||||
if (!this.hass || !this.stateObj) {
|
||||
return html``;
|
||||
@@ -29,6 +31,7 @@ class StateInfo extends LitElement {
|
||||
return html`<state-badge
|
||||
.stateObj=${this.stateObj}
|
||||
.stateColor=${true}
|
||||
.color=${this.color}
|
||||
></state-badge>
|
||||
<div class="info">
|
||||
<div class="name" .title=${name} .inDialog=${this.inDialog}>
|
||||
|
||||
@@ -16,7 +16,11 @@ const rowRenderer: ComboBoxLitRenderer<HassioAddonInfo> = (
|
||||
<span>${item.name}</span>
|
||||
<span slot="secondary">${item.slug}</span>
|
||||
${item.icon
|
||||
? html`<img slot="graphic" .src="/api/hassio/addons/${item.slug}/icon" />`
|
||||
? html`<img
|
||||
alt=""
|
||||
slot="graphic"
|
||||
.src="/api/hassio/addons/${item.slug}/icon"
|
||||
/>`
|
||||
: ""}
|
||||
</mwc-list-item>`;
|
||||
|
||||
@@ -80,7 +84,9 @@ class HaAddonPicker extends LitElement {
|
||||
const addonsInfo = await fetchHassioAddonsInfo(this.hass);
|
||||
this._addons = addonsInfo.addons
|
||||
.filter((addon) => addon.version)
|
||||
.sort((a, b) => stringCompare(a.name, b.name));
|
||||
.sort((a, b) =>
|
||||
stringCompare(a.name, b.name, this.hass.locale.language)
|
||||
);
|
||||
} else {
|
||||
showAlertDialog(this, {
|
||||
title: this.hass.localize(
|
||||
|
||||
@@ -73,6 +73,14 @@ export class HaAreaPicker extends LitElement {
|
||||
@property({ type: Array, attribute: "include-device-classes" })
|
||||
public includeDeviceClasses?: string[];
|
||||
|
||||
/**
|
||||
* List of areas to be excluded.
|
||||
* @type {Array}
|
||||
* @attr exclude-areas
|
||||
*/
|
||||
@property({ type: Array, attribute: "exclude-areas" })
|
||||
public excludeAreas?: string[];
|
||||
|
||||
@property() public deviceFilter?: HaDevicePickerDeviceFilterFunc;
|
||||
|
||||
@property() public entityFilter?: (entity: EntityRegistryEntry) => boolean;
|
||||
@@ -109,7 +117,8 @@ export class HaAreaPicker extends LitElement {
|
||||
includeDeviceClasses: this["includeDeviceClasses"],
|
||||
deviceFilter: this["deviceFilter"],
|
||||
entityFilter: this["entityFilter"],
|
||||
noAdd: this["noAdd"]
|
||||
noAdd: this["noAdd"],
|
||||
excludeAreas: this["excludeAreas"]
|
||||
): AreaRegistryEntry[] => {
|
||||
if (!areas.length) {
|
||||
return [
|
||||
@@ -235,6 +244,12 @@ export class HaAreaPicker extends LitElement {
|
||||
outputAreas = areas.filter((area) => areaIds!.includes(area.area_id));
|
||||
}
|
||||
|
||||
if (excludeAreas) {
|
||||
outputAreas = outputAreas.filter(
|
||||
(area) => !excludeAreas!.includes(area.area_id)
|
||||
);
|
||||
}
|
||||
|
||||
if (!outputAreas.length) {
|
||||
outputAreas = [
|
||||
{
|
||||
@@ -264,7 +279,7 @@ export class HaAreaPicker extends LitElement {
|
||||
(this._init && changedProps.has("_opened") && this._opened)
|
||||
) {
|
||||
this._init = true;
|
||||
(this.comboBox as any).items = this._getAreas(
|
||||
const areas = this._getAreas(
|
||||
Object.values(this.hass.areas),
|
||||
Object.values(this.hass.devices),
|
||||
Object.values(this.hass.entities),
|
||||
@@ -273,8 +288,11 @@ export class HaAreaPicker extends LitElement {
|
||||
this.includeDeviceClasses,
|
||||
this.deviceFilter,
|
||||
this.entityFilter,
|
||||
this.noAdd
|
||||
this.noAdd,
|
||||
this.excludeAreas
|
||||
);
|
||||
(this.comboBox as any).items = areas;
|
||||
(this.comboBox as any).filteredItems = areas;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,7 +402,8 @@ export class HaAreaPicker extends LitElement {
|
||||
this.includeDeviceClasses,
|
||||
this.deviceFilter,
|
||||
this.entityFilter,
|
||||
this.noAdd
|
||||
this.noAdd,
|
||||
this.excludeAreas
|
||||
);
|
||||
await this.updateComplete;
|
||||
await this.comboBox.updateComplete;
|
||||
|
||||
@@ -2,13 +2,12 @@ import { css, html, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { fireEvent } from "../common/dom/fire_event";
|
||||
import type { EntityRegistryEntry } from "../data/entity_registry";
|
||||
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
||||
import type { HomeAssistant } from "../types";
|
||||
import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker";
|
||||
import "./ha-area-picker";
|
||||
|
||||
@customElement("ha-areas-picker")
|
||||
export class HaAreasPicker extends SubscribeMixin(LitElement) {
|
||||
export class HaAreasPicker extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property() public label?: string;
|
||||
|
||||
@@ -272,7 +272,8 @@ export class HaBarSlider extends LitElement {
|
||||
:host {
|
||||
display: block;
|
||||
--slider-bar-color: rgb(var(--rgb-primary-color));
|
||||
--slider-bar-background: rgba(var(--rgb-disabled-color), 0.2);
|
||||
--slider-bar-background: rgb(var(--rgb-disabled-color));
|
||||
--slider-bar-background-opacity: 0.2;
|
||||
--slider-bar-thickness: 40px;
|
||||
--slider-bar-border-radius: 10px;
|
||||
height: var(--slider-bar-thickness);
|
||||
@@ -301,6 +302,7 @@ export class HaBarSlider extends LitElement {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background: var(--slider-bar-background);
|
||||
opacity: var(--slider-bar-background-opacity);
|
||||
}
|
||||
.slider .slider-track-bar {
|
||||
--border-radius: var(--slider-bar-border-radius);
|
||||
|
||||
@@ -74,6 +74,7 @@ export class HaBarSwitch extends LitElement {
|
||||
protected render(): TemplateResult {
|
||||
return html`
|
||||
<div class="switch">
|
||||
<div class="background"></div>
|
||||
<div class="button" aria-hidden="true">
|
||||
${this.checked
|
||||
? this.pathOn
|
||||
@@ -91,8 +92,9 @@ export class HaBarSwitch extends LitElement {
|
||||
return css`
|
||||
:host {
|
||||
display: block;
|
||||
--switch-bar-color-on: var(--rgb-primary-color);
|
||||
--switch-bar-color-off: var(--rgb-disabled-color);
|
||||
--switch-bar-on-color: rgb(var(--rgb-primary-color));
|
||||
--switch-bar-off-color: rgb(var(--rgb-disabled-color));
|
||||
--switch-bar-background-opacity: 0.2;
|
||||
--switch-bar-thickness: 40px;
|
||||
--switch-bar-border-radius: 12px;
|
||||
--switch-bar-padding: 4px;
|
||||
@@ -109,11 +111,20 @@ export class HaBarSwitch extends LitElement {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
border-radius: var(--switch-bar-border-radius);
|
||||
background-color: rgba(var(--switch-bar-color-off), 0.3);
|
||||
overflow: hidden;
|
||||
padding: var(--switch-bar-padding);
|
||||
transition: background-color 180ms ease-in-out;
|
||||
display: flex;
|
||||
}
|
||||
.switch .background {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background-color: var(--switch-bar-off-color);
|
||||
transition: background-color 180ms ease-in-out;
|
||||
opacity: var(--switch-bar-background-opacity);
|
||||
}
|
||||
.switch .button {
|
||||
width: 50%;
|
||||
height: 100%;
|
||||
@@ -123,18 +134,18 @@ export class HaBarSwitch extends LitElement {
|
||||
);
|
||||
transition: transform 180ms ease-in-out,
|
||||
background-color 180ms ease-in-out;
|
||||
background-color: rgb(var(--switch-bar-color-off));
|
||||
background-color: var(--switch-bar-off-color);
|
||||
color: white;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
:host([checked]) .switch {
|
||||
background-color: rgba(var(--switch-bar-color-on), 0.3);
|
||||
:host([checked]) .switch .background {
|
||||
background-color: var(--switch-bar-on-color);
|
||||
}
|
||||
:host([checked]) .switch .button {
|
||||
transform: translateX(100%);
|
||||
background-color: rgb(var(--switch-bar-color-on));
|
||||
background-color: var(--switch-bar-on-color);
|
||||
}
|
||||
:host([reversed]) .switch {
|
||||
flex-direction: row-reverse;
|
||||
|
||||
@@ -266,6 +266,9 @@ export class HaBaseTimeInput extends LitElement {
|
||||
seconds: this.seconds,
|
||||
milliseconds: this.milliseconds,
|
||||
};
|
||||
if (this.enableDay) {
|
||||
value.days = this.days;
|
||||
}
|
||||
if (this.format === 12) {
|
||||
value.amPm = this.amPm;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,9 @@ class HaBluePrintPicker extends LitElement {
|
||||
...(blueprint as Blueprint).metadata,
|
||||
path,
|
||||
}));
|
||||
return result.sort((a, b) => stringCompare(a.name, b.name));
|
||||
return result.sort((a, b) =>
|
||||
stringCompare(a.name, b.name, this.hass!.locale.language)
|
||||
);
|
||||
});
|
||||
|
||||
protected render(): TemplateResult {
|
||||
|
||||
@@ -1,37 +1,41 @@
|
||||
import { HassEntity } from "home-assistant-js-websocket";
|
||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { computeAttributeValueDisplay } from "../common/entity/compute_attribute_display";
|
||||
import { computeStateDisplay } from "../common/entity/compute_state_display";
|
||||
import { formatNumber } from "../common/number/format_number";
|
||||
import { CLIMATE_PRESET_NONE } from "../data/climate";
|
||||
import { UNAVAILABLE_STATES } from "../data/entity";
|
||||
import { ClimateEntity, CLIMATE_PRESET_NONE } from "../data/climate";
|
||||
import { isUnavailableState } from "../data/entity";
|
||||
import type { HomeAssistant } from "../types";
|
||||
|
||||
@customElement("ha-climate-state")
|
||||
class HaClimateState extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property({ attribute: false }) public stateObj!: HassEntity;
|
||||
@property({ attribute: false }) public stateObj!: ClimateEntity;
|
||||
|
||||
protected render(): TemplateResult {
|
||||
const currentStatus = this._computeCurrentStatus();
|
||||
|
||||
return html`<div class="target">
|
||||
${!UNAVAILABLE_STATES.includes(this.stateObj.state)
|
||||
${!isUnavailableState(this.stateObj.state)
|
||||
? html`<span class="state-label">
|
||||
${this._localizeState()}
|
||||
${this.stateObj.attributes.preset_mode &&
|
||||
this.stateObj.attributes.preset_mode !== CLIMATE_PRESET_NONE
|
||||
? html`-
|
||||
${this.hass.localize(
|
||||
`state_attributes.climate.preset_mode.${this.stateObj.attributes.preset_mode}`
|
||||
) || this.stateObj.attributes.preset_mode}`
|
||||
${computeAttributeValueDisplay(
|
||||
this.hass.localize,
|
||||
this.stateObj,
|
||||
this.hass.entities,
|
||||
"preset_mode"
|
||||
)}`
|
||||
: ""}
|
||||
</span>
|
||||
<div class="unit">${this._computeTarget()}</div>`
|
||||
: this._localizeState()}
|
||||
</div>
|
||||
|
||||
${currentStatus && !UNAVAILABLE_STATES.includes(this.stateObj.state)
|
||||
${currentStatus && !isUnavailableState(this.stateObj.state)
|
||||
? html`<div class="current">
|
||||
${this.hass.localize("ui.card.climate.currently")}:
|
||||
<div class="unit">${currentStatus}</div>
|
||||
@@ -109,17 +113,23 @@ class HaClimateState extends LitElement {
|
||||
}
|
||||
|
||||
private _localizeState(): string {
|
||||
if (UNAVAILABLE_STATES.includes(this.stateObj.state)) {
|
||||
if (isUnavailableState(this.stateObj.state)) {
|
||||
return this.hass.localize(`state.default.${this.stateObj.state}`);
|
||||
}
|
||||
|
||||
const stateString = this.hass.localize(
|
||||
`component.climate.state._.${this.stateObj.state}`
|
||||
const stateString = computeStateDisplay(
|
||||
this.hass.localize,
|
||||
this.stateObj,
|
||||
this.hass.locale,
|
||||
this.hass.entities
|
||||
);
|
||||
|
||||
return this.stateObj.attributes.hvac_action
|
||||
? `${this.hass.localize(
|
||||
`state_attributes.climate.hvac_action.${this.stateObj.attributes.hvac_action}`
|
||||
? `${computeAttributeValueDisplay(
|
||||
this.hass.localize,
|
||||
this.stateObj,
|
||||
this.hass.entities,
|
||||
"hvac_action"
|
||||
)} (${stateString})`
|
||||
: stateString;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ class HaConfigEntryPicker extends LitElement {
|
||||
>
|
||||
<span slot="secondary">${item.localized_domain_name}</span>
|
||||
<img
|
||||
alt=""
|
||||
slot="graphic"
|
||||
src=${brandsUrl({
|
||||
domain: item.domain,
|
||||
@@ -121,7 +122,8 @@ class HaConfigEntryPicker extends LitElement {
|
||||
.sort((conf1, conf2) =>
|
||||
caseInsensitiveStringCompare(
|
||||
conf1.localized_domain_name + conf1.title,
|
||||
conf2.localized_domain_name + conf2.title
|
||||
conf2.localized_domain_name + conf2.title,
|
||||
this.hass.locale.language
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
@@ -3,10 +3,12 @@ import { styles } from "@material/mwc-dialog/mwc-dialog.css";
|
||||
import { mdiClose } from "@mdi/js";
|
||||
import { css, html, TemplateResult } from "lit";
|
||||
import { customElement } from "lit/decorators";
|
||||
import type { HomeAssistant } from "../types";
|
||||
import { FOCUS_TARGET } from "../dialogs/make-dialog-manager";
|
||||
import type { HomeAssistant } from "../types";
|
||||
import "./ha-icon-button";
|
||||
|
||||
const SUPPRESS_DEFAULT_PRESS_SELECTOR = ["button"];
|
||||
|
||||
export const createCloseHeading = (
|
||||
hass: HomeAssistant,
|
||||
title: string | TemplateResult
|
||||
@@ -32,6 +34,14 @@ export class HaDialog extends DialogBase {
|
||||
return html`<slot name="heading"> ${super.renderHeading()} </slot>`;
|
||||
}
|
||||
|
||||
protected firstUpdated(): void {
|
||||
super.firstUpdated();
|
||||
this.suppressDefaultPressSelector = [
|
||||
this.suppressDefaultPressSelector,
|
||||
SUPPRESS_DEFAULT_PRESS_SELECTOR,
|
||||
].join(", ");
|
||||
}
|
||||
|
||||
static override styles = [
|
||||
styles,
|
||||
css`
|
||||
|
||||
@@ -67,6 +67,9 @@ export class HaFormInteger extends LitElement implements HaFormElement {
|
||||
@change=${this._valueChanged}
|
||||
></ha-slider>
|
||||
</div>
|
||||
${this.helper
|
||||
? html`<ha-input-helper-text>${this.helper}</ha-input-helper-text>`
|
||||
: ""}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ export class HaForm extends LitElement implements HaFormElement {
|
||||
.selector=${item.selector}
|
||||
.value=${getValue(this.data, item)}
|
||||
.label=${this._computeLabel(item, this.data)}
|
||||
.disabled=${item.disabled || this.disabled}
|
||||
.disabled=${item.disabled || this.disabled || false}
|
||||
.helper=${this._computeHelper(item)}
|
||||
.required=${item.required || false}
|
||||
.context=${this._generateContext(item)}
|
||||
@@ -95,7 +95,7 @@ export class HaForm extends LitElement implements HaFormElement {
|
||||
data: getValue(this.data, item),
|
||||
label: this._computeLabel(item, this.data),
|
||||
helper: this._computeHelper(item),
|
||||
disabled: this.disabled || item.disabled,
|
||||
disabled: this.disabled || item.disabled || false,
|
||||
hass: this.hass,
|
||||
computeLabel: this.computeLabel,
|
||||
computeHelper: this.computeHelper,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import { HassEntity } from "home-assistant-js-websocket";
|
||||
import {
|
||||
css,
|
||||
CSSResultGroup,
|
||||
@@ -9,23 +9,16 @@ import {
|
||||
} from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { fireEvent } from "../common/dom/fire_event";
|
||||
import {
|
||||
AreaRegistryEntry,
|
||||
subscribeAreaRegistry,
|
||||
} from "../data/area_registry";
|
||||
import { AreaRegistryEntry } from "../data/area_registry";
|
||||
import { ConfigEntry, getConfigEntries } from "../data/config_entries";
|
||||
import {
|
||||
DeviceRegistryEntry,
|
||||
subscribeDeviceRegistry,
|
||||
} from "../data/device_registry";
|
||||
import { DeviceRegistryEntry } from "../data/device_registry";
|
||||
import { SceneEntity } from "../data/scene";
|
||||
import { findRelated, ItemType, RelatedResult } from "../data/search";
|
||||
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
||||
import { HomeAssistant } from "../types";
|
||||
import "./ha-switch";
|
||||
|
||||
@customElement("ha-related-items")
|
||||
export class HaRelatedItems extends SubscribeMixin(LitElement) {
|
||||
export class HaRelatedItems extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property() public itemType!: ItemType;
|
||||
@@ -34,23 +27,8 @@ export class HaRelatedItems extends SubscribeMixin(LitElement) {
|
||||
|
||||
@state() private _entries?: ConfigEntry[];
|
||||
|
||||
@state() private _devices?: DeviceRegistryEntry[];
|
||||
|
||||
@state() private _areas?: AreaRegistryEntry[];
|
||||
|
||||
@state() private _related?: RelatedResult;
|
||||
|
||||
public hassSubscribe(): UnsubscribeFunc[] {
|
||||
return [
|
||||
subscribeDeviceRegistry(this.hass.connection!, (devices) => {
|
||||
this._devices = devices;
|
||||
}),
|
||||
subscribeAreaRegistry(this.hass.connection!, (areas) => {
|
||||
this._areas = areas;
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
protected firstUpdated(changedProps: PropertyValues) {
|
||||
super.firstUpdated(changedProps);
|
||||
getConfigEntries(this.hass).then((configEntries) => {
|
||||
@@ -104,11 +82,10 @@ export class HaRelatedItems extends SubscribeMixin(LitElement) {
|
||||
`;
|
||||
})
|
||||
: ""}
|
||||
${this._related.device && this._devices
|
||||
${this._related.device
|
||||
? this._related.device.map((relatedDeviceId) => {
|
||||
const device: DeviceRegistryEntry | undefined = this._devices!.find(
|
||||
(dev) => dev.id === relatedDeviceId
|
||||
);
|
||||
const device: DeviceRegistryEntry | undefined =
|
||||
this.hass.devices[relatedDeviceId];
|
||||
if (!device) {
|
||||
return "";
|
||||
}
|
||||
@@ -125,11 +102,10 @@ export class HaRelatedItems extends SubscribeMixin(LitElement) {
|
||||
`;
|
||||
})
|
||||
: ""}
|
||||
${this._related.area && this._areas
|
||||
${this._related.area
|
||||
? this._related.area.map((relatedAreaId) => {
|
||||
const area: AreaRegistryEntry | undefined = this._areas!.find(
|
||||
(ar) => ar.area_id === relatedAreaId
|
||||
);
|
||||
const area: AreaRegistryEntry | undefined =
|
||||
this.hass.areas[relatedAreaId];
|
||||
if (!area) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import { HassEntity } from "home-assistant-js-websocket";
|
||||
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
import type { DeviceRegistryEntry } from "../../data/device_registry";
|
||||
import { getDeviceIntegrationLookup } from "../../data/device_registry";
|
||||
import {
|
||||
EntityRegistryEntry,
|
||||
subscribeEntityRegistry,
|
||||
} from "../../data/entity_registry";
|
||||
import { EntityRegistryEntry } from "../../data/entity_registry";
|
||||
import {
|
||||
EntitySources,
|
||||
fetchEntitySourcesWithCache,
|
||||
@@ -17,13 +14,12 @@ import {
|
||||
filterSelectorDevices,
|
||||
filterSelectorEntities,
|
||||
} from "../../data/selector";
|
||||
import { SubscribeMixin } from "../../mixins/subscribe-mixin";
|
||||
import { HomeAssistant } from "../../types";
|
||||
import "../ha-area-picker";
|
||||
import "../ha-areas-picker";
|
||||
|
||||
@customElement("ha-selector-area")
|
||||
export class HaAreaSelector extends SubscribeMixin(LitElement) {
|
||||
export class HaAreaSelector extends LitElement {
|
||||
@property() public hass!: HomeAssistant;
|
||||
|
||||
@property() public selector!: AreaSelector;
|
||||
@@ -44,12 +40,16 @@ export class HaAreaSelector extends SubscribeMixin(LitElement) {
|
||||
|
||||
private _deviceIntegrationLookup = memoizeOne(getDeviceIntegrationLookup);
|
||||
|
||||
public hassSubscribe(): UnsubscribeFunc[] {
|
||||
return [
|
||||
subscribeEntityRegistry(this.hass.connection!, (entities) => {
|
||||
this._entities = entities.filter((entity) => entity.device_id !== null);
|
||||
}),
|
||||
];
|
||||
protected willUpdate(changedProperties: PropertyValues): void {
|
||||
if (
|
||||
changedProperties.has("hass") &&
|
||||
(changedProperties.get("hass") as HomeAssistant | undefined)?.entities !==
|
||||
this.hass.entities
|
||||
) {
|
||||
this._entities = Object.values(this.hass.entities).filter(
|
||||
(entity) => entity.device_id !== null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected updated(changedProperties: PropertyValues): void {
|
||||
|
||||
@@ -88,6 +88,10 @@ export class HaSelectSelector extends LitElement {
|
||||
const value =
|
||||
!this.value || this.value === "" ? [] : (this.value as string[]);
|
||||
|
||||
const optionItems = options.filter(
|
||||
(option) => !option.disabled && !value?.includes(option.value)
|
||||
);
|
||||
|
||||
return html`
|
||||
${value?.length
|
||||
? html`<ha-chip-set>
|
||||
@@ -118,11 +122,11 @@ export class HaSelectSelector extends LitElement {
|
||||
.disabled=${this.disabled}
|
||||
.required=${this.required && !value.length}
|
||||
.value=${this._filter}
|
||||
.filteredItems=${options.filter(
|
||||
(option) => !option.disabled && !value?.includes(option.value)
|
||||
)}
|
||||
.items=${optionItems}
|
||||
.allowCustomValue=${this.selector.select.custom_value ?? false}
|
||||
@filter-changed=${this._filterChanged}
|
||||
@value-changed=${this._comboBoxValueChanged}
|
||||
@opened-changed=${this._openedChanged}
|
||||
></ha-combo-box>
|
||||
`;
|
||||
}
|
||||
@@ -130,11 +134,14 @@ export class HaSelectSelector extends LitElement {
|
||||
if (this.selector.select?.custom_value) {
|
||||
if (
|
||||
this.value !== undefined &&
|
||||
!Array.isArray(this.value) &&
|
||||
!options.find((option) => option.value === this.value)
|
||||
) {
|
||||
options.unshift({ value: this.value, label: this.value });
|
||||
}
|
||||
|
||||
const optionItems = options.filter((option) => !option.disabled);
|
||||
|
||||
return html`
|
||||
<ha-combo-box
|
||||
item-value-path="value"
|
||||
@@ -144,10 +151,11 @@ export class HaSelectSelector extends LitElement {
|
||||
.helper=${this.helper}
|
||||
.disabled=${this.disabled}
|
||||
.required=${this.required}
|
||||
.items=${options.filter((item) => !item.disabled)}
|
||||
.items=${optionItems}
|
||||
.value=${this.value}
|
||||
@filter-changed=${this._filterChanged}
|
||||
@value-changed=${this._comboBoxValueChanged}
|
||||
@opened-changed=${this._openedChanged}
|
||||
></ha-combo-box>
|
||||
`;
|
||||
}
|
||||
@@ -190,7 +198,7 @@ export class HaSelectSelector extends LitElement {
|
||||
private _valueChanged(ev) {
|
||||
ev.stopPropagation();
|
||||
const value = ev.detail?.value || ev.target.value;
|
||||
if (this.disabled || !value) {
|
||||
if (this.disabled || value === undefined) {
|
||||
return;
|
||||
}
|
||||
fireEvent(this, "value-changed", {
|
||||
@@ -271,13 +279,16 @@ export class HaSelectSelector extends LitElement {
|
||||
});
|
||||
}
|
||||
|
||||
private _openedChanged(ev?: CustomEvent): void {
|
||||
if (ev?.detail.value) {
|
||||
this._filterChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private _filterChanged(ev?: CustomEvent): void {
|
||||
this._filter = ev?.detail.value || "";
|
||||
|
||||
const filteredItems = this.comboBox.items?.filter((item) => {
|
||||
if (this.selector.select?.multiple && this.value?.includes(item.value)) {
|
||||
return false;
|
||||
}
|
||||
const label = item.label || item.value;
|
||||
return label.toLowerCase().includes(this._filter?.toLowerCase());
|
||||
});
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import {
|
||||
HassEntity,
|
||||
HassServiceTarget,
|
||||
UnsubscribeFunc,
|
||||
} from "home-assistant-js-websocket";
|
||||
import { HassEntity, HassServiceTarget } from "home-assistant-js-websocket";
|
||||
import {
|
||||
css,
|
||||
CSSResultGroup,
|
||||
@@ -17,8 +13,7 @@ import {
|
||||
DeviceRegistryEntry,
|
||||
getDeviceIntegrationLookup,
|
||||
} from "../../data/device_registry";
|
||||
import type { EntityRegistryEntry } from "../../data/entity_registry";
|
||||
import { subscribeEntityRegistry } from "../../data/entity_registry";
|
||||
import { EntityRegistryEntry } from "../../data/entity_registry";
|
||||
import {
|
||||
EntitySources,
|
||||
fetchEntitySourcesWithCache,
|
||||
@@ -28,12 +23,11 @@ import {
|
||||
filterSelectorEntities,
|
||||
TargetSelector,
|
||||
} from "../../data/selector";
|
||||
import { SubscribeMixin } from "../../mixins/subscribe-mixin";
|
||||
import type { HomeAssistant } from "../../types";
|
||||
import "../ha-target-picker";
|
||||
|
||||
@customElement("ha-selector-target")
|
||||
export class HaTargetSelector extends SubscribeMixin(LitElement) {
|
||||
export class HaTargetSelector extends LitElement {
|
||||
@property() public hass!: HomeAssistant;
|
||||
|
||||
@property() public selector!: TargetSelector;
|
||||
@@ -48,18 +42,8 @@ export class HaTargetSelector extends SubscribeMixin(LitElement) {
|
||||
|
||||
@state() private _entitySources?: EntitySources;
|
||||
|
||||
@state() private _entities?: EntityRegistryEntry[];
|
||||
|
||||
private _deviceIntegrationLookup = memoizeOne(getDeviceIntegrationLookup);
|
||||
|
||||
public hassSubscribe(): UnsubscribeFunc[] {
|
||||
return [
|
||||
subscribeEntityRegistry(this.hass.connection!, (entities) => {
|
||||
this._entities = entities.filter((entity) => entity.device_id !== null);
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
protected updated(changedProperties: PropertyValues): void {
|
||||
super.updated(changedProperties);
|
||||
if (
|
||||
@@ -88,12 +72,19 @@ export class HaTargetSelector extends SubscribeMixin(LitElement) {
|
||||
.value=${this.value}
|
||||
.helper=${this.helper}
|
||||
.deviceFilter=${this._filterDevices}
|
||||
.entityFilter=${this._filterEntities}
|
||||
.entityFilter=${this._filterStates}
|
||||
.entityRegFilter=${this._filterRegEntities}
|
||||
.includeDeviceClasses=${this.selector.target?.entity?.device_class
|
||||
? [this.selector.target?.entity.device_class]
|
||||
: undefined}
|
||||
.includeDomains=${this.selector.target?.entity?.domain
|
||||
? [this.selector.target?.entity.domain]
|
||||
: undefined}
|
||||
.disabled=${this.disabled}
|
||||
></ha-target-picker>`;
|
||||
}
|
||||
|
||||
private _filterEntities = (entity: HassEntity): boolean => {
|
||||
private _filterStates = (entity: HassEntity): boolean => {
|
||||
if (!this.selector.target?.entity) {
|
||||
return true;
|
||||
}
|
||||
@@ -105,15 +96,26 @@ export class HaTargetSelector extends SubscribeMixin(LitElement) {
|
||||
);
|
||||
};
|
||||
|
||||
private _filterRegEntities = (entity: EntityRegistryEntry): boolean => {
|
||||
if (this.selector.target?.entity?.integration) {
|
||||
if (entity.platform !== this.selector.target.entity.integration) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
private _filterDevices = (device: DeviceRegistryEntry): boolean => {
|
||||
if (!this.selector.target?.device) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const deviceIntegrations =
|
||||
this._entitySources && this._entities
|
||||
? this._deviceIntegrationLookup(this._entitySources, this._entities)
|
||||
: undefined;
|
||||
const deviceIntegrations = this._entitySources
|
||||
? this._deviceIntegrationLookup(
|
||||
this._entitySources,
|
||||
Object.values(this.hass.entities)
|
||||
)
|
||||
: undefined;
|
||||
|
||||
return filterSelectorDevices(
|
||||
this.selector.target.device,
|
||||
|
||||
@@ -87,7 +87,8 @@ const panelSorter = (
|
||||
reverseSort: string[],
|
||||
defaultPanel: string,
|
||||
a: PanelInfo,
|
||||
b: PanelInfo
|
||||
b: PanelInfo,
|
||||
language: string
|
||||
) => {
|
||||
const indexA = reverseSort.indexOf(a.url_path);
|
||||
const indexB = reverseSort.indexOf(b.url_path);
|
||||
@@ -97,13 +98,14 @@ const panelSorter = (
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return defaultPanelSorter(defaultPanel, a, b);
|
||||
return defaultPanelSorter(defaultPanel, a, b, language);
|
||||
};
|
||||
|
||||
const defaultPanelSorter = (
|
||||
defaultPanel: string,
|
||||
a: PanelInfo,
|
||||
b: PanelInfo
|
||||
b: PanelInfo,
|
||||
language: string
|
||||
) => {
|
||||
// Put all the Lovelace at the top.
|
||||
const aLovelace = a.component_name === "lovelace";
|
||||
@@ -117,7 +119,7 @@ const defaultPanelSorter = (
|
||||
}
|
||||
|
||||
if (aLovelace && bLovelace) {
|
||||
return stringCompare(a.title!, b.title!);
|
||||
return stringCompare(a.title!, b.title!, language);
|
||||
}
|
||||
if (aLovelace && !bLovelace) {
|
||||
return -1;
|
||||
@@ -139,7 +141,7 @@ const defaultPanelSorter = (
|
||||
return 1;
|
||||
}
|
||||
// both not built in, sort by title
|
||||
return stringCompare(a.title!, b.title!);
|
||||
return stringCompare(a.title!, b.title!, language);
|
||||
};
|
||||
|
||||
const computePanels = memoizeOne(
|
||||
@@ -147,7 +149,8 @@ const computePanels = memoizeOne(
|
||||
panels: HomeAssistant["panels"],
|
||||
defaultPanel: HomeAssistant["defaultPanel"],
|
||||
panelsOrder: string[],
|
||||
hiddenPanels: string[]
|
||||
hiddenPanels: string[],
|
||||
locale: HomeAssistant["locale"]
|
||||
): [PanelInfo[], PanelInfo[]] => {
|
||||
if (!panels) {
|
||||
return [[], []];
|
||||
@@ -171,8 +174,12 @@ const computePanels = memoizeOne(
|
||||
|
||||
const reverseSort = [...panelsOrder].reverse();
|
||||
|
||||
beforeSpacer.sort((a, b) => panelSorter(reverseSort, defaultPanel, a, b));
|
||||
afterSpacer.sort((a, b) => panelSorter(reverseSort, defaultPanel, a, b));
|
||||
beforeSpacer.sort((a, b) =>
|
||||
panelSorter(reverseSort, defaultPanel, a, b, locale.language)
|
||||
);
|
||||
afterSpacer.sort((a, b) =>
|
||||
panelSorter(reverseSort, defaultPanel, a, b, locale.language)
|
||||
);
|
||||
|
||||
return [beforeSpacer, afterSpacer];
|
||||
}
|
||||
@@ -374,7 +381,8 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
||||
this.hass.panels,
|
||||
this.hass.defaultPanel,
|
||||
this._panelOrder,
|
||||
this._hiddenPanels
|
||||
this._hiddenPanels,
|
||||
this.hass.locale
|
||||
);
|
||||
|
||||
// Show the supervisor as beeing part of configuration
|
||||
|
||||
@@ -345,6 +345,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
||||
.entityFilter=${this.entityRegFilter}
|
||||
.includeDeviceClasses=${this.includeDeviceClasses}
|
||||
.includeDomains=${this.includeDomains}
|
||||
.excludeAreas=${ensureArray(this.value?.area_id)}
|
||||
@value-changed=${this._targetPicked}
|
||||
></ha-area-picker>
|
||||
`;
|
||||
@@ -358,9 +359,9 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
||||
"ui.components.target-picker.add_device_id"
|
||||
)}
|
||||
.deviceFilter=${this.deviceFilter}
|
||||
.entityFilter=${this.entityRegFilter}
|
||||
.includeDeviceClasses=${this.includeDeviceClasses}
|
||||
.includeDomains=${this.includeDomains}
|
||||
.excludeDevices=${ensureArray(this.value?.device_id)}
|
||||
@value-changed=${this._targetPicked}
|
||||
></ha-device-picker>
|
||||
`;
|
||||
@@ -376,6 +377,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
||||
.entityFilter=${this.entityFilter}
|
||||
.includeDeviceClasses=${this.includeDeviceClasses}
|
||||
.includeDomains=${this.includeDomains}
|
||||
.excludeEntities=${ensureArray(this.value?.entity_id)}
|
||||
@value-changed=${this._targetPicked}
|
||||
allow-custom-entity
|
||||
></ha-entity-picker>
|
||||
@@ -393,6 +395,13 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
||||
const target = ev.currentTarget;
|
||||
target.value = "";
|
||||
this._addMode = undefined;
|
||||
if (
|
||||
this.value &&
|
||||
this.value[target.type] &&
|
||||
ensureArray(this.value[target.type]).includes(value)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
fireEvent(this, "value-changed", {
|
||||
value: this.value
|
||||
? {
|
||||
|
||||
@@ -67,23 +67,28 @@ export class HaLocationsEditor extends LitElement {
|
||||
|
||||
private Leaflet?: LeafletModuleType;
|
||||
|
||||
private _loadPromise: Promise<boolean | void>;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
import("leaflet").then((module) => {
|
||||
this._loadPromise = import("leaflet").then((module) =>
|
||||
import("leaflet-draw").then(() => {
|
||||
this.Leaflet = module.default as LeafletModuleType;
|
||||
this._updateMarkers();
|
||||
this.updateComplete.then(() => this.fitMap());
|
||||
});
|
||||
});
|
||||
return this.updateComplete.then(() => this.fitMap());
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public fitMap(): void {
|
||||
this.map.fitMap();
|
||||
}
|
||||
|
||||
public fitMarker(id: string): void {
|
||||
public async fitMarker(id: string): Promise<void> {
|
||||
if (!this.Leaflet) {
|
||||
await this._loadPromise;
|
||||
}
|
||||
if (!this.map.leafletMap || !this._locationMarkers) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,12 @@ import "./ha-entity-marker";
|
||||
const getEntityId = (entity: string | HaMapEntity): string =>
|
||||
typeof entity === "string" ? entity : entity.entity_id;
|
||||
|
||||
export interface HaMapPathPoint {
|
||||
point: LatLngTuple;
|
||||
tooltip: string;
|
||||
}
|
||||
export interface HaMapPaths {
|
||||
points: LatLngTuple[];
|
||||
points: HaMapPathPoint[];
|
||||
color?: string;
|
||||
gradualOpacity?: number;
|
||||
}
|
||||
@@ -247,19 +251,21 @@ export class HaMap extends ReactiveElement {
|
||||
|
||||
// DRAW point
|
||||
this._mapPaths.push(
|
||||
Leaflet!.circleMarker(path.points[pointIndex], {
|
||||
radius: 3,
|
||||
color: path.color || darkPrimaryColor,
|
||||
opacity,
|
||||
fillOpacity: opacity,
|
||||
interactive: false,
|
||||
})
|
||||
Leaflet!
|
||||
.circleMarker(path.points[pointIndex].point, {
|
||||
radius: 3,
|
||||
color: path.color || darkPrimaryColor,
|
||||
opacity,
|
||||
fillOpacity: opacity,
|
||||
interactive: true,
|
||||
})
|
||||
.bindTooltip(path.points[pointIndex].tooltip, { direction: "top" })
|
||||
);
|
||||
|
||||
// DRAW line between this and next point
|
||||
this._mapPaths.push(
|
||||
Leaflet!.polyline(
|
||||
[path.points[pointIndex], path.points[pointIndex + 1]],
|
||||
[path.points[pointIndex].point, path.points[pointIndex + 1].point],
|
||||
{
|
||||
color: path.color || darkPrimaryColor,
|
||||
opacity,
|
||||
@@ -275,13 +281,15 @@ export class HaMap extends ReactiveElement {
|
||||
: undefined;
|
||||
// DRAW end path point
|
||||
this._mapPaths.push(
|
||||
Leaflet!.circleMarker(path.points[pointIndex], {
|
||||
radius: 3,
|
||||
color: path.color || darkPrimaryColor,
|
||||
opacity,
|
||||
fillOpacity: opacity,
|
||||
interactive: false,
|
||||
})
|
||||
Leaflet!
|
||||
.circleMarker(path.points[pointIndex].point, {
|
||||
radius: 3,
|
||||
color: path.color || darkPrimaryColor,
|
||||
opacity,
|
||||
fillOpacity: opacity,
|
||||
interactive: true,
|
||||
})
|
||||
.bindTooltip(path.points[pointIndex].tooltip, { direction: "top" })
|
||||
);
|
||||
}
|
||||
this._mapPaths.forEach((marker) => map.addLayer(marker));
|
||||
@@ -491,6 +499,14 @@ export class HaMap extends ReactiveElement {
|
||||
.leaflet-bottom {
|
||||
z-index: 1 !important;
|
||||
}
|
||||
.leaflet-tooltip {
|
||||
padding: 8px;
|
||||
font-size: 90%;
|
||||
background: rgba(80, 80, 80, 0.9) !important;
|
||||
color: white !important;
|
||||
border-radius: 4px;
|
||||
box-shadow: none !important;
|
||||
}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,7 @@ import { until } from "lit/directives/until";
|
||||
import { fireEvent } from "../../common/dom/fire_event";
|
||||
import { computeRTLDirection } from "../../common/util/compute_rtl";
|
||||
import { debounce } from "../../common/util/debounce";
|
||||
import { getSignedPath } from "../../data/auth";
|
||||
import { UNAVAILABLE_STATES } from "../../data/entity";
|
||||
import { isUnavailableState } from "../../data/entity";
|
||||
import type { MediaPlayerItem } from "../../data/media-player";
|
||||
import {
|
||||
browseMediaPlayer,
|
||||
@@ -248,7 +247,7 @@ export class HaMediaPlayerBrowse extends LitElement {
|
||||
});
|
||||
} else if (
|
||||
err.code === "entity_not_found" &&
|
||||
UNAVAILABLE_STATES.includes(this.hass.states[this.entityId]?.state)
|
||||
isUnavailableState(this.hass.states[this.entityId]?.state)
|
||||
) {
|
||||
this._setError({
|
||||
message: this.hass.localize(
|
||||
@@ -339,7 +338,7 @@ export class HaMediaPlayerBrowse extends LitElement {
|
||||
: MediaClassBrowserSettings.directory;
|
||||
|
||||
const backgroundImage = currentItem.thumbnail
|
||||
? this._getSignedThumbnail(currentItem.thumbnail).then(
|
||||
? this._getThumbnailURLorBase64(currentItem.thumbnail).then(
|
||||
(value) => `url(${value})`
|
||||
)
|
||||
: "none";
|
||||
@@ -550,7 +549,7 @@ export class HaMediaPlayerBrowse extends LitElement {
|
||||
|
||||
private _renderGridItem = (child: MediaPlayerItem): TemplateResult => {
|
||||
const backgroundImage = child.thumbnail
|
||||
? this._getSignedThumbnail(child.thumbnail).then(
|
||||
? this._getThumbnailURLorBase64(child.thumbnail).then(
|
||||
(value) => `url(${value})`
|
||||
)
|
||||
: "none";
|
||||
@@ -615,7 +614,7 @@ export class HaMediaPlayerBrowse extends LitElement {
|
||||
|
||||
const backgroundImage =
|
||||
mediaClass.show_list_images && child.thumbnail
|
||||
? this._getSignedThumbnail(child.thumbnail).then(
|
||||
? this._getThumbnailURLorBase64(child.thumbnail).then(
|
||||
(value) => `url(${value})`
|
||||
)
|
||||
: "none";
|
||||
@@ -652,7 +651,7 @@ export class HaMediaPlayerBrowse extends LitElement {
|
||||
`;
|
||||
};
|
||||
|
||||
private async _getSignedThumbnail(
|
||||
private async _getThumbnailURLorBase64(
|
||||
thumbnailUrl: string | undefined
|
||||
): Promise<string> {
|
||||
if (!thumbnailUrl) {
|
||||
@@ -661,7 +660,24 @@ export class HaMediaPlayerBrowse extends LitElement {
|
||||
|
||||
if (thumbnailUrl.startsWith("/")) {
|
||||
// Thumbnails served by local API require authentication
|
||||
return (await getSignedPath(this.hass, thumbnailUrl)).path;
|
||||
return new Promise((resolve, reject) => {
|
||||
this.hass
|
||||
.fetchWithAuth(thumbnailUrl!)
|
||||
// Since we are fetching with an authorization header, we cannot just put the
|
||||
// URL directly into the document; we need to embed the image. We could do this
|
||||
// using blob URLs, but then we would need to keep track of them in order to
|
||||
// release them properly. Instead, we embed the thumbnail using base64.
|
||||
.then((response) => response.blob())
|
||||
.then((blob) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
const result = reader.result;
|
||||
resolve(typeof result === "string" ? result : "");
|
||||
};
|
||||
reader.onerror = (e) => reject(e);
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (isBrandUrl(thumbnailUrl)) {
|
||||
|
||||
@@ -41,7 +41,9 @@ export class HaTileButton extends LitElement {
|
||||
@touchcancel=${this.handleRippleDeactivate}
|
||||
>
|
||||
<slot></slot>
|
||||
${this._shouldRenderRipple ? html`<mwc-ripple></mwc-ripple>` : ""}
|
||||
${this._shouldRenderRipple && !this.disabled
|
||||
? html`<mwc-ripple></mwc-ripple>`
|
||||
: ""}
|
||||
</button>
|
||||
`;
|
||||
}
|
||||
@@ -79,9 +81,10 @@ export class HaTileButton extends LitElement {
|
||||
static get styles(): CSSResultGroup {
|
||||
return css`
|
||||
:host {
|
||||
--icon-color: rgb(var(--color, var(--rgb-primary-text-color)));
|
||||
--bg-color: rgba(var(--color, var(--rgb-disabled-color)), 0.2);
|
||||
--mdc-ripple-color: rgba(var(--color, var(--rgb-disabled-color)));
|
||||
--tile-button-icon-color: var(--primary-text-color);
|
||||
--tile-button-background-color: rgb(var(--rgb-disabled-color));
|
||||
--tile-button-background-opacity: 0.2;
|
||||
--mdc-ripple-color: var(--tile-button-background-color);
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
@@ -97,25 +100,37 @@ export class HaTileButton extends LitElement {
|
||||
height: 100%;
|
||||
border-radius: 10px;
|
||||
border: none;
|
||||
background-color: var(--bg-color);
|
||||
transition: background-color 280ms ease-in-out, transform 180ms ease-out;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
line-height: 0;
|
||||
outline: none;
|
||||
overflow: hidden;
|
||||
background: none;
|
||||
}
|
||||
.button::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background-color: var(--tile-button-background-color);
|
||||
transition: background-color 180ms ease-in-out,
|
||||
opacity 180ms ease-in-out;
|
||||
opacity: var(--tile-button-background-opacity);
|
||||
}
|
||||
.button ::slotted(*) {
|
||||
--mdc-icon-size: 20px;
|
||||
color: var(--icon-color);
|
||||
transition: color 180ms ease-in-out;
|
||||
color: var(--tile-button-icon-color);
|
||||
pointer-events: none;
|
||||
}
|
||||
.button:disabled {
|
||||
cursor: not-allowed;
|
||||
background-color: rgba(var(--rgb-disabled-color), 0.2);
|
||||
}
|
||||
.button:disabled ::slotted(*) {
|
||||
color: rgb(var(--rgb-disabled-color));
|
||||
--tile-button-background-color: rgb(var(--rgb-disabled-color));
|
||||
--tile-button-icon-color: var(--disabled-text-color);
|
||||
--tile-button-background-opacity: 0.2;
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -22,10 +22,20 @@ export class HaTileIcon extends LitElement {
|
||||
static get styles(): CSSResultGroup {
|
||||
return css`
|
||||
:host {
|
||||
--icon-color: rgb(var(--color));
|
||||
--shape-color: rgba(var(--color), 0.2);
|
||||
--tile-icon-color: rgb(var(--rgb-disabled-color));
|
||||
--mdc-icon-size: 24px;
|
||||
}
|
||||
.shape::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background-color: var(--tile-icon-color);
|
||||
transition: background-color 180ms ease-in-out;
|
||||
opacity: 0.2;
|
||||
}
|
||||
.shape {
|
||||
position: relative;
|
||||
width: 40px;
|
||||
@@ -34,13 +44,13 @@ export class HaTileIcon extends LitElement {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: var(--shape-color);
|
||||
transition: background-color 180ms ease-in-out, color 180ms ease-in-out;
|
||||
transition: color 180ms ease-in-out;
|
||||
overflow: hidden;
|
||||
}
|
||||
.shape ha-icon,
|
||||
.shape ha-svg-icon {
|
||||
display: flex;
|
||||
color: var(--icon-color);
|
||||
color: var(--tile-icon-color);
|
||||
transition: color 180ms ease-in-out;
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
import { CSSResultGroup, html, css, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
|
||||
@customElement("ha-tile-image")
|
||||
export class HaTileImage extends LitElement {
|
||||
@property() public imageUrl?: string;
|
||||
|
||||
@property() public imageAlt?: string;
|
||||
|
||||
protected render(): TemplateResult {
|
||||
return html`
|
||||
<div class="image">
|
||||
${this.imageUrl ? html`<img src=${this.imageUrl} />` : null}
|
||||
${this.imageUrl
|
||||
? html`<img alt=${ifDefined(this.imageAlt)} src=${this.imageUrl} />`
|
||||
: null}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -48,12 +48,16 @@ export class HaTileSlider extends LitElement {
|
||||
return css`
|
||||
ha-bar-slider {
|
||||
--slider-bar-color: var(
|
||||
--tile-slider-bar-color,
|
||||
--tile-slider-color,
|
||||
rgb(var(--rgb-primary-color))
|
||||
);
|
||||
--slider-bar-background: var(
|
||||
--tile-slider-bar-background,
|
||||
rgba(var(--rgb-disabled-color), 0.2)
|
||||
--tile-slider-background,
|
||||
rgb(var(--rgb-disabled-color))
|
||||
);
|
||||
--slider-bar-background-opacity: var(
|
||||
--tile-slider-background-opacity,
|
||||
0.2
|
||||
);
|
||||
--slider-bar-thickness: 40px;
|
||||
--slider-bar-border-radius: 10px;
|
||||
|
||||
@@ -30,7 +30,9 @@ class HaUserPicker extends LitElement {
|
||||
|
||||
return users
|
||||
.filter((user) => !user.system_generated)
|
||||
.sort((a, b) => stringCompare(a.name, b.name));
|
||||
.sort((a, b) =>
|
||||
stringCompare(a.name, b.name, this.hass!.locale.language)
|
||||
);
|
||||
});
|
||||
|
||||
protected render(): TemplateResult {
|
||||
|
||||
@@ -23,63 +23,8 @@ interface CachedResults {
|
||||
data: HistoryResult;
|
||||
}
|
||||
|
||||
// This is a different interface, a different cache :(
|
||||
interface RecentCacheResults {
|
||||
created: number;
|
||||
language: string;
|
||||
data: Promise<HistoryResult>;
|
||||
}
|
||||
|
||||
const RECENT_THRESHOLD = 60000; // 1 minute
|
||||
const RECENT_CACHE: { [cacheKey: string]: RecentCacheResults } = {};
|
||||
const stateHistoryCache: { [cacheKey: string]: CachedResults } = {};
|
||||
|
||||
// Cached type 1 function. Without cache config.
|
||||
export const getRecent = (
|
||||
hass: HomeAssistant,
|
||||
entityId: string,
|
||||
startTime: Date,
|
||||
endTime: Date,
|
||||
localize: LocalizeFunc,
|
||||
language: string
|
||||
) => {
|
||||
const cacheKey = entityId;
|
||||
const cache = RECENT_CACHE[cacheKey];
|
||||
|
||||
if (
|
||||
cache &&
|
||||
Date.now() - cache.created < RECENT_THRESHOLD &&
|
||||
cache.language === language
|
||||
) {
|
||||
return cache.data;
|
||||
}
|
||||
|
||||
const noAttributes = !entityIdHistoryNeedsAttributes(hass, entityId);
|
||||
const prom = fetchRecentWS(
|
||||
hass,
|
||||
entityId,
|
||||
startTime,
|
||||
endTime,
|
||||
false,
|
||||
undefined,
|
||||
true,
|
||||
noAttributes
|
||||
).then(
|
||||
(stateHistory) => computeHistory(hass, stateHistory, localize),
|
||||
(err) => {
|
||||
delete RECENT_CACHE[entityId];
|
||||
throw err;
|
||||
}
|
||||
);
|
||||
|
||||
RECENT_CACHE[cacheKey] = {
|
||||
created: Date.now(),
|
||||
language,
|
||||
data: prom,
|
||||
};
|
||||
return prom;
|
||||
};
|
||||
|
||||
// Cache type 2 functionality
|
||||
function getEmptyCache(
|
||||
language: string,
|
||||
@@ -97,7 +42,7 @@ function getEmptyCache(
|
||||
|
||||
export const getRecentWithCache = (
|
||||
hass: HomeAssistant,
|
||||
entityId: string,
|
||||
entityIds: string[],
|
||||
cacheConfig: CacheConfig,
|
||||
localize: LocalizeFunc,
|
||||
language: string
|
||||
@@ -132,7 +77,9 @@ export const getRecentWithCache = (
|
||||
}
|
||||
|
||||
const curCacheProm = cache.prom;
|
||||
const noAttributes = !entityIdHistoryNeedsAttributes(hass, entityId);
|
||||
const noAttributes = !entityIds.some((entityId) =>
|
||||
entityIdHistoryNeedsAttributes(hass, entityId)
|
||||
);
|
||||
|
||||
const genProm = async () => {
|
||||
let fetchedHistory: HistoryStates;
|
||||
@@ -142,7 +89,7 @@ export const getRecentWithCache = (
|
||||
curCacheProm,
|
||||
fetchRecentWS(
|
||||
hass,
|
||||
entityId,
|
||||
entityIds,
|
||||
toFetchStartTime,
|
||||
endTime,
|
||||
appendingToCache,
|
||||
|
||||
+11
-4
@@ -2,7 +2,7 @@ import { getColorByIndex } from "../common/color/colors";
|
||||
import { computeDomain } from "../common/entity/compute_domain";
|
||||
import { computeStateName } from "../common/entity/compute_state_name";
|
||||
import type { HomeAssistant } from "../types";
|
||||
import { UNAVAILABLE_STATES } from "./entity";
|
||||
import { isUnavailableState } from "./entity";
|
||||
|
||||
export interface Calendar {
|
||||
entity_id: string;
|
||||
@@ -50,6 +50,7 @@ export enum RecurrenceRange {
|
||||
export const enum CalendarEntityFeature {
|
||||
CREATE_EVENT = 1,
|
||||
DELETE_EVENT = 2,
|
||||
UPDATE_EVENT = 4,
|
||||
}
|
||||
|
||||
export const fetchCalendarEvents = async (
|
||||
@@ -138,7 +139,7 @@ export const getCalendars = (hass: HomeAssistant): Calendar[] =>
|
||||
.filter(
|
||||
(eid) =>
|
||||
computeDomain(eid) === "calendar" &&
|
||||
!UNAVAILABLE_STATES.includes(hass.states[eid].state)
|
||||
!isUnavailableState(hass.states[eid].state)
|
||||
)
|
||||
.sort()
|
||||
.map((eid, idx) => ({
|
||||
@@ -161,12 +162,18 @@ export const createCalendarEvent = (
|
||||
export const updateCalendarEvent = (
|
||||
hass: HomeAssistant,
|
||||
entityId: string,
|
||||
event: CalendarEventMutableParams
|
||||
uid: string,
|
||||
event: CalendarEventMutableParams,
|
||||
recurrence_id?: string,
|
||||
recurrence_range?: RecurrenceRange
|
||||
) =>
|
||||
hass.callWS<void>({
|
||||
type: "calendar/event/update",
|
||||
entity_id: entityId,
|
||||
event: event,
|
||||
uid,
|
||||
recurrence_id,
|
||||
recurrence_range,
|
||||
event,
|
||||
});
|
||||
|
||||
export const deleteCalendarEvent = (
|
||||
|
||||
+16
-8
@@ -14,7 +14,13 @@ export type HvacMode =
|
||||
|
||||
export const CLIMATE_PRESET_NONE = "none";
|
||||
|
||||
export type HvacAction = "off" | "heating" | "cooling" | "drying" | "idle";
|
||||
export type HvacAction =
|
||||
| "off"
|
||||
| "heating"
|
||||
| "cooling"
|
||||
| "drying"
|
||||
| "idle"
|
||||
| "fan";
|
||||
|
||||
export type ClimateEntity = HassEntityBase & {
|
||||
attributes: HassEntityAttributeBase & {
|
||||
@@ -44,13 +50,15 @@ export type ClimateEntity = HassEntityBase & {
|
||||
};
|
||||
};
|
||||
|
||||
export const CLIMATE_SUPPORT_TARGET_TEMPERATURE = 1;
|
||||
export const CLIMATE_SUPPORT_TARGET_TEMPERATURE_RANGE = 2;
|
||||
export const CLIMATE_SUPPORT_TARGET_HUMIDITY = 4;
|
||||
export const CLIMATE_SUPPORT_FAN_MODE = 8;
|
||||
export const CLIMATE_SUPPORT_PRESET_MODE = 16;
|
||||
export const CLIMATE_SUPPORT_SWING_MODE = 32;
|
||||
export const CLIMATE_SUPPORT_AUX_HEAT = 64;
|
||||
export const enum ClimateEntityFeature {
|
||||
TARGET_TEMPERATURE = 1,
|
||||
TARGET_TEMPERATURE_RANGE = 2,
|
||||
TARGET_HUMIDITY = 4,
|
||||
FAN_MODE = 8,
|
||||
PRESET_MODE = 16,
|
||||
SWING_MODE = 32,
|
||||
AUX_HEAT = 64,
|
||||
}
|
||||
|
||||
const hvacModeOrdering: { [key in HvacMode]: number } = {
|
||||
auto: 1,
|
||||
|
||||
@@ -1,27 +1,74 @@
|
||||
import { HomeAssistant } from "../types";
|
||||
|
||||
interface ProcessResults {
|
||||
card: { [key: string]: Record<string, string> };
|
||||
speech: {
|
||||
[SpeechType in "plain" | "ssml"]: { extra_data: any; speech: string };
|
||||
interface IntentTarget {
|
||||
type: "area" | "device" | "entity" | "domain" | "device_class" | "custom";
|
||||
name: string;
|
||||
id: string | null;
|
||||
}
|
||||
|
||||
interface IntentResultBase {
|
||||
language: string;
|
||||
speech:
|
||||
| {
|
||||
[SpeechType in "plain" | "ssml"]: { extra_data: any; speech: string };
|
||||
}
|
||||
| null;
|
||||
}
|
||||
|
||||
interface IntentResultActionDone extends IntentResultBase {
|
||||
response_type: "action_done";
|
||||
data: {
|
||||
targets: IntentTarget[];
|
||||
success: IntentTarget[];
|
||||
failed: IntentTarget[];
|
||||
};
|
||||
}
|
||||
|
||||
interface IntentResultQueryAnswer extends IntentResultBase {
|
||||
response_type: "query_answer";
|
||||
data: {
|
||||
targets: IntentTarget[];
|
||||
success: IntentTarget[];
|
||||
failed: IntentTarget[];
|
||||
};
|
||||
}
|
||||
|
||||
interface IntentResultError extends IntentResultBase {
|
||||
response_type: "error";
|
||||
data: {
|
||||
code:
|
||||
| "no_intent_match"
|
||||
| "no_valid_targets"
|
||||
| "failed_to_handle"
|
||||
| "unknown";
|
||||
};
|
||||
}
|
||||
|
||||
interface ConversationResult {
|
||||
conversation_id: string | null;
|
||||
response:
|
||||
| IntentResultActionDone
|
||||
| IntentResultQueryAnswer
|
||||
| IntentResultError;
|
||||
}
|
||||
|
||||
export interface AgentInfo {
|
||||
attribution?: { name: string; url: string };
|
||||
onboarding?: { text: string; url: string };
|
||||
}
|
||||
|
||||
export const processText = (
|
||||
export const processConversationInput = (
|
||||
hass: HomeAssistant,
|
||||
text: string,
|
||||
// eslint-disable-next-line: variable-name
|
||||
conversation_id: string
|
||||
): Promise<ProcessResults> =>
|
||||
conversation_id: string | null,
|
||||
language: string
|
||||
): Promise<ConversationResult> =>
|
||||
hass.callWS({
|
||||
type: "conversation/process",
|
||||
text,
|
||||
conversation_id,
|
||||
language,
|
||||
});
|
||||
|
||||
export const getAgentInfo = (hass: HomeAssistant): Promise<AgentInfo> =>
|
||||
|
||||
@@ -123,9 +123,12 @@ export const subscribeDeviceRegistry = (
|
||||
onChange
|
||||
);
|
||||
|
||||
export const sortDeviceRegistryByName = (entries: DeviceRegistryEntry[]) =>
|
||||
export const sortDeviceRegistryByName = (
|
||||
entries: DeviceRegistryEntry[],
|
||||
language: string
|
||||
) =>
|
||||
entries.sort((entry1, entry2) =>
|
||||
caseInsensitiveStringCompare(entry1.name || "", entry2.name || "")
|
||||
caseInsensitiveStringCompare(entry1.name || "", entry2.name || "", language)
|
||||
);
|
||||
|
||||
export const getDeviceEntityLookup = (
|
||||
|
||||
+1
-1
@@ -451,7 +451,7 @@ const getEnergyData = async (
|
||||
...(await fetchStatistics(
|
||||
hass!,
|
||||
compareStartMinHour,
|
||||
end,
|
||||
endCompare,
|
||||
waterStatIds,
|
||||
period,
|
||||
waterUnits,
|
||||
|
||||
+7
-2
@@ -1,7 +1,12 @@
|
||||
import { arrayLiteralIncludes } from "../common/array/literal-includes";
|
||||
|
||||
export const UNAVAILABLE = "unavailable";
|
||||
export const UNKNOWN = "unknown";
|
||||
export const ON = "on";
|
||||
export const OFF = "off";
|
||||
|
||||
export const UNAVAILABLE_STATES = [UNAVAILABLE, UNKNOWN];
|
||||
export const OFF_STATES = [UNAVAILABLE, UNKNOWN, OFF];
|
||||
export const UNAVAILABLE_STATES = [UNAVAILABLE, UNKNOWN] as const;
|
||||
export const OFF_STATES = [UNAVAILABLE, UNKNOWN, OFF] as const;
|
||||
|
||||
export const isUnavailableState = arrayLiteralIncludes(UNAVAILABLE_STATES);
|
||||
export const isOffState = arrayLiteralIncludes(OFF_STATES);
|
||||
|
||||
@@ -29,6 +29,7 @@ export interface ExtEntityRegistryEntry extends EntityRegistryEntry {
|
||||
original_icon?: string;
|
||||
device_class?: string;
|
||||
original_device_class?: string;
|
||||
aliases: string[];
|
||||
}
|
||||
|
||||
export interface UpdateEntityRegistryEntryResult {
|
||||
@@ -63,6 +64,7 @@ export interface EntityRegistryEntryUpdateParams {
|
||||
new_entity_id?: string;
|
||||
options_domain?: string;
|
||||
options?: SensorEntityOptions | NumberEntityOptions | WeatherEntityOptions;
|
||||
aliases?: string[];
|
||||
}
|
||||
|
||||
export const findBatteryEntity = (
|
||||
@@ -162,9 +164,12 @@ export const subscribeEntityRegistry = (
|
||||
onChange
|
||||
);
|
||||
|
||||
export const sortEntityRegistryByName = (entries: EntityRegistryEntry[]) =>
|
||||
export const sortEntityRegistryByName = (
|
||||
entries: EntityRegistryEntry[],
|
||||
language: string
|
||||
) =>
|
||||
entries.sort((entry1, entry2) =>
|
||||
caseInsensitiveStringCompare(entry1.name || "", entry2.name || "")
|
||||
caseInsensitiveStringCompare(entry1.name || "", entry2.name || "", language)
|
||||
);
|
||||
|
||||
export const entityRegistryById = memoizeOne(
|
||||
|
||||
+20
-7
@@ -1,4 +1,8 @@
|
||||
import { HassEntities, HassEntity } from "home-assistant-js-websocket";
|
||||
import {
|
||||
HassEntities,
|
||||
HassEntity,
|
||||
HassEntityAttributeBase,
|
||||
} from "home-assistant-js-websocket";
|
||||
import { computeDomain } from "../common/entity/compute_domain";
|
||||
import { computeStateDisplayFromEntityAttributes } from "../common/entity/compute_state_display";
|
||||
import { computeStateNameFromEntityAttributes } from "../common/entity/compute_state_name";
|
||||
@@ -117,7 +121,7 @@ export const fetchRecent = (
|
||||
|
||||
export const fetchRecentWS = (
|
||||
hass: HomeAssistant,
|
||||
entityId: string, // This may be CSV
|
||||
entityIds: string[],
|
||||
startTime: Date,
|
||||
endTime: Date,
|
||||
skipInitialState = false,
|
||||
@@ -133,7 +137,7 @@ export const fetchRecentWS = (
|
||||
include_start_time_state: !skipInitialState,
|
||||
minimal_response: minimalResponse,
|
||||
no_attributes: noAttributes || false,
|
||||
entity_ids: entityId.split(","),
|
||||
entity_ids: entityIds,
|
||||
});
|
||||
|
||||
export const fetchDate = (
|
||||
@@ -160,9 +164,9 @@ export const fetchDateWS = (
|
||||
start_time: startTime.toISOString(),
|
||||
end_time: endTime.toISOString(),
|
||||
minimal_response: true,
|
||||
no_attributes: !entityIds
|
||||
.map((entityId) => entityIdHistoryNeedsAttributes(hass, entityId))
|
||||
.reduce((cur, next) => cur || next, false),
|
||||
no_attributes: !entityIds.some((entityId) =>
|
||||
entityIdHistoryNeedsAttributes(hass, entityId)
|
||||
),
|
||||
};
|
||||
if (entityIds.length !== 0) {
|
||||
return hass.callWS<HistoryStates>({ ...params, entity_ids: entityIds });
|
||||
@@ -195,13 +199,22 @@ const processTimelineEntity = (
|
||||
if (data.length > 0 && state.s === data[data.length - 1].state) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const currentAttributes: HassEntityAttributeBase = {};
|
||||
if (current_state?.attributes.device_class) {
|
||||
currentAttributes.device_class = current_state?.attributes.device_class;
|
||||
}
|
||||
|
||||
data.push({
|
||||
state_localize: computeStateDisplayFromEntityAttributes(
|
||||
localize,
|
||||
language,
|
||||
entities,
|
||||
entityId,
|
||||
state.a || first.a,
|
||||
{
|
||||
...(state.a || first.a),
|
||||
...currentAttributes,
|
||||
},
|
||||
state.s
|
||||
),
|
||||
state: state.s,
|
||||
|
||||
+12
-2
@@ -2,14 +2,24 @@ import {
|
||||
HassEntityAttributeBase,
|
||||
HassEntityBase,
|
||||
} from "home-assistant-js-websocket";
|
||||
import { FIXED_DOMAIN_STATES } from "../common/entity/get_states";
|
||||
import { TranslationDict } from "../types";
|
||||
import { UNAVAILABLE_STATES } from "./entity";
|
||||
|
||||
type HumidifierState =
|
||||
| typeof FIXED_DOMAIN_STATES.humidifier[number]
|
||||
| typeof UNAVAILABLE_STATES[number];
|
||||
type HumidifierMode =
|
||||
keyof TranslationDict["state_attributes"]["humidifier"]["mode"];
|
||||
|
||||
export type HumidifierEntity = HassEntityBase & {
|
||||
state: HumidifierState;
|
||||
attributes: HassEntityAttributeBase & {
|
||||
humidity?: number;
|
||||
min_humidity?: number;
|
||||
max_humidity?: number;
|
||||
mode?: string;
|
||||
available_modes?: string[];
|
||||
mode?: HumidifierMode;
|
||||
available_modes?: HumidifierMode[];
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import type {
|
||||
import { supportsFeature } from "../common/entity/supports-feature";
|
||||
import { MediaPlayerItemId } from "../components/media-player/ha-media-player-browse";
|
||||
import type { HomeAssistant, TranslationDict } from "../types";
|
||||
import { UNAVAILABLE_STATES } from "./entity";
|
||||
import { isUnavailableState } from "./entity";
|
||||
import { isTTSMediaSource } from "./tts";
|
||||
|
||||
interface MediaPlayerEntityAttributes extends HassEntityAttributeBase {
|
||||
@@ -259,7 +259,7 @@ export const computeMediaControls = (
|
||||
|
||||
const state = stateObj.state;
|
||||
|
||||
if (UNAVAILABLE_STATES.includes(state)) {
|
||||
if (isUnavailableState(state)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -37,11 +37,13 @@ export interface MQTTDeviceDebugInfo {
|
||||
export const subscribeMQTTTopic = (
|
||||
hass: HomeAssistant,
|
||||
topic: string,
|
||||
callback: (message: MQTTMessage) => void
|
||||
callback: (message: MQTTMessage) => void,
|
||||
qos?: number
|
||||
) =>
|
||||
hass.connection.subscribeMessage<MQTTMessage>(callback, {
|
||||
type: "mqtt/subscribe",
|
||||
topic,
|
||||
qos,
|
||||
});
|
||||
|
||||
export const fetchMQTTDebugInfo = (
|
||||
|
||||
@@ -44,6 +44,7 @@ declare global {
|
||||
export type TranslationCategory =
|
||||
| "title"
|
||||
| "state"
|
||||
| "state_attributes"
|
||||
| "entity"
|
||||
| "config"
|
||||
| "config_panel"
|
||||
|
||||
+7
-3
@@ -68,7 +68,10 @@ export const updateReleaseNotes = (hass: HomeAssistant, entityId: string) =>
|
||||
entity_id: entityId,
|
||||
});
|
||||
|
||||
export const filterUpdateEntities = (entities: HassEntities) =>
|
||||
export const filterUpdateEntities = (
|
||||
entities: HassEntities,
|
||||
language?: string
|
||||
) =>
|
||||
(
|
||||
Object.values(entities).filter(
|
||||
(entity) => computeStateDomain(entity) === "update"
|
||||
@@ -94,7 +97,8 @@ export const filterUpdateEntities = (entities: HassEntities) =>
|
||||
}
|
||||
return caseInsensitiveStringCompare(
|
||||
a.attributes.title || a.attributes.friendly_name || "",
|
||||
b.attributes.title || b.attributes.friendly_name || ""
|
||||
b.attributes.title || b.attributes.friendly_name || "",
|
||||
language
|
||||
);
|
||||
});
|
||||
|
||||
@@ -110,7 +114,7 @@ export const checkForEntityUpdates = async (
|
||||
element: HTMLElement,
|
||||
hass: HomeAssistant
|
||||
) => {
|
||||
const entities = filterUpdateEntities(hass.states).map(
|
||||
const entities = filterUpdateEntities(hass.states, hass.locale.language).map(
|
||||
(entity) => entity.entity_id
|
||||
);
|
||||
|
||||
|
||||
+9
-3
@@ -319,6 +319,12 @@ export const weatherSVGStyles = css`
|
||||
.cloud-front {
|
||||
fill: var(--weather-icon-cloud-front-color, #f9f9f9);
|
||||
}
|
||||
.snow {
|
||||
fill: var(--weather-icon-snow-color, #f9f9f9);
|
||||
stroke: var(--weather-icon-snow-stroke-color, #d4d4d4);
|
||||
stroke-width: 1;
|
||||
paint-order: stroke;
|
||||
}
|
||||
`;
|
||||
|
||||
const getWeatherStateSVG = (
|
||||
@@ -434,15 +440,15 @@ const getWeatherStateSVG = (
|
||||
snowyStates.has(state)
|
||||
? svg`
|
||||
<path
|
||||
class="rain"
|
||||
class="snow"
|
||||
d="m 8.4319893,15.348341 c 0,0.257881 -0.209197,0.467079 -0.467078,0.467079 -0.258586,0 -0.46743,-0.209198 -0.46743,-0.467079 0,-0.258233 0.208844,-0.467431 0.46743,-0.467431 0.257881,0 0.467078,0.209198 0.467078,0.467431"
|
||||
/>
|
||||
<path
|
||||
class="rain"
|
||||
class="snow"
|
||||
d="m 11.263878,14.358553 c 0,0.364067 -0.295275,0.659694 -0.659695,0.659694 -0.364419,0 -0.6596937,-0.295627 -0.6596937,-0.659694 0,-0.364419 0.2952747,-0.659694 0.6596937,-0.659694 0.36442,0 0.659695,0.295275 0.659695,0.659694"
|
||||
/>
|
||||
<path
|
||||
class="rain"
|
||||
class="snow"
|
||||
d="m 5.3252173,13.69847 c 0,0.364419 -0.295275,0.660047 -0.659695,0.660047 -0.364067,0 -0.659694,-0.295628 -0.659694,-0.660047 0,-0.364067 0.295627,-0.659694 0.659694,-0.659694 0.36442,0 0.659695,0.295627 0.659695,0.659694"
|
||||
/>
|
||||
`
|
||||
|
||||
@@ -74,7 +74,7 @@ export class HaImagecropperDialog extends LitElement {
|
||||
round: Boolean(this._params?.options.round),
|
||||
})}"
|
||||
>
|
||||
<img />
|
||||
<img alt=${this.hass.localize("ui.dialogs.image_cropper.crop_image")} />
|
||||
</div>
|
||||
<mwc-button slot="secondaryAction" @click=${this.closeDialog}>
|
||||
${this.hass.localize("ui.common.cancel")}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import "../../../components/ha-relative-time";
|
||||
import { triggerAutomationActions } from "../../../data/automation";
|
||||
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||
import { isUnavailableState } from "../../../data/entity";
|
||||
import { HomeAssistant } from "../../../types";
|
||||
|
||||
@customElement("more-info-automation")
|
||||
@@ -32,7 +32,7 @@ class MoreInfoAutomation extends LitElement {
|
||||
<div class="actions">
|
||||
<mwc-button
|
||||
@click=${this._runActions}
|
||||
.disabled=${UNAVAILABLE_STATES.includes(this.stateObj!.state)}
|
||||
.disabled=${isUnavailableState(this.stateObj!.state)}
|
||||
>
|
||||
${this.hass.localize("ui.card.automation.trigger")}
|
||||
</mwc-button>
|
||||
|
||||
@@ -11,6 +11,11 @@ import { property } 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 {
|
||||
computeAttributeNameDisplay,
|
||||
computeAttributeValueDisplay,
|
||||
} from "../../../common/entity/compute_attribute_display";
|
||||
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
|
||||
import { supportsFeature } from "../../../common/entity/supports-feature";
|
||||
import { computeRTLDirection } from "../../../common/util/compute_rtl";
|
||||
import "../../../components/ha-climate-control";
|
||||
@@ -19,13 +24,7 @@ import "../../../components/ha-slider";
|
||||
import "../../../components/ha-switch";
|
||||
import {
|
||||
ClimateEntity,
|
||||
CLIMATE_SUPPORT_AUX_HEAT,
|
||||
CLIMATE_SUPPORT_FAN_MODE,
|
||||
CLIMATE_SUPPORT_PRESET_MODE,
|
||||
CLIMATE_SUPPORT_SWING_MODE,
|
||||
CLIMATE_SUPPORT_TARGET_HUMIDITY,
|
||||
CLIMATE_SUPPORT_TARGET_TEMPERATURE,
|
||||
CLIMATE_SUPPORT_TARGET_TEMPERATURE_RANGE,
|
||||
ClimateEntityFeature,
|
||||
compareClimateHvacModes,
|
||||
} from "../../../data/climate";
|
||||
import { HomeAssistant } from "../../../types";
|
||||
@@ -47,26 +46,32 @@ class MoreInfoClimate extends LitElement {
|
||||
|
||||
const supportTargetTemperature = supportsFeature(
|
||||
stateObj,
|
||||
CLIMATE_SUPPORT_TARGET_TEMPERATURE
|
||||
ClimateEntityFeature.TARGET_TEMPERATURE
|
||||
);
|
||||
const supportTargetTemperatureRange = supportsFeature(
|
||||
stateObj,
|
||||
CLIMATE_SUPPORT_TARGET_TEMPERATURE_RANGE
|
||||
ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
|
||||
);
|
||||
const supportTargetHumidity = supportsFeature(
|
||||
stateObj,
|
||||
CLIMATE_SUPPORT_TARGET_HUMIDITY
|
||||
ClimateEntityFeature.TARGET_HUMIDITY
|
||||
);
|
||||
const supportFanMode = supportsFeature(
|
||||
stateObj,
|
||||
ClimateEntityFeature.FAN_MODE
|
||||
);
|
||||
const supportFanMode = supportsFeature(stateObj, CLIMATE_SUPPORT_FAN_MODE);
|
||||
const supportPresetMode = supportsFeature(
|
||||
stateObj,
|
||||
CLIMATE_SUPPORT_PRESET_MODE
|
||||
ClimateEntityFeature.PRESET_MODE
|
||||
);
|
||||
const supportSwingMode = supportsFeature(
|
||||
stateObj,
|
||||
CLIMATE_SUPPORT_SWING_MODE
|
||||
ClimateEntityFeature.SWING_MODE
|
||||
);
|
||||
const supportAuxHeat = supportsFeature(
|
||||
stateObj,
|
||||
ClimateEntityFeature.AUX_HEAT
|
||||
);
|
||||
const supportAuxHeat = supportsFeature(stateObj, CLIMATE_SUPPORT_AUX_HEAT);
|
||||
|
||||
const temperatureStepSize =
|
||||
stateObj.attributes.target_temp_step ||
|
||||
@@ -94,7 +99,12 @@ class MoreInfoClimate extends LitElement {
|
||||
${supportTargetTemperature || supportTargetTemperatureRange
|
||||
? html`
|
||||
<div>
|
||||
${hass.localize("ui.card.climate.target_temperature")}
|
||||
${computeAttributeNameDisplay(
|
||||
hass.localize,
|
||||
stateObj,
|
||||
hass.entities,
|
||||
"temperature"
|
||||
)}
|
||||
</div>
|
||||
`
|
||||
: ""}
|
||||
@@ -145,7 +155,14 @@ class MoreInfoClimate extends LitElement {
|
||||
${supportTargetHumidity
|
||||
? html`
|
||||
<div class="container-humidity">
|
||||
<div>${hass.localize("ui.card.climate.target_humidity")}</div>
|
||||
<div>
|
||||
${computeAttributeNameDisplay(
|
||||
hass.localize,
|
||||
stateObj,
|
||||
hass.entities,
|
||||
"humidity"
|
||||
)}
|
||||
</div>
|
||||
<div class="single-row">
|
||||
<div class="target-humidity">
|
||||
${stateObj.attributes.humidity} %
|
||||
@@ -182,7 +199,13 @@ class MoreInfoClimate extends LitElement {
|
||||
.map(
|
||||
(mode) => html`
|
||||
<mwc-list-item .value=${mode}>
|
||||
${hass.localize(`component.climate.state._.${mode}`)}
|
||||
${computeStateDisplay(
|
||||
hass.localize,
|
||||
stateObj,
|
||||
hass.locale,
|
||||
hass.entities,
|
||||
mode
|
||||
)}
|
||||
</mwc-list-item>
|
||||
`
|
||||
)}
|
||||
@@ -194,7 +217,12 @@ class MoreInfoClimate extends LitElement {
|
||||
? html`
|
||||
<div class="container-preset_modes">
|
||||
<ha-select
|
||||
.label=${hass.localize("ui.card.climate.preset_mode")}
|
||||
.label=${computeAttributeNameDisplay(
|
||||
hass.localize,
|
||||
stateObj,
|
||||
hass.entities,
|
||||
"preset_mode"
|
||||
)}
|
||||
.value=${stateObj.attributes.preset_mode}
|
||||
fixedMenuPosition
|
||||
naturalMenuWidth
|
||||
@@ -204,9 +232,13 @@ class MoreInfoClimate extends LitElement {
|
||||
${stateObj.attributes.preset_modes!.map(
|
||||
(mode) => html`
|
||||
<mwc-list-item .value=${mode}>
|
||||
${hass.localize(
|
||||
`state_attributes.climate.preset_mode.${mode}`
|
||||
) || mode}
|
||||
${computeAttributeValueDisplay(
|
||||
hass.localize,
|
||||
stateObj,
|
||||
hass.entities,
|
||||
"preset_mode",
|
||||
mode
|
||||
)}
|
||||
</mwc-list-item>
|
||||
`
|
||||
)}
|
||||
@@ -218,7 +250,12 @@ class MoreInfoClimate extends LitElement {
|
||||
? html`
|
||||
<div class="container-fan_list">
|
||||
<ha-select
|
||||
.label=${hass.localize("ui.card.climate.fan_mode")}
|
||||
.label=${computeAttributeNameDisplay(
|
||||
hass.localize,
|
||||
stateObj,
|
||||
hass.entities,
|
||||
"fan_mode"
|
||||
)}
|
||||
.value=${stateObj.attributes.fan_mode}
|
||||
fixedMenuPosition
|
||||
naturalMenuWidth
|
||||
@@ -228,9 +265,13 @@ class MoreInfoClimate extends LitElement {
|
||||
${stateObj.attributes.fan_modes!.map(
|
||||
(mode) => html`
|
||||
<mwc-list-item .value=${mode}>
|
||||
${hass.localize(
|
||||
`state_attributes.climate.fan_mode.${mode}`
|
||||
) || mode}
|
||||
${computeAttributeValueDisplay(
|
||||
hass.localize,
|
||||
stateObj,
|
||||
hass.entities,
|
||||
"fan_mode",
|
||||
mode
|
||||
)}
|
||||
</mwc-list-item>
|
||||
`
|
||||
)}
|
||||
@@ -242,7 +283,12 @@ class MoreInfoClimate extends LitElement {
|
||||
? html`
|
||||
<div class="container-swing_list">
|
||||
<ha-select
|
||||
.label=${hass.localize("ui.card.climate.swing_mode")}
|
||||
.label=${computeAttributeNameDisplay(
|
||||
hass.localize,
|
||||
stateObj,
|
||||
hass.entities,
|
||||
"swing_mode"
|
||||
)}
|
||||
.value=${stateObj.attributes.swing_mode}
|
||||
fixedMenuPosition
|
||||
naturalMenuWidth
|
||||
@@ -251,7 +297,15 @@ class MoreInfoClimate extends LitElement {
|
||||
>
|
||||
${stateObj.attributes.swing_modes!.map(
|
||||
(mode) => html`
|
||||
<mwc-list-item .value=${mode}>${mode}</mwc-list-item>
|
||||
<mwc-list-item .value=${mode}>
|
||||
${computeAttributeValueDisplay(
|
||||
hass.localize,
|
||||
stateObj,
|
||||
hass.entities,
|
||||
"swing_mode",
|
||||
mode
|
||||
)}
|
||||
</mwc-list-item>
|
||||
`
|
||||
)}
|
||||
</ha-select>
|
||||
@@ -263,7 +317,12 @@ class MoreInfoClimate extends LitElement {
|
||||
<div class="container-aux_heat">
|
||||
<div class="center horizontal layout single-row">
|
||||
<div class="flex">
|
||||
${hass.localize("ui.card.climate.aux_heat")}
|
||||
${computeAttributeNameDisplay(
|
||||
hass.localize,
|
||||
stateObj,
|
||||
hass.entities,
|
||||
"aux_heat"
|
||||
)}
|
||||
</div>
|
||||
<ha-switch
|
||||
.checked=${stateObj.attributes.aux_heat === "on"}
|
||||
|
||||
@@ -2,7 +2,7 @@ import "@material/mwc-button";
|
||||
import { HassEntity } from "home-assistant-js-websocket";
|
||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||
import { isUnavailableState } from "../../../data/entity";
|
||||
import { HomeAssistant } from "../../../types";
|
||||
|
||||
@customElement("more-info-counter")
|
||||
@@ -16,7 +16,7 @@ class MoreInfoCounter extends LitElement {
|
||||
return html``;
|
||||
}
|
||||
|
||||
const disabled = UNAVAILABLE_STATES.includes(this.stateObj!.state);
|
||||
const disabled = isUnavailableState(this.stateObj!.state);
|
||||
|
||||
return html`
|
||||
<div class="actions">
|
||||
|
||||
@@ -3,7 +3,7 @@ import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import "../../../components/ha-date-input";
|
||||
import "../../../components/ha-time-input";
|
||||
import { UNAVAILABLE_STATES, UNKNOWN } from "../../../data/entity";
|
||||
import { isUnavailableState, UNKNOWN } from "../../../data/entity";
|
||||
import {
|
||||
setInputDateTimeValue,
|
||||
stateToIsoDateString,
|
||||
@@ -28,7 +28,7 @@ class MoreInfoInputDatetime extends LitElement {
|
||||
<ha-date-input
|
||||
.locale=${this.hass.locale}
|
||||
.value=${stateToIsoDateString(this.stateObj)}
|
||||
.disabled=${UNAVAILABLE_STATES.includes(this.stateObj.state)}
|
||||
.disabled=${isUnavailableState(this.stateObj.state)}
|
||||
@value-changed=${this._dateChanged}
|
||||
>
|
||||
</ha-date-input>
|
||||
@@ -45,7 +45,7 @@ class MoreInfoInputDatetime extends LitElement {
|
||||
? this.stateObj.state.split(" ")[1]
|
||||
: this.stateObj.state}
|
||||
.locale=${this.hass.locale}
|
||||
.disabled=${UNAVAILABLE_STATES.includes(this.stateObj.state)}
|
||||
.disabled=${isUnavailableState(this.stateObj.state)}
|
||||
@value-changed=${this._timeChanged}
|
||||
@click=${this._stopEventPropagation}
|
||||
></ha-time-input>
|
||||
|
||||
@@ -9,7 +9,7 @@ import "../../../components/ha-checkbox";
|
||||
import "../../../components/ha-circular-progress";
|
||||
import "../../../components/ha-formfield";
|
||||
import "../../../components/ha-markdown";
|
||||
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||
import { isUnavailableState } from "../../../data/entity";
|
||||
import {
|
||||
UpdateEntity,
|
||||
updateIsInstalling,
|
||||
@@ -37,7 +37,7 @@ class MoreInfoUpdate extends LitElement {
|
||||
if (
|
||||
!this.hass ||
|
||||
!this.stateObj ||
|
||||
UNAVAILABLE_STATES.includes(this.stateObj.state)
|
||||
isUnavailableState(this.stateObj.state)
|
||||
) {
|
||||
return html``;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ export class MoreInfoHistory extends LitElement {
|
||||
}
|
||||
this._stateHistory = await getRecentWithCache(
|
||||
this.hass!,
|
||||
this.entityId,
|
||||
[this.entityId],
|
||||
{
|
||||
cacheKey: `more_info.${this.entityId}`,
|
||||
hoursToShow: 24,
|
||||
|
||||
@@ -484,7 +484,11 @@ export class QuickBar extends LitElement {
|
||||
};
|
||||
})
|
||||
.sort((a, b) =>
|
||||
caseInsensitiveStringCompare(a.primaryText, b.primaryText)
|
||||
caseInsensitiveStringCompare(
|
||||
a.primaryText,
|
||||
b.primaryText,
|
||||
this.hass.locale.language
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -494,7 +498,11 @@ export class QuickBar extends LitElement {
|
||||
...this._generateServerControlCommands(),
|
||||
...(await this._generateNavigationCommands()),
|
||||
].sort((a, b) =>
|
||||
caseInsensitiveStringCompare(a.strings.join(" "), b.strings.join(" "))
|
||||
caseInsensitiveStringCompare(
|
||||
a.strings.join(" "),
|
||||
b.strings.join(" "),
|
||||
this.hass.locale.language
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import { customElement, property, query, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { fireEvent } from "../../common/dom/fire_event";
|
||||
import { SpeechRecognition } from "../../common/dom/speech-recognition";
|
||||
import { uid } from "../../common/util/uid";
|
||||
import "../../components/ha-dialog";
|
||||
import type { HaDialog } from "../../components/ha-dialog";
|
||||
import "../../components/ha-icon-button";
|
||||
@@ -22,7 +21,7 @@ import type { HaTextField } from "../../components/ha-textfield";
|
||||
import {
|
||||
AgentInfo,
|
||||
getAgentInfo,
|
||||
processText,
|
||||
processConversationInput,
|
||||
setConversationOnboarding,
|
||||
} from "../../data/conversation";
|
||||
import { haStyleDialog } from "../../resources/styles";
|
||||
@@ -60,7 +59,7 @@ export class HaVoiceCommandDialog extends LitElement {
|
||||
|
||||
private recognition!: SpeechRecognition;
|
||||
|
||||
private _conversationId?: string;
|
||||
private _conversationId: string | null = null;
|
||||
|
||||
public async showDialog(): Promise<void> {
|
||||
this._opened = true;
|
||||
@@ -175,7 +174,6 @@ export class HaVoiceCommandDialog extends LitElement {
|
||||
|
||||
protected firstUpdated(changedProps: PropertyValues) {
|
||||
super.updated(changedProps);
|
||||
this._conversationId = uid();
|
||||
this._conversation = [
|
||||
{
|
||||
who: "hass",
|
||||
@@ -211,18 +209,29 @@ export class HaVoiceCommandDialog extends LitElement {
|
||||
private _initRecognition() {
|
||||
this.recognition = new SpeechRecognition();
|
||||
this.recognition.interimResults = true;
|
||||
this.recognition.lang = "en-US";
|
||||
this.recognition.lang = this.hass.language;
|
||||
|
||||
this.recognition.onstart = () => {
|
||||
this.recognition.addEventListener("start", () => {
|
||||
this.results = {
|
||||
final: false,
|
||||
transcript: "",
|
||||
};
|
||||
};
|
||||
this.recognition.onerror = (event) => {
|
||||
});
|
||||
this.recognition.addEventListener("nomatch", () => {
|
||||
this._addMessage({
|
||||
who: "user",
|
||||
text: `<${this.hass.localize(
|
||||
"ui.dialogs.voice_command.did_not_understand"
|
||||
)}>`,
|
||||
error: true,
|
||||
});
|
||||
});
|
||||
this.recognition.addEventListener("error", (event) => {
|
||||
// eslint-disable-next-line
|
||||
console.error("Error recognizing text", event);
|
||||
this.recognition!.abort();
|
||||
// @ts-ignore
|
||||
if (event.error !== "aborted") {
|
||||
if (event.error !== "aborted" && event.error !== "no-speech") {
|
||||
const text =
|
||||
this.results && this.results.transcript
|
||||
? this.results.transcript
|
||||
@@ -232,8 +241,8 @@ export class HaVoiceCommandDialog extends LitElement {
|
||||
this._addMessage({ who: "user", text, error: true });
|
||||
}
|
||||
this.results = null;
|
||||
};
|
||||
this.recognition.onend = () => {
|
||||
});
|
||||
this.recognition.addEventListener("end", () => {
|
||||
// Already handled by onerror
|
||||
if (this.results == null) {
|
||||
return;
|
||||
@@ -251,15 +260,14 @@ export class HaVoiceCommandDialog extends LitElement {
|
||||
error: true,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.recognition.onresult = (event) => {
|
||||
});
|
||||
this.recognition.addEventListener("result", (event) => {
|
||||
const result = event.results[0];
|
||||
this.results = {
|
||||
transcript: result[0].transcript,
|
||||
final: result.isFinal,
|
||||
};
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private async _processText(text: string) {
|
||||
@@ -274,13 +282,19 @@ export class HaVoiceCommandDialog extends LitElement {
|
||||
// To make sure the answer is placed at the right user text, we add it before we process it
|
||||
this._addMessage(message);
|
||||
try {
|
||||
const response = await processText(
|
||||
const response = await processConversationInput(
|
||||
this.hass,
|
||||
text,
|
||||
this._conversationId!
|
||||
this._conversationId,
|
||||
this.hass.language
|
||||
);
|
||||
const plain = response.speech.plain;
|
||||
message.text = plain.speech;
|
||||
this._conversationId = response.conversation_id;
|
||||
const plain = response.response.speech?.plain;
|
||||
if (plain) {
|
||||
message.text = plain.speech;
|
||||
} else {
|
||||
message.text = "<silence>";
|
||||
}
|
||||
|
||||
this.requestUpdate("_conversation");
|
||||
} catch {
|
||||
|
||||
@@ -138,6 +138,8 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
|
||||
// @ts-ignore
|
||||
this._loadHassTranslations(this.hass!.language, "state");
|
||||
// @ts-ignore
|
||||
this._loadHassTranslations(this.hass!.language, "state_attributes");
|
||||
// @ts-ignore
|
||||
this._loadHassTranslations(this.hass!.language, "entity");
|
||||
|
||||
document.addEventListener(
|
||||
|
||||
@@ -19,6 +19,7 @@ class IntegrationBadge extends LitElement {
|
||||
return html`
|
||||
<div class="icon">
|
||||
<img
|
||||
alt=""
|
||||
src=${brandsUrl({
|
||||
domain: this.domain,
|
||||
type: "icon",
|
||||
|
||||
@@ -156,13 +156,11 @@ class OnboardingCoreConfig extends LitElement {
|
||||
type="number"
|
||||
.disabled=${this._working}
|
||||
.value=${this._elevationValue}
|
||||
.suffix=${this.hass.localize(
|
||||
"ui.panel.config.core.section.core.core_config.elevation_meters"
|
||||
)}
|
||||
@change=${this._handleChange}
|
||||
>
|
||||
<span slot="suffix">
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.core.section.core.core_config.elevation_meters"
|
||||
)}
|
||||
</span>
|
||||
</ha-textfield>
|
||||
</div>
|
||||
|
||||
@@ -273,7 +271,9 @@ class OnboardingCoreConfig extends LitElement {
|
||||
"[name=currency]"
|
||||
) as HaTextField;
|
||||
curInput.updateComplete.then(() => {
|
||||
curInput.shadowRoot!.appendChild(createCurrencyListEl());
|
||||
curInput.shadowRoot!.appendChild(
|
||||
createCurrencyListEl(this.hass.locale.language)
|
||||
);
|
||||
curInput.formElement.setAttribute("list", "currencies");
|
||||
});
|
||||
|
||||
@@ -281,7 +281,9 @@ class OnboardingCoreConfig extends LitElement {
|
||||
"[name=country]"
|
||||
) as HaTextField;
|
||||
countryInput.updateComplete.then(() => {
|
||||
countryInput.shadowRoot!.appendChild(createCountryListEl());
|
||||
countryInput.shadowRoot!.appendChild(
|
||||
createCountryListEl(this.hass.locale.language)
|
||||
);
|
||||
countryInput.formElement.setAttribute("list", "countries");
|
||||
});
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user