mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Fixes
This commit is contained in:
parent
d73e12df93
commit
ebb450db48
@ -159,7 +159,15 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up Compensation from a config entry."""
|
"""Set up Compensation from a config entry."""
|
||||||
await create_compensation_data(hass, entry.entry_id, dict(entry.options), True)
|
config = dict(entry.options)
|
||||||
|
data_points = config[CONF_DATAPOINTS]
|
||||||
|
new_data_points = []
|
||||||
|
for data_point in data_points:
|
||||||
|
values = data_point.split(",", maxsplit=1)
|
||||||
|
new_data_points.append([float(values[0]), float(values[1])])
|
||||||
|
config[CONF_DATAPOINTS] = new_data_points
|
||||||
|
|
||||||
|
await create_compensation_data(hass, entry.entry_id, config, True)
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
entry.async_on_unload(entry.add_update_listener(update_listener))
|
entry.async_on_unload(entry.add_update_listener(update_listener))
|
||||||
|
|
||||||
|
@ -76,6 +76,20 @@ async def get_options_schema(handler: SchemaCommonFlowHandler) -> vol.Schema:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _is_valid_data_points(check_data_points: list[str]) -> bool:
|
||||||
|
"""Validate data points."""
|
||||||
|
for data_point in check_data_points:
|
||||||
|
if data_point.find(",") > 0:
|
||||||
|
values = data_point.split(",", maxsplit=1)
|
||||||
|
for value in values:
|
||||||
|
try:
|
||||||
|
float(value)
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def validate_options(
|
async def validate_options(
|
||||||
handler: SchemaCommonFlowHandler, user_input: dict[str, Any]
|
handler: SchemaCommonFlowHandler, user_input: dict[str, Any]
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
@ -84,9 +98,8 @@ async def validate_options(
|
|||||||
user_input[CONF_PRECISION] = int(user_input[CONF_PRECISION])
|
user_input[CONF_PRECISION] = int(user_input[CONF_PRECISION])
|
||||||
user_input[CONF_DEGREE] = int(user_input[CONF_DEGREE])
|
user_input[CONF_DEGREE] = int(user_input[CONF_DEGREE])
|
||||||
|
|
||||||
for datapoint in user_input[CONF_DATAPOINTS]:
|
if not _is_valid_data_points(user_input[CONF_DATAPOINTS]):
|
||||||
if not isinstance(datapoint, list):
|
raise SchemaFlowError("incorrect_datapoints")
|
||||||
raise SchemaFlowError("incorrect_datapoints")
|
|
||||||
|
|
||||||
if len(user_input[CONF_DATAPOINTS]) <= user_input[CONF_DEGREE]:
|
if len(user_input[CONF_DATAPOINTS]) <= user_input[CONF_DEGREE]:
|
||||||
raise SchemaFlowError("not_enough_datapoints")
|
raise SchemaFlowError("not_enough_datapoints")
|
||||||
|
@ -12,6 +12,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
CONF_ATTRIBUTE,
|
CONF_ATTRIBUTE,
|
||||||
|
CONF_ENTITY_ID,
|
||||||
CONF_MAXIMUM,
|
CONF_MAXIMUM,
|
||||||
CONF_MINIMUM,
|
CONF_MINIMUM,
|
||||||
CONF_SOURCE,
|
CONF_SOURCE,
|
||||||
@ -90,14 +91,14 @@ async def async_setup_entry(
|
|||||||
compensation = entry.entry_id
|
compensation = entry.entry_id
|
||||||
conf: dict[str, Any] = hass.data[DATA_COMPENSATION][compensation]
|
conf: dict[str, Any] = hass.data[DATA_COMPENSATION][compensation]
|
||||||
|
|
||||||
source: str = conf[CONF_SOURCE]
|
source: str = conf[CONF_ENTITY_ID]
|
||||||
attribute: str | None = conf.get(CONF_ATTRIBUTE)
|
attribute: str | None = conf.get(CONF_ATTRIBUTE)
|
||||||
name = entry.title
|
name = entry.title
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
CompensationSensor(
|
CompensationSensor(
|
||||||
conf.get(CONF_UNIQUE_ID),
|
entry.entry_id,
|
||||||
name,
|
name,
|
||||||
source,
|
source,
|
||||||
attribute,
|
attribute,
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
|
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"incorrect_datapoints": "Datapoints needs to be provided in list-format, ex. '[1.0, 0.0]'.",
|
"incorrect_datapoints": "Datapoints needs to be provided in the right format, ex. '1.0, 0.0'.",
|
||||||
"not_enough_datapoints": "The number of datapoints needs to be less or equal to configured degree."
|
"not_enough_datapoints": "The number of datapoints needs to be more than the configured degree."
|
||||||
},
|
},
|
||||||
"step": {
|
"step": {
|
||||||
"user": {
|
"user": {
|
||||||
@ -31,7 +31,7 @@
|
|||||||
"unit_of_measurement": "Unit of measurement"
|
"unit_of_measurement": "Unit of measurement"
|
||||||
},
|
},
|
||||||
"data_description": {
|
"data_description": {
|
||||||
"data_points": "The collection of data point conversions with the format '[uncompensated_value, compensated_value]'",
|
"data_points": "The collection of data point conversions with the format 'uncompensated_value, compensated_value', ex. '1.0, 0.0'",
|
||||||
"attribute": "Attribute from the source to monitor/compensate.",
|
"attribute": "Attribute from the source to monitor/compensate.",
|
||||||
"upper_limit": "Enables an upper limit for the sensor. The upper limit is defined by the data collections (data_points) greatest uncompensated value.",
|
"upper_limit": "Enables an upper limit for the sensor. The upper limit is defined by the data collections (data_points) greatest uncompensated value.",
|
||||||
"lower_limit": "Enables a lower limit for the sensor. The lower limit is defined by the data collections (data_points) lowest uncompensated value.",
|
"lower_limit": "Enables a lower limit for the sensor. The lower limit is defined by the data collections (data_points) lowest uncompensated value.",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user