Move netatmo camera and climate service registrations to services module (#184422)

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
epenet
2026-10-06 09:40:16 +02:00
committed by GitHub
co-authored by Claude Opus 5
parent 8994cd239f
commit 5819bbea54
3 changed files with 112 additions and 80 deletions
@@ -4,7 +4,6 @@ import logging
from typing import Any, cast, override
import aiohttp
import probatio
from pyatmo import ApiError as NetatmoApiError, modules as NaModules
from pyatmo.event import Event as NaEvent
@@ -12,7 +11,6 @@ from homeassistant.components.camera import Camera, CameraEntityFeature
from homeassistant.const import ATTR_PERSONS
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@@ -20,7 +18,6 @@ from .const import (
ATTR_CAMERA_LIGHT_MODE,
ATTR_EVENT_TYPE,
ATTR_PERSON,
CAMERA_LIGHT_MODES,
CAMERA_TRIGGERS,
CONF_URL_SECURITY,
DOMAIN,
@@ -32,9 +29,6 @@ from .const import (
MANUFACTURER,
NETATMO_ALIM_STATUS_ONLINE,
NETATMO_CREATE_CAMERA,
SERVICE_SET_CAMERA_LIGHT,
SERVICE_SET_PERSON_AWAY,
SERVICE_SET_PERSONS_HOME,
WEBHOOK_PUSH_TYPE,
)
from .coordinator import EVENT, HOME, SIGNAL_NAME, NetatmoConfigEntry, NetatmoDevice
@@ -64,28 +58,6 @@ async def async_setup_entry(
async_dispatcher_connect(hass, NETATMO_CREATE_CAMERA, _create_entity)
)
platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service(
SERVICE_SET_PERSONS_HOME,
{
probatio.Required(ATTR_PERSONS): probatio.All(
probatio.EnsureList(), [cv.string]
)
},
"_service_set_persons_home",
)
platform.async_register_entity_service(
SERVICE_SET_PERSON_AWAY,
{probatio.Optional(ATTR_PERSON): cv.string},
"_service_set_person_away",
)
platform.async_register_entity_service(
SERVICE_SET_CAMERA_LIGHT,
{probatio.Required(ATTR_CAMERA_LIGHT_MODE): probatio.In(CAMERA_LIGHT_MODES)},
"_service_set_camera_light",
)
class NetatmoCamera(NetatmoModuleEntity, Camera):
"""Representation of a Netatmo camera."""
@@ -3,7 +3,6 @@
import logging
from typing import Any, cast, override
import probatio
from pyatmo.modules import NATherm1
from pyatmo.modules.device_types import DeviceType
@@ -25,7 +24,6 @@ from homeassistant.const import (
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.util import dt as dt_util
@@ -44,11 +42,6 @@ from .const import (
EVENT_TYPE_SET_POINT,
EVENT_TYPE_THERM_MODE,
NETATMO_CREATE_CLIMATE,
SERVICE_CLEAR_TEMPERATURE_SETTING,
SERVICE_SET_PRESET_MODE_WITH_END_DATETIME,
SERVICE_SET_SCHEDULE,
SERVICE_SET_TEMPERATURE_WITH_END_DATETIME,
SERVICE_SET_TEMPERATURE_WITH_TIME_PERIOD,
)
from .coordinator import HOME, SIGNAL_NAME, NetatmoConfigEntry, NetatmoRoom
from .entity import NetatmoRoomEntity
@@ -137,49 +130,6 @@ async def async_setup_entry(
async_dispatcher_connect(hass, NETATMO_CREATE_CLIMATE, _create_entity)
)
platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service(
SERVICE_SET_SCHEDULE,
{probatio.Required(ATTR_SCHEDULE_NAME): cv.string},
"_async_service_set_schedule",
)
platform.async_register_entity_service(
SERVICE_SET_PRESET_MODE_WITH_END_DATETIME,
{
probatio.Required(ATTR_PRESET_MODE): probatio.In(THERM_MODES),
probatio.Required(ATTR_END_DATETIME): cv.datetime,
},
"_async_service_set_preset_mode_with_end_datetime",
)
platform.async_register_entity_service(
SERVICE_SET_TEMPERATURE_WITH_END_DATETIME,
{
probatio.Required(ATTR_TARGET_TEMPERATURE): probatio.All(
probatio.Coerce(float), probatio.Range(min=7, max=30)
),
probatio.Required(ATTR_END_DATETIME): cv.datetime,
},
"_async_service_set_temperature_with_end_datetime",
)
platform.async_register_entity_service(
SERVICE_SET_TEMPERATURE_WITH_TIME_PERIOD,
{
probatio.Required(ATTR_TARGET_TEMPERATURE): probatio.All(
probatio.Coerce(float), probatio.Range(min=7, max=30)
),
probatio.Required(ATTR_TIME_PERIOD): probatio.All(
cv.time_period,
cv.positive_timedelta,
),
},
"_async_service_set_temperature_with_time_period",
)
platform.async_register_entity_service(
SERVICE_CLEAR_TEMPERATURE_SETTING,
None,
"_async_service_clear_temperature_setting",
)
class NetatmoThermostat(NetatmoRoomEntity, ClimateEntity):
"""Representation a Netatmo thermostat."""
+112 -2
View File
@@ -1,10 +1,34 @@
"""Services for the Netatmo integration."""
import probatio
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
from homeassistant.components.climate import ATTR_PRESET_MODE, DOMAIN as CLIMATE_DOMAIN
from homeassistant.const import ATTR_PERSONS
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers import issue_registry as ir
from homeassistant.helpers import config_validation as cv, issue_registry as ir
from homeassistant.helpers.service import async_register_platform_entity_service
from .const import DOMAIN
from .climate import THERM_MODES
from .const import (
ATTR_CAMERA_LIGHT_MODE,
ATTR_END_DATETIME,
ATTR_PERSON,
ATTR_SCHEDULE_NAME,
ATTR_TARGET_TEMPERATURE,
ATTR_TIME_PERIOD,
CAMERA_LIGHT_MODES,
DOMAIN,
SERVICE_CLEAR_TEMPERATURE_SETTING,
SERVICE_SET_CAMERA_LIGHT,
SERVICE_SET_PERSON_AWAY,
SERVICE_SET_PERSONS_HOME,
SERVICE_SET_PRESET_MODE_WITH_END_DATETIME,
SERVICE_SET_SCHEDULE,
SERVICE_SET_TEMPERATURE_WITH_END_DATETIME,
SERVICE_SET_TEMPERATURE_WITH_TIME_PERIOD,
)
from .coordinator import NetatmoConfigEntry, async_get_loaded_entry
from .webhook import async_register_webhook, async_unregister_webhook
@@ -58,3 +82,89 @@ def async_setup_services(hass: HomeAssistant) -> None:
hass.services.async_register(
DOMAIN, SERVICE_UNREGISTER_WEBHOOK, _unregister_webhook
)
async_register_platform_entity_service(
hass,
DOMAIN,
SERVICE_SET_PERSONS_HOME,
entity_domain=CAMERA_DOMAIN,
func="_service_set_persons_home",
schema={
probatio.Required(ATTR_PERSONS): probatio.All(
probatio.EnsureList(), [cv.string]
)
},
)
async_register_platform_entity_service(
hass,
DOMAIN,
SERVICE_SET_PERSON_AWAY,
entity_domain=CAMERA_DOMAIN,
func="_service_set_person_away",
schema={probatio.Optional(ATTR_PERSON): cv.string},
)
async_register_platform_entity_service(
hass,
DOMAIN,
SERVICE_SET_CAMERA_LIGHT,
entity_domain=CAMERA_DOMAIN,
func="_service_set_camera_light",
schema={
probatio.Required(ATTR_CAMERA_LIGHT_MODE): probatio.In(CAMERA_LIGHT_MODES)
},
)
async_register_platform_entity_service(
hass,
DOMAIN,
SERVICE_SET_SCHEDULE,
entity_domain=CLIMATE_DOMAIN,
func="_async_service_set_schedule",
schema={probatio.Required(ATTR_SCHEDULE_NAME): cv.string},
)
async_register_platform_entity_service(
hass,
DOMAIN,
SERVICE_SET_PRESET_MODE_WITH_END_DATETIME,
entity_domain=CLIMATE_DOMAIN,
func="_async_service_set_preset_mode_with_end_datetime",
schema={
probatio.Required(ATTR_PRESET_MODE): probatio.In(THERM_MODES),
probatio.Required(ATTR_END_DATETIME): cv.datetime,
},
)
async_register_platform_entity_service(
hass,
DOMAIN,
SERVICE_SET_TEMPERATURE_WITH_END_DATETIME,
entity_domain=CLIMATE_DOMAIN,
func="_async_service_set_temperature_with_end_datetime",
schema={
probatio.Required(ATTR_TARGET_TEMPERATURE): probatio.All(
probatio.Coerce(float), probatio.Range(min=7, max=30)
),
probatio.Required(ATTR_END_DATETIME): cv.datetime,
},
)
async_register_platform_entity_service(
hass,
DOMAIN,
SERVICE_SET_TEMPERATURE_WITH_TIME_PERIOD,
entity_domain=CLIMATE_DOMAIN,
func="_async_service_set_temperature_with_time_period",
schema={
probatio.Required(ATTR_TARGET_TEMPERATURE): probatio.All(
probatio.Coerce(float), probatio.Range(min=7, max=30)
),
probatio.Required(ATTR_TIME_PERIOD): probatio.All(
cv.time_period,
cv.positive_timedelta,
),
},
)
async_register_platform_entity_service(
hass,
DOMAIN,
SERVICE_CLEAR_TEMPERATURE_SETTING,
entity_domain=CLIMATE_DOMAIN,
func="_async_service_clear_temperature_setting",
schema=None,
)