mirror of
https://github.com/home-assistant/core.git
synced 2026-12-05 05:14:01 -04:00
Move motioneye service registration to services module (#184605)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
b0f226dc75
commit
de68f036d6
@@ -47,13 +47,14 @@ from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import ATTR_DEVICE_ID, ATTR_NAME, CONF_URL, CONF_WEBHOOK_ID
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_connect,
|
||||
async_dispatcher_send,
|
||||
)
|
||||
from homeassistant.helpers.network import NoURLAvailableError, get_url
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import (
|
||||
ATTR_EVENT_TYPE,
|
||||
@@ -79,6 +80,7 @@ from .const import (
|
||||
WEB_HOOK_SENTINEL_VALUE,
|
||||
)
|
||||
from .coordinator import MotionEyeConfigEntry, MotionEyeUpdateCoordinator
|
||||
from .services import async_setup_services
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
PLATFORMS = [CAMERA_DOMAIN, SENSOR_DOMAIN, SWITCH_DOMAIN]
|
||||
@@ -272,6 +274,15 @@ def _add_camera(
|
||||
)
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the motionEye integration."""
|
||||
async_setup_services(hass)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: MotionEyeConfigEntry) -> bool:
|
||||
"""Set up motionEye from a config entry."""
|
||||
|
||||
|
||||
@@ -12,16 +12,11 @@ from motioneye_client.const import (
|
||||
KEY_ACTION_SNAPSHOT,
|
||||
KEY_MOTION_DETECTION,
|
||||
KEY_STREAMING_AUTH_MODE,
|
||||
KEY_TEXT_OVERLAY_CAMERA_NAME,
|
||||
KEY_TEXT_OVERLAY_CUSTOM_TEXT,
|
||||
KEY_TEXT_OVERLAY_CUSTOM_TEXT_LEFT,
|
||||
KEY_TEXT_OVERLAY_CUSTOM_TEXT_RIGHT,
|
||||
KEY_TEXT_OVERLAY_DISABLED,
|
||||
KEY_TEXT_OVERLAY_LEFT,
|
||||
KEY_TEXT_OVERLAY_RIGHT,
|
||||
KEY_TEXT_OVERLAY_TIMESTAMP,
|
||||
)
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.mjpeg import (
|
||||
CONF_MJPEG_URL,
|
||||
@@ -29,7 +24,6 @@ from homeassistant.components.mjpeg import (
|
||||
MjpegCamera,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_ACTION,
|
||||
CONF_AUTHENTICATION,
|
||||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
@@ -39,7 +33,6 @@ from homeassistant.const import (
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import get_camera_from_cameras, is_acceptable_camera, listen_for_new_cameras
|
||||
@@ -48,9 +41,6 @@ from .const import (
|
||||
CONF_SURVEILLANCE_PASSWORD,
|
||||
CONF_SURVEILLANCE_USERNAME,
|
||||
MOTIONEYE_MANUFACTURER,
|
||||
SERVICE_ACTION,
|
||||
SERVICE_SET_TEXT_OVERLAY,
|
||||
SERVICE_SNAPSHOT,
|
||||
TYPE_MOTIONEYE_MJPEG_CAMERA,
|
||||
)
|
||||
from .coordinator import MotionEyeConfigEntry, MotionEyeUpdateCoordinator
|
||||
@@ -58,33 +48,6 @@ from .entity import MotionEyeEntity
|
||||
|
||||
PLATFORMS = [Platform.CAMERA]
|
||||
|
||||
SCHEMA_TEXT_OVERLAY = probatio.In(
|
||||
[
|
||||
KEY_TEXT_OVERLAY_DISABLED,
|
||||
KEY_TEXT_OVERLAY_TIMESTAMP,
|
||||
KEY_TEXT_OVERLAY_CUSTOM_TEXT,
|
||||
KEY_TEXT_OVERLAY_CAMERA_NAME,
|
||||
]
|
||||
)
|
||||
SCHEMA_SERVICE_SET_TEXT = probatio.Schema(
|
||||
probatio.All(
|
||||
cv.make_entity_service_schema(
|
||||
{
|
||||
probatio.Optional(KEY_TEXT_OVERLAY_LEFT): SCHEMA_TEXT_OVERLAY,
|
||||
probatio.Optional(KEY_TEXT_OVERLAY_CUSTOM_TEXT_LEFT): cv.string,
|
||||
probatio.Optional(KEY_TEXT_OVERLAY_RIGHT): SCHEMA_TEXT_OVERLAY,
|
||||
probatio.Optional(KEY_TEXT_OVERLAY_CUSTOM_TEXT_RIGHT): cv.string,
|
||||
},
|
||||
),
|
||||
probatio.AtLeastOne(
|
||||
KEY_TEXT_OVERLAY_LEFT,
|
||||
KEY_TEXT_OVERLAY_CUSTOM_TEXT_LEFT,
|
||||
KEY_TEXT_OVERLAY_RIGHT,
|
||||
KEY_TEXT_OVERLAY_CUSTOM_TEXT_RIGHT,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
@@ -115,23 +78,6 @@ async def async_setup_entry(
|
||||
|
||||
listen_for_new_cameras(hass, entry, camera_add)
|
||||
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_SET_TEXT_OVERLAY,
|
||||
SCHEMA_SERVICE_SET_TEXT,
|
||||
"async_set_text_overlay",
|
||||
)
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_ACTION,
|
||||
{probatio.Required(CONF_ACTION): cv.string},
|
||||
"async_request_action",
|
||||
)
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_SNAPSHOT,
|
||||
None,
|
||||
"async_request_snapshot",
|
||||
)
|
||||
|
||||
|
||||
class MotionEyeMjpegCamera(MotionEyeEntity, MjpegCamera):
|
||||
"""motionEye mjpeg camera."""
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
"""Services for the motionEye integration."""
|
||||
|
||||
from motioneye_client.const import (
|
||||
KEY_TEXT_OVERLAY_CAMERA_NAME,
|
||||
KEY_TEXT_OVERLAY_CUSTOM_TEXT,
|
||||
KEY_TEXT_OVERLAY_CUSTOM_TEXT_LEFT,
|
||||
KEY_TEXT_OVERLAY_CUSTOM_TEXT_RIGHT,
|
||||
KEY_TEXT_OVERLAY_DISABLED,
|
||||
KEY_TEXT_OVERLAY_LEFT,
|
||||
KEY_TEXT_OVERLAY_RIGHT,
|
||||
KEY_TEXT_OVERLAY_TIMESTAMP,
|
||||
)
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
|
||||
from homeassistant.const import CONF_ACTION
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, service
|
||||
|
||||
from .const import DOMAIN, SERVICE_ACTION, SERVICE_SET_TEXT_OVERLAY, SERVICE_SNAPSHOT
|
||||
|
||||
SCHEMA_TEXT_OVERLAY = probatio.In(
|
||||
[
|
||||
KEY_TEXT_OVERLAY_DISABLED,
|
||||
KEY_TEXT_OVERLAY_TIMESTAMP,
|
||||
KEY_TEXT_OVERLAY_CUSTOM_TEXT,
|
||||
KEY_TEXT_OVERLAY_CAMERA_NAME,
|
||||
]
|
||||
)
|
||||
SCHEMA_SERVICE_SET_TEXT = probatio.Schema(
|
||||
probatio.All(
|
||||
cv.make_entity_service_schema(
|
||||
{
|
||||
probatio.Optional(KEY_TEXT_OVERLAY_LEFT): SCHEMA_TEXT_OVERLAY,
|
||||
probatio.Optional(KEY_TEXT_OVERLAY_CUSTOM_TEXT_LEFT): cv.string,
|
||||
probatio.Optional(KEY_TEXT_OVERLAY_RIGHT): SCHEMA_TEXT_OVERLAY,
|
||||
probatio.Optional(KEY_TEXT_OVERLAY_CUSTOM_TEXT_RIGHT): cv.string,
|
||||
},
|
||||
),
|
||||
probatio.AtLeastOne(
|
||||
KEY_TEXT_OVERLAY_LEFT,
|
||||
KEY_TEXT_OVERLAY_CUSTOM_TEXT_LEFT,
|
||||
KEY_TEXT_OVERLAY_RIGHT,
|
||||
KEY_TEXT_OVERLAY_CUSTOM_TEXT_RIGHT,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up the services for the motionEye integration."""
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_SET_TEXT_OVERLAY,
|
||||
entity_domain=CAMERA_DOMAIN,
|
||||
schema=SCHEMA_SERVICE_SET_TEXT,
|
||||
func="async_set_text_overlay",
|
||||
)
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_ACTION,
|
||||
entity_domain=CAMERA_DOMAIN,
|
||||
schema={probatio.Required(CONF_ACTION): cv.string},
|
||||
func="async_request_action",
|
||||
)
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_SNAPSHOT,
|
||||
entity_domain=CAMERA_DOMAIN,
|
||||
schema=None,
|
||||
func="async_request_snapshot",
|
||||
)
|
||||
Reference in New Issue
Block a user