Add "start_irrigation" service for Yardian (#100257)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Marty Sun 2023-09-27 14:59:15 +08:00 committed by GitHub
parent d70308ae9f
commit 4788dd2905
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 0 deletions

View File

@ -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"

View File

@ -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."
}
}
}
}
}

View File

@ -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."""