Skip to content

Commit

Permalink
unit changed from c€/kWh to €/kWh in order to allow easier comparisio…
Browse files Browse the repository at this point in the history
…n and integration in HA
  • Loading branch information
myTselection committed Sep 27, 2023
1 parent ef95a66 commit f968c20
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Device `MyEnergy` should become available with the following sensors:

| Attribute | Description |
| --------- | ----------- |
| State | cost in c€ per kWh |
| State | cost in € per kWh |
| Last update | Timestamp of last data refresh, throttled to limit data fetch to 1h |
| Postalcode | Postalcode used to retrieve the prices |
| Fuel type | Fuel type (Electricity or Gas) used to retrieve the prices |
Expand Down
2 changes: 1 addition & 1 deletion custom_components/MyEnergy/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/myTselection/MyEnergy/issues",
"requirements": ["bs4","requests"],
"version": "1.1.0"
"version": "1.2.0"
}
12 changes: 9 additions & 3 deletions custom_components/MyEnergy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def __init__(self, config, hass):
self._online_support = config.get("online_support", True)
self._details = {}
self._last_update = None
self._refresh_required = True

@property
def unique_id(self):
Expand All @@ -159,7 +160,11 @@ async def _forced_update(self):
for contract_type in ContractType:
if self._session:
_LOGGER.debug("Getting data for " + NAME)
self._details[contract_type.code] = await self._hass.async_add_executor_job(lambda: self._session.get_data(self._config, contract_type))
try:
self._details[contract_type.code] = await self._hass.async_add_executor_job(lambda: self._session.get_data(self._config, contract_type))
self._refresh_required = False
except:
self._refresh_required = True
_LOGGER.debug("Data fetched completed " + NAME)
else:
_LOGGER.debug(f"{NAME} no session available")
Expand All @@ -170,7 +175,7 @@ async def _update(self):

async def update(self):
# force update if (some) values are still unknown
if self._details is None or self._details is {}:
if self._details is None or self._details is {} or self._refresh_required:
await self._forced_update()
else:
await self._update()
Expand Down Expand Up @@ -225,6 +230,7 @@ async def async_update(self):
if len(price_info) > 0:
self._price = price_info[0]
self._price = self._price.replace('c€/kWh','').replace('c€/kWh','')
self._price = float(self._price.replace(',', '.'))/100
if len(price_info) >= 2:
self._kWhyear = price_info[1]
self._priceyear = price_info[2]
Expand Down Expand Up @@ -290,7 +296,7 @@ def unit(self) -> int:
@property
def unit_of_measurement(self) -> str:
"""Return the unit of measurement this sensor expresses itself in."""
return "c€/kWh"
return "€/kWh"

@property
def device_class(self):
Expand Down

0 comments on commit f968c20

Please sign in to comment.