Skip to content

Commit

Permalink
async_register_entity_service for cleaner and future-proof service re…
Browse files Browse the repository at this point in the history
…gistration
  • Loading branch information
Xerolux authored Oct 15, 2024
1 parent 1da57f7 commit 62e3c85
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions custom_components/violet_pool_controller/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"},
Expand Down

0 comments on commit 62e3c85

Please sign in to comment.