mirror of
https://github.com/home-assistant/core.git
synced 2025-07-04 11:57:05 +00:00
Use correct inputs for relative time and duration options (#138619)
This commit is contained in:
parent
9573f7828b
commit
c75707ec79
@ -3,7 +3,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Awaitable
|
from collections.abc import Awaitable
|
||||||
from datetime import timedelta
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
@ -74,6 +73,9 @@ PROGRAM_OPTIONS = {
|
|||||||
value,
|
value,
|
||||||
)
|
)
|
||||||
for key, value in {
|
for key, value in {
|
||||||
|
OptionKey.BSH_COMMON_DURATION: int,
|
||||||
|
OptionKey.BSH_COMMON_START_IN_RELATIVE: int,
|
||||||
|
OptionKey.BSH_COMMON_FINISH_IN_RELATIVE: int,
|
||||||
OptionKey.CONSUMER_PRODUCTS_COFFEE_MAKER_FILL_QUANTITY: int,
|
OptionKey.CONSUMER_PRODUCTS_COFFEE_MAKER_FILL_QUANTITY: int,
|
||||||
OptionKey.CONSUMER_PRODUCTS_COFFEE_MAKER_MULTIPLE_BEVERAGES: bool,
|
OptionKey.CONSUMER_PRODUCTS_COFFEE_MAKER_MULTIPLE_BEVERAGES: bool,
|
||||||
OptionKey.DISHCARE_DISHWASHER_INTENSIV_ZONE: bool,
|
OptionKey.DISHCARE_DISHWASHER_INTENSIV_ZONE: bool,
|
||||||
@ -92,18 +94,6 @@ PROGRAM_OPTIONS = {
|
|||||||
}.items()
|
}.items()
|
||||||
}
|
}
|
||||||
|
|
||||||
TIME_PROGRAM_OPTIONS = {
|
|
||||||
bsh_key_to_translation_key(key): (
|
|
||||||
key,
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
for key, value in {
|
|
||||||
OptionKey.BSH_COMMON_START_IN_RELATIVE: cv.time_period_str,
|
|
||||||
OptionKey.BSH_COMMON_DURATION: cv.time_period_str,
|
|
||||||
OptionKey.BSH_COMMON_FINISH_IN_RELATIVE: cv.time_period_str,
|
|
||||||
}.items()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SERVICE_SETTING_SCHEMA = vol.Schema(
|
SERVICE_SETTING_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
@ -156,10 +146,7 @@ SERVICE_PROGRAM_SCHEMA = vol.Any(
|
|||||||
|
|
||||||
def _require_program_or_at_least_one_option(data: dict) -> dict:
|
def _require_program_or_at_least_one_option(data: dict) -> dict:
|
||||||
if ATTR_PROGRAM not in data and not any(
|
if ATTR_PROGRAM not in data and not any(
|
||||||
option_key in data
|
option_key in data for option_key in (PROGRAM_ENUM_OPTIONS | PROGRAM_OPTIONS)
|
||||||
for option_key in (
|
|
||||||
PROGRAM_ENUM_OPTIONS | PROGRAM_OPTIONS | TIME_PROGRAM_OPTIONS
|
|
||||||
)
|
|
||||||
):
|
):
|
||||||
raise ServiceValidationError(
|
raise ServiceValidationError(
|
||||||
translation_domain=DOMAIN,
|
translation_domain=DOMAIN,
|
||||||
@ -190,9 +177,7 @@ SERVICE_PROGRAM_AND_OPTIONS_SCHEMA = vol.All(
|
|||||||
.extend(
|
.extend(
|
||||||
{
|
{
|
||||||
vol.Optional(translation_key): schema
|
vol.Optional(translation_key): schema
|
||||||
for translation_key, (key, schema) in (
|
for translation_key, (key, schema) in PROGRAM_OPTIONS.items()
|
||||||
PROGRAM_OPTIONS | TIME_PROGRAM_OPTIONS
|
|
||||||
).items()
|
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
_require_program_or_at_least_one_option,
|
_require_program_or_at_least_one_option,
|
||||||
@ -486,13 +471,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
|
|||||||
elif option in PROGRAM_OPTIONS:
|
elif option in PROGRAM_OPTIONS:
|
||||||
option_key = PROGRAM_OPTIONS[option][0]
|
option_key = PROGRAM_OPTIONS[option][0]
|
||||||
options.append(Option(option_key, value))
|
options.append(Option(option_key, value))
|
||||||
elif option in TIME_PROGRAM_OPTIONS:
|
|
||||||
options.append(
|
|
||||||
Option(
|
|
||||||
TIME_PROGRAM_OPTIONS[option][0],
|
|
||||||
int(cast(timedelta, value).total_seconds()),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
method_call: Awaitable[Any]
|
method_call: Awaitable[Any]
|
||||||
exception_translation_key: str
|
exception_translation_key: str
|
||||||
if program:
|
if program:
|
||||||
|
@ -387,10 +387,14 @@ set_program_and_options:
|
|||||||
collapsed: true
|
collapsed: true
|
||||||
fields:
|
fields:
|
||||||
b_s_h_common_option_start_in_relative:
|
b_s_h_common_option_start_in_relative:
|
||||||
example: "30:00"
|
example: 3600
|
||||||
required: false
|
required: false
|
||||||
selector:
|
selector:
|
||||||
time:
|
number:
|
||||||
|
min: 0
|
||||||
|
step: 1
|
||||||
|
mode: box
|
||||||
|
unit_of_measurement: s
|
||||||
dishcare_dishwasher_option_intensiv_zone:
|
dishcare_dishwasher_option_intensiv_zone:
|
||||||
example: false
|
example: false
|
||||||
required: false
|
required: false
|
||||||
@ -493,10 +497,14 @@ set_program_and_options:
|
|||||||
mode: box
|
mode: box
|
||||||
unit_of_measurement: °C/°F
|
unit_of_measurement: °C/°F
|
||||||
b_s_h_common_option_duration:
|
b_s_h_common_option_duration:
|
||||||
example: "30:00"
|
example: 900
|
||||||
required: false
|
required: false
|
||||||
selector:
|
selector:
|
||||||
time:
|
number:
|
||||||
|
min: 0
|
||||||
|
step: 1
|
||||||
|
mode: box
|
||||||
|
unit_of_measurement: s
|
||||||
cooking_oven_option_fast_pre_heat:
|
cooking_oven_option_fast_pre_heat:
|
||||||
example: false
|
example: false
|
||||||
required: false
|
required: false
|
||||||
@ -561,10 +569,14 @@ set_program_and_options:
|
|||||||
- laundry_care_washer_enum_type_spin_speed_ul_medium
|
- laundry_care_washer_enum_type_spin_speed_ul_medium
|
||||||
- laundry_care_washer_enum_type_spin_speed_ul_high
|
- laundry_care_washer_enum_type_spin_speed_ul_high
|
||||||
b_s_h_common_option_finish_in_relative:
|
b_s_h_common_option_finish_in_relative:
|
||||||
example: "30:00"
|
example: 3600
|
||||||
required: false
|
required: false
|
||||||
selector:
|
selector:
|
||||||
time:
|
number:
|
||||||
|
min: 0
|
||||||
|
step: 1
|
||||||
|
mode: box
|
||||||
|
unit_of_measurement: s
|
||||||
laundry_care_washer_option_i_dos1_active:
|
laundry_care_washer_option_i_dos1_active:
|
||||||
example: false
|
example: false
|
||||||
required: false
|
required: false
|
||||||
|
@ -152,7 +152,7 @@ SERVICES_SET_PROGRAM_AND_OPTIONS = [
|
|||||||
"device_id": "DEVICE_ID",
|
"device_id": "DEVICE_ID",
|
||||||
"affects_to": "selected_program",
|
"affects_to": "selected_program",
|
||||||
"program": "dishcare_dishwasher_program_eco_50",
|
"program": "dishcare_dishwasher_program_eco_50",
|
||||||
"b_s_h_common_option_start_in_relative": "00:30:00",
|
"b_s_h_common_option_start_in_relative": 1800,
|
||||||
},
|
},
|
||||||
"blocking": True,
|
"blocking": True,
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user