Correct water heater service schemas (#124038)

* Correct water heater service schemas

* Update tests
This commit is contained in:
Erik Montnemery 2024-08-16 12:58:05 +02:00 committed by GitHub
parent 0093276e93
commit 99ab2566c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 32 deletions

View File

@ -35,7 +35,7 @@ from homeassistant.helpers.deprecation import (
from homeassistant.helpers.entity import Entity, EntityDescription from homeassistant.helpers.entity import Entity, EntityDescription
from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.temperature import display_temp as show_temp from homeassistant.helpers.temperature import display_temp as show_temp
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType, VolDictType
from homeassistant.util.unit_conversion import TemperatureConverter from homeassistant.util.unit_conversion import TemperatureConverter
from .const import DOMAIN from .const import DOMAIN
@ -94,29 +94,17 @@ CONVERTIBLE_ATTRIBUTE = [ATTR_TEMPERATURE]
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
ON_OFF_SERVICE_SCHEMA = vol.Schema({vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids}) SET_AWAY_MODE_SCHEMA: VolDictType = {
SET_AWAY_MODE_SCHEMA = vol.Schema(
{
vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids,
vol.Required(ATTR_AWAY_MODE): cv.boolean, vol.Required(ATTR_AWAY_MODE): cv.boolean,
} }
) SET_TEMPERATURE_SCHEMA: VolDictType = {
SET_TEMPERATURE_SCHEMA = vol.Schema(
vol.All(
{
vol.Required(ATTR_TEMPERATURE, "temperature"): vol.Coerce(float), vol.Required(ATTR_TEMPERATURE, "temperature"): vol.Coerce(float),
vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids, vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids,
vol.Optional(ATTR_OPERATION_MODE): cv.string, vol.Optional(ATTR_OPERATION_MODE): cv.string,
} }
) SET_OPERATION_MODE_SCHEMA: VolDictType = {
)
SET_OPERATION_MODE_SCHEMA = vol.Schema(
{
vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids,
vol.Required(ATTR_OPERATION_MODE): cv.string, vol.Required(ATTR_OPERATION_MODE): cv.string,
} }
)
# mypy: disallow-any-generics # mypy: disallow-any-generics
@ -145,12 +133,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
SET_OPERATION_MODE_SCHEMA, SET_OPERATION_MODE_SCHEMA,
"async_handle_set_operation_mode", "async_handle_set_operation_mode",
) )
component.async_register_entity_service(
SERVICE_TURN_OFF, ON_OFF_SERVICE_SCHEMA, "async_turn_off"
)
component.async_register_entity_service(
SERVICE_TURN_ON, ON_OFF_SERVICE_SCHEMA, "async_turn_on"
)
return True return True

View File

@ -22,6 +22,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import UnitOfTemperature from homeassistant.const import UnitOfTemperature
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from tests.common import ( from tests.common import (
@ -42,7 +43,7 @@ async def test_set_temp_schema_no_req(
"""Test the set temperature schema with missing required data.""" """Test the set temperature schema with missing required data."""
domain = "climate" domain = "climate"
service = "test_set_temperature" service = "test_set_temperature"
schema = SET_TEMPERATURE_SCHEMA schema = cv.make_entity_service_schema(SET_TEMPERATURE_SCHEMA)
calls = async_mock_service(hass, domain, service, schema) calls = async_mock_service(hass, domain, service, schema)
data = {"hvac_mode": "off", "entity_id": ["climate.test_id"]} data = {"hvac_mode": "off", "entity_id": ["climate.test_id"]}
@ -59,7 +60,7 @@ async def test_set_temp_schema(
"""Test the set temperature schema with ok required data.""" """Test the set temperature schema with ok required data."""
domain = "water_heater" domain = "water_heater"
service = "test_set_temperature" service = "test_set_temperature"
schema = SET_TEMPERATURE_SCHEMA schema = cv.make_entity_service_schema(SET_TEMPERATURE_SCHEMA)
calls = async_mock_service(hass, domain, service, schema) calls = async_mock_service(hass, domain, service, schema)
data = { data = {