mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Move raincloud shared constants to separate module (#126174)
Move shared raincloud constants to separate module
This commit is contained in:
parent
bbe64e99e1
commit
47657af173
@ -8,13 +8,7 @@ from requests.exceptions import ConnectTimeout, HTTPError
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import persistent_notification
|
from homeassistant.components import persistent_notification
|
||||||
from homeassistant.const import (
|
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
|
||||||
CONF_PASSWORD,
|
|
||||||
CONF_SCAN_INTERVAL,
|
|
||||||
CONF_USERNAME,
|
|
||||||
PERCENTAGE,
|
|
||||||
UnitOfTime,
|
|
||||||
)
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
||||||
@ -22,18 +16,14 @@ from homeassistant.helpers.entity import Entity
|
|||||||
from homeassistant.helpers.event import track_time_interval
|
from homeassistant.helpers.event import track_time_interval
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
|
from .const import DATA_RAINCLOUD, SIGNAL_UPDATE_RAINCLOUD
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ALLOWED_WATERING_TIME = [5, 10, 15, 30, 45, 60]
|
|
||||||
|
|
||||||
CONF_WATERING_TIME = "watering_minutes"
|
|
||||||
|
|
||||||
NOTIFICATION_ID = "raincloud_notification"
|
NOTIFICATION_ID = "raincloud_notification"
|
||||||
NOTIFICATION_TITLE = "Rain Cloud Setup"
|
NOTIFICATION_TITLE = "Rain Cloud Setup"
|
||||||
|
|
||||||
DATA_RAINCLOUD = "raincloud"
|
|
||||||
DOMAIN = "raincloud"
|
DOMAIN = "raincloud"
|
||||||
DEFAULT_WATERING_TIME = 15
|
|
||||||
|
|
||||||
KEY_MAP = {
|
KEY_MAP = {
|
||||||
"auto_watering": "Automatic Watering",
|
"auto_watering": "Automatic Watering",
|
||||||
@ -57,27 +47,9 @@ ICON_MAP = {
|
|||||||
"watering_time": "mdi:water-pump",
|
"watering_time": "mdi:water-pump",
|
||||||
}
|
}
|
||||||
|
|
||||||
UNIT_OF_MEASUREMENT_MAP = {
|
|
||||||
"auto_watering": "",
|
|
||||||
"battery": PERCENTAGE,
|
|
||||||
"is_watering": "",
|
|
||||||
"manual_watering": "",
|
|
||||||
"next_cycle": "",
|
|
||||||
"rain_delay": UnitOfTime.DAYS,
|
|
||||||
"status": "",
|
|
||||||
"watering_time": UnitOfTime.MINUTES,
|
|
||||||
}
|
|
||||||
|
|
||||||
BINARY_SENSORS = ["is_watering", "status"]
|
|
||||||
|
|
||||||
SENSORS = ["battery", "next_cycle", "rain_delay", "watering_time"]
|
|
||||||
|
|
||||||
SWITCHES = ["auto_watering", "manual_watering"]
|
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=20)
|
SCAN_INTERVAL = timedelta(seconds=20)
|
||||||
|
|
||||||
SIGNAL_UPDATE_RAINCLOUD = "raincloud_update"
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
DOMAIN: vol.Schema(
|
DOMAIN: vol.Schema(
|
||||||
|
@ -16,10 +16,13 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import BINARY_SENSORS, DATA_RAINCLOUD, ICON_MAP, RainCloudEntity
|
from . import RainCloudEntity
|
||||||
|
from .const import DATA_RAINCLOUD, ICON_MAP
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
BINARY_SENSORS = ["is_watering", "status"]
|
||||||
|
|
||||||
PLATFORM_SCHEMA = BINARY_SENSOR_PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = BINARY_SENSOR_PLATFORM_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
vol.Optional(CONF_MONITORED_CONDITIONS, default=list(BINARY_SENSORS)): vol.All(
|
vol.Optional(CONF_MONITORED_CONDITIONS, default=list(BINARY_SENSORS)): vol.All(
|
||||||
|
17
homeassistant/components/raincloud/const.py
Normal file
17
homeassistant/components/raincloud/const.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
"""Support for Melnor RainCloud sprinkler water timer."""
|
||||||
|
|
||||||
|
DATA_RAINCLOUD = "raincloud"
|
||||||
|
|
||||||
|
ICON_MAP = {
|
||||||
|
"auto_watering": "mdi:autorenew",
|
||||||
|
"battery": "",
|
||||||
|
"is_watering": "",
|
||||||
|
"manual_watering": "mdi:water-pump",
|
||||||
|
"next_cycle": "mdi:calendar-clock",
|
||||||
|
"rain_delay": "mdi:weather-rainy",
|
||||||
|
"status": "",
|
||||||
|
"watering_time": "mdi:water-pump",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SIGNAL_UPDATE_RAINCLOUD = "raincloud_update"
|
@ -10,23 +10,20 @@ from homeassistant.components.sensor import (
|
|||||||
PLATFORM_SCHEMA as SENSOR_PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA as SENSOR_PLATFORM_SCHEMA,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_MONITORED_CONDITIONS
|
from homeassistant.const import CONF_MONITORED_CONDITIONS, PERCENTAGE, UnitOfTime
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.icon import icon_for_battery_level
|
from homeassistant.helpers.icon import icon_for_battery_level
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import (
|
from . import RainCloudEntity
|
||||||
DATA_RAINCLOUD,
|
from .const import DATA_RAINCLOUD, ICON_MAP
|
||||||
ICON_MAP,
|
|
||||||
SENSORS,
|
|
||||||
UNIT_OF_MEASUREMENT_MAP,
|
|
||||||
RainCloudEntity,
|
|
||||||
)
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
SENSORS = ["battery", "next_cycle", "rain_delay", "watering_time"]
|
||||||
|
|
||||||
PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
vol.Optional(CONF_MONITORED_CONDITIONS, default=list(SENSORS)): vol.All(
|
vol.Optional(CONF_MONITORED_CONDITIONS, default=list(SENSORS)): vol.All(
|
||||||
@ -35,6 +32,17 @@ PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
UNIT_OF_MEASUREMENT_MAP = {
|
||||||
|
"auto_watering": "",
|
||||||
|
"battery": PERCENTAGE,
|
||||||
|
"is_watering": "",
|
||||||
|
"manual_watering": "",
|
||||||
|
"next_cycle": "",
|
||||||
|
"rain_delay": UnitOfTime.DAYS,
|
||||||
|
"status": "",
|
||||||
|
"watering_time": UnitOfTime.MINUTES,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(
|
def setup_platform(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
@ -17,17 +17,17 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import (
|
from . import RainCloudEntity
|
||||||
ALLOWED_WATERING_TIME,
|
from .const import DATA_RAINCLOUD
|
||||||
CONF_WATERING_TIME,
|
|
||||||
DATA_RAINCLOUD,
|
|
||||||
DEFAULT_WATERING_TIME,
|
|
||||||
SWITCHES,
|
|
||||||
RainCloudEntity,
|
|
||||||
)
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
ALLOWED_WATERING_TIME = [5, 10, 15, 30, 45, 60]
|
||||||
|
CONF_WATERING_TIME = "watering_minutes"
|
||||||
|
DEFAULT_WATERING_TIME = 15
|
||||||
|
|
||||||
|
SWITCHES = ["auto_watering", "manual_watering"]
|
||||||
|
|
||||||
PLATFORM_SCHEMA = SWITCH_PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = SWITCH_PLATFORM_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
vol.Optional(CONF_MONITORED_CONDITIONS, default=list(SWITCHES)): vol.All(
|
vol.Optional(CONF_MONITORED_CONDITIONS, default=list(SWITCHES)): vol.All(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user