genielabs / HomeGenie

HomeGenie, the programmable automation intelligence
https://homegenie.it
GNU General Public License v3.0
388 stars 154 forks source link

Update homegenie.webapp.utility.js for displaying Temp with no decimal placed on Dashboard #398

Closed soxfan1966 closed 1 year ago

soxfan1966 commented 4 years ago

The temperature that is displayed in the Groups drop down (i.e. Dashboard) and in the upper right corner of the Dashboard if it contains the Weather Widget with a decimal place and one significant digit.

I made some changes to the Weather Widget to round the temperature up on that (along with the Fahrenheit display changes in another pull request) and I was able to find that making these changes as noted will round the temp display on the main Dashboard and Group drop down. Not sure if this would be better as an option or just allow the no decimal place code to be the default but wanted to share what I found.

Thanks

Bounz commented 4 years ago

Hi @soxfan1966! What's the reason to drop decimal places of the temperature displayed on Dashboard and Groups drop-down?

soxfan1966 commented 4 years ago

Its more in line with how the weather temps are reported - i.e. its 35 degrees not 35.2 degrees, just looks cleaner.

image

Bounz commented 4 years ago

Looks like it depends on settings and data provider (and also one's preferences). Here is how my Weather widged looks like: image

I think it would be better if user can control display options (like it's possible to change C/F) globally.

soxfan1966 commented 4 years ago

I agree -a user preference would make sense. I also tweaked the weather widget, this is what mine looks like now:

image

tuicemen commented 4 years ago

I believe the decimal is more relevant with metric measurements then imperial. However I'm more inclined to agree it should be a user preference

soxfan1966 commented 4 years ago

OK, I will work on that - may take me some time thought.

soxfan1966 commented 4 years ago

In regards to a user preference for this, I was thinking of where this would need to be defined - its not really part of a Widget but more of a system preference.

With that, would it make sense to just use the existing User Preference for Celsius or Fahrenheit ?

image

Or a new preference under Maintenance / User Interface? If a new preference, I would need to see how / where that would be defined.

mralapete commented 4 years ago

Probably best to put it in as Options in the Startup code. Have a look at the Email Account for an example of this.

soxfan1966 commented 4 years ago

This is not a HG program or Widget change, it is a change to the system file "homegenie.webapp.utility.js"

mralapete commented 4 years ago

Surely in the global settings the user will have already defined Celsius or Fahrenheit to be displayed. Why would they need to define it again. Could you reference the global settings in your program and pull it down from there.

soxfan1966 commented 4 years ago

That is what I was suggesting: "would it make sense to just use the existing User Preference for Celsius or Fahrenheit ?"

mralapete commented 4 years ago

Yes. It’s a binary choice for all so best to use what’s already configured in the initial setup of HG.

soxfan1966 commented 4 years ago

I have updated my previous pull request so that the existing user preference for F or C is used to determine if the temperature should be rounded or not. If it is F, then the new rounding to zero decimal places is used and if it is C then the existing option to use decimal places is used.

Bounz commented 4 years ago

I have controversial thoughts about this change. On the one hand Farenheit scale is more precise than Celcius so the decimals may be unneeded, but on the the other hand this change will break existing user's interface. Imaging you are a HG user and for years there is a decimal values in the interface. And after the update 1) your interface changes and 2) you have no way to enable decimals for F at all - this all may be really frustrating.

I still think it's better to have a separate option to turn decimals on and off. You can save the setting on the browser's side like it's made for temperature unit and then use the value in HG interface and widgets code:

HG.WebApp.Store.set('UI.TemperatureUnit')
HG.WebApp.Store.get('UI.TemperatureUnit')
soxfan1966 commented 4 years ago

I think either option makes sense (speaking as someone who uses F and is not accustomed to seeing decimals). You mention HG.WebApp.Store.set('UI.TemperatureUnit')

Where would one define the UI.TemperatureUnit field? I assume this would be either decimal precision or just a Yes/No field ?

Bounz commented 4 years ago

UI.TemperatureUnit was only an example of storing user settings in browser's local store. It's used in homegenie.webapp.utility.js, for example (you can easily find it using any editor or IDE like VS Code, VS, Rider, etc).

To make the whole thing you will need to implement:

  1. helper methods to get and set setting UI.TemperaturePrecision (example name) in _maintenance.js
  2. add UI controls for editing this setting in maintenance/main.html
  3. refactor $$.GetLocaleTemperature and $$.FormatTemperature methods in homegenie.webapp.utility.js