mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Add an action enum to stookwijzer (#192202)
This commit is contained in:
@@ -5,5 +5,3 @@ from typing import Final
|
||||
|
||||
DOMAIN: Final = "stookwijzer"
|
||||
LOGGER = logging.getLogger(__package__)
|
||||
|
||||
SERVICE_GET_FORECAST = "get_forecast"
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
"""Define services for the Stookwijzer integration."""
|
||||
|
||||
from enum import StrEnum
|
||||
from typing import Required, TypedDict, cast
|
||||
|
||||
import probatio
|
||||
|
||||
from homeassistant.const import ATTR_CONFIG_ENTRY_ID
|
||||
from homeassistant.const import CommonServiceArgument
|
||||
from homeassistant.core import (
|
||||
HomeAssistant,
|
||||
ServiceCall,
|
||||
@@ -14,12 +15,19 @@ from homeassistant.core import (
|
||||
)
|
||||
from homeassistant.helpers import service
|
||||
|
||||
from .const import DOMAIN, SERVICE_GET_FORECAST
|
||||
from .const import DOMAIN
|
||||
from .coordinator import StookwijzerConfigEntry
|
||||
|
||||
|
||||
class StookwijzerService(StrEnum):
|
||||
"""Store keys for Stookwijzer services."""
|
||||
|
||||
GET_FORECAST = "get_forecast"
|
||||
|
||||
|
||||
SERVICE_GET_FORECAST_SCHEMA = probatio.Schema(
|
||||
{
|
||||
probatio.Required(ATTR_CONFIG_ENTRY_ID): str,
|
||||
probatio.Required(CommonServiceArgument.CONFIG_ENTRY_ID): str,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -39,7 +47,7 @@ def async_setup_services(hass: HomeAssistant) -> None:
|
||||
async def async_get_forecast(call: ServiceCall) -> ServiceResponse:
|
||||
"""Get the forecast from API endpoint."""
|
||||
entry: StookwijzerConfigEntry = service.async_get_config_entry(
|
||||
call.hass, DOMAIN, call.data[ATTR_CONFIG_ENTRY_ID]
|
||||
call.hass, DOMAIN, call.data[CommonServiceArgument.CONFIG_ENTRY_ID]
|
||||
)
|
||||
client = entry.runtime_data.client
|
||||
|
||||
@@ -54,7 +62,7 @@ def async_setup_services(hass: HomeAssistant) -> None:
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
SERVICE_GET_FORECAST,
|
||||
StookwijzerService.GET_FORECAST,
|
||||
async_get_forecast,
|
||||
schema=SERVICE_GET_FORECAST_SCHEMA,
|
||||
supports_response=SupportsResponse.ONLY,
|
||||
|
||||
@@ -4,8 +4,9 @@ import pytest
|
||||
from pytest_homeassistant.common import MockConfigEntry
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.stookwijzer.const import DOMAIN, SERVICE_GET_FORECAST
|
||||
from homeassistant.const import ATTR_CONFIG_ENTRY_ID
|
||||
from homeassistant.components.stookwijzer.const import DOMAIN
|
||||
from homeassistant.components.stookwijzer.services import StookwijzerService
|
||||
from homeassistant.const import CommonServiceArgument
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@@ -22,8 +23,8 @@ async def test_service_get_forecast(
|
||||
|
||||
assert snapshot == await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_GET_FORECAST,
|
||||
{ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id},
|
||||
StookwijzerService.GET_FORECAST,
|
||||
{CommonServiceArgument.CONFIG_ENTRY_ID: mock_config_entry.entry_id},
|
||||
blocking=True,
|
||||
return_response=True,
|
||||
)
|
||||
@@ -42,8 +43,8 @@ async def test_service_entry_not_loaded(
|
||||
with pytest.raises(ServiceValidationError) as err:
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_GET_FORECAST,
|
||||
{ATTR_CONFIG_ENTRY_ID: mock_config_entry2.entry_id},
|
||||
StookwijzerService.GET_FORECAST,
|
||||
{CommonServiceArgument.CONFIG_ENTRY_ID: mock_config_entry2.entry_id},
|
||||
blocking=True,
|
||||
return_response=True,
|
||||
)
|
||||
@@ -60,8 +61,8 @@ async def test_service_integration_not_found(
|
||||
with pytest.raises(ServiceValidationError) as err:
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_GET_FORECAST,
|
||||
{ATTR_CONFIG_ENTRY_ID: "bad-config_id"},
|
||||
StookwijzerService.GET_FORECAST,
|
||||
{CommonServiceArgument.CONFIG_ENTRY_ID: "bad-config_id"},
|
||||
blocking=True,
|
||||
return_response=True,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user