Skip to content

Commit

Permalink
Designate 0.3.4
Browse files Browse the repository at this point in the history
Fixed state localization for 2023.4
  • Loading branch information
berrywhite96 committed Apr 22, 2023
1 parent 4e5e723 commit bd6c702
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
18 changes: 15 additions & 3 deletions shutter-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()} %`;
}

Expand Down
2 changes: 1 addition & 1 deletion src/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
12 changes: 12 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
6 changes: 3 additions & 3 deletions src/shutter-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()} %`;
}

Expand Down

0 comments on commit bd6c702

Please sign in to comment.