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

feat: add value_multiplier and extend value_factor #608

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

OmgImAlexis
Copy link
Collaborator

@OmgImAlexis OmgImAlexis commented May 24, 2021

This adds value_multiplier which similarly to the value_factor only it multiplies the value directly. By default it's set to 1.

I've also added the value_factor to the entity itself to allow different factors for each entity. Personally I like this as it allows cards to show more than a single type of data. For example I want to show data usage and power usage on one, the issue is one is in bytes(I want MB) and one is watts(I want KW). I need one to be divided by 1024 and the other 1000.

I haven't tested this yet so please let me know if there's anything I need to fix.

Closes #607 and #591

@PulsarFX
Copy link

Is there anything missing to complete this PR?
I'd like to compare sun elevation with solar power and I need to scale the evelation up to make it visible :)

@OmgImAlexis
Copy link
Collaborator Author

@maulwuff I don't think so.

@kalkih
Copy link
Owner

kalkih commented Sep 24, 2021

Is there anything missing to complete this PR?
I'd like to compare sun elevation with solar power and I need to scale the evelation up to make it visible :)

The review comments need to be addressed before we can merge this.

@OmgImAlexis
Copy link
Collaborator Author

The review comments need to be addressed before we can merge this.

There are no review comments..?

@@ -5,7 +5,19 @@ import {
} from './const';

export default class Graph {
constructor(width, height, margin, hours = 24, points = 1, aggregateFuncName = 'avg', groupBy = 'interval', smoothing = true, logarithmic = false) {
Copy link
Owner

Choose a reason for hiding this comment

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

We should not need to pass valueFactor & valueMultiplier here, they aren't used in the class.


const x = 10 ** dec;
return (Math.round(state * value_factor * x) / x).toFixed(dec);
return (Math.round(state * value_factor * x) / x).toFixed(dec) * value_multipler;
Copy link
Owner

Choose a reason for hiding this comment

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

The decimals option will not play nicely together with this change as we first round the value and then multiply with the multiplier value. Should apply the multiplier first and then do the rounding.

@@ -666,12 +667,14 @@ class MiniGraphCard extends LitElement {
}
const dec = this.config.decimals;
const value_factor = 10 ** this.config.value_factor;
const value_multipler = this.config.value_multipler || 1;
Copy link
Owner

Choose a reason for hiding this comment

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

If we want to add this as an option on the entity config level we need to check the entity specific config here as well.

@PulsarFX
Copy link

PulsarFX commented Oct 8, 2021

@OmgImAlexis come on, you can fix that ;-)

@kalkih
Copy link
Owner

kalkih commented Oct 8, 2021

Please also add documentation for the option in the readme 👍🏼

@smiba
Copy link

smiba commented Nov 15, 2021

Would love to see this in mini-graph-card, currently this prohibits me from making a total power draw card. My total consumption is reported in kW, while individual devices report in W.

@kalkih
Copy link
Owner

kalkih commented Nov 15, 2021

Would love to see this in mini-graph-card, currently this prohibits me from making a total power draw card. My total consumption is reported in kW, while individual devices report in W.

In the meantime you could look at creating a template_sensor and handle the conversion there.

@jlsjonas
Copy link
Collaborator

jlsjonas commented Jan 2, 2022

@OmgImAlexis Do you need some help addressing these (minor) comments & getting this merged?

@ildar170975
Copy link
Collaborator

ildar170975 commented Feb 11, 2022

Please check this: #591 (comment)
As far as I understood, this PR introduces a new value_multiplier property in addition to the already present (but not per-entity) value_factor property.
IMHO there should be ONE per-entity multiplying property.

@andrewjswan
Copy link

Great idea, then I can invert the graph to get this result:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

value_factor should be per-entity
7 participants