Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated services from Ezviz #107582

Merged
merged 1 commit into from Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
104 changes: 1 addition & 103 deletions homeassistant/components/ezviz/camera.py
Expand Up @@ -4,7 +4,6 @@
import logging

from pyezviz.exceptions import HTTPError, InvalidHost, PyEzvizError
import voluptuous as vol

from homeassistant.components import ffmpeg
from homeassistant.components.camera import Camera, CameraEntityFeature
Expand All @@ -17,34 +16,19 @@
)
from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.helpers import (
config_validation as cv,
discovery_flow,
issue_registry as ir,
)
from homeassistant.helpers import discovery_flow
from homeassistant.helpers.entity_platform import (
AddEntitiesCallback,
async_get_current_platform,
)

from .const import (
ATTR_DIRECTION,
ATTR_ENABLE,
ATTR_LEVEL,
ATTR_SERIAL,
ATTR_SPEED,
CONF_FFMPEG_ARGUMENTS,
DATA_COORDINATOR,
DEFAULT_CAMERA_USERNAME,
DEFAULT_FFMPEG_ARGUMENTS,
DIR_DOWN,
DIR_LEFT,
DIR_RIGHT,
DIR_UP,
DOMAIN,
SERVICE_ALARM_SOUND,
SERVICE_ALARM_TRIGGER,
SERVICE_PTZ,
SERVICE_WAKE_DEVICE,
)
from .coordinator import EzvizDataUpdateCoordinator
Expand Down Expand Up @@ -126,35 +110,10 @@ async def async_setup_entry(

platform = async_get_current_platform()

platform.async_register_entity_service(
SERVICE_PTZ,
{
vol.Required(ATTR_DIRECTION): vol.In(
[DIR_UP, DIR_DOWN, DIR_LEFT, DIR_RIGHT]
),
vol.Required(ATTR_SPEED): cv.positive_int,
},
"perform_ptz",
)

platform.async_register_entity_service(
SERVICE_ALARM_TRIGGER,
{
vol.Required(ATTR_ENABLE): cv.positive_int,
},
"perform_sound_alarm",
)

platform.async_register_entity_service(
SERVICE_WAKE_DEVICE, {}, "perform_wake_device"
)

platform.async_register_entity_service(
SERVICE_ALARM_SOUND,
{vol.Required(ATTR_LEVEL): cv.positive_int},
"perform_alarm_sound",
)


class EzvizCamera(EzvizEntity, Camera):
"""An implementation of a EZVIZ security camera."""
Expand Down Expand Up @@ -251,70 +210,9 @@ async def stream_source(self) -> str | None:

return self._rtsp_stream

def perform_ptz(self, direction: str, speed: int) -> None:
"""Perform a PTZ action on the camera."""
ir.async_create_issue(
self.hass,
DOMAIN,
"service_depreciation_ptz",
breaks_in_ha_version="2024.2.0",
is_fixable=True,
is_persistent=True,
severity=ir.IssueSeverity.WARNING,
translation_key="service_depreciation_ptz",
)

try:
self.coordinator.ezviz_client.ptz_control(
str(direction).upper(), self._serial, "START", speed
)
self.coordinator.ezviz_client.ptz_control(
str(direction).upper(), self._serial, "STOP", speed
)

except HTTPError as err:
raise HTTPError("Cannot perform PTZ") from err

def perform_sound_alarm(self, enable: int) -> None:
"""Sound the alarm on a camera."""
ir.async_create_issue(
self.hass,
DOMAIN,
"service_depreciation_sound_alarm",
breaks_in_ha_version="2024.3.0",
is_fixable=True,
is_persistent=True,
severity=ir.IssueSeverity.WARNING,
translation_key="service_depreciation_sound_alarm",
)

try:
self.coordinator.ezviz_client.sound_alarm(self._serial, enable)
except HTTPError as err:
raise HTTPError("Cannot sound alarm") from err

def perform_wake_device(self) -> None:
"""Basically wakes the camera by querying the device."""
try:
self.coordinator.ezviz_client.get_detection_sensibility(self._serial)
except (HTTPError, PyEzvizError) as err:
raise PyEzvizError("Cannot wake device") from err

def perform_alarm_sound(self, level: int) -> None:
"""Enable/Disable movement sound alarm."""
ir.async_create_issue(
self.hass,
DOMAIN,
"service_deprecation_alarm_sound_level",
breaks_in_ha_version="2024.2.0",
is_fixable=True,
is_persistent=True,
severity=ir.IssueSeverity.WARNING,
translation_key="service_deprecation_alarm_sound_level",
)
try:
self.coordinator.ezviz_client.alarm_sound(self._serial, level, 1)
except HTTPError as err:
raise HTTPError(
"Cannot set alarm sound level for on movement detected"
) from err
3 changes: 0 additions & 3 deletions homeassistant/components/ezviz/const.py
Expand Up @@ -24,10 +24,7 @@
ATTR_TYPE = "type_value"

# Service names
SERVICE_PTZ = "ptz"
SERVICE_ALARM_TRIGGER = "sound_alarm"
SERVICE_WAKE_DEVICE = "wake_device"
SERVICE_ALARM_SOUND = "alarm_sound"
SERVICE_DETECTION_SENSITIVITY = "set_alarm_detection_sensibility"

# Defaults
Expand Down
60 changes: 1 addition & 59 deletions homeassistant/components/ezviz/services.yaml
@@ -1,46 +1,3 @@
alarm_sound:
target:
entity:
integration: ezviz
domain: camera
fields:
level:
required: true
example: 0
default: 0
selector:
number:
min: 0
max: 2
step: 1
mode: box
ptz:
target:
entity:
integration: ezviz
domain: camera
fields:
direction:
required: true
example: "up"
default: "up"
selector:
select:
options:
- "up"
- "down"
- "left"
- "right"
speed:
required: true
example: 5
default: 5
selector:
number:
min: 1
max: 9
step: 1
mode: box
set_alarm_detection_sensibility:
target:
entity:
Expand All @@ -66,22 +23,7 @@ set_alarm_detection_sensibility:
options:
- "0"
- "3"
sound_alarm:
target:
entity:
integration: ezviz
domain: camera
fields:
enable:
required: true
example: 1
default: 1
selector:
number:
min: 1
max: 2
step: 1
mode: box

wake_device:
target:
entity:
Expand Down
69 changes: 0 additions & 69 deletions homeassistant/components/ezviz/strings.json
Expand Up @@ -59,41 +59,6 @@
}
}
},
"issues": {
"service_deprecation_alarm_sound_level": {
"title": "Ezviz Alarm sound level service is being removed",
"fix_flow": {
"step": {
"confirm": {
"title": "[%key:component::ezviz::issues::service_deprecation_alarm_sound_level::title%]",
"description": "Ezviz Alarm sound level service is deprecated and will be removed.\nTo set the Alarm sound level, you can instead use the `select.select_option` service targetting the Warning sound entity.\n\nPlease remove this service from your automations and scripts and select **submit** to close this issue."
}
}
}
},
"service_depreciation_ptz": {
"title": "EZVIZ PTZ service is being removed",
"fix_flow": {
"step": {
"confirm": {
"title": "[%key:component::ezviz::issues::service_depreciation_ptz::title%]",
"description": "EZVIZ PTZ service is deprecated and will be removed.\nTo move the camera, you can instead use the `button.press` service targetting the PTZ* entities.\n\nPlease remove the use of this service from your automations and scripts and select **submit** to close this issue."
}
}
}
},
"service_depreciation_sound_alarm": {
"title": "Ezviz Sound alarm service is being removed",
"fix_flow": {
"step": {
"confirm": {
"title": "[%key:component::ezviz::issues::service_depreciation_sound_alarm::title%]",
"description": "Ezviz Sound alarm service is deprecated and will be removed.\nTo sound the alarm, you can instead use the `siren.toggle` service targeting the Siren entity.\n\nPlease remove the use of this service from your automations and scripts and select **submit** to fix this issue."
}
}
}
}
},
"entity": {
"select": {
"alarm_sound_mode": {
Expand Down Expand Up @@ -219,30 +184,6 @@
}
},
"services": {
"alarm_sound": {
"name": "Set warning sound level.",
"description": "Setx movement warning sound level.",
"fields": {
"level": {
"name": "Sound level",
"description": "Sound level (2 is disabled, 1 intensive, 0 soft)."
}
}
},
"ptz": {
"name": "PTZ",
"description": "Moves the camera to the direction, with defined speed.",
"fields": {
"direction": {
"name": "Direction",
"description": "Direction to move camera (up, down, left, right)."
},
"speed": {
"name": "Speed",
"description": "Speed of movement (from 1 to 9)."
}
}
},
"set_alarm_detection_sensibility": {
"name": "Detection sensitivity",
"description": "Sets the detection sensibility level.",
Expand All @@ -257,16 +198,6 @@
}
}
},
"sound_alarm": {
"name": "Sound alarm",
"description": "Sounds the alarm on your camera.",
"fields": {
"enable": {
"name": "Alarm sound",
"description": "Enter 1 or 2 (1=disable, 2=enable)."
}
}
},
"wake_device": {
"name": "Wake camera",
"description": "This can be used to wake the camera/device from hibernation."
Expand Down