Isolate consts better to where they are used (#63569)

This commit is contained in:
Christopher Bailey 2022-01-06 16:57:56 -05:00 committed by GitHub
parent 442690b885
commit 3e2495f417
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 33 deletions

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from copy import copy from copy import copy
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime from datetime import datetime, timedelta
import logging import logging
from typing import Any, Final 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.helpers.event import async_call_later
from homeassistant.util.dt import utcnow from homeassistant.util.dt import utcnow
from .const import DOMAIN, RING_INTERVAL from .const import DOMAIN
from .data import ProtectData from .data import ProtectData
from .entity import ProtectDeviceEntity, ProtectNVREntity, async_all_device_entities from .entity import ProtectDeviceEntity, ProtectNVREntity, async_all_device_entities
from .models import ProtectRequiredKeysMixin from .models import ProtectRequiredKeysMixin
@ -49,6 +49,7 @@ _KEY_BATTERY_LOW = "battery_low"
_KEY_DISK_HEALTH = "disk_health" _KEY_DISK_HEALTH = "disk_health"
DEVICE_CLASS_RING: Final = "unifiprotect__ring" DEVICE_CLASS_RING: Final = "unifiprotect__ring"
RING_INTERVAL = timedelta(seconds=3)
CAMERA_SENSORS: tuple[ProtectBinaryEntityDescription, ...] = ( CAMERA_SENSORS: tuple[ProtectBinaryEntityDescription, ...] = (

View File

@ -1,12 +1,8 @@
"""Constant definitions for UniFi Protect Integration.""" """Constant definitions for UniFi Protect Integration."""
from datetime import timedelta
from pyunifiprotect.data.types import ModelType, Version from pyunifiprotect.data.types import ModelType, Version
import voluptuous as vol
from homeassistant.const import ATTR_ENTITY_ID, Platform from homeassistant.const import Platform
from homeassistant.helpers import config_validation as cv
DOMAIN = "unifiprotect" DOMAIN = "unifiprotect"
@ -34,9 +30,6 @@ DEFAULT_BRAND = "Ubiquiti"
DEFAULT_SCAN_INTERVAL = 5 DEFAULT_SCAN_INTERVAL = 5
DEFAULT_VERIFY_SSL = False DEFAULT_VERIFY_SSL = False
RING_INTERVAL = timedelta(seconds=3)
DEVICE_TYPE_CAMERA = "camera"
DEVICES_THAT_ADOPT = { DEVICES_THAT_ADOPT = {
ModelType.CAMERA, ModelType.CAMERA,
ModelType.LIGHT, ModelType.LIGHT,
@ -49,8 +42,6 @@ DEVICES_FOR_SUBSCRIBE = DEVICES_WITH_ENTITIES | {ModelType.EVENT}
MIN_REQUIRED_PROTECT_V = Version("1.20.0") 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" 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 = "" TYPE_EMPTY_VALUE = ""
PLATFORMS = [ PLATFORMS = [
@ -64,11 +55,3 @@ PLATFORMS = [
Platform.SENSOR, Platform.SENSOR,
Platform.SWITCH, 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,
}
)

View File

@ -19,21 +19,18 @@ from pyunifiprotect.data import (
Viewer, Viewer,
) )
from pyunifiprotect.data.devices import LCDMessage from pyunifiprotect.data.devices import LCDMessage
import voluptuous as vol
from homeassistant.components.select import SelectEntity, SelectEntityDescription from homeassistant.components.select import SelectEntity, SelectEntityDescription
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError 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.helpers.entity import EntityCategory
from homeassistant.util.dt import utcnow from homeassistant.util.dt import utcnow
from .const import ( from .const import ATTR_DURATION, ATTR_MESSAGE, DOMAIN, TYPE_EMPTY_VALUE
DOMAIN,
SERVICE_SET_DOORBELL_MESSAGE,
SET_DOORBELL_LCD_MESSAGE_SCHEMA,
TYPE_EMPTY_VALUE,
)
from .data import ProtectData from .data import ProtectData
from .entity import ProtectDeviceEntity, async_all_device_entities from .entity import ProtectDeviceEntity, async_all_device_entities
from .models import ProtectRequiredKeysMixin from .models import ProtectRequiredKeysMixin
@ -55,7 +52,6 @@ INFRARED_MODES = [
{"id": IRLEDMode.OFF.value, "name": "Always Disable"}, {"id": IRLEDMode.OFF.value, "name": "Always Disable"},
] ]
LIGHT_MODE_MOTION = "On Motion - Always" LIGHT_MODE_MOTION = "On Motion - Always"
LIGHT_MODE_MOTION_DARK = "On Motion - When Dark" LIGHT_MODE_MOTION_DARK = "On Motion - When Dark"
LIGHT_MODE_DARK = "When Dark" LIGHT_MODE_DARK = "When Dark"
@ -85,6 +81,16 @@ DEVICE_RECORDING_MODES = [
DEVICE_CLASS_LCD_MESSAGE: Final = "unifiprotect__lcd_message" 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 @dataclass
class ProtectSelectEntityDescription(ProtectRequiredKeysMixin, SelectEntityDescription): class ProtectSelectEntityDescription(ProtectRequiredKeysMixin, SelectEntityDescription):

View File

@ -13,12 +13,10 @@ from pyunifiprotect.data.devices import Sensor
from homeassistant.components.unifiprotect.binary_sensor import ( from homeassistant.components.unifiprotect.binary_sensor import (
CAMERA_SENSORS, CAMERA_SENSORS,
LIGHT_SENSORS, LIGHT_SENSORS,
RING_INTERVAL,
SENSE_SENSORS, SENSE_SENSORS,
) )
from homeassistant.components.unifiprotect.const import ( from homeassistant.components.unifiprotect.const import DEFAULT_ATTRIBUTION
DEFAULT_ATTRIBUTION,
RING_INTERVAL,
)
from homeassistant.const import ( from homeassistant.const import (
ATTR_ATTRIBUTION, ATTR_ATTRIBUTION,
ATTR_LAST_TRIP_TIME, ATTR_LAST_TRIP_TIME,

View File

@ -23,12 +23,12 @@ from homeassistant.components.unifiprotect.const import (
ATTR_DURATION, ATTR_DURATION,
ATTR_MESSAGE, ATTR_MESSAGE,
DEFAULT_ATTRIBUTION, DEFAULT_ATTRIBUTION,
SERVICE_SET_DOORBELL_MESSAGE,
) )
from homeassistant.components.unifiprotect.select import ( from homeassistant.components.unifiprotect.select import (
CAMERA_SELECTS, CAMERA_SELECTS,
LIGHT_MODE_OFF, LIGHT_MODE_OFF,
LIGHT_SELECTS, LIGHT_SELECTS,
SERVICE_SET_DOORBELL_MESSAGE,
VIEWER_SELECTS, VIEWER_SELECTS,
) )
from homeassistant.const import ATTR_ATTRIBUTION, ATTR_ENTITY_ID, ATTR_OPTION, Platform from homeassistant.const import ATTR_ATTRIBUTION, ATTR_ENTITY_ID, ATTR_OPTION, Platform