",
"license": "MIT",
"dependencies": {
+ "jinja-js": "^0.1.8",
"lit-element": "^2.2.1",
"lit-html": "^1.1.2",
"resize-observer-polyfill": "^1.5.1"
@@ -29,11 +30,12 @@
"@babel/plugin-transform-template-literals": "^7.2.0",
"@babel/preset-env": "^7.3.1",
"babel-plugin-iife-wrap": "^1.1.0",
- "babel-preset-minify": "^0.5.0",
+ "babel-preset-minify": "^0.5.1",
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "2.16.0",
- "rollup": "^0.66.6",
+ "rollup": "^2.10.5",
+ "rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^3.4.0"
},
"scripts": {
diff --git a/release_notes/v1.0.7.md b/release_notes/v1.0.7.md
index a51bfcc..711244f 100644
--- a/release_notes/v1.0.7.md
+++ b/release_notes/v1.0.7.md
@@ -1,5 +1,5 @@
## v1.0.7
-[![Downloads](https://img.shields.io/github/downloads/artem-sedykh/mini-humidifier/v1.0.4/total.svg)](https://github.com/artem-sedykh/mini-humidifier/releases/tag/v1.0.4)
+[![Downloads](https://img.shields.io/github/downloads/artem-sedykh/mini-humidifier/v1.0.7/total.svg)](https://github.com/artem-sedykh/mini-humidifier/releases/tag/v1.0.7)
### ADDED
- Added rounding configuration for temperature and humidity
- Added `strong` option(hidden by default) for fan_mode_button source, for zhimi.humidifier.v1
diff --git a/release_notes/v1.0.8.md b/release_notes/v1.0.8.md
new file mode 100644
index 0000000..ae1542c
--- /dev/null
+++ b/release_notes/v1.0.8.md
@@ -0,0 +1,27 @@
+## v1.0.8
+[![Downloads](https://img.shields.io/github/downloads/artem-sedykh/mini-humidifier/v1.0.8/total.svg)](https://github.com/artem-sedykh/mini-humidifier/releases/tag/v1.0.8)
+### ADDED
+- Added `humidity: icon_template` icon template for humidity indicator, a simple template engine is used [jinja-js](https://github.com/sstur/jinja-js)
+- Added `target_humidity: icon_template` icon template for target_humidity indicator, a simple template engine is used [jinja-js](https://github.com/sstur/jinja-js)
+- Added `temperature: icon_template` icon template for temperature indicator, a simple template engine is used [jinja-js](https://github.com/sstur/jinja-js)
+- Added `depth: icon_template` icon template for temperature indicator, a simple template engine is used [jinja-js](https://github.com/sstur/jinja-js)
+
+#####Example
+```yaml
+- type: custom:mini-humidifier
+ entity: fan.xiaomi_miio_device
+ depth:
+ icon_template: >
+ {% if depth < 10 %}
+
+ {% elseif depth < 45 %}
+
+ {% else %}
+
+ {% endif %}
+```
+
+### CHANGED
+- styles
+- `humidity:icon` changed default icon from `mdi:water-outline` to `mdi:water`
+- `depth:icon` changed default icon from `mdi:beaker-outline` to `mdi:tray-full`
diff --git a/rollup.config.js b/rollup.config.js
index 8d2f740..2bbcfd8 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -1,4 +1,5 @@
import resolve from 'rollup-plugin-node-resolve';
+import commonjs from 'rollup-plugin-commonjs';
export default {
input: 'src/main.js',
@@ -9,5 +10,6 @@ export default {
},
plugins: [
resolve(),
+ commonjs(),
],
};
diff --git a/src/components/info.js b/src/components/info.js
index dcfc905..94b456c 100644
--- a/src/components/info.js
+++ b/src/components/info.js
@@ -1,4 +1,5 @@
import { LitElement, html, css } from 'lit-element';
+import { unsafeHTML } from 'lit-html/directives/unsafe-html';
class MiniHumidifierInfo extends LitElement {
static get properties() {
@@ -10,9 +11,13 @@ class MiniHumidifierInfo extends LitElement {
}
renderDepth(context) {
+ const icon = context.config.depth.icon_template
+ ? unsafeHTML(context.humidifier.depthIcon)
+ : html``;
+
return html`
-
+ ${icon}
${context.humidifier.depth}
${context.config.depth.unit}
@@ -20,9 +25,13 @@ class MiniHumidifierInfo extends LitElement {
}
renderTemperature(context) {
+ const icon = context.config.temperature.icon_template
+ ? unsafeHTML(context.humidifier.temperatureIcon)
+ : html``;
+
return html`
-
+ ${icon}
${context.humidifier.temperature}
${context.config.temperature.unit}
@@ -30,9 +39,12 @@ class MiniHumidifierInfo extends LitElement {
}
renderHumidity(context) {
+ const icon = context.config.humidity.icon_template
+ ? unsafeHTML(context.humidifier.humidityIcon)
+ : html``;
return html`
-
+ ${icon}
${context.humidifier.humidity}
${context.config.humidity.unit}
@@ -66,8 +78,8 @@ class MiniHumidifierInfo extends LitElement {
box-sizing: border-box;
min-width: 0;
overflow: hidden;
- font-size: calc(var(--mh-unit) * .325);
- line-height: calc(var(--mh-unit) / 2);
+ font-size: calc(var(--mh-unit) * .35);
+ line-height: calc(var(--mh-unit) * .35);
}
.mh-humidifier-state__container {
display: flex;
@@ -80,13 +92,14 @@ class MiniHumidifierInfo extends LitElement {
}
.state__value_icon {
height: calc(var(--mh-unit) * .475);
- width: calc(var(--mh-unit) * .425);
+ width: calc(var(--mh-unit) * .5);
color: var(--mh-icon-color);
--mdc-icon-size: calc(var(--mh-unit) * .425);
}
.state__value {
margin: 0 1px;
font-weight: var(--mh-info-font-weight);
+ line-height: calc(var(--mh-unit) * .475);
}
.state__uom {
font-size: calc(var(--mh-unit) * .275);
diff --git a/src/components/targetHumiditySlider.js b/src/components/targetHumiditySlider.js
index 04a1ed2..34bc885 100644
--- a/src/components/targetHumiditySlider.js
+++ b/src/components/targetHumiditySlider.js
@@ -1,4 +1,5 @@
import { LitElement, html, css } from 'lit-element';
+import { unsafeHTML } from 'lit-html/directives/unsafe-html';
class MiniHumidifierTargetHumiditySlider extends LitElement {
static get properties() {
@@ -19,9 +20,13 @@ class MiniHumidifierTargetHumiditySlider extends LitElement {
if (this.config.target_humidity.hide)
return html``;
+ const icon = this.config.humidity.icon_template
+ ? unsafeHTML(this.humidifier.targetHumidityIcon)
+ : html``;
+
return html`
-
+ ${icon}
${sliderValue}
${this.config.target_humidity.unit}
@@ -75,13 +80,14 @@ class MiniHumidifierTargetHumiditySlider extends LitElement {
}
.state__value_icon {
height: calc(var(--mh-unit) * .475);
- width: calc(var(--mh-unit) * .425);
- --mdc-icon-size: calc(var(--mh-unit) * .425);
+ width: calc(var(--mh-unit) * .5);
color: var(--mh-icon-color);
+ --mdc-icon-size: calc(var(--mh-unit) * .425);
}
.state__value {
- font-size: calc(var(--mh-unit) * .325);
- line-height: calc(var(--mh-unit) / 2);
+ font-size: calc(var(--mh-unit) * .35);
+ line-height: calc(var(--mh-unit) * .475);
+ margin: 0px 1px;
}
.state__uom {
font-size: calc(var(--mh-unit) * .275);
diff --git a/src/const.js b/src/const.js
index 763c579..d844c06 100644
--- a/src/const.js
+++ b/src/const.js
@@ -2,9 +2,9 @@
const ICON = {
DEFAULT: 'mdi:air-filter',
FAN: 'mdi:fan',
- HUMIDITY: 'mdi:water-outline',
+ HUMIDITY: 'mdi:water',
TEMPERATURE: 'mdi:thermometer-low',
- DEPTH: 'mdi:beaker-outline',
+ DEPTH: 'mdi:tray-full',
DRY: 'mdi:weather-sunny',
BUZZER: 'mdi:bell-outline',
LEDBUTTON: 'mdi:lightbulb-on-outline',
diff --git a/src/main.js b/src/main.js
index 3c63921..f7cd2c1 100644
--- a/src/main.js
+++ b/src/main.js
@@ -5,6 +5,7 @@ import HumidifierObject from './model';
import style from './style';
import sharedStyle from './sharedStyle';
import handleClick from './utils/handleClick';
+import trimTo from './utils/trimTo';
import './components/dropdown';
import './components/powerstrip';
@@ -235,6 +236,7 @@ class MiniHumidifier extends LitElement {
this.config.depth = {
icon: ICON.DEPTH,
+ icon_template: '',
max_value: 125,
unit_type: 'percent',
fixed: 0,
@@ -414,7 +416,8 @@ class MiniHumidifier extends LitElement {
get secondaryInfoLabel() {
const item = this.humidifier.fanSpeed;
- return item ? item.name : '';
+
+ return trimTo(item ? item.name : '', 9);
}
computeIcon() {
diff --git a/src/model.js b/src/model.js
index a29c752..0f97080 100644
--- a/src/model.js
+++ b/src/model.js
@@ -1,3 +1,4 @@
+import jinja from 'jinja-js';
export default class HumidifierObject {
constructor(hass, config, entity) {
@@ -38,6 +39,14 @@ export default class HumidifierObject {
return this.round(value, this.config.depth.fixed);
}
+ get depthIcon() {
+ if (!this.config.depth.icon_template)
+ return '';
+
+ const context = { depth: this.depth, raw: this.attr.depth || 0 };
+ return jinja.render(this.config.depth.icon_template, context);
+ }
+
get targetHumidity() {
const humidity = this.attr.target_humidity || 0;
return {
@@ -48,6 +57,14 @@ export default class HumidifierObject {
};
}
+ get targetHumidityIcon() {
+ if (!this.config.target_humidity.icon_template)
+ return '';
+
+ const context = { targetHumidity: this.targetHumidity.value };
+ return jinja.render(this.config.target_humidity.icon_template, context);
+ }
+
get fanSpeed() {
if (this.attr.mode)
return this.fanSpeedSource.find(s => s.value.toUpperCase() === this.attr.mode.toUpperCase());
@@ -116,11 +133,27 @@ export default class HumidifierObject {
return this.round(value, this.config.temperature.fixed);
}
+ get temperatureIcon() {
+ if (!this.config.temperature.icon_template)
+ return '';
+
+ const context = { temperature: this.temperature };
+ return jinja.render(this.config.temperature.icon_template, context);
+ }
+
get humidity() {
const value = this.getValue(this.config.humidity.source, this.attr.humidity);
return this.round(value, this.config.humidity.fixed);
}
+ get humidityIcon() {
+ if (!this.config.humidity.icon_template)
+ return '';
+
+ const context = { humidity: this.humidity };
+ return jinja.render(this.config.humidity.icon_template, context);
+ }
+
getValue(config, defaultValue) {
if (!config)
return defaultValue;
diff --git a/src/style.js b/src/style.js
index 02bd15f..db37eb3 100644
--- a/src/style.js
+++ b/src/style.js
@@ -117,17 +117,18 @@ const style = css`
}
.entity__secondary_info_icon {
color: var(--mh-icon-color);
- width: calc(var(--mh-unit) * .375);
- height: calc(var(--mh-unit) * .375);
- min-width: calc(var(--mh-unit) * .375);
+ height: calc(var(--mh-unit) * .475);
+ width: calc(var(--mh-unit) * .5);
+ min-width: calc(var(--mh-unit) * .5);
--mdc-icon-size: calc(var(--mh-unit) * .375);
}
.entity__secondary_info {
margin-top: -2px;
}
.entity__secondary_info__name {
- font-size: calc(var(--mh-unit) * 0.325);
+ font-size: calc(var(--mh-unit) * .35);
font-weight: var(--mh-info-font-weight);
+ line-height: calc(var(--mh-unit) * .525);
}
mh-powerstrip {
flex: 1;
@@ -151,6 +152,7 @@ const style = css`
}
.mh-humidifier__bottom {
margin: 0;
+ margin-top: calc(var(--mh-unit) * .075);
margin-left: calc(calc(calc(var(--mh-unit) / 5) + var(--mh-unit)) + var(--mh-entity-info-left-offset));
justify-content: space-between;
}
diff --git a/src/utils/trimTo.js b/src/utils/trimTo.js
new file mode 100644
index 0000000..c90281d
--- /dev/null
+++ b/src/utils/trimTo.js
@@ -0,0 +1,13 @@
+const trimTo = (value, size) => {
+ if (!value)
+ return value;
+
+ const str = value.toString();
+
+ if (str && str.length > size)
+ return str.substr(0, str.length - 3).concat('...');
+
+ return str;
+};
+
+export default trimTo;