Skip to content

Commit

Permalink
Merge pull request #161 from maxwroc/vNext
Browse files Browse the repository at this point in the history
Release 1.6.0
  • Loading branch information
maxwroc authored Nov 5, 2020
2 parents 3a8db1a + 043a90f commit cbe2f95
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ This card was inspired by [another great card](https://github.com/cbulock/lovela
| Name | Type | Default | Since | Description |
|:-----|:-----|:-----|:-----|:-----|
| entity | string | **(required)** | v0.9.0 | Entity ID
| name | string | | v0.9.0 | Entity name override
| name | string | | v0.9.0 | Entity name override
| icon | string | | v1.6.0 | Icon override (if you want to set a static custom one)
| attribute | string | | v0.9.0 | Name of attribute (override) to extract the value from. By default we look for values in the following attributes: `battery_level`, `battery`. If they are not present we take entity state.
| multiplier | number | `1` | v0.9.0 | If the value is not in 0-100 range we can adjust it by specifying multiplier. E.g. if the values are in 0-10 range you can make them working by putting `10` as multiplier.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "battery-state-card",
"version": "1.5.2",
"version": "1.6.0",
"description": "Battery State card for Home Assistant",
"main": "dist/battery-state-card.js",
"repository": {
Expand Down
9 changes: 6 additions & 3 deletions src/battery-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { getBatteryCollections } from "./grouping";
/**
* Properties which should be copied over to individual entities from the card
*/
const entititesGlobalProps = [ "tap_action", "state_map", "charging_state", "secondary_info", "color_thresholds", "color_gradient", "bulk_rename" ];
const entititesGlobalProps = [ "tap_action", "state_map", "charging_state", "secondary_info", "color_thresholds", "color_gradient", "bulk_rename", "icon" ];

const regExpPattern = /\/([^/]+)\/([igmsuy]*)/;

/**
* Functions to check if filter condition is met
Expand All @@ -29,9 +31,10 @@ const operatorHandlers: { [key in FilterOperator]: (val: string | number | undef
pattern = pattern.toString();

let exp: RegExp | undefined;
if (pattern[0] == "/" && pattern[pattern.length - 1] == "/") {
const regexpMatch = pattern.match(regExpPattern);
if (regexpMatch) {
// create regexp after removing slashes
exp = new RegExp(pattern.substr(1, pattern.length - 2));
exp = new RegExp(regexpMatch[1], regexpMatch[2]);
} else if (pattern.indexOf("*") != -1) {
exp = new RegExp("^" + pattern.replace(/\*/g, ".*") + "$");
}
Expand Down
4 changes: 4 additions & 0 deletions src/battery-vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ class BatteryViewModel {
*/
get icon(): string {

if (this.config.icon) {
return this.config.icon;
}

const level = Number(this._level);

if (this.charging && this.config.charging_state?.icon) {
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ export interface IBatteryEntity {
*/
name?: string;

/**
* Icon override
*/
icon?: string;

/**
* Attribute name to extract batterly level from
*/
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HomeAssistant } from "./ha-types";

console.info(
"%c BATTERY-STATE-CARD %c 1.5.2",
"%c BATTERY-STATE-CARD %c 1.6.0",
"color: white; background: forestgreen; font-weight: 700;",
"color: forestgreen; background: white; font-weight: 700;",
);
Expand Down

0 comments on commit cbe2f95

Please sign in to comment.