Skip to content

Commit

Permalink
Merge pull request #83 from dala318/dala318/issue69
Browse files Browse the repository at this point in the history
Get price entities by integration
  • Loading branch information
dala318 authored Jan 9, 2025
2 parents b19c4a8 + 7e117de commit 9a62935
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions custom_components/nordpool_planner/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from homeassistant import config_entries
from homeassistant.const import ATTR_NAME, ATTR_UNIT_OF_MEASUREMENT
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers import selector
from homeassistant.helpers import selector, template

from .const import (
CONF_ACCEPT_COST_ENTITY,
Expand All @@ -37,6 +37,18 @@

_LOGGER = logging.getLogger(__name__)

ENTOSOE_DOMAIN = None
try:
from ..entsoe.const import DOMAIN as ENTOSOE_DOMAIN
except ImportError:
_LOGGER.warning("Could not import ENTSO-e integration")

NORDPOOL_DOMAIN = None
try:
from ..nordpool import DOMAIN as NORDPOOL_DOMAIN
except ImportError:
_LOGGER.warning("Could not import Nord Pool integration")


class NordpoolPlannerConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Nordpool Planner config flow."""
Expand Down Expand Up @@ -96,16 +108,14 @@ async def async_step_user(
title=self.data[ATTR_NAME], data=self.data, options=self.options
)

sensor_entities = self.hass.states.async_entity_ids(domain_filter="sensor")
selected_entities = [
s
for s in sensor_entities
if "nordpool" in s or "average_electricity_price" in s
]

# if len(selected_entities) == 0:
# errors["base"] = "No Nordpool entity found"

selected_entities = []
if NORDPOOL_DOMAIN:
selected_entities.extend(
template.integration_entities(self.hass, NORDPOOL_DOMAIN)
)
if ENTOSOE_DOMAIN:
ent = template.integration_entities(self.hass, ENTOSOE_DOMAIN)
selected_entities.extend([s for s in ent if "average" in s])
selected_entities.append(NAME_FILE_READER)

schema = vol.Schema(
Expand Down

0 comments on commit 9a62935

Please sign in to comment.