diff --git a/custom_components/violet_pool_controller/switch.py b/custom_components/violet_pool_controller/switch.py index 0ae52d9..0f3275e 100644 --- a/custom_components/violet_pool_controller/switch.py +++ b/custom_components/violet_pool_controller/switch.py @@ -5,6 +5,9 @@ from homeassistant.components.switch import SwitchEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity import async_timeout +import voluptuous as vol +from homeassistant.helpers import entity_platform +from homeassistant.helpers import config_validation as cv from .const import ( DOMAIN, @@ -150,6 +153,36 @@ async def async_setup_entry(hass, config_entry, async_add_entities): ] async_add_entities(switches) + # Register entity-specific services using async_register_entity_service + platform = entity_platform.async_get_current_platform() + + # Register `turn_auto` service + platform.async_register_entity_service( + "turn_auto", + { + vol.Optional("auto_delay", default=0): vol.Coerce(int), + vol.Optional("last_value", default=0): vol.Coerce(int), + }, + "async_turn_auto" + ) + + # Register `turn_on` service + platform.async_register_entity_service( + "turn_on", + { + vol.Optional("duration", default=0): vol.Coerce(int), + vol.Optional("last_value", default=0): vol.Coerce(int), + }, + "async_turn_on" + ) + + # Register `turn_off` service + platform.async_register_entity_service( + "turn_off", + {}, + "async_turn_off" + ) + SWITCHES = [ {"name": "Violet Pump", "key": "PUMP", "icon": "mdi:water-pump"}, {"name": "Violet Light", "key": "LIGHT", "icon": "mdi:lightbulb"},