From c75707ec79f50e8cc24a06c61b43b9ee610eab3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Diego=20Rodr=C3=ADguez=20Royo?= Date: Sun, 16 Feb 2025 00:29:38 +0100 Subject: [PATCH] Use correct inputs for relative time and duration options (#138619) --- .../components/home_connect/__init__.py | 33 ++++--------------- .../components/home_connect/services.yaml | 24 ++++++++++---- tests/components/home_connect/test_init.py | 2 +- 3 files changed, 25 insertions(+), 34 deletions(-) diff --git a/homeassistant/components/home_connect/__init__.py b/homeassistant/components/home_connect/__init__.py index 01eb6e8fbea..a020b2370b9 100644 --- a/homeassistant/components/home_connect/__init__.py +++ b/homeassistant/components/home_connect/__init__.py @@ -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: diff --git a/homeassistant/components/home_connect/services.yaml b/homeassistant/components/home_connect/services.yaml index 50e50afd598..91b0089d653 100644 --- a/homeassistant/components/home_connect/services.yaml +++ b/homeassistant/components/home_connect/services.yaml @@ -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 diff --git a/tests/components/home_connect/test_init.py b/tests/components/home_connect/test_init.py index 9e514824147..5e309a7446e 100644 --- a/tests/components/home_connect/test_init.py +++ b/tests/components/home_connect/test_init.py @@ -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, },