From 73ef03e33f1eeaaa8edf3ac6298ee3b94b2ab19a Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 29 Apr 2019 11:27:40 -0700 Subject: [PATCH 01/11] Use signed path for camera snapshot (#3138) --- .../snapshot/dialog-hassio-snapshot.ts | 2 +- src/auth/data.ts | 7 ----- src/auth/types.ts | 3 -- src/cards/ha-camera-card.js | 27 ++++++++++-------- src/data/auth.ts | 11 ++++++++ src/data/camera.ts | 22 ++++++++++++--- src/panels/lovelace/components/hui-image.ts | 28 +++++++++---------- 7 files changed, 58 insertions(+), 42 deletions(-) delete mode 100644 src/auth/data.ts delete mode 100644 src/auth/types.ts diff --git a/hassio/src/dialogs/snapshot/dialog-hassio-snapshot.ts b/hassio/src/dialogs/snapshot/dialog-hassio-snapshot.ts index 6ced46ca76..3d1cc54cdd 100644 --- a/hassio/src/dialogs/snapshot/dialog-hassio-snapshot.ts +++ b/hassio/src/dialogs/snapshot/dialog-hassio-snapshot.ts @@ -6,7 +6,7 @@ import "@polymer/paper-icon-button/paper-icon-button"; import "@polymer/paper-input/paper-input"; import { html } from "@polymer/polymer/lib/utils/html-tag"; import { PolymerElement } from "@polymer/polymer/polymer-element"; -import { getSignedPath } from "../../../../src/auth/data"; +import { getSignedPath } from "../../../../src/data/auth"; import "../../../../src/resources/ha-style"; import "../../../../src/components/dialog/ha-paper-dialog"; diff --git a/src/auth/data.ts b/src/auth/data.ts deleted file mode 100644 index f970e90d52..0000000000 --- a/src/auth/data.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { HomeAssistant } from "../types"; -import { SignedPath } from "./types"; - -export const getSignedPath = ( - hass: HomeAssistant, - path: string -): Promise => hass.callWS({ type: "auth/sign_path", path }); diff --git a/src/auth/types.ts b/src/auth/types.ts deleted file mode 100644 index bb1b00180a..0000000000 --- a/src/auth/types.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface SignedPath { - path: string; -} diff --git a/src/cards/ha-camera-card.js b/src/cards/ha-camera-card.js index c26b60b72c..c59f847429 100644 --- a/src/cards/ha-camera-card.js +++ b/src/cards/ha-camera-card.js @@ -5,6 +5,7 @@ import { PolymerElement } from "@polymer/polymer/polymer-element"; import computeStateName from "../common/entity/compute_state_name"; import EventsMixin from "../mixins/events-mixin"; import LocalizeMixin from "../mixins/localize-mixin"; +import { fetchThumbnailUrlWithCache } from "../data/camera"; const UPDATE_INTERVAL = 10000; // ms /* @@ -54,6 +55,8 @@ class HaCameraCard extends LocalizeMixin(EventsMixin(PolymerElement)) { src="[[cameraFeedSrc]]" class="camera-feed" alt="[[_computeStateName(stateObj)]]" + on-load="_imageLoaded" + on-error="_imageError" />
@@ -98,23 +101,23 @@ class HaCameraCard extends LocalizeMixin(EventsMixin(PolymerElement)) { clearInterval(this.timer); } + _imageLoaded() { + this.imageLoaded = true; + } + + _imageError() { + this.imageLoaded = false; + } + cardTapped() { this.fire("hass-more-info", { entityId: this.stateObj.entity_id }); } async updateCameraFeedSrc() { - try { - const { content_type: contentType, content } = await this.hass.callWS({ - type: "camera_thumbnail", - entity_id: this.stateObj.entity_id, - }); - this.setProperties({ - imageLoaded: true, - cameraFeedSrc: `data:${contentType};base64, ${content}`, - }); - } catch (err) { - this.imageLoaded = false; - } + this.cameraFeedSrc = await fetchThumbnailUrlWithCache( + this.hass, + this.stateObj.entity_id + ); } _computeStateName(stateObj) { diff --git a/src/data/auth.ts b/src/data/auth.ts index 92a44130e2..0c5d1a9493 100644 --- a/src/data/auth.ts +++ b/src/data/auth.ts @@ -1,3 +1,5 @@ +import { HomeAssistant } from "../types"; + export interface AuthProvider { name: string; id: string; @@ -7,3 +9,12 @@ export interface AuthProvider { export interface Credential { type: string; } + +export interface SignedPath { + path: string; +} + +export const getSignedPath = ( + hass: HomeAssistant, + path: string +): Promise => hass.callWS({ type: "auth/sign_path", path }); diff --git a/src/data/camera.ts b/src/data/camera.ts index 62ff707130..ab40da3dd8 100644 --- a/src/data/camera.ts +++ b/src/data/camera.ts @@ -1,5 +1,6 @@ import { HomeAssistant, CameraEntity } from "../types"; import { timeCachePromiseFunc } from "../common/util/time-cache-function-promise"; +import { getSignedPath } from "./auth"; export const CAMERA_SUPPORT_ON_OFF = 1; export const CAMERA_SUPPORT_STREAM = 2; @@ -22,16 +23,29 @@ export const computeMJPEGStreamUrl = (entity: CameraEntity) => entity.attributes.access_token }`; -export const fetchThumbnailWithCache = ( +export const fetchThumbnailUrlWithCache = ( hass: HomeAssistant, entityId: string -) => timeCachePromiseFunc("_cameraTmb", 9000, fetchThumbnail, hass, entityId); +) => + timeCachePromiseFunc( + "_cameraTmbUrl", + 9000, + fetchThumbnailUrl, + hass, + entityId + ); -export const fetchThumbnail = (hass: HomeAssistant, entityId: string) => - hass.callWS({ +export const fetchThumbnailUrl = (hass: HomeAssistant, entityId: string) => + getSignedPath(hass, `/api/camera_proxy/${entityId}`).then(({ path }) => path); + +export const fetchThumbnail = (hass: HomeAssistant, entityId: string) => { + // tslint:disable-next-line: no-console + console.warn("This method has been deprecated."); + return hass.callWS({ type: "camera_thumbnail", entity_id: entityId, }); +}; export const fetchStreamUrl = ( hass: HomeAssistant, diff --git a/src/panels/lovelace/components/hui-image.ts b/src/panels/lovelace/components/hui-image.ts index 0d5ad799d7..870ff7b51c 100644 --- a/src/panels/lovelace/components/hui-image.ts +++ b/src/panels/lovelace/components/hui-image.ts @@ -17,8 +17,7 @@ import { import { HomeAssistant, CameraEntity } from "../../../types"; import { styleMap } from "lit-html/directives/style-map"; import { classMap } from "lit-html/directives/class-map"; -import { b64toBlob } from "../../../common/file/b64-to-blob"; -import { fetchThumbnailWithCache } from "../../../data/camera"; +import { fetchThumbnailUrlWithCache } from "../../../data/camera"; const UPDATE_INTERVAL = 10000; const DEFAULT_FILTER = "grayscale(100%)"; @@ -197,21 +196,20 @@ export class HuiImage extends LitElement { if (!this.hass || !this.cameraImage) { return; } - try { - const { - content_type: contentType, - content, - } = await fetchThumbnailWithCache(this.hass, this.cameraImage); - if (this._cameraImageSrc) { - URL.revokeObjectURL(this._cameraImageSrc); - } - this._cameraImageSrc = URL.createObjectURL( - b64toBlob(content, contentType) - ); - this._onImageLoad(); - } catch (err) { + + const cameraState = this.hass.states[this.cameraImage] as + | CameraEntity + | undefined; + + if (!cameraState) { this._onImageError(); + return; } + + this._cameraImageSrc = await fetchThumbnailUrlWithCache( + this.hass, + this.cameraImage + ); } static get styles(): CSSResult { From d8f21d99af1f7391bcd3917d79adcb528c919183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Mon, 29 Apr 2019 20:31:27 +0200 Subject: [PATCH 02/11] Use named slots to have advanced ha-card headers (#3127) * Use named slots to have advanced ha-card headers * Fix header text color --- src/components/ha-card.ts | 11 +++++---- .../lovelace/cards/hui-entities-card.ts | 24 ++++--------------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/components/ha-card.ts b/src/components/ha-card.ts index 3cc329a87f..471905673f 100644 --- a/src/components/ha-card.ts +++ b/src/components/ha-card.ts @@ -28,19 +28,22 @@ class HaCard extends LitElement { display: block; transition: all 0.3s ease-out; } - .header:not(:empty) { - font-size: 24px; + .header:not(:empty), + .header::slotted(*) { + color: var(--ha-card-header-color, --primary-text-color); + font-family: var(--ha-card-header-font-family, inherit); + font-size: var(--ha-card-header-font-size, 24px); letter-spacing: -0.012em; line-height: 32px; - opacity: 0.87; padding: 24px 16px 16px; + display: block; } `; } protected render(): TemplateResult { return html` -
${this.header}
+ ${this.header} `; } diff --git a/src/panels/lovelace/cards/hui-entities-card.ts b/src/panels/lovelace/cards/hui-entities-card.ts index 3ff8951ece..0e7ca75f1b 100644 --- a/src/panels/lovelace/cards/hui-entities-card.ts +++ b/src/panels/lovelace/cards/hui-entities-card.ts @@ -89,7 +89,7 @@ class HuiEntitiesCard extends LitElement implements LovelaceCard { ${!title && !show_header_toggle ? html`` : html` -
+
${title}
${show_header_toggle === false ? html`` @@ -114,12 +114,8 @@ class HuiEntitiesCard extends LitElement implements LovelaceCard { static get styles(): CSSResult { return css` - ha-card { - padding: 16px; - } - #states { - margin: -4px 0; + padding: 12px 16px; } #states > * { @@ -131,28 +127,16 @@ class HuiEntitiesCard extends LitElement implements LovelaceCard { } .header { - /* start paper-font-headline style */ - font-family: "Roboto", "Noto", sans-serif; - -webkit-font-smoothing: antialiased; /* OS X subpixel AA bleed bug */ - text-rendering: optimizeLegibility; - font-size: 24px; - font-weight: 400; - letter-spacing: -0.012em; - /* end paper-font-headline style */ - - line-height: 40px; - color: var(--primary-text-color); - padding: 4px 0 12px; + margin-bottom: -8px; + padding-bottom: 0px; display: flex; justify-content: space-between; } .header .name { - /* start paper-font-common-nowrap style */ white-space: nowrap; overflow: hidden; text-overflow: ellipsis; - /* end paper-font-common-nowrap */ } .state-card-dialog { From f943393adef4672008c357228b77fa7f051db609 Mon Sep 17 00:00:00 2001 From: Joakim Plate Date: Tue, 30 Apr 2019 19:21:43 +0200 Subject: [PATCH 03/11] Switch source selection to same logic as SoundMode with using (#3136) actual value as selected item instead of index. This avoids the bug with selected: https://github.com/PolymerElements/paper-dropdown-menu/issues/197 https://github.com/PolymerElements/paper-dropdown-menu/issues/114 Fixes: #3022 Side note: it actually mainly hides the issue. If we should allow a key, value setup with source being a key and the display value being a localized value it likely would return. --- .../controls/more-info-media_player.js | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/dialogs/more-info/controls/more-info-media_player.js b/src/dialogs/more-info/controls/more-info-media_player.js index 0251f67f07..fd22c1a111 100644 --- a/src/dialogs/more-info/controls/more-info-media_player.js +++ b/src/dialogs/more-info/controls/more-info-media_player.js @@ -154,9 +154,13 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) { label-float="" label="[[localize('ui.card.media_player.source')]]" > - + @@ -214,9 +218,9 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) { observer: "playerObjChanged", }, - sourceIndex: { - type: Number, - value: 0, + SourceInput: { + type: String, + value: "", observer: "handleSourceChanged", }, @@ -249,7 +253,7 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) { playerObjChanged(newVal, oldVal) { if (newVal && newVal.sourceList !== undefined) { - this.sourceIndex = newVal.sourceList.indexOf(newVal.source); + this.SourceInput = newVal.source; } if (newVal && newVal.soundModeList !== undefined) { @@ -342,26 +346,16 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) { this.playerObj.nextTrack(); } - handleSourceChanged(sourceIndex, sourceIndexOld) { + handleSourceChanged(newVal, oldVal) { // Selected Option will transition to '' before transitioning to new value if ( - !this.playerObj || - !this.playerObj.supportsSelectSource || - this.playerObj.sourceList === undefined || - sourceIndex < 0 || - sourceIndex >= this.playerObj.sourceList || - sourceIndexOld === undefined + oldVal && + newVal && + newVal !== this.playerObj.source && + this.playerObj.supportsSelectSource ) { - return; + this.playerObj.selectSource(newVal); } - - const sourceInput = this.playerObj.sourceList[sourceIndex]; - - if (sourceInput === this.playerObj.source) { - return; - } - - this.playerObj.selectSource(sourceInput); } handleSoundModeChanged(newVal, oldVal) { From ca0ded8587b78f1c473fe87983eb2c7c78546b81 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 30 Apr 2019 11:38:17 -0700 Subject: [PATCH 04/11] Fix webpack chunkname --- src/panels/lovelace/common/generate-lovelace-config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/panels/lovelace/common/generate-lovelace-config.ts b/src/panels/lovelace/common/generate-lovelace-config.ts index 3e771733a2..c0b115e523 100644 --- a/src/panels/lovelace/common/generate-lovelace-config.ts +++ b/src/panels/lovelace/common/generate-lovelace-config.ts @@ -287,7 +287,7 @@ export const generateLovelaceConfig = ( // User has no entities if (views.length === 1 && views[0].cards!.length === 0) { - import("../cards/hui-empty-state-card"); + import(/* webpackChunkName: "hui-empty-state-card" */ "../cards/hui-empty-state-card"); views[0].cards!.push({ type: "custom:hui-empty-state-card", }); From 652cd1048391b1734d6fee893698dbc5320e6801 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 30 Apr 2019 12:16:41 -0700 Subject: [PATCH 05/11] Use Node 12 (#3141) * Use Node 12 * Remove tests that don't work in Node --- .nvmrc | 2 +- test-mocha/common/datetime/format_date.ts | 6 ------ .../common/datetime/format_date_time.ts | 6 ------ test-mocha/common/datetime/format_time.ts | 6 ------ yarn.lock | 20 +++++++++---------- 5 files changed, 11 insertions(+), 29 deletions(-) diff --git a/.nvmrc b/.nvmrc index 2f76972966..40e6bd96a6 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -8.11.1 +12.1 diff --git a/test-mocha/common/datetime/format_date.ts b/test-mocha/common/datetime/format_date.ts index 9431d919ea..2ef3162799 100644 --- a/test-mocha/common/datetime/format_date.ts +++ b/test-mocha/common/datetime/format_date.ts @@ -8,10 +8,4 @@ describe("formatDate", () => { it("Formats English dates", () => { assert.strictEqual(formatDate(dateObj, "en"), "November 18, 2017"); }); - - // Node only contains intl support for english formats. This test at least ensures - // the fallback to a different locale - it("Formats other dates", () => { - assert.strictEqual(formatDate(dateObj, "fr"), "2017 M11 18"); - }); }); diff --git a/test-mocha/common/datetime/format_date_time.ts b/test-mocha/common/datetime/format_date_time.ts index 74a91d8c53..d909839b92 100644 --- a/test-mocha/common/datetime/format_date_time.ts +++ b/test-mocha/common/datetime/format_date_time.ts @@ -11,10 +11,4 @@ describe("formatDateTime", () => { "November 18, 2017, 11:12 AM" ); }); - - // Node only contains intl support for english formats. This test at least ensures - // the fallback to a different locale - it("Formats other date times", () => { - assert.strictEqual(formatDateTime(dateObj, "fr"), "2017 M11 18 11:12"); - }); }); diff --git a/test-mocha/common/datetime/format_time.ts b/test-mocha/common/datetime/format_time.ts index 84620e783a..4926e55663 100644 --- a/test-mocha/common/datetime/format_time.ts +++ b/test-mocha/common/datetime/format_time.ts @@ -8,10 +8,4 @@ describe("formatTime", () => { it("Formats English times", () => { assert.strictEqual(formatTime(dateObj, "en"), "11:12 AM"); }); - - // Node only contains intl support for english formats. This test at least ensures - // the fallback to a different locale - it("Formats other times", () => { - assert.strictEqual(formatTime(dateObj, "fr"), "11:12"); - }); }); diff --git a/yarn.lock b/yarn.lock index a0ae7e1bc2..c839a7208e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6451,12 +6451,12 @@ fs.realpath@^1.0.0: integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= fsevents@^1.0.0, fsevents@^1.2.7: - version "1.2.7" - resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-1.2.7.tgz#4851b664a3783e52003b3c66eb0eee1074933aa4" - integrity sha512-Pxm6sI2MeBD7RdD12RYsqaP0nMiwx8eZBXCa6z2L+mRHm2DYrOYwihmhjpkdjUHwQhslWQjRpEgNq4XvBmaAuw== + version "1.2.9" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-1.2.9.tgz#3f5ed66583ccd6f400b5a00db6f7e861363e388f" + integrity sha512-oeyj2H3EjjonWcFjD5NvZNE9Rqe4UW+nQBU2HNeKw0koVLEFIhtyETyAakeAM3de7Z/SW5kcA+fZUait9EApnw== dependencies: - nan "^2.9.2" - node-pre-gyp "^0.10.0" + nan "^2.12.1" + node-pre-gyp "^0.12.0" function-bind@^1.1.1: version "1.1.1" @@ -9560,7 +9560,7 @@ mz@^2.4.0, mz@^2.6.0: object-assign "^4.0.1" thenify-all "^1.0.0" -nan@^2.9.2: +nan@^2.12.1: version "2.13.2" resolved "https://registry.yarnpkg.com/nan/-/nan-2.13.2.tgz#f51dc7ae66ba7d5d55e1e6d4d8092e802c9aefe7" integrity sha512-TghvYc72wlMGMVMluVo9WRJc0mB8KxxF/gZ4YYFy7V2ZQX9l7rgbPg7vjS9mt6U5HXODVFVI2bOduCzwOMv/lw== @@ -9685,10 +9685,10 @@ node-forge@0.7.5: util "^0.11.0" vm-browserify "0.0.4" -node-pre-gyp@^0.10.0: - version "0.10.3" - resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.10.3.tgz#3070040716afdc778747b61b6887bf78880b80fc" - integrity sha512-d1xFs+C/IPS8Id0qPTZ4bUT8wWryfR/OzzAFxweG+uLN85oPzyo2Iw6bVlLQ/JOdgNonXLCoRyqDzDWq4iw72A== +node-pre-gyp@^0.12.0: + version "0.12.0" + resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.12.0.tgz#39ba4bb1439da030295f899e3b520b7785766149" + integrity sha512-4KghwV8vH5k+g2ylT+sLTjy5wmUOb9vPhnM8NHvRf9dHmnW/CndrFXy2aRPaPST6dugXSdHXfeaHQm77PIz/1A== dependencies: detect-libc "^1.0.2" mkdirp "^0.5.1" From 5b12ca94e9b730e7ca919e52824aecd069e06fe9 Mon Sep 17 00:00:00 2001 From: Robbie Trencheny Date: Wed, 1 May 2019 22:49:33 -0700 Subject: [PATCH 06/11] Add missing key for app configuration in sidebar (#3146) * Add missing key for app configuration in sidebar * avoid lokalise round trip --- src/translations/en.json | 1 + translations/en.json | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/translations/en.json b/src/translations/en.json index fe58a46fdc..43c310c22b 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -549,6 +549,7 @@ }, "sidebar": { "developer_tools": "Developer tools", + "external_app_configuration": "App Configuration", "log_out": "Log out" }, "panel": { diff --git a/translations/en.json b/translations/en.json index afd3e713df..301f59a25c 100644 --- a/translations/en.json +++ b/translations/en.json @@ -925,7 +925,8 @@ }, "sidebar": { "log_out": "Log out", - "developer_tools": "Developer tools" + "developer_tools": "Developer tools", + "external_app_configuration": "App Configuration" }, "common": { "loading": "Loading", @@ -1181,4 +1182,4 @@ "system-users": "Users", "system-read-only": "Read-Only Users" } -} \ No newline at end of file +} From 8a86dd8426b9563b0d1f9741d5b40cf59588b1d0 Mon Sep 17 00:00:00 2001 From: Joakim Plate Date: Thu, 2 May 2019 16:09:06 +0200 Subject: [PATCH 07/11] Simplify list selection (#3148) * water_heater: Use attr-for-selected for operation mode * climate: Use attr-for-selected for operation, fan, swing mode * fan: Use attr-for-selected for speed * fan: skip extra property * climate: drop extra property * water_heater: avoid extra property * media_player: drop extra variable for source and sound_mode * water_heater: missed change --- .../more-info/controls/more-info-climate.js | 112 ++++++------------ .../more-info/controls/more-info-fan.js | 30 ++--- .../controls/more-info-media_player.js | 62 ++++------ .../controls/more-info-water_heater.js | 36 ++---- 4 files changed, 78 insertions(+), 162 deletions(-) diff --git a/src/dialogs/more-info/controls/more-info-climate.js b/src/dialogs/more-info/controls/more-info-climate.js index d0c4d419af..3fb90fed61 100644 --- a/src/dialogs/more-info/controls/more-info-climate.js +++ b/src/dialogs/more-info/controls/more-info-climate.js @@ -200,14 +200,15 @@ class MoreInfoClimate extends LocalizeMixin(EventsMixin(PolymerElement)) { > @@ -224,13 +225,19 @@ class MoreInfoClimate extends LocalizeMixin(EventsMixin(PolymerElement)) { dynamic-align="" label="[[localize('ui.card.climate.fan_mode')]]" > - + @@ -244,13 +251,17 @@ class MoreInfoClimate extends LocalizeMixin(EventsMixin(PolymerElement)) { dynamic-align="" label="[[localize('ui.card.climate.swing_mode')]]" > - + @@ -297,23 +308,6 @@ class MoreInfoClimate extends LocalizeMixin(EventsMixin(PolymerElement)) { observer: "stateObjChanged", }, - operationIndex: { - type: Number, - value: -1, - observer: "handleOperationmodeChanged", - }, - - fanIndex: { - type: Number, - value: -1, - observer: "handleFanmodeChanged", - }, - - swingIndex: { - type: Number, - value: -1, - observer: "handleSwingmodeChanged", - }, awayToggleChecked: Boolean, auxToggleChecked: Boolean, onToggleChecked: Boolean, @@ -346,36 +340,6 @@ class MoreInfoClimate extends LocalizeMixin(EventsMixin(PolymerElement)) { } } - handleOperationListUpdate() { - // force polymer to recognize selected item change (to update actual label) - this.operationIndex = -1; - if (this.stateObj.attributes.operation_list) { - this.operationIndex = this.stateObj.attributes.operation_list.indexOf( - this.stateObj.attributes.operation_mode - ); - } - } - - handleSwingListUpdate() { - // force polymer to recognize selected item change (to update actual label) - this.swingIndex = -1; - if (this.stateObj.attributes.swing_list) { - this.swingIndex = this.stateObj.attributes.swing_list.indexOf( - this.stateObj.attributes.swing_mode - ); - } - } - - handleFanListUpdate() { - // force polymer to recognize selected item change (to update actual label) - this.fanIndex = -1; - if (this.stateObj.attributes.fan_list) { - this.fanIndex = this.stateObj.attributes.fan_list.indexOf( - this.stateObj.attributes.fan_mode - ); - } - } - computeTemperatureStepSize(hass, stateObj) { if (stateObj.attributes.target_temp_step) { return stateObj.attributes.target_temp_step; @@ -517,33 +481,27 @@ class MoreInfoClimate extends LocalizeMixin(EventsMixin(PolymerElement)) { this.callServiceHelper(newVal ? "turn_on" : "turn_off", {}); } - handleFanmodeChanged(fanIndex) { - // Selected Option will transition to '' before transitioning to new value - if (fanIndex === "" || fanIndex === -1) return; - const fanInput = this.stateObj.attributes.fan_list[fanIndex]; - if (fanInput === this.stateObj.attributes.fan_mode) return; - this.callServiceHelper("set_fan_mode", { fan_mode: fanInput }); + handleFanmodeChanged(ev) { + const oldVal = this.stateObj.attributes.fan_mode; + const newVal = ev.detail.value; + if (!newVal || oldVal === newVal) return; + this.callServiceHelper("set_fan_mode", { fan_mode: newVal }); } - handleOperationmodeChanged(operationIndex) { - // Selected Option will transition to '' before transitioning to new value - if (operationIndex === "" || operationIndex === -1) return; - const operationInput = this.stateObj.attributes.operation_list[ - operationIndex - ]; - if (operationInput === this.stateObj.attributes.operation_mode) return; - + handleOperationmodeChanged(ev) { + const oldVal = this.stateObj.attributes.operation_mode; + const newVal = ev.detail.value; + if (!newVal || oldVal === newVal) return; this.callServiceHelper("set_operation_mode", { - operation_mode: operationInput, + operation_mode: newVal, }); } - handleSwingmodeChanged(swingIndex) { - // Selected Option will transition to '' before transitioning to new value - if (swingIndex === "" || swingIndex === -1) return; - const swingInput = this.stateObj.attributes.swing_list[swingIndex]; - if (swingInput === this.stateObj.attributes.swing_mode) return; - this.callServiceHelper("set_swing_mode", { swing_mode: swingInput }); + handleSwingmodeChanged(ev) { + const oldVal = this.stateObj.attributes.swing_mode; + const newVal = ev.detail.value; + if (!newVal || oldVal === newVal) return; + this.callServiceHelper("set_swing_mode", { swing_mode: newVal }); } callServiceHelper(service, data) { diff --git a/src/dialogs/more-info/controls/more-info-fan.js b/src/dialogs/more-info/controls/more-info-fan.js index a57b702f9f..63837ea052 100644 --- a/src/dialogs/more-info/controls/more-info-fan.js +++ b/src/dialogs/more-info/controls/more-info-fan.js @@ -49,12 +49,17 @@ class MoreInfoFan extends LocalizeMixin(EventsMixin(PolymerElement)) { dynamic-align="" label="[[localize('ui.card.fan.speed')]]" > - + @@ -108,12 +113,6 @@ class MoreInfoFan extends LocalizeMixin(EventsMixin(PolymerElement)) { observer: "stateObjChanged", }, - speedIndex: { - type: Number, - value: -1, - observer: "speedChanged", - }, - oscillationToggleChecked: { type: Boolean, }, @@ -124,9 +123,6 @@ class MoreInfoFan extends LocalizeMixin(EventsMixin(PolymerElement)) { if (newVal) { this.setProperties({ oscillationToggleChecked: newVal.attributes.oscillating, - speedIndex: newVal.attributes.speed_list - ? newVal.attributes.speed_list.indexOf(newVal.attributes.speed) - : -1, }); } @@ -144,17 +140,15 @@ class MoreInfoFan extends LocalizeMixin(EventsMixin(PolymerElement)) { ); } - speedChanged(speedIndex) { - var speedInput; - // Selected Option will transition to '' before transitioning to new value - if (speedIndex === "" || speedIndex === -1) return; + speedChanged(ev) { + var oldVal = this.stateObj.attributes.speed; + var newVal = ev.detail.value; - speedInput = this.stateObj.attributes.speed_list[speedIndex]; - if (speedInput === this.stateObj.attributes.speed) return; + if (!newVal || oldVal === newVal) return; this.hass.callService("fan", "turn_on", { entity_id: this.stateObj.entity_id, - speed: speedInput, + speed: newVal, }); } diff --git a/src/dialogs/more-info/controls/more-info-media_player.js b/src/dialogs/more-info/controls/more-info-media_player.js index fd22c1a111..495cb33fbd 100644 --- a/src/dialogs/more-info/controls/more-info-media_player.js +++ b/src/dialogs/more-info/controls/more-info-media_player.js @@ -157,7 +157,8 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) {