Use correct inputs for relative time and duration options (#138619)

This commit is contained in:
J. Diego Rodríguez Royo 2025-02-16 00:29:38 +01:00 committed by GitHub
parent 9573f7828b
commit c75707ec79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 34 deletions

View File

@ -3,7 +3,6 @@
from __future__ import annotations
from collections.abc import Awaitable
from datetime import timedelta
import logging
from typing import Any, cast
@ -74,6 +73,9 @@ PROGRAM_OPTIONS = {
value,
)
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_MULTIPLE_BEVERAGES: bool,
OptionKey.DISHCARE_DISHWASHER_INTENSIV_ZONE: bool,
@ -92,18 +94,6 @@ PROGRAM_OPTIONS = {
}.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(
{
@ -156,10 +146,7 @@ SERVICE_PROGRAM_SCHEMA = vol.Any(
def _require_program_or_at_least_one_option(data: dict) -> dict:
if ATTR_PROGRAM not in data and not any(
option_key in data
for option_key in (
PROGRAM_ENUM_OPTIONS | PROGRAM_OPTIONS | TIME_PROGRAM_OPTIONS
)
option_key in data for option_key in (PROGRAM_ENUM_OPTIONS | PROGRAM_OPTIONS)
):
raise ServiceValidationError(
translation_domain=DOMAIN,
@ -190,9 +177,7 @@ SERVICE_PROGRAM_AND_OPTIONS_SCHEMA = vol.All(
.extend(
{
vol.Optional(translation_key): schema
for translation_key, (key, schema) in (
PROGRAM_OPTIONS | TIME_PROGRAM_OPTIONS
).items()
for translation_key, (key, schema) in PROGRAM_OPTIONS.items()
}
),
_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:
option_key = PROGRAM_OPTIONS[option][0]
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]
exception_translation_key: str
if program:

View File

@ -387,10 +387,14 @@ set_program_and_options:
collapsed: true
fields:
b_s_h_common_option_start_in_relative:
example: "30:00"
example: 3600
required: false
selector:
time:
number:
min: 0
step: 1
mode: box
unit_of_measurement: s
dishcare_dishwasher_option_intensiv_zone:
example: false
required: false
@ -493,10 +497,14 @@ set_program_and_options:
mode: box
unit_of_measurement: °C/°F
b_s_h_common_option_duration:
example: "30:00"
example: 900
required: false
selector:
time:
number:
min: 0
step: 1
mode: box
unit_of_measurement: s
cooking_oven_option_fast_pre_heat:
example: 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_high
b_s_h_common_option_finish_in_relative:
example: "30:00"
example: 3600
required: false
selector:
time:
number:
min: 0
step: 1
mode: box
unit_of_measurement: s
laundry_care_washer_option_i_dos1_active:
example: false
required: false

View File

@ -152,7 +152,7 @@ SERVICES_SET_PROGRAM_AND_OPTIONS = [
"device_id": "DEVICE_ID",
"affects_to": "selected_program",
"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,
},