diff --git a/homeassistant/components/unifiprotect/binary_sensor.py b/homeassistant/components/unifiprotect/binary_sensor.py index 2bad7d509d4..91401700376 100644 --- a/homeassistant/components/unifiprotect/binary_sensor.py +++ b/homeassistant/components/unifiprotect/binary_sensor.py @@ -3,7 +3,7 @@ from __future__ import annotations from copy import copy from dataclasses import dataclass -from datetime import datetime +from datetime import datetime, timedelta import logging from typing import Any, Final @@ -25,7 +25,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.event import async_call_later from homeassistant.util.dt import utcnow -from .const import DOMAIN, RING_INTERVAL +from .const import DOMAIN from .data import ProtectData from .entity import ProtectDeviceEntity, ProtectNVREntity, async_all_device_entities from .models import ProtectRequiredKeysMixin @@ -49,6 +49,7 @@ _KEY_BATTERY_LOW = "battery_low" _KEY_DISK_HEALTH = "disk_health" DEVICE_CLASS_RING: Final = "unifiprotect__ring" +RING_INTERVAL = timedelta(seconds=3) CAMERA_SENSORS: tuple[ProtectBinaryEntityDescription, ...] = ( diff --git a/homeassistant/components/unifiprotect/const.py b/homeassistant/components/unifiprotect/const.py index 891912ebf09..ad81207dfc1 100644 --- a/homeassistant/components/unifiprotect/const.py +++ b/homeassistant/components/unifiprotect/const.py @@ -1,12 +1,8 @@ """Constant definitions for UniFi Protect Integration.""" -from datetime import timedelta - from pyunifiprotect.data.types import ModelType, Version -import voluptuous as vol -from homeassistant.const import ATTR_ENTITY_ID, Platform -from homeassistant.helpers import config_validation as cv +from homeassistant.const import Platform DOMAIN = "unifiprotect" @@ -34,9 +30,6 @@ DEFAULT_BRAND = "Ubiquiti" DEFAULT_SCAN_INTERVAL = 5 DEFAULT_VERIFY_SSL = False -RING_INTERVAL = timedelta(seconds=3) - -DEVICE_TYPE_CAMERA = "camera" DEVICES_THAT_ADOPT = { ModelType.CAMERA, ModelType.LIGHT, @@ -49,8 +42,6 @@ DEVICES_FOR_SUBSCRIBE = DEVICES_WITH_ENTITIES | {ModelType.EVENT} MIN_REQUIRED_PROTECT_V = Version("1.20.0") OUTDATED_LOG_MESSAGE = "You are running v%s of UniFi Protect. Minimum required version is v%s. Please upgrade UniFi Protect and then retry" -SERVICE_SET_DOORBELL_MESSAGE = "set_doorbell_message" - TYPE_EMPTY_VALUE = "" PLATFORMS = [ @@ -64,11 +55,3 @@ PLATFORMS = [ Platform.SENSOR, Platform.SWITCH, ] - -SET_DOORBELL_LCD_MESSAGE_SCHEMA = vol.Schema( - { - vol.Required(ATTR_ENTITY_ID): cv.entity_ids, - vol.Required(ATTR_MESSAGE): cv.string, - vol.Optional(ATTR_DURATION, default=""): cv.string, - } -) diff --git a/homeassistant/components/unifiprotect/select.py b/homeassistant/components/unifiprotect/select.py index e3e93734e67..707d92cb06e 100644 --- a/homeassistant/components/unifiprotect/select.py +++ b/homeassistant/components/unifiprotect/select.py @@ -19,21 +19,18 @@ from pyunifiprotect.data import ( Viewer, ) from pyunifiprotect.data.devices import LCDMessage +import voluptuous as vol from homeassistant.components.select import SelectEntity, SelectEntityDescription from homeassistant.config_entries import ConfigEntry +from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers import entity_platform +from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers.entity import EntityCategory from homeassistant.util.dt import utcnow -from .const import ( - DOMAIN, - SERVICE_SET_DOORBELL_MESSAGE, - SET_DOORBELL_LCD_MESSAGE_SCHEMA, - TYPE_EMPTY_VALUE, -) +from .const import ATTR_DURATION, ATTR_MESSAGE, DOMAIN, TYPE_EMPTY_VALUE from .data import ProtectData from .entity import ProtectDeviceEntity, async_all_device_entities from .models import ProtectRequiredKeysMixin @@ -55,7 +52,6 @@ INFRARED_MODES = [ {"id": IRLEDMode.OFF.value, "name": "Always Disable"}, ] - LIGHT_MODE_MOTION = "On Motion - Always" LIGHT_MODE_MOTION_DARK = "On Motion - When Dark" LIGHT_MODE_DARK = "When Dark" @@ -85,6 +81,16 @@ DEVICE_RECORDING_MODES = [ DEVICE_CLASS_LCD_MESSAGE: Final = "unifiprotect__lcd_message" +SERVICE_SET_DOORBELL_MESSAGE = "set_doorbell_message" + +SET_DOORBELL_LCD_MESSAGE_SCHEMA = vol.Schema( + { + vol.Required(ATTR_ENTITY_ID): cv.entity_ids, + vol.Required(ATTR_MESSAGE): cv.string, + vol.Optional(ATTR_DURATION, default=""): cv.string, + } +) + @dataclass class ProtectSelectEntityDescription(ProtectRequiredKeysMixin, SelectEntityDescription): diff --git a/tests/components/unifiprotect/test_binary_sensor.py b/tests/components/unifiprotect/test_binary_sensor.py index e6a720d0c94..52030ef768b 100644 --- a/tests/components/unifiprotect/test_binary_sensor.py +++ b/tests/components/unifiprotect/test_binary_sensor.py @@ -13,12 +13,10 @@ from pyunifiprotect.data.devices import Sensor from homeassistant.components.unifiprotect.binary_sensor import ( CAMERA_SENSORS, LIGHT_SENSORS, + RING_INTERVAL, SENSE_SENSORS, ) -from homeassistant.components.unifiprotect.const import ( - DEFAULT_ATTRIBUTION, - RING_INTERVAL, -) +from homeassistant.components.unifiprotect.const import DEFAULT_ATTRIBUTION from homeassistant.const import ( ATTR_ATTRIBUTION, ATTR_LAST_TRIP_TIME, diff --git a/tests/components/unifiprotect/test_select.py b/tests/components/unifiprotect/test_select.py index 53adcdbe3ed..1b216b1642b 100644 --- a/tests/components/unifiprotect/test_select.py +++ b/tests/components/unifiprotect/test_select.py @@ -23,12 +23,12 @@ from homeassistant.components.unifiprotect.const import ( ATTR_DURATION, ATTR_MESSAGE, DEFAULT_ATTRIBUTION, - SERVICE_SET_DOORBELL_MESSAGE, ) from homeassistant.components.unifiprotect.select import ( CAMERA_SELECTS, LIGHT_MODE_OFF, LIGHT_SELECTS, + SERVICE_SET_DOORBELL_MESSAGE, VIEWER_SELECTS, ) from homeassistant.const import ATTR_ATTRIBUTION, ATTR_ENTITY_ID, ATTR_OPTION, Platform