diff --git a/package-lock.json b/package-lock.json index 042a041..0277240 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@berrywhite/lovelace-shutter-row", - "version": "0.3.3", + "version": "0.3.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@berrywhite/lovelace-shutter-row", - "version": "0.3.3", + "version": "0.3.4", "license": "MIT", "dependencies": { "@mdi/js": "^7.0.96", diff --git a/package.json b/package.json index 81abd15..1d9df98 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@berrywhite/lovelace-shutter-row", "private": true, - "version": "0.3.3", + "version": "0.3.4", "description": "Home Assistant Lovelace Shutter Row Card", "main": "shutter-row.js", "module": "shutter-row.js", diff --git a/shutter-row.js b/shutter-row.js index 0d79f67..28e1ae5 100644 --- a/shutter-row.js +++ b/shutter-row.js @@ -136,7 +136,7 @@ var mdiStop = "M18,18H6V6H18V18Z"; const HASSIO_CARD_ID = "shutter-row"; const HASSIO_CARD_EDITOR_ID = HASSIO_CARD_ID + "-editor"; const HASSIO_CARD_NAME = "Shutter Row"; -const VERSION = "0.3.3"; +const VERSION = "0.3.4"; // SVG PATHS const PATH_SHUTTER_100 = @@ -384,6 +384,18 @@ function moveElementInArray(arr, fromIndex, toIndex) { return arr; } +/** + * Localize entity state - HA 2023.4 < downgrade compatible + * @param {Hass} hass + * @param {string} state + * @returns + */ +function localizeState(hass, state) { + let newLocalize = hass.localize(`component.cover.entity_component._.state.${state}`); + if (newLocalize != "") return newLocalize; + return hass.localize(`component.cover.state._.${state}`); +} + function styleInject(css, ref) { if ( ref === void 0 ) ref = {}; var insertAt = ref.insertAt; @@ -935,12 +947,12 @@ class ShutterRow extends s { (this.config.invert_position_label && this.getPosition() == 100) || (!this.config.invert_position_label && this.getPosition() == 0) ) - return this.hass.localize("component.cover.state._.closed"); + return localizeState(this.hass, "closed"); if ( (this.config.invert_position_label && this.getPosition() == 0) || (!this.config.invert_position_label && this.getPosition() == 100) ) - return this.hass.localize("component.cover.state._.open"); + return localizeState(this.hass, "open"); return `${this.getPosition()} %`; } diff --git a/src/const.js b/src/const.js index 932e55f..7ee9e91 100644 --- a/src/const.js +++ b/src/const.js @@ -2,7 +2,7 @@ export const HASSIO_CARD_ID = "shutter-row"; export const HASSIO_CARD_EDITOR_ID = HASSIO_CARD_ID + "-editor"; export const HASSIO_CARD_NAME = "Shutter Row"; -export const VERSION = "0.3.3"; +export const VERSION = "0.3.4"; // SVG PATHS export const PATH_SHUTTER_100 = diff --git a/src/helpers.js b/src/helpers.js index f23f822..4d3c17f 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -56,3 +56,15 @@ export function moveElementInArray(arr, fromIndex, toIndex) { arr.splice(toIndex, 0, element); return arr; } + +/** + * Localize entity state - HA 2023.4 < downgrade compatible + * @param {Hass} hass + * @param {string} state + * @returns + */ +export function localizeState(hass, state) { + let newLocalize = hass.localize(`component.cover.entity_component._.state.${state}`); + if (newLocalize != "") return newLocalize; + return hass.localize(`component.cover.state._.${state}`); +} diff --git a/src/shutter-row.js b/src/shutter-row.js index a3bfa16..5b5a4d4 100644 --- a/src/shutter-row.js +++ b/src/shutter-row.js @@ -16,7 +16,7 @@ import { PATH_SHUTTER_DOWN, } from "./const.js"; import "./editor/editor.js"; -import { onHoldPointerDown, onPointerUp, getRippleElement } from "./helpers.js"; +import { onHoldPointerDown, onPointerUp, getRippleElement, localizeState } from "./helpers.js"; import style from "./style.css"; class ShutterRow extends LitElement { @@ -199,12 +199,12 @@ class ShutterRow extends LitElement { (this.config.invert_position_label && this.getPosition() == 100) || (!this.config.invert_position_label && this.getPosition() == 0) ) - return this.hass.localize("component.cover.state._.closed"); + return localizeState(this.hass, "closed"); if ( (this.config.invert_position_label && this.getPosition() == 0) || (!this.config.invert_position_label && this.getPosition() == 100) ) - return this.hass.localize("component.cover.state._.open"); + return localizeState(this.hass, "open"); return `${this.getPosition()} %`; }