Skip to content

Commit

Permalink
Added dynamic penny units
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-r committed Jan 20, 2024
1 parent 7bff0af commit 63c4474
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ohme EV Charger for Home Assistant

A basic integration for interacting with Ohme EV Chargers.
An integration for interacting with Ohme EV Chargers.

This is an unofficial integration. I have no affiliation with Ohme besides owning one of their EV chargers.

Expand Down
14 changes: 13 additions & 1 deletion custom_components/ohme/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ def native_value(self):

class PriceCapNumber(NumberEntity):
_attr_name = "Price Cap"
_attr_native_unit_of_measurement = "p"
_attr_device_class = NumberDeviceClass.MONETARY
_attr_mode = NumberMode.BOX
_attr_native_step = 0.1
Expand Down Expand Up @@ -230,6 +229,19 @@ async def async_set_native_value(self, value: float) -> None:
await asyncio.sleep(1)
await self.coordinator.async_refresh()

@property
def native_unit_of_measurement(self):
if self.coordinator.data is None:
return None

penny_unit = {
"GBP": "p",
"EUR": "c"
}
currency = self.coordinator.data["userSettings"].get("currencyCode", "XXX")

return penny_unit.get(currency, f"{currency}/100")

@property
def icon(self):
"""Icon of the sensor."""
Expand Down

0 comments on commit 63c4474

Please sign in to comment.