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

Use time_zone (or new param) to calculate local currency symbol #155

Closed
GeoDerp opened this issue Jan 25, 2024 · 10 comments
Closed

Use time_zone (or new param) to calculate local currency symbol #155

GeoDerp opened this issue Jan 25, 2024 · 10 comments
Labels
enhancement New feature or request

Comments

@GeoDerp
Copy link
Contributor

GeoDerp commented Jan 25, 2024

emhass/src/emhass/utils.py

Lines 140 to 141 in 3dfcf1b

'custom_unit_load_cost_id': {"entity_id": "sensor.unit_load_cost", "unit_of_measurement": "€/kWh", "friendly_name": "Unit Load Cost"},
'custom_unit_prod_price_id': {"entity_id": "sensor.unit_prod_price", "unit_of_measurement": "€/kWh", "friendly_name": "Unit Prod Price"},

I could see this having multiple solutions.

  • new pram that just has the currency sign
    • currency="$"
  • pass the time_zone param using an python library
  • new param that overrides locale country code, otherwise let local guess
.
.
.
import locale

if CountryCode != "":
   locale.setlocale(locale.LC_ALL, CountryCode)
else:
   locale.setlocale(locale.LC_ALL, '')

currency_symbol = locale.localeconv()["int_curr_symbol"] 
.
.
.
'custom_unit_load_cost_id': {"entity_id": "sensor.unit_load_cost", "unit_of_measurement": "currency_symbol", "friendly_name": "Unit Load Cost"}, 
'custom_unit_prod_price_id': {"entity_id": "sensor.unit_prod_price", "unit_of_measurement": "currency_symbol", "friendly_name": "Unit Prod Price"},
.
.
.
@davidusb-geek
Copy link
Owner

What is the problem with the existent?
There is a method to pass your own custom names, currency, etc

@GeoDerp
Copy link
Contributor Author

GeoDerp commented Jan 25, 2024

ah my bad.

@GeoDerp GeoDerp closed this as completed Jan 25, 2024
@davidusb-geek
Copy link
Owner

Yes no problem. Those lines that you posted are just there as default values but the user can change to whatever they want.

@GeoDerp
Copy link
Contributor Author

GeoDerp commented Jan 27, 2024

@davidusb-geek is the "currency" homeassistant variable being passed in. Could that be used as default?

@GeoDerp GeoDerp reopened this Jan 27, 2024
@davidusb-geek
Copy link
Owner

No, currency is not being fetched from HA. It could be interesting to fetch it directly yes.

@GeoDerp
Copy link
Contributor Author

GeoDerp commented Jan 27, 2024

A temporary stop gap could be another param (for addon users):

web_server.py

...
        params['retrieve_hass_conf']['alt'] = options['Altitude']
        params['retrieve_hass_conf']['unit_of_measurement']  =  options['Currency']
        params['optim_conf']['set_use_battery'] = options['set_use_battery']
...        

utils.py

...
if 'custom_unit_load_cost_id' in runtimeparams.keys():
            params['passed_data']['custom_unit_load_cost_id'] = runtimeparams['custom_unit_load_cost_id']
        elif 'unit_of_measurement' in params['retrieve_hass_conf']:
            params['passed_data']['custom_unit_load_cost_id']['unit_of_measurement'] = str(params['retrieve_hass_conf']['unit_of_measurement']+"/kWh") 
        if 'custom_unit_prod_price_id' in runtimeparams.keys():
            params['passed_data']['custom_unit_prod_price_id'] = runtimeparams['custom_unit_prod_price_id']
        elif 'unit_of_measurement' in params['retrieve_hass_conf']:
            params['passed_data']['custom_unit_prod_price_id']['unit_of_measurement'] = str(params['retrieve_hass_conf']['unit_of_measurement']+"/kWh")
...

@davidusb-geek
Copy link
Owner

To implement this, there should not be any stop gap for add-on users or any other installation method.
Actually if we do:

url = self.hass_url+"api/config"
response = get(url, headers=headers)
response.json()['currency']

In my case I obtain 'EUR'. So we actually have access to all the configuration parameters directly retrieved from HA.

@davidusb-geek
Copy link
Owner

So @GeoDerp do you think that it is possible to fetch the currency directly from the HA configuration?

@purcell-lab
Copy link
Contributor

My current work around for this is:

  publish_data:
    url: http://localhost:5000/action/publish-data
    method: POST
    content_type: "application/json"
    payload: '{"custom_unit_load_cost_id": {"entity_id": "sensor.unit_load_cost", "unit_of_measurement": "$/kWh", "friendly_name": "Load Cost"}, "custom_unit_prod_price_id": {"entity_id": "sensor.unit_prod_price", "unit_of_measurement": "$/kWh", "friendly_name": "Prod Price"}}'

I would welcome it automatically pulling the locale currency.

@davidusb-geek
Copy link
Owner

Support for this was added on PR #399
Closing as completed

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

No branches or pull requests

3 participants