Skip to content

Commit

Permalink
Merge pull request #54 from gurbyz/dev
Browse files Browse the repository at this point in the history
Release 0.1.2
  • Loading branch information
gurbyz authored Jul 10, 2020
2 parents cc4eafd + cbeb346 commit a7492e5
Show file tree
Hide file tree
Showing 13 changed files with 483 additions and 16 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
Changelog
====
## 0.1.2
### New features
* Allowing to hide the title. Default value for `title` is empty now. If you want the previous behavior you could add `title: 'Power wheel'` to your config. Issue #51.
* ** BETA.** You can switch the polarity of `battery_power_entity` with the new card parameter `charging_is_positive`. No need to make an extra template sensor for this anymore. Issue #46.
### Improvements
* Removed deprecated input parameter `energy_price`. This parameter was deprecated since version 0.1.0.
### Fixes
* After a startup of HA sensor validation errors stayed visible since the new startup order of HA 0.111.0. Sensor validation is disabled temporarily.

## 0.1.1
### New features
* Custom color for active arrows. New card parameter `active_arrow_color`.
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ views:
- id: example_view
cards:
- type: custom:power-wheel-card
title: "Power wheel"
solar_power_entity: sensor.YOUR_SOLAR_POWER_SENSOR
grid_power_consumption_entity: sensor.YOUR_GRID_POWER_CONSUMPTION_SENSOR
grid_power_production_entity: sensor.YOUR_GRID_POWER_PRODUCTION_SENSOR
Expand All @@ -250,21 +251,21 @@ There are many more card parameters available, but it's advised to start with th
| Parameter | Type | Mandatory? | Default | Description |
|-----------|------|------------|---------|-------------|
|type|string|**required**| |Type of the card. Use `"custom:power-wheel-card"`.|
|title|string|optional|`"Power wheel"`|Title of the card in all views, if not overridden with a title per view.|
|title|string|optional|No title|Title of the card in all views, if not overridden with a title per view.|
|title_power|string|optional|Value of `title`.|Title of the card in *power view*.|
|title_energy|string|optional|Value of `title`.|Title of the card in *energy view*.|
|title_money|string|optional|Value of `title`.|Title of the card in *money view*.|
|solar_power_entity|string|**required**| |Entity id of your solar power sensor. E.g. `sensor.YOUR_SOLAR_POWER_SENSOR`. See requirements above.|
|grid_power_consumption_entity (A)|string|optional, always together with B| |Entity id of your sensor for power that you are consuming from the grid. E.g. `sensor.YOUR_GRID_POWER_CONSUMPTION_SENSOR`. See requirements above.|
|grid_power_production_entity (B)|string|optional, always together with A| |Entity id of your sensor for power that you are producing to the grid. E.g. `sensor.YOUR_GRID_POWER_PRODUCTION_SENSOR`. See requirements above.|
|BETA: battery_power_entity|string|optional| |Entity id of your sensor for power you use to charge the battery. Charging should have positive values. Discharging should have negative values. Battery feature is in BETA, [expect issues](#Known-issues-for-the-battery-feature).|
|BETA: battery_soc_entity|string|optional| |Entity id of your sensor for *state of charge* of your battery. Unit should be %. Battery feature is in BETA, [expect issues](#Known-issues-for-the-battery-feature).|
|BETA: charging_is_positive|boolean|optional|`true`|You can specify the polarity of your input sensor `battery_power_entity`. Use `true` for charging the battery has positive values in your input sensor. Use `false` for charging the battery has negative values.|
|BETA: battery_soc_entity|string|optional| |Entity id of your sensor for *state of charge* of your battery. Unit should be %.|
|solar_energy_entity|string|optional|Default the *energy view* will not be enabled.|Entity id of your solar energy sensor. E.g. `sensor.YOUR_SOLAR_ENERGY_SENSOR`. See requirements above.|
|grid_energy_consumption_entity (D)|string|optional, always together with E|Default the *energy view* will not be enabled.|Entity id of your sensor for energy that's consumed from the grid. E.g. `sensor.YOUR_GRID_ENERGY_CONSUMPTION_SENSOR`. See requirements above.|
|grid_energy_production_entity (E)|string|optional, always together with D|Default the *energy view* will not be enabled.|Entity id of your sensor for energy that's produced to the grid. E.g. `sensor.YOUR_GRID_ENERGY_PRODUCTION_SENSOR`. See requirements above.|
|energy_consumption_rate|float|optional|Default the *money view* will not be enabled.|The rate of your energy consumed from the grid per unit of energy. E.g. `0.20`.|
|energy_production_rate|float|optional|The value of `energy_consumption_rate`.|The rate of your energy produced to the grid per unit of energy. E.g. `0.15`.|
|energy_price *(deprecated)*|float|optional| |Deprecated. Please use `energy_consumption_rate` and evt. the optional `energy_production_rate` as of version 0.0.13.|
|money_unit|string|optional|`"€"`|The unit of `energy_consumption_rate` and `energy_production_rate`. This unit will be used for displaying all money values.|
|solar_icon|string|optional|The icon of your own customized solar sensor(s). If not available, then `"mdi:weather-sunny"` will be used.|Icon for solar power and energy.|
|grid_icon|string|optional|The icon of your own customized grid sensor(s) if its entity parameter is set. If not available, then `"mdi:transmission-tower"` will be used.|Icon for grid power and energy.|
Expand Down Expand Up @@ -329,7 +330,9 @@ A more advanced example for in the `ui-lovelace.yaml` file:
solar_power_entity: sensor.YOUR_SOLAR_POWER_SENSOR
grid_power_consumption_entity: sensor.YOUR_GRID_POWER_CONSUMPTION_SENSOR
grid_power_production_entity: sensor.YOUR_GRID_POWER_PRODUCTION_SENSOR
production_is_positive: true
battery_power_entity: sensor.YOUR_BATTERY_POWER_SENSOR # Battery feature is in BETA, expect issues.
charging_is_positive: true # Battery feature is in BETA, expect issues.
battery_soc_entity: sensor.YOUR_BATTERY_SOC_SENSOR # Battery feature is in BETA, expect issues.
solar_energy_entity: sensor.YOUR_SOLAR_ENERGY_SENSOR
grid_energy_consumption_entity: sensor.YOUR_GRID_ENERGY_CONSUMPTION_SENSOR
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": "power-wheel-card",
"version": "0.1.1",
"version": "0.1.2",
"description": "An intuitive way to represent the power and energy that your home is consuming or producing.",
"directories": {
"test": "test"
Expand Down
23 changes: 12 additions & 11 deletions power-wheel-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
*/

const __VERSION = "0.1.1";
const __VERSION = "0.1.2";

const LitElement = Object.getPrototypeOf(customElements.get("hui-view"));
const html = LitElement.prototype.html;
Expand Down Expand Up @@ -42,6 +42,7 @@ class PowerWheelCard extends LitElement {
padding: 4px 0 12px;
display: flex;
justify-content: space-between;
min-height: 12px;
}
ha-card .wheel {
position: relative;
Expand Down Expand Up @@ -180,11 +181,16 @@ class PowerWheelCard extends LitElement {
? undefined : value * this.config.production_is_positive;
}

_setBatteryPolarity(value) {
return typeof value === 'undefined'
? undefined : value * this.config.charging_is_positive;
}

// Get all entity states (view dependent) and save in this.input
// Since battery functions this.input.grid_solo_production is not always the same as this.data.solar2grid anymore.
_saveEntityStates(solar_entity, grid_production_entity, grid_consumption_entity, battery_entity, grid_entity, home_entity) {
this.input.solar_production = this._getEntityState(solar_entity);
this.input.battery_charging = this._getEntityState(battery_entity);
this.input.battery_charging = this._setBatteryPolarity(this._getEntityState(battery_entity));
this.input.home_production = this._setPolarity(this._getEntityState(home_entity));
if (this.views[this.view].twoGridSensors) {
this.input.grid_solo_production = this._getEntityState(grid_production_entity);
Expand Down Expand Up @@ -384,10 +390,7 @@ class PowerWheelCard extends LitElement {
} else {
PowerWheelCard._logConsole(`Version: ${__VERSION}`);
}
this._validateSensors();
if (this.config.energy_price) {
this._addMessage('warn', 'Deprecated card parameter \'energy_price\' is used. Please replace it by \'energy_consumption_rate\' in your setup.');
}
// this._validateSensors(); // todo: Have to find a better trigger than firstUpdated. Disabled in version 0.1.2 because new startup order in HA 0.111.0.
}

_sensorChangeDetected(oldValue) {
Expand Down Expand Up @@ -416,7 +419,6 @@ class PowerWheelCard extends LitElement {
this.views.energy.unit = this._defineUnit('energy', this.config.solar_energy_entity, this.config.grid_energy_entity,
this.config.grid_energy_consumption_entity, this.config.grid_energy_production_entity);
this.views.money.unit = this.config.money_unit;
// this.views = { ...this.views };

if (this.view === 'money' && this.views.money.capable) {
// Calculate energy values first
Expand Down Expand Up @@ -639,9 +641,11 @@ class PowerWheelCard extends LitElement {
if (config.grid_power_consumption_entity && !config.grid_power_production_entity) {
throw new Error('You need to define a grid_power_production_entity');
}
config.charging_is_positive = config.charging_is_positive !== false;
config.charging_is_positive = config.charging_is_positive ? 1 : -1;
config.production_is_positive = config.production_is_positive !== false;
config.production_is_positive = config.production_is_positive ? 1 : -1;
config.title = config.title ? config.title : 'Power wheel';
config.title = config.title ? config.title : '';
config.title_power = config.title_power ? config.title_power : config.title;
config.title_energy = config.title_energy ? config.title_energy : config.title;
config.title_money = config.title_money ? config.title_money : config.title;
Expand Down Expand Up @@ -679,9 +683,6 @@ class PowerWheelCard extends LitElement {
}
config.auto_toggle_view_period = config.auto_toggle_view_period ? config.auto_toggle_view_period : 10;
config.debug = config.debug ? config.debug : false;
if (config.energy_price && config.energy_consumption_rate === undefined) {
config.energy_consumption_rate = config.energy_price;
}
if (config.energy_production_rate === undefined && config.energy_consumption_rate) {
config.energy_production_rate = config.energy_consumption_rate;
}
Expand Down
2 changes: 2 additions & 0 deletions test/basic_config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('<power-wheel-card> with most basic config', () => {
beforeEach(async () => {
config = {
type: "custom:power-wheel-card",
title: "Power wheel",
solar_power_entity: "sensor.solar_power",
grid_power_consumption_entity: "sensor.grid_power_consumption",
grid_power_production_entity: "sensor.grid_power_production",
Expand Down Expand Up @@ -67,6 +68,7 @@ describe('<power-wheel-card> with most basic config', () => {
it('has set default config values', () => {
assert.isFalse(card.config.color_icons, 'Card parameter color_icons should be set');
assert.equal(card.config.production_is_positive, 1, 'Card parameter production_is_positive should be default 1');
assert.equal(card.config.charging_is_positive, 1, 'Card parameter charging_is_positive should be default 1');
assert.isFalse(card.config.debug, 'Card parameter debug should be default false');
assert.equal(card.config.title, 'Power wheel', 'Card parameter title should have default value');
assert.equal(card.config.title_power, 'Power wheel', 'Card parameter title_power should have default value');
Expand Down
2 changes: 1 addition & 1 deletion test/basic_one_grid_sensor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('<power-wheel-card> with most basic config for one grid sensor', () =>
});

it('displays values', () => {
assert.equal(card.shadowRoot.querySelector('#title').innerText, "Power wheel");
assert.equal(card.shadowRoot.querySelector('#title').innerText, "");
assert.equal(card.shadowRoot.querySelector('#unit').innerText, "W");
});

Expand Down
1 change: 1 addition & 0 deletions test/basic_one_grid_sensor_switched_polarity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('<power-wheel-card> with most basic config for one grid sensor with swi
beforeEach(async () => {
config = {
type: "custom:power-wheel-card",
title: "Power wheel",
solar_power_entity: "sensor.solar_power",
grid_power_entity: "sensor.grid_power",
production_is_positive: false,
Expand Down
Loading

0 comments on commit a7492e5

Please sign in to comment.