Add action enums to pi_hole (#191863)

This commit is contained in:
epenet
2026-11-10 13:59:45 +01:00
committed by GitHub
parent c038fd49c9
commit 512e8b382b
3 changed files with 24 additions and 13 deletions
@@ -13,9 +13,6 @@ DEFAULT_SSL = False
DEFAULT_VERIFY_SSL = True
DEFAULT_STATISTICS_ONLY = True
SERVICE_DISABLE = "disable"
SERVICE_DISABLE_ATTR_DURATION = "duration"
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=5)
# See https://github.com/pi-hole/FTL/blob/88737f6248cd3df3202eed72aeec89b9fb572631/src/webserver/lua_web.c#L83
+17 -3
View File
@@ -1,12 +1,26 @@
"""Services for the Pi-hole integration."""
from enum import StrEnum
import probatio
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv, service
from .const import DOMAIN, SERVICE_DISABLE, SERVICE_DISABLE_ATTR_DURATION
from .const import DOMAIN
class PiHoleService(StrEnum):
"""Store keys for Pi-hole services."""
DISABLE = "disable"
class PiHoleServiceArgument(StrEnum):
"""Store keys for Pi-hole service arguments."""
DURATION = "duration"
@callback
@@ -16,10 +30,10 @@ def async_setup_services(hass: HomeAssistant) -> None:
service.async_register_platform_entity_service(
hass,
DOMAIN,
SERVICE_DISABLE,
PiHoleService.DISABLE,
entity_domain=SWITCH_DOMAIN,
schema={
probatio.Required(SERVICE_DISABLE_ATTR_DURATION): probatio.All(
probatio.Required(PiHoleServiceArgument.DURATION): probatio.All(
cv.time_period_str, cv.positive_timedelta
)
},
+7 -7
View File
@@ -7,12 +7,12 @@ import pytest
from pytest_homeassistant.common import MockConfigEntry
from homeassistant.components import pi_hole, switch
from homeassistant.components.pi_hole.const import (
CONF_STATISTICS_ONLY,
SERVICE_DISABLE,
SERVICE_DISABLE_ATTR_DURATION,
)
from homeassistant.components.pi_hole.const import CONF_STATISTICS_ONLY
from homeassistant.components.pi_hole.coordinator import PiHoleData
from homeassistant.components.pi_hole.services import (
PiHoleService,
PiHoleServiceArgument,
)
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import (
ATTR_ENTITY_ID,
@@ -365,8 +365,8 @@ async def test_disable_service_call(hass: HomeAssistant) -> None:
await hass.services.async_call(
pi_hole.DOMAIN,
SERVICE_DISABLE,
{ATTR_ENTITY_ID: "all", SERVICE_DISABLE_ATTR_DURATION: "00:00:01"},
PiHoleService.DISABLE,
{ATTR_ENTITY_ID: "all", PiHoleServiceArgument.DURATION: "00:00:01"},
blocking=True,
)