mirror of
https://github.com/home-assistant/core.git
synced 2026-12-05 05:14:01 -04:00
Move modern_forms service registration to services module (#184603)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e07df2a291
commit
23f2302b14
@@ -8,10 +8,13 @@ from aiomodernforms import ModernFormsConnectionError, ModernFormsError
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import ModernFormsConfigEntry, ModernFormsDataUpdateCoordinator
|
||||
from .entity import ModernFormsDeviceEntity
|
||||
from .services import async_setup_services
|
||||
|
||||
PLATFORMS = [
|
||||
Platform.BINARY_SENSOR,
|
||||
@@ -24,6 +27,15 @@ PLATFORMS = [
|
||||
]
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Modern Forms integration."""
|
||||
async_setup_services(hass)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ModernFormsConfigEntry) -> bool:
|
||||
"""Set up a Modern Forms device from a config entry."""
|
||||
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
from typing import Any, override
|
||||
|
||||
from aiomodernforms.const import FAN_POWER_OFF, FAN_POWER_ON
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.fan import FanEntity, FanEntityFeature
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.util.percentage import (
|
||||
percentage_to_ranged_value,
|
||||
@@ -17,16 +15,7 @@ from homeassistant.util.percentage import (
|
||||
from homeassistant.util.scaling import int_states_in_range
|
||||
|
||||
from . import modernforms_exception_handler
|
||||
from .const import (
|
||||
ATTR_SLEEP_TIME,
|
||||
CLEAR_TIMER,
|
||||
DOMAIN,
|
||||
OPT_ON,
|
||||
OPT_SPEED,
|
||||
OPT_WIND,
|
||||
SERVICE_CLEAR_FAN_SLEEP_TIMER,
|
||||
SERVICE_SET_FAN_SLEEP_TIMER,
|
||||
)
|
||||
from .const import CLEAR_TIMER, DOMAIN, OPT_ON, OPT_SPEED, OPT_WIND
|
||||
from .coordinator import ModernFormsConfigEntry, ModernFormsDataUpdateCoordinator
|
||||
from .entity import ModernFormsDeviceEntity
|
||||
|
||||
@@ -43,24 +32,6 @@ async def async_setup_entry(
|
||||
|
||||
coordinator = config_entry.runtime_data
|
||||
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_SET_FAN_SLEEP_TIMER,
|
||||
{
|
||||
probatio.Required(ATTR_SLEEP_TIME): probatio.All(
|
||||
probatio.Coerce(int), probatio.Range(min=1, max=1440)
|
||||
),
|
||||
},
|
||||
"async_set_fan_sleep_timer",
|
||||
)
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_CLEAR_FAN_SLEEP_TIMER,
|
||||
None,
|
||||
"async_clear_fan_sleep_timer",
|
||||
)
|
||||
|
||||
async_add_entities(
|
||||
[ModernFormsFanEntity(entry_id=config_entry.entry_id, coordinator=coordinator)]
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ from typing import Any, override
|
||||
|
||||
from aiomodernforms.const import LIGHT_POWER_OFF, LIGHT_POWER_ON
|
||||
from aiomodernforms.models import Light
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
@@ -14,7 +13,6 @@ from homeassistant.components.light import (
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.util.percentage import (
|
||||
percentage_to_ranged_value,
|
||||
@@ -22,16 +20,7 @@ from homeassistant.util.percentage import (
|
||||
)
|
||||
|
||||
from . import modernforms_exception_handler
|
||||
from .const import (
|
||||
ATTR_SLEEP_TIME,
|
||||
CLEAR_TIMER,
|
||||
DOMAIN,
|
||||
OPT_BRIGHTNESS,
|
||||
OPT_COLOR_TEMP_KELVIN,
|
||||
OPT_ON,
|
||||
SERVICE_CLEAR_LIGHT_SLEEP_TIMER,
|
||||
SERVICE_SET_LIGHT_SLEEP_TIMER,
|
||||
)
|
||||
from .const import CLEAR_TIMER, DOMAIN, OPT_BRIGHTNESS, OPT_COLOR_TEMP_KELVIN, OPT_ON
|
||||
from .coordinator import ModernFormsConfigEntry, ModernFormsDataUpdateCoordinator
|
||||
from .entity import ModernFormsDeviceEntity, strip_device_name_prefix
|
||||
|
||||
@@ -51,24 +40,6 @@ async def async_setup_entry(
|
||||
if not coordinator.data.info.light_type:
|
||||
return
|
||||
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_SET_LIGHT_SLEEP_TIMER,
|
||||
{
|
||||
probatio.Required(ATTR_SLEEP_TIME): probatio.All(
|
||||
probatio.Coerce(int), probatio.Range(min=1, max=1440)
|
||||
),
|
||||
},
|
||||
"async_set_light_sleep_timer",
|
||||
)
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_CLEAR_LIGHT_SLEEP_TIMER,
|
||||
None,
|
||||
"async_clear_light_sleep_timer",
|
||||
)
|
||||
|
||||
async_add_entities(
|
||||
ModernFormsLightEntity(
|
||||
entry_id=config_entry.entry_id,
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
"""Services for the Modern Forms integration."""
|
||||
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.fan import DOMAIN as FAN_DOMAIN
|
||||
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import service
|
||||
|
||||
from .const import (
|
||||
ATTR_SLEEP_TIME,
|
||||
DOMAIN,
|
||||
SERVICE_CLEAR_FAN_SLEEP_TIMER,
|
||||
SERVICE_CLEAR_LIGHT_SLEEP_TIMER,
|
||||
SERVICE_SET_FAN_SLEEP_TIMER,
|
||||
SERVICE_SET_LIGHT_SLEEP_TIMER,
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up the services for the Modern Forms integration."""
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_SET_FAN_SLEEP_TIMER,
|
||||
entity_domain=FAN_DOMAIN,
|
||||
schema={
|
||||
probatio.Required(ATTR_SLEEP_TIME): probatio.All(
|
||||
probatio.Coerce(int), probatio.Range(min=1, max=1440)
|
||||
)
|
||||
},
|
||||
func="async_set_fan_sleep_timer",
|
||||
)
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_CLEAR_FAN_SLEEP_TIMER,
|
||||
entity_domain=FAN_DOMAIN,
|
||||
schema=None,
|
||||
func="async_clear_fan_sleep_timer",
|
||||
)
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_SET_LIGHT_SLEEP_TIMER,
|
||||
entity_domain=LIGHT_DOMAIN,
|
||||
schema={
|
||||
probatio.Required(ATTR_SLEEP_TIME): probatio.All(
|
||||
probatio.Coerce(int), probatio.Range(min=1, max=1440)
|
||||
)
|
||||
},
|
||||
func="async_set_light_sleep_timer",
|
||||
)
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_CLEAR_LIGHT_SLEEP_TIMER,
|
||||
entity_domain=LIGHT_DOMAIN,
|
||||
schema=None,
|
||||
func="async_clear_light_sleep_timer",
|
||||
)
|
||||
Reference in New Issue
Block a user