diff --git a/homeassistant/components/pi_hole/const.py b/homeassistant/components/pi_hole/const.py index 395100fd2b60..b9d7d9973722 100644 --- a/homeassistant/components/pi_hole/const.py +++ b/homeassistant/components/pi_hole/const.py @@ -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 diff --git a/homeassistant/components/pi_hole/services.py b/homeassistant/components/pi_hole/services.py index 88e0cd33dddb..7bbbe976bf72 100644 --- a/homeassistant/components/pi_hole/services.py +++ b/homeassistant/components/pi_hole/services.py @@ -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 ) }, diff --git a/tests/components/pi_hole/test_init.py b/tests/components/pi_hole/test_init.py index 4051d5a40268..05ad5bda800e 100644 --- a/tests/components/pi_hole/test_init.py +++ b/tests/components/pi_hole/test_init.py @@ -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, )