mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Fix airgradient select entities (#120549)
This commit is contained in:
parent
34e266762e
commit
e8a3e3c8db
@ -79,62 +79,59 @@ LED_BAR_ENTITIES: tuple[AirGradientSelectEntityDescription, ...] = (
|
||||
),
|
||||
)
|
||||
|
||||
LEARNING_TIME_OFFSET_OPTIONS = {
|
||||
12: "12",
|
||||
60: "60",
|
||||
120: "120",
|
||||
360: "360",
|
||||
720: "720",
|
||||
}
|
||||
LEARNING_TIME_OFFSET_OPTIONS_INVERSE = {
|
||||
v: k for k, v in LEARNING_TIME_OFFSET_OPTIONS.items()
|
||||
}
|
||||
ABC_DAYS = {
|
||||
8: "8",
|
||||
30: "30",
|
||||
90: "90",
|
||||
180: "180",
|
||||
0: "off",
|
||||
}
|
||||
ABC_DAYS_INVERSE = {v: k for k, v in ABC_DAYS.items()}
|
||||
LEARNING_TIME_OFFSET_OPTIONS = [
|
||||
"12",
|
||||
"60",
|
||||
"120",
|
||||
"360",
|
||||
"720",
|
||||
]
|
||||
|
||||
ABC_DAYS = [
|
||||
"8",
|
||||
"30",
|
||||
"90",
|
||||
"180",
|
||||
"0",
|
||||
]
|
||||
|
||||
|
||||
def _get_value(value: int, values: list[str]) -> str | None:
|
||||
str_value = str(value)
|
||||
return str_value if str_value in values else None
|
||||
|
||||
|
||||
CONTROL_ENTITIES: tuple[AirGradientSelectEntityDescription, ...] = (
|
||||
AirGradientSelectEntityDescription(
|
||||
key="nox_index_learning_time_offset",
|
||||
translation_key="nox_index_learning_time_offset",
|
||||
options=list(LEARNING_TIME_OFFSET_OPTIONS_INVERSE),
|
||||
options=LEARNING_TIME_OFFSET_OPTIONS,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
value_fn=lambda config: LEARNING_TIME_OFFSET_OPTIONS.get(
|
||||
config.nox_learning_offset
|
||||
),
|
||||
set_value_fn=lambda client, value: client.set_nox_learning_offset(
|
||||
LEARNING_TIME_OFFSET_OPTIONS_INVERSE.get(value, 12)
|
||||
value_fn=lambda config: _get_value(
|
||||
config.nox_learning_offset, LEARNING_TIME_OFFSET_OPTIONS
|
||||
),
|
||||
set_value_fn=lambda client, value: client.set_nox_learning_offset(int(value)),
|
||||
),
|
||||
AirGradientSelectEntityDescription(
|
||||
key="voc_index_learning_time_offset",
|
||||
translation_key="voc_index_learning_time_offset",
|
||||
options=list(LEARNING_TIME_OFFSET_OPTIONS_INVERSE),
|
||||
options=LEARNING_TIME_OFFSET_OPTIONS,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
value_fn=lambda config: LEARNING_TIME_OFFSET_OPTIONS.get(
|
||||
config.nox_learning_offset
|
||||
),
|
||||
set_value_fn=lambda client, value: client.set_tvoc_learning_offset(
|
||||
LEARNING_TIME_OFFSET_OPTIONS_INVERSE.get(value, 12)
|
||||
value_fn=lambda config: _get_value(
|
||||
config.tvoc_learning_offset, LEARNING_TIME_OFFSET_OPTIONS
|
||||
),
|
||||
set_value_fn=lambda client, value: client.set_tvoc_learning_offset(int(value)),
|
||||
),
|
||||
AirGradientSelectEntityDescription(
|
||||
key="co2_automatic_baseline_calibration",
|
||||
translation_key="co2_automatic_baseline_calibration",
|
||||
options=list(ABC_DAYS_INVERSE),
|
||||
options=ABC_DAYS,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
value_fn=lambda config: ABC_DAYS.get(
|
||||
config.co2_automatic_baseline_calibration_days
|
||||
value_fn=lambda config: _get_value(
|
||||
config.co2_automatic_baseline_calibration_days, ABC_DAYS
|
||||
),
|
||||
set_value_fn=lambda client,
|
||||
value: client.set_co2_automatic_baseline_calibration(
|
||||
ABC_DAYS_INVERSE.get(value, 0)
|
||||
),
|
||||
value: client.set_co2_automatic_baseline_calibration(int(value)),
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
'30',
|
||||
'90',
|
||||
'180',
|
||||
'off',
|
||||
'0',
|
||||
]),
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
@ -49,7 +49,7 @@
|
||||
'30',
|
||||
'90',
|
||||
'180',
|
||||
'off',
|
||||
'0',
|
||||
]),
|
||||
}),
|
||||
'context': <ANY>,
|
||||
@ -415,7 +415,7 @@
|
||||
'30',
|
||||
'90',
|
||||
'180',
|
||||
'off',
|
||||
'0',
|
||||
]),
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
@ -454,7 +454,7 @@
|
||||
'30',
|
||||
'90',
|
||||
'180',
|
||||
'off',
|
||||
'0',
|
||||
]),
|
||||
}),
|
||||
'context': <ANY>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user