mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 12:21:04 -04:00
Move snooz service registration to services module (#184488)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
306349ebf8
commit
d643ea362d
@@ -14,9 +14,20 @@ from homeassistant.components.bluetooth import (
|
||||
from homeassistant.const import CONF_ADDRESS, CONF_TOKEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import DOMAIN, PLATFORMS
|
||||
from .models import SnoozConfigEntry, SnoozConfigurationData
|
||||
from .services import async_setup_services
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Snooz integration."""
|
||||
async_setup_services(hass)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: SnoozConfigEntry) -> bool:
|
||||
|
||||
@@ -4,7 +4,6 @@ from collections.abc import Callable
|
||||
from datetime import timedelta
|
||||
from typing import Any, override
|
||||
|
||||
import probatio
|
||||
from pysnooz import UnknownSnoozState
|
||||
from pysnooz.commands import (
|
||||
SnoozCommandData,
|
||||
@@ -22,19 +21,11 @@ from homeassistant.components.fan import (
|
||||
from homeassistant.const import STATE_OFF, STATE_ON
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_platform
|
||||
from homeassistant.helpers.device_registry import CONNECTION_BLUETOOTH, DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
|
||||
from .const import (
|
||||
ATTR_DURATION,
|
||||
ATTR_VOLUME,
|
||||
DEFAULT_TRANSITION_DURATION,
|
||||
DOMAIN,
|
||||
SERVICE_TRANSITION_OFF,
|
||||
SERVICE_TRANSITION_ON,
|
||||
)
|
||||
from .const import DOMAIN
|
||||
from .models import SnoozConfigEntry, SnoozConfigurationData
|
||||
|
||||
|
||||
@@ -45,29 +36,6 @@ async def async_setup_entry(
|
||||
) -> None:
|
||||
"""Set up Snooz device from a config entry."""
|
||||
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_TRANSITION_ON,
|
||||
{
|
||||
probatio.Optional(ATTR_VOLUME): probatio.All(
|
||||
probatio.Coerce(int), probatio.Percentage()
|
||||
),
|
||||
probatio.Optional(
|
||||
ATTR_DURATION, default=DEFAULT_TRANSITION_DURATION
|
||||
): probatio.All(probatio.Coerce(int), probatio.Range(min=1, max=300)),
|
||||
},
|
||||
"async_transition_on",
|
||||
)
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_TRANSITION_OFF,
|
||||
{
|
||||
probatio.Optional(
|
||||
ATTR_DURATION, default=DEFAULT_TRANSITION_DURATION
|
||||
): probatio.All(probatio.Coerce(int), probatio.Range(min=1, max=300)),
|
||||
},
|
||||
"async_transition_off",
|
||||
)
|
||||
|
||||
async_add_entities([SnoozFan(entry.runtime_data)])
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
"""Services for the Snooz integration."""
|
||||
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.fan import DOMAIN as FAN_DOMAIN
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import service
|
||||
|
||||
from .const import (
|
||||
ATTR_DURATION,
|
||||
ATTR_VOLUME,
|
||||
DEFAULT_TRANSITION_DURATION,
|
||||
DOMAIN,
|
||||
SERVICE_TRANSITION_OFF,
|
||||
SERVICE_TRANSITION_ON,
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up the services for the Snooz integration."""
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_TRANSITION_ON,
|
||||
entity_domain=FAN_DOMAIN,
|
||||
schema={
|
||||
probatio.Optional(ATTR_VOLUME): probatio.All(
|
||||
probatio.Coerce(int), probatio.Percentage()
|
||||
),
|
||||
probatio.Optional(
|
||||
ATTR_DURATION, default=DEFAULT_TRANSITION_DURATION
|
||||
): probatio.All(probatio.Coerce(int), probatio.Range(min=1, max=300)),
|
||||
},
|
||||
func="async_transition_on",
|
||||
)
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_TRANSITION_OFF,
|
||||
entity_domain=FAN_DOMAIN,
|
||||
schema={
|
||||
probatio.Optional(
|
||||
ATTR_DURATION, default=DEFAULT_TRANSITION_DURATION
|
||||
): probatio.All(probatio.Coerce(int), probatio.Range(min=1, max=300))
|
||||
},
|
||||
func="async_transition_off",
|
||||
)
|
||||
Reference in New Issue
Block a user