mirror of
https://github.com/home-assistant/core.git
synced 2026-12-06 13:45:55 -04:00
Add action enums to Indevolt integration (#191868)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot Autofix powered by AI
parent
a93d1f8ec0
commit
46c9097c14
@@ -1,6 +1,7 @@
|
||||
"""Services for Indevolt integration."""
|
||||
|
||||
import asyncio
|
||||
from enum import StrEnum
|
||||
from typing import Final, Never
|
||||
|
||||
from indevolt_api import (
|
||||
@@ -10,6 +11,7 @@ from indevolt_api import (
|
||||
)
|
||||
import probatio
|
||||
|
||||
from homeassistant.const import CommonServiceArgument
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
@@ -18,17 +20,32 @@ from homeassistant.helpers.service import async_extract_config_entry_ids
|
||||
from .const import DOMAIN
|
||||
from .coordinator import IndevoltCoordinator
|
||||
|
||||
|
||||
class IndevoltService(StrEnum):
|
||||
"""Store keys for Indevolt services."""
|
||||
|
||||
CHARGE = "charge"
|
||||
DISCHARGE = "discharge"
|
||||
|
||||
|
||||
class IndevoltServiceArgument(StrEnum):
|
||||
"""Store keys for Indevolt service arguments."""
|
||||
|
||||
POWER = "power"
|
||||
TARGET_SOC = "target_soc"
|
||||
|
||||
|
||||
RT_ACTION_SERVICE_SCHEMA: Final = probatio.Schema(
|
||||
{
|
||||
probatio.Required("device_id"): probatio.All(
|
||||
probatio.Required(CommonServiceArgument.DEVICE_ID): probatio.All(
|
||||
probatio.EnsureList(),
|
||||
[cv.string],
|
||||
),
|
||||
probatio.Required("target_soc"): probatio.All(
|
||||
probatio.Required(IndevoltServiceArgument.TARGET_SOC): probatio.All(
|
||||
probatio.Coerce(int),
|
||||
probatio.Range(min=0, max=100),
|
||||
),
|
||||
probatio.Required("power"): probatio.All(
|
||||
probatio.Required(IndevoltServiceArgument.POWER): probatio.All(
|
||||
probatio.Coerce(int),
|
||||
probatio.Range(min=0, max=10800),
|
||||
),
|
||||
@@ -51,10 +68,10 @@ def async_setup_services(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN, "charge", charge, schema=RT_ACTION_SERVICE_SCHEMA
|
||||
DOMAIN, IndevoltService.CHARGE, charge, schema=RT_ACTION_SERVICE_SCHEMA
|
||||
)
|
||||
hass.services.async_register(
|
||||
DOMAIN, "discharge", discharge, schema=RT_ACTION_SERVICE_SCHEMA
|
||||
DOMAIN, IndevoltService.DISCHARGE, discharge, schema=RT_ACTION_SERVICE_SCHEMA
|
||||
)
|
||||
|
||||
|
||||
@@ -66,8 +83,8 @@ async def _async_handle_realtime_action(
|
||||
"""Validate and execute a realtime action for one or more coordinators."""
|
||||
coordinators = await _async_get_coordinators_from_call(hass, call)
|
||||
|
||||
power: int = call.data["power"]
|
||||
target_soc: int = call.data["target_soc"]
|
||||
power: int = call.data[IndevoltServiceArgument.POWER]
|
||||
target_soc: int = call.data[IndevoltServiceArgument.TARGET_SOC]
|
||||
|
||||
_validate_realtime_action(coordinators, action, power, target_soc)
|
||||
await _execute_realtime_action(coordinators, action, power, target_soc)
|
||||
|
||||
Reference in New Issue
Block a user