Skip to content

Commit

Permalink
Fix #42 and #29 by evaluating if we use cents/øre.
Browse files Browse the repository at this point in the history
  • Loading branch information
erlendsellie authored Dec 4, 2024
1 parent 1b6a6c9 commit 6665e11
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions custom_components/priceanalyzer/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
_PRICE_IN
)

# Needed incase a user wants the prices in non local currency
_CURRENCY_TO_LOCAL = {"DKK": "Kr", "NOK": "Kr", "SEK": "Kr", "EUR": "€"}
_CURRENTY_TO_CENTS = {"DKK": "Øre", "NOK": "Øre", "SEK": "Öre", "EUR": "c"}



from homeassistant.helpers.template import Template, attach
from homeassistant.util import dt as dt_utils
Expand Down Expand Up @@ -397,8 +402,13 @@ def unit(self) -> str:
return self._data._price_type

@property
def unit_of_measurement(self) -> str:
return self._data._currency + '/' + self._data._price_type
def unit_of_measurement(self) -> str: # FIXME
"""Return the unit of measurement this sensor expresses itself in."""
_currency = self._data._currency
if self._data._use_cents is True:
# Convert unit of measurement to cents based on chosen currency
_currency = _CURRENTY_TO_CENTS[_currency]
return "%s/%s" % (_currency, self._data._price_type)


@property
Expand Down

0 comments on commit 6665e11

Please sign in to comment.