mirror of
https://github.com/home-assistant/core.git
synced 2025-04-29 11:47:50 +00:00
Add option to select quality of camera snapshots taken from Synology DSM connected cameras (#58306)
This commit is contained in:
parent
d2eda91588
commit
eda5cfc12d
@ -22,7 +22,14 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
from . import SynoApi, SynologyDSMBaseEntity
|
from . import SynoApi, SynologyDSMBaseEntity
|
||||||
from .const import COORDINATOR_CAMERAS, DOMAIN, SYNO_API, SynologyDSMEntityDescription
|
from .const import (
|
||||||
|
CONF_SNAPSHOT_QUALITY,
|
||||||
|
COORDINATOR_CAMERAS,
|
||||||
|
DEFAULT_SNAPSHOT_QUALITY,
|
||||||
|
DOMAIN,
|
||||||
|
SYNO_API,
|
||||||
|
SynologyDSMEntityDescription,
|
||||||
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -78,6 +85,9 @@ class SynoDSMCamera(SynologyDSMBaseEntity, Camera):
|
|||||||
camera_id
|
camera_id
|
||||||
].is_enabled,
|
].is_enabled,
|
||||||
)
|
)
|
||||||
|
self.snapshot_quality = api._entry.options.get(
|
||||||
|
CONF_SNAPSHOT_QUALITY, DEFAULT_SNAPSHOT_QUALITY
|
||||||
|
)
|
||||||
super().__init__(api, coordinator, description)
|
super().__init__(api, coordinator, description)
|
||||||
Camera.__init__(self)
|
Camera.__init__(self)
|
||||||
|
|
||||||
@ -135,7 +145,7 @@ class SynoDSMCamera(SynologyDSMBaseEntity, Camera):
|
|||||||
if not self.available:
|
if not self.available:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
return self._api.surveillance_station.get_camera_image(self.entity_description.key) # type: ignore[no-any-return]
|
return self._api.surveillance_station.get_camera_image(self.entity_description.key, self.snapshot_quality) # type: ignore[no-any-return]
|
||||||
except (
|
except (
|
||||||
SynologyDSMAPIErrorException,
|
SynologyDSMAPIErrorException,
|
||||||
SynologyDSMRequestException,
|
SynologyDSMRequestException,
|
||||||
|
@ -39,10 +39,12 @@ from homeassistant.helpers.typing import DiscoveryInfoType
|
|||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_DEVICE_TOKEN,
|
CONF_DEVICE_TOKEN,
|
||||||
|
CONF_SNAPSHOT_QUALITY,
|
||||||
CONF_VOLUMES,
|
CONF_VOLUMES,
|
||||||
DEFAULT_PORT,
|
DEFAULT_PORT,
|
||||||
DEFAULT_PORT_SSL,
|
DEFAULT_PORT_SSL,
|
||||||
DEFAULT_SCAN_INTERVAL,
|
DEFAULT_SCAN_INTERVAL,
|
||||||
|
DEFAULT_SNAPSHOT_QUALITY,
|
||||||
DEFAULT_TIMEOUT,
|
DEFAULT_TIMEOUT,
|
||||||
DEFAULT_USE_SSL,
|
DEFAULT_USE_SSL,
|
||||||
DEFAULT_VERIFY_SSL,
|
DEFAULT_VERIFY_SSL,
|
||||||
@ -357,18 +359,24 @@ class SynologyDSMOptionsFlowHandler(OptionsFlow):
|
|||||||
|
|
||||||
data_schema = vol.Schema(
|
data_schema = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Optional(
|
vol.Required(
|
||||||
CONF_SCAN_INTERVAL,
|
CONF_SCAN_INTERVAL,
|
||||||
default=self.config_entry.options.get(
|
default=self.config_entry.options.get(
|
||||||
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
|
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
|
||||||
),
|
),
|
||||||
): cv.positive_int,
|
): cv.positive_int,
|
||||||
vol.Optional(
|
vol.Required(
|
||||||
CONF_TIMEOUT,
|
CONF_TIMEOUT,
|
||||||
default=self.config_entry.options.get(
|
default=self.config_entry.options.get(
|
||||||
CONF_TIMEOUT, DEFAULT_TIMEOUT
|
CONF_TIMEOUT, DEFAULT_TIMEOUT
|
||||||
),
|
),
|
||||||
): cv.positive_int,
|
): cv.positive_int,
|
||||||
|
vol.Required(
|
||||||
|
CONF_SNAPSHOT_QUALITY,
|
||||||
|
default=self.config_entry.options.get(
|
||||||
|
CONF_SNAPSHOT_QUALITY, DEFAULT_SNAPSHOT_QUALITY
|
||||||
|
),
|
||||||
|
): vol.All(vol.Coerce(int), vol.Range(min=0, max=2)),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return self.async_show_form(step_id="init", data_schema=data_schema)
|
return self.async_show_form(step_id="init", data_schema=data_schema)
|
||||||
|
@ -9,6 +9,7 @@ from synology_dsm.api.core.utilization import SynoCoreUtilization
|
|||||||
from synology_dsm.api.dsm.information import SynoDSMInformation
|
from synology_dsm.api.dsm.information import SynoDSMInformation
|
||||||
from synology_dsm.api.storage.storage import SynoStorage
|
from synology_dsm.api.storage.storage import SynoStorage
|
||||||
from synology_dsm.api.surveillance_station import SynoSurveillanceStation
|
from synology_dsm.api.surveillance_station import SynoSurveillanceStation
|
||||||
|
from synology_dsm.api.surveillance_station.const import SNAPSHOT_PROFILE_BALANCED
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorDeviceClass,
|
BinarySensorDeviceClass,
|
||||||
@ -47,6 +48,7 @@ UNDO_UPDATE_LISTENER = "undo_update_listener"
|
|||||||
CONF_SERIAL = "serial"
|
CONF_SERIAL = "serial"
|
||||||
CONF_VOLUMES = "volumes"
|
CONF_VOLUMES = "volumes"
|
||||||
CONF_DEVICE_TOKEN = "device_token"
|
CONF_DEVICE_TOKEN = "device_token"
|
||||||
|
CONF_SNAPSHOT_QUALITY = "snap_profile_type"
|
||||||
|
|
||||||
DEFAULT_USE_SSL = True
|
DEFAULT_USE_SSL = True
|
||||||
DEFAULT_VERIFY_SSL = False
|
DEFAULT_VERIFY_SSL = False
|
||||||
@ -55,6 +57,7 @@ DEFAULT_PORT_SSL = 5001
|
|||||||
# Options
|
# Options
|
||||||
DEFAULT_SCAN_INTERVAL = 15 # min
|
DEFAULT_SCAN_INTERVAL = 15 # min
|
||||||
DEFAULT_TIMEOUT = 10 # sec
|
DEFAULT_TIMEOUT = 10 # sec
|
||||||
|
DEFAULT_SNAPSHOT_QUALITY = SNAPSHOT_PROFILE_BALANCED
|
||||||
|
|
||||||
ENTITY_UNIT_LOAD = "load"
|
ENTITY_UNIT_LOAD = "load"
|
||||||
|
|
||||||
|
@ -56,7 +56,8 @@
|
|||||||
"init": {
|
"init": {
|
||||||
"data": {
|
"data": {
|
||||||
"scan_interval": "Minutes between scans",
|
"scan_interval": "Minutes between scans",
|
||||||
"timeout": "Timeout (seconds)"
|
"timeout": "Timeout (seconds)",
|
||||||
|
"snap_profile_type": "Quality level of camera snapshots (0:high 1:medium 2:low)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,14 +31,6 @@
|
|||||||
"description": "Do you want to setup {name} ({host})?",
|
"description": "Do you want to setup {name} ({host})?",
|
||||||
"title": "Synology DSM"
|
"title": "Synology DSM"
|
||||||
},
|
},
|
||||||
"reauth": {
|
|
||||||
"data": {
|
|
||||||
"password": "Password",
|
|
||||||
"username": "Username"
|
|
||||||
},
|
|
||||||
"description": "Reason: {details}",
|
|
||||||
"title": "Synology DSM Reauthenticate Integration"
|
|
||||||
},
|
|
||||||
"reauth_confirm": {
|
"reauth_confirm": {
|
||||||
"data": {
|
"data": {
|
||||||
"password": "Password",
|
"password": "Password",
|
||||||
@ -64,6 +56,7 @@
|
|||||||
"init": {
|
"init": {
|
||||||
"data": {
|
"data": {
|
||||||
"scan_interval": "Minutes between scans",
|
"scan_interval": "Minutes between scans",
|
||||||
|
"snap_profile_type": "Quality level of camera snapshots (0:high 1:medium 2:low)",
|
||||||
"timeout": "Timeout (seconds)"
|
"timeout": "Timeout (seconds)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,12 @@ from homeassistant import data_entry_flow
|
|||||||
from homeassistant.components import ssdp
|
from homeassistant.components import ssdp
|
||||||
from homeassistant.components.synology_dsm.config_flow import CONF_OTP_CODE
|
from homeassistant.components.synology_dsm.config_flow import CONF_OTP_CODE
|
||||||
from homeassistant.components.synology_dsm.const import (
|
from homeassistant.components.synology_dsm.const import (
|
||||||
|
CONF_SNAPSHOT_QUALITY,
|
||||||
CONF_VOLUMES,
|
CONF_VOLUMES,
|
||||||
DEFAULT_PORT,
|
DEFAULT_PORT,
|
||||||
DEFAULT_PORT_SSL,
|
DEFAULT_PORT_SSL,
|
||||||
DEFAULT_SCAN_INTERVAL,
|
DEFAULT_SCAN_INTERVAL,
|
||||||
|
DEFAULT_SNAPSHOT_QUALITY,
|
||||||
DEFAULT_TIMEOUT,
|
DEFAULT_TIMEOUT,
|
||||||
DEFAULT_USE_SSL,
|
DEFAULT_USE_SSL,
|
||||||
DEFAULT_VERIFY_SSL,
|
DEFAULT_VERIFY_SSL,
|
||||||
@ -545,13 +547,15 @@ async def test_options_flow(hass: HomeAssistant, service: MagicMock):
|
|||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
assert config_entry.options[CONF_SCAN_INTERVAL] == DEFAULT_SCAN_INTERVAL
|
assert config_entry.options[CONF_SCAN_INTERVAL] == DEFAULT_SCAN_INTERVAL
|
||||||
assert config_entry.options[CONF_TIMEOUT] == DEFAULT_TIMEOUT
|
assert config_entry.options[CONF_TIMEOUT] == DEFAULT_TIMEOUT
|
||||||
|
assert config_entry.options[CONF_SNAPSHOT_QUALITY] == DEFAULT_SNAPSHOT_QUALITY
|
||||||
|
|
||||||
# Manual
|
# Manual
|
||||||
result = await hass.config_entries.options.async_init(config_entry.entry_id)
|
result = await hass.config_entries.options.async_init(config_entry.entry_id)
|
||||||
result = await hass.config_entries.options.async_configure(
|
result = await hass.config_entries.options.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
user_input={CONF_SCAN_INTERVAL: 2, CONF_TIMEOUT: 30},
|
user_input={CONF_SCAN_INTERVAL: 2, CONF_TIMEOUT: 30, CONF_SNAPSHOT_QUALITY: 0},
|
||||||
)
|
)
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
assert config_entry.options[CONF_SCAN_INTERVAL] == 2
|
assert config_entry.options[CONF_SCAN_INTERVAL] == 2
|
||||||
assert config_entry.options[CONF_TIMEOUT] == 30
|
assert config_entry.options[CONF_TIMEOUT] == 30
|
||||||
|
assert config_entry.options[CONF_SNAPSHOT_QUALITY] == 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user