Skip to content

Commit

Permalink
make netprice default value and remove price sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
suaveolent committed Sep 17, 2024
1 parent da2749b commit 312cbfa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 43 deletions.
7 changes: 3 additions & 4 deletions custom_components/epex_spot/SourceShell.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,10 @@ def find_extreme_price_interval(self, call_data, cmp):
if result is None:
return EMPTY_EXTREME_PRICE_INTERVAL_RESP

_LOGGER.error(f"result: {result}")

return {
"start": result["start"],
"end": result["start"] + duration,
"price_per_kwh": round(result["price_per_hour"] / 1000, 6),
"net_price_ct_per_kwh": self.to_net_price(result["price_per_hour"]),
"price_per_kwh": self.to_net_price(
round(result["price_per_hour"] / 1000, 6)
),
}
1 change: 0 additions & 1 deletion custom_components/epex_spot/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"start": None,
"end": None,
"price_per_kwh": None,
"net_price_ct_per_kwh": None,
}

UOM_EUR_PER_KWH = "€/kWh"
Expand Down
40 changes: 2 additions & 38 deletions custom_components/epex_spot/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
"""
coordinator: DataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
entities = [
EpexSpotPriceSensorEntity(coordinator),
EpexSpotNetPriceSensorEntity(coordinator),
EpexSpotRankSensorEntity(coordinator),
EpexSpotQuantileSensorEntity(coordinator),
Expand All @@ -57,47 +56,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_add_entities(entities)


class EpexSpotPriceSensorEntity(EpexSpotEntity, SensorEntity):
"""Home Assistant sensor containing all EPEX spot data."""
class EpexSpotNetPriceSensorEntity(EpexSpotEntity, SensorEntity):
"""Home Assistant net price sensor."""

entity_description = SensorEntityDescription(
key="Price",
name="Price",
state_class=SensorStateClass.MEASUREMENT,
)

def __init__(self, coordinator: DataUpdateCoordinator):
super().__init__(coordinator, self.entity_description)
self._attr_icon = self._localized.icon
self._attr_native_unit_of_measurement = self._localized.uom_per_kwh

@property
def native_value(self) -> StateType:
return self._source.marketdata_now.price_per_kwh

@property
def extra_state_attributes(self):
data = [
{
ATTR_START_TIME: dt_util.as_local(e.start_time).isoformat(),
ATTR_END_TIME: dt_util.as_local(e.end_time).isoformat(),
self._localized.attr_name_per_kwh: e.price_per_kwh,
}
for e in self._source.marketdata
]

return {
ATTR_DATA: data,
self._localized.attr_name_per_kwh: self.native_value,
}


class EpexSpotNetPriceSensorEntity(EpexSpotEntity, SensorEntity):
"""Home Assistant sensor containing all EPEX spot data."""

entity_description = SensorEntityDescription(
key="Net Price",
name="Net Price",
suggested_display_precision=6,
state_class=SensorStateClass.MEASUREMENT,
)
Expand Down

0 comments on commit 312cbfa

Please sign in to comment.