Skip to content

Commit

Permalink
feat(attribute): Retrieve an attribute instead of the state (kalkih#564)
Browse files Browse the repository at this point in the history
* feat(attribute): Retrieve an attribute instead of the state

* Fix lint

Fixes kalkih#411, Fixes kalkih#245, Fixes kalkih#501
  • Loading branch information
RomRider authored and jlsjonas committed Jan 22, 2022
1 parent e88962d commit 708bfde
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .devcontainer/ui-lovelace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ views:
- sensor.pressure
show:
extrema: true
- type: custom:mini-graph-card
entities:
- entity: weather.home
attribute: pressure
show:
extrema: true
- type: custom:mini-graph-card
hours_to_show: 1
points_per_hour: 60
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ properties of the Entity object detailed in the following table (as per `sensor.
| Name | Type | Default | Description |
|------|:----:|:-------:|-------------|
| entity ***(required)*** | string | | Entity id of the sensor.
| attribute | string | | Retrieves an attribute instead of the state
| name | string | | Set a custom display name, defaults to entity's friendly_name.
| color | string | | Set a custom color, overrides all other color options including thresholds.
| unit | string | | Set a custom unit of measurement, overrides `unit` set in base config.
Expand Down
139 changes: 137 additions & 2 deletions package-lock.json

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

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"@kalkih/lz-string": "^1.4.5",
"custom-card-helpers": "^1.6.6",
"lit-element": "^2.2.1",
"localforage": "^1.7.3"
"localforage": "^1.7.3",
"spark-md5": "^3.0.1"
},
"devDependencies": {
"@babel/cli": "^7.6.4",
Expand All @@ -33,6 +34,7 @@
"@babel/plugin-transform-spread": "^7.2.2",
"@babel/plugin-transform-template-literals": "^7.2.0",
"@babel/preset-env": "^7.3.1",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-json": "^4.1.0",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/commit-analyzer": "^8.0.1",
Expand All @@ -41,6 +43,7 @@
"@semantic-release/github": "^7.2.0",
"@semantic-release/npm": "^7.0.9",
"@semantic-release/release-notes-generator": "^9.0.1",
"@types/spark-md5": "^3.0.2",
"babel-plugin-iife-wrap": "^1.1.0",
"babel-preset-minify": "^0.5.0",
"eslint": "^5.3.0",
Expand Down
2 changes: 2 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import resolve from 'rollup-plugin-node-resolve';
import json from '@rollup/plugin-json';
import serve from 'rollup-plugin-serve';
import commonjs from '@rollup/plugin-commonjs';

const dev = process.env.ROLLUP_WATCH;
const serveopts = {
Expand All @@ -22,6 +23,7 @@ export default {
sourcemap: dev ? true : false,
},
plugins: [
commonjs(),
json({
include: 'package.json',
preferConst: true,
Expand Down
2 changes: 1 addition & 1 deletion src/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ localForage.iterate((data, key) => {
const value = key.endsWith('-raw') ? data : decompress(data);
const start = new Date();
start.setHours(start.getHours() - value.hours_to_show);
if (new Date(value.last_fetched) < start) {
if (data.version !== version || new Date(value.last_fetched) < start) {
localForage.removeItem(key);
}