Add config flow to Scrape (#81193)
* Scrape take 2 * cleanup * new entity name * Fix name, add tests * Use FlowResultType * Add test abort * hassfest * Remove not needed test * clean * Remove config entry and implement datacoordinator * fix codeowners * fix codeowners * codeowners reset * Fix coordinator * Remove test config_flow * Fix tests * hassfest * reset config flow * reset strings * reset sensor * Reconfig * Fix tests * coverage * Remove coverage * Remove print * Add config flow * Fix config flow * Add back init * Add entry to sensor * float to int * Fix SelectSelector * Add tests for config entry to existing * Test config flow * Fix test reload * Fix rebase * Fix strings * clean init * Clean test_sensor * Align sensor setup entry * Add error to strings * review changes * clean tests * Add back options flow * review changes * update_listener * Add tests * Remove duplicate abort * strings * sensors to sensor * review changes * more review changes * clarify test payload * fixture name
This commit is contained in:
parent
848821139d
commit
b3dd59f202
13 changed files with 528 additions and 87 deletions
|
@ -14,6 +14,7 @@ from homeassistant.components.sensor import (
|
|||
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
|
||||
STATE_CLASSES_SCHEMA,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_ATTRIBUTE,
|
||||
CONF_AUTHENTICATION,
|
||||
|
@ -144,6 +145,45 @@ async def async_setup_platform(
|
|||
async_add_entities(entities)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up the Scrape sensor entry."""
|
||||
entities: list = []
|
||||
|
||||
coordinator: ScrapeCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
config = dict(entry.options)
|
||||
for sensor in config["sensor"]:
|
||||
sensor_config: ConfigType = vol.Schema(
|
||||
TEMPLATE_SENSOR_BASE_SCHEMA.schema, extra=vol.ALLOW_EXTRA
|
||||
)(sensor)
|
||||
|
||||
name: str = sensor_config[CONF_NAME]
|
||||
select: str = sensor_config[CONF_SELECT]
|
||||
attr: str | None = sensor_config.get(CONF_ATTRIBUTE)
|
||||
index: int = int(sensor_config[CONF_INDEX])
|
||||
value_string: str | None = sensor_config.get(CONF_VALUE_TEMPLATE)
|
||||
|
||||
value_template: Template | None = (
|
||||
Template(value_string, hass) if value_string is not None else None
|
||||
)
|
||||
entities.append(
|
||||
ScrapeSensor(
|
||||
hass,
|
||||
coordinator,
|
||||
sensor_config,
|
||||
name,
|
||||
None,
|
||||
select,
|
||||
attr,
|
||||
index,
|
||||
value_template,
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class ScrapeSensor(CoordinatorEntity[ScrapeCoordinator], TemplateSensor):
|
||||
"""Representation of a web scrape sensor."""
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue