Skip to content

Commit

Permalink
Correct water heater service schemas (#124038)
Browse files Browse the repository at this point in the history
* Correct water heater service schemas

* Update tests
  • Loading branch information
emontnemery authored Aug 16, 2024
1 parent 0093276 commit 99ab256
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 32 deletions.
42 changes: 12 additions & 30 deletions homeassistant/components/water_heater/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from homeassistant.helpers.entity import Entity, EntityDescription
from homeassistant.helpers.entity_component import EntityComponent
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 .const import DOMAIN
Expand Down Expand Up @@ -94,29 +94,17 @@ class WaterHeaterEntityFeature(IntFlag):

_LOGGER = logging.getLogger(__name__)

ON_OFF_SERVICE_SCHEMA = vol.Schema({vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids})

SET_AWAY_MODE_SCHEMA = vol.Schema(
{
vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids,
vol.Required(ATTR_AWAY_MODE): cv.boolean,
}
)
SET_TEMPERATURE_SCHEMA = vol.Schema(
vol.All(
{
vol.Required(ATTR_TEMPERATURE, "temperature"): vol.Coerce(float),
vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids,
vol.Optional(ATTR_OPERATION_MODE): cv.string,
}
)
)
SET_OPERATION_MODE_SCHEMA = vol.Schema(
{
vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids,
vol.Required(ATTR_OPERATION_MODE): cv.string,
}
)
SET_AWAY_MODE_SCHEMA: VolDictType = {
vol.Required(ATTR_AWAY_MODE): cv.boolean,
}
SET_TEMPERATURE_SCHEMA: VolDictType = {
vol.Required(ATTR_TEMPERATURE, "temperature"): vol.Coerce(float),
vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids,
vol.Optional(ATTR_OPERATION_MODE): cv.string,
}
SET_OPERATION_MODE_SCHEMA: VolDictType = {
vol.Required(ATTR_OPERATION_MODE): cv.string,
}

# mypy: disallow-any-generics

Expand Down Expand Up @@ -145,12 +133,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
SET_OPERATION_MODE_SCHEMA,
"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

Expand Down
5 changes: 3 additions & 2 deletions tests/components/water_heater/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from homeassistant.const import UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from tests.common import (
Expand All @@ -42,7 +43,7 @@ async def test_set_temp_schema_no_req(
"""Test the set temperature schema with missing required data."""
domain = "climate"
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)

data = {"hvac_mode": "off", "entity_id": ["climate.test_id"]}
Expand All @@ -59,7 +60,7 @@ async def test_set_temp_schema(
"""Test the set temperature schema with ok required data."""
domain = "water_heater"
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)

data = {
Expand Down

0 comments on commit 99ab256

Please sign in to comment.