emhass
emhass copied to clipboard
Use time_zone (or new param) to calculate local currency symbol
https://github.com/davidusb-geek/emhass/blob/3dfcf1b4032fc0677b489049a98e93581218b44a/src/emhass/utils.py#L140-L141
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"},
.
.
.
What is the problem with the existent? There is a method to pass your own custom names, currency, etc
ah my bad.
Yes no problem. Those lines that you posted are just there as default values but the user can change to whatever they want.
@davidusb-geek is the "currency" homeassistant variable being passed in. Could that be used as default?
No, currency is not being fetched from HA. It could be interesting to fetch it directly yes.
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")
...
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.