mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Add action enums to workday (#191564)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"""Sensor to indicate whether the current day is a workday."""
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Final, override
|
||||
from typing import override
|
||||
|
||||
from holidays import HolidayBase
|
||||
|
||||
@@ -13,9 +13,6 @@ from . import WorkdayConfigEntry
|
||||
from .const import CONF_EXCLUDES, CONF_OFFSET, CONF_WORKDAYS
|
||||
from .entity import BaseWorkdayEntity
|
||||
|
||||
SERVICE_CHECK_DATE: Final = "check_date"
|
||||
CHECK_DATE: Final = "check_date"
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"""Services for the Workday integration."""
|
||||
|
||||
from enum import StrEnum
|
||||
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
@@ -8,8 +10,17 @@ from homeassistant.helpers import config_validation as cv, service
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
SERVICE_CHECK_DATE = "check_date"
|
||||
CHECK_DATE = "check_date"
|
||||
|
||||
class WorkdayService(StrEnum):
|
||||
"""Store keys for Workday services."""
|
||||
|
||||
CHECK_DATE = "check_date"
|
||||
|
||||
|
||||
class WorkdayServiceArgument(StrEnum):
|
||||
"""Store keys for Workday service arguments."""
|
||||
|
||||
CHECK_DATE = "check_date"
|
||||
|
||||
|
||||
@callback
|
||||
@@ -19,9 +30,9 @@ def async_setup_services(hass: HomeAssistant) -> None:
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_CHECK_DATE,
|
||||
WorkdayService.CHECK_DATE,
|
||||
entity_domain=BINARY_SENSOR_DOMAIN,
|
||||
schema={probatio.Required(CHECK_DATE): cv.date},
|
||||
schema={probatio.Required(WorkdayServiceArgument.CHECK_DATE): cv.date},
|
||||
func="check_date",
|
||||
supports_response=SupportsResponse.ONLY,
|
||||
)
|
||||
|
||||
@@ -8,7 +8,6 @@ import pytest
|
||||
from pytest_homeassistant.common import async_fire_time_changed
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.workday.binary_sensor import SERVICE_CHECK_DATE
|
||||
from homeassistant.components.workday.const import (
|
||||
DEFAULT_EXCLUDES,
|
||||
DEFAULT_NAME,
|
||||
@@ -16,6 +15,7 @@ from homeassistant.components.workday.const import (
|
||||
DEFAULT_WORKDAYS,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.components.workday.services import WorkdayService
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
from homeassistant.setup import async_setup_component
|
||||
@@ -358,7 +358,7 @@ async def test_check_date_service(
|
||||
|
||||
response = await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_CHECK_DATE,
|
||||
WorkdayService.CHECK_DATE,
|
||||
{
|
||||
"entity_id": "binary_sensor.workday_sensor_de_bw",
|
||||
"check_date": date(2022, 12, 25), # Christmas Day
|
||||
@@ -370,7 +370,7 @@ async def test_check_date_service(
|
||||
|
||||
response = await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_CHECK_DATE,
|
||||
WorkdayService.CHECK_DATE,
|
||||
{
|
||||
"entity_id": "binary_sensor.workday_sensor_de_bw",
|
||||
"check_date": date(2022, 12, 23), # Normal Friday
|
||||
@@ -382,7 +382,7 @@ async def test_check_date_service(
|
||||
|
||||
response = await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_CHECK_DATE,
|
||||
WorkdayService.CHECK_DATE,
|
||||
{
|
||||
"entity_id": "binary_sensor.workday_sensor_de_bw",
|
||||
"check_date": date(2022, 12, 17), # Saturday (no workday)
|
||||
|
||||
Reference in New Issue
Block a user