mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Add action enums to ebusd (#190207)
This commit is contained in:
@@ -13,7 +13,7 @@ from homeassistant.const import (
|
||||
CONF_PORT,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.discovery import load_platform
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
@@ -110,11 +110,8 @@ class EbusdData:
|
||||
_LOGGER.error(err)
|
||||
raise RuntimeError(err) from err
|
||||
|
||||
def write(self, call: ServiceCall) -> None:
|
||||
def write(self, name: str, value: str) -> None:
|
||||
"""Call write method on ebusd."""
|
||||
name = call.data.get("name")
|
||||
value = call.data.get("value")
|
||||
|
||||
try:
|
||||
_LOGGER.debug("Opening socket to ebusd %s", name)
|
||||
command_result = ebusdpy.write(self._address, self._circuit, name, value)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"""Services for the Ebusd integration."""
|
||||
|
||||
from enum import StrEnum
|
||||
|
||||
import probatio
|
||||
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
@@ -7,23 +9,37 @@ from homeassistant.helpers import config_validation as cv
|
||||
|
||||
from .const import DOMAIN, EBUSD_DATA
|
||||
|
||||
SERVICE_EBUSD_WRITE = "ebusd_write"
|
||||
|
||||
class EbusdService(StrEnum):
|
||||
"""Store keys for ebusd services."""
|
||||
|
||||
WRITE = "ebusd_write"
|
||||
|
||||
|
||||
class EbusdServiceArgument(StrEnum):
|
||||
"""Store keys for ebusd service arguments."""
|
||||
|
||||
NAME = "name"
|
||||
VALUE = "value"
|
||||
|
||||
|
||||
SERVICE_EBUSD_WRITE_SCHEMA = probatio.Schema(
|
||||
{
|
||||
probatio.Required("name"): cv.string,
|
||||
probatio.Required("value"): cv.string,
|
||||
probatio.Required(EbusdServiceArgument.NAME): cv.string,
|
||||
probatio.Required(EbusdServiceArgument.VALUE): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def _ebusd_write(call: ServiceCall) -> None:
|
||||
"""Call write method on ebusd."""
|
||||
call.hass.data[EBUSD_DATA].write(call)
|
||||
call.hass.data[EBUSD_DATA].write(
|
||||
call.data[EbusdServiceArgument.NAME], call.data[EbusdServiceArgument.VALUE]
|
||||
)
|
||||
|
||||
|
||||
def setup_services(hass: HomeAssistant) -> None:
|
||||
"""Register the Ebusd services."""
|
||||
hass.services.register(
|
||||
DOMAIN, SERVICE_EBUSD_WRITE, _ebusd_write, schema=SERVICE_EBUSD_WRITE_SCHEMA
|
||||
DOMAIN, EbusdService.WRITE, _ebusd_write, schema=SERVICE_EBUSD_WRITE_SCHEMA
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user