diff --git a/homeassistant/components/yardian/services.yaml b/homeassistant/components/yardian/services.yaml new file mode 100644 index 00000000000..a8d05133f51 --- /dev/null +++ b/homeassistant/components/yardian/services.yaml @@ -0,0 +1,14 @@ +start_irrigation: + target: + entity: + integration: yardian + domain: switch + fields: + duration: + required: true + default: 6 + selector: + number: + min: 1 + max: 1440 + unit_of_measurement: "minutes" diff --git a/homeassistant/components/yardian/strings.json b/homeassistant/components/yardian/strings.json index 6577c99456c..f841f3d3ed1 100644 --- a/homeassistant/components/yardian/strings.json +++ b/homeassistant/components/yardian/strings.json @@ -16,5 +16,17 @@ "abort": { "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" } + }, + "services": { + "start_irrigation": { + "name": "Start irrigation", + "description": "Starts the irrigation.", + "fields": { + "duration": { + "name": "Duration", + "description": "Duration for the target to be turned on." + } + } + } } } diff --git a/homeassistant/components/yardian/switch.py b/homeassistant/components/yardian/switch.py index af5703e0fd4..8598e4a8732 100644 --- a/homeassistant/components/yardian/switch.py +++ b/homeassistant/components/yardian/switch.py @@ -3,15 +3,23 @@ from __future__ import annotations from typing import Any +import voluptuous as vol + from homeassistant.components.switch import SwitchEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant +from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import DEFAULT_WATERING_DURATION, DOMAIN from .coordinator import YardianUpdateCoordinator +SERVICE_START_IRRIGATION = "start_irrigation" +SERVICE_SCHEMA_START_IRRIGATION = { + vol.Required("duration"): cv.positive_int, +} + async def async_setup_entry( hass: HomeAssistant, @@ -28,6 +36,13 @@ async def async_setup_entry( for i in range(len(coordinator.data.zones)) ) + platform = entity_platform.async_get_current_platform() + platform.async_register_entity_service( + SERVICE_START_IRRIGATION, + SERVICE_SCHEMA_START_IRRIGATION, + "async_turn_on", + ) + class YardianSwitch(CoordinatorEntity[YardianUpdateCoordinator], SwitchEntity): """Representation of a Yardian switch."""