Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement more group_by options #833

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,37 @@ state_map:
label: Detected
```

#### Showing additional info on the card

![изображение](https://user-images.githubusercontent.com/71872483/170584118-ef826b60-dce3-42ec-a005-0f467616cd37.png)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I added the other comment on the code. Here are three more:

  • There seems to have sneaked in some non-English characters. Possibly from uploading the image?
  • Should the image be part of the commit?
  • Should the new grouping options be documented? If so, I'd suggest to also going on the caveat that month and year will not be 100% accurate, because they use fixed intervals.


It is possible to show a state without displaying a graph for a sensor.
Imagine there are two CO-2 sensors & one humidity sensor; graphs are displayed for the CO-2 only, and the humidity is shown as a state only.
```
type: custom:mini-graph-card
entities:
- entity: sensor.xiaomi_cg_1_humidity
show_state: true
show_graph: false
- entity: sensor.xiaomi_cg_1_co2
color: green
show_state: false
name: CO2-1
- entity: sensor.xiaomi_cg_2_co2
color: orange
show_state: false
name: CO2-2
name: Humidity
hours_to_show: 4
points_per_hour: 60
show:
name: true
legend: true
icon: false
labels: true
```
This method may be also used to add a calculated value with it's own `aggregate_func` option.


## Development

Expand Down
9 changes: 9 additions & 0 deletions src/buildConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ export default (config) => {

// override points per hour to mach group_by function
switch (conf.group_by) {
case 'year':
conf.points_per_hour = 1 / (24 * 365);
break;
case 'month':
conf.points_per_hour = 1 / (24 * 365 / 12);
break;
case 'week':
conf.points_per_hour = 1 / (24 * 7);
break;
case 'date':
conf.points_per_hour = 1 / 24;
break;
Expand Down
13 changes: 13 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,19 @@ class MiniGraphCard extends LitElement {
getEndDate() {
const date = new Date();
switch (this.config.group_by) {
case 'year':
date.setDate(1); // First day
date.setMonth(0); // of January
date.setHours(0, 0, 0); // 00:00:00
break;
case 'month':
date.setDate(1); // First day of current month
date.setHours(0, 0, 0);
break;
case 'week':
date.setDate(date.getDate() - date.getDay() + 1); // First day of the week
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just flipped through the PRs here and noticed: should this not be the first day of next week at 0h00? See the date case below... The same applies to month and year.

date.setHours(0, 0, 0);
break;
case 'date':
date.setDate(date.getDate() + 1);
date.setHours(0, 0, 0);
Expand Down