Use enums in rainmachine (#62058)
This commit is contained in:
parent
f9cc6c069e
commit
d660d68c34
3 changed files with 26 additions and 29 deletions
|
@ -7,8 +7,8 @@ from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorEntityDescription,
|
BinarySensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC
|
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import RainMachineEntity
|
from . import RainMachineEntity
|
||||||
|
@ -51,28 +51,28 @@ BINARY_SENSOR_DESCRIPTIONS = (
|
||||||
key=TYPE_FREEZE,
|
key=TYPE_FREEZE,
|
||||||
name="Freeze Restrictions",
|
name="Freeze Restrictions",
|
||||||
icon="mdi:cancel",
|
icon="mdi:cancel",
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
api_category=DATA_RESTRICTIONS_CURRENT,
|
api_category=DATA_RESTRICTIONS_CURRENT,
|
||||||
),
|
),
|
||||||
RainMachineBinarySensorDescription(
|
RainMachineBinarySensorDescription(
|
||||||
key=TYPE_FREEZE_PROTECTION,
|
key=TYPE_FREEZE_PROTECTION,
|
||||||
name="Freeze Protection",
|
name="Freeze Protection",
|
||||||
icon="mdi:weather-snowy",
|
icon="mdi:weather-snowy",
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
api_category=DATA_RESTRICTIONS_UNIVERSAL,
|
api_category=DATA_RESTRICTIONS_UNIVERSAL,
|
||||||
),
|
),
|
||||||
RainMachineBinarySensorDescription(
|
RainMachineBinarySensorDescription(
|
||||||
key=TYPE_HOT_DAYS,
|
key=TYPE_HOT_DAYS,
|
||||||
name="Extra Water on Hot Days",
|
name="Extra Water on Hot Days",
|
||||||
icon="mdi:thermometer-lines",
|
icon="mdi:thermometer-lines",
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
api_category=DATA_RESTRICTIONS_UNIVERSAL,
|
api_category=DATA_RESTRICTIONS_UNIVERSAL,
|
||||||
),
|
),
|
||||||
RainMachineBinarySensorDescription(
|
RainMachineBinarySensorDescription(
|
||||||
key=TYPE_HOURLY,
|
key=TYPE_HOURLY,
|
||||||
name="Hourly Restrictions",
|
name="Hourly Restrictions",
|
||||||
icon="mdi:cancel",
|
icon="mdi:cancel",
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
api_category=DATA_RESTRICTIONS_CURRENT,
|
api_category=DATA_RESTRICTIONS_CURRENT,
|
||||||
),
|
),
|
||||||
|
@ -80,7 +80,7 @@ BINARY_SENSOR_DESCRIPTIONS = (
|
||||||
key=TYPE_MONTH,
|
key=TYPE_MONTH,
|
||||||
name="Month Restrictions",
|
name="Month Restrictions",
|
||||||
icon="mdi:cancel",
|
icon="mdi:cancel",
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
api_category=DATA_RESTRICTIONS_CURRENT,
|
api_category=DATA_RESTRICTIONS_CURRENT,
|
||||||
),
|
),
|
||||||
|
@ -88,7 +88,7 @@ BINARY_SENSOR_DESCRIPTIONS = (
|
||||||
key=TYPE_RAINDELAY,
|
key=TYPE_RAINDELAY,
|
||||||
name="Rain Delay Restrictions",
|
name="Rain Delay Restrictions",
|
||||||
icon="mdi:cancel",
|
icon="mdi:cancel",
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
api_category=DATA_RESTRICTIONS_CURRENT,
|
api_category=DATA_RESTRICTIONS_CURRENT,
|
||||||
),
|
),
|
||||||
|
@ -96,7 +96,7 @@ BINARY_SENSOR_DESCRIPTIONS = (
|
||||||
key=TYPE_RAINSENSOR,
|
key=TYPE_RAINSENSOR,
|
||||||
name="Rain Sensor Restrictions",
|
name="Rain Sensor Restrictions",
|
||||||
icon="mdi:cancel",
|
icon="mdi:cancel",
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
api_category=DATA_RESTRICTIONS_CURRENT,
|
api_category=DATA_RESTRICTIONS_CURRENT,
|
||||||
),
|
),
|
||||||
|
@ -104,7 +104,7 @@ BINARY_SENSOR_DESCRIPTIONS = (
|
||||||
key=TYPE_WEEKDAY,
|
key=TYPE_WEEKDAY,
|
||||||
name="Weekday Restrictions",
|
name="Weekday Restrictions",
|
||||||
icon="mdi:cancel",
|
icon="mdi:cancel",
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
api_category=DATA_RESTRICTIONS_CURRENT,
|
api_category=DATA_RESTRICTIONS_CURRENT,
|
||||||
),
|
),
|
||||||
|
|
|
@ -5,19 +5,15 @@ from dataclasses import dataclass
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
STATE_CLASS_MEASUREMENT,
|
SensorDeviceClass,
|
||||||
STATE_CLASS_TOTAL_INCREASING,
|
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import TEMP_CELSIUS, VOLUME_CUBIC_METERS
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
|
||||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
|
||||||
TEMP_CELSIUS,
|
|
||||||
VOLUME_CUBIC_METERS,
|
|
||||||
)
|
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import RainMachineEntity
|
from . import RainMachineEntity
|
||||||
|
@ -50,26 +46,26 @@ SENSOR_DESCRIPTIONS = (
|
||||||
name="Flow Sensor Clicks per Cubic Meter",
|
name="Flow Sensor Clicks per Cubic Meter",
|
||||||
icon="mdi:water-pump",
|
icon="mdi:water-pump",
|
||||||
native_unit_of_measurement=f"clicks/{VOLUME_CUBIC_METERS}",
|
native_unit_of_measurement=f"clicks/{VOLUME_CUBIC_METERS}",
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
api_category=DATA_PROVISION_SETTINGS,
|
api_category=DATA_PROVISION_SETTINGS,
|
||||||
),
|
),
|
||||||
RainMachineSensorEntityDescription(
|
RainMachineSensorEntityDescription(
|
||||||
key=TYPE_FLOW_SENSOR_CONSUMED_LITERS,
|
key=TYPE_FLOW_SENSOR_CONSUMED_LITERS,
|
||||||
name="Flow Sensor Consumed Liters",
|
name="Flow Sensor Consumed Liters",
|
||||||
icon="mdi:water-pump",
|
icon="mdi:water-pump",
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
native_unit_of_measurement="liter",
|
native_unit_of_measurement="liter",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
state_class=STATE_CLASS_TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
api_category=DATA_PROVISION_SETTINGS,
|
api_category=DATA_PROVISION_SETTINGS,
|
||||||
),
|
),
|
||||||
RainMachineSensorEntityDescription(
|
RainMachineSensorEntityDescription(
|
||||||
key=TYPE_FLOW_SENSOR_START_INDEX,
|
key=TYPE_FLOW_SENSOR_START_INDEX,
|
||||||
name="Flow Sensor Start Index",
|
name="Flow Sensor Start Index",
|
||||||
icon="mdi:water-pump",
|
icon="mdi:water-pump",
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
native_unit_of_measurement="index",
|
native_unit_of_measurement="index",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
api_category=DATA_PROVISION_SETTINGS,
|
api_category=DATA_PROVISION_SETTINGS,
|
||||||
|
@ -78,20 +74,20 @@ SENSOR_DESCRIPTIONS = (
|
||||||
key=TYPE_FLOW_SENSOR_WATERING_CLICKS,
|
key=TYPE_FLOW_SENSOR_WATERING_CLICKS,
|
||||||
name="Flow Sensor Clicks",
|
name="Flow Sensor Clicks",
|
||||||
icon="mdi:water-pump",
|
icon="mdi:water-pump",
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
native_unit_of_measurement="clicks",
|
native_unit_of_measurement="clicks",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
api_category=DATA_PROVISION_SETTINGS,
|
api_category=DATA_PROVISION_SETTINGS,
|
||||||
),
|
),
|
||||||
RainMachineSensorEntityDescription(
|
RainMachineSensorEntityDescription(
|
||||||
key=TYPE_FREEZE_TEMP,
|
key=TYPE_FREEZE_TEMP,
|
||||||
name="Freeze Protect Temperature",
|
name="Freeze Protect Temperature",
|
||||||
icon="mdi:thermometer",
|
icon="mdi:thermometer",
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=TEMP_CELSIUS,
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
api_category=DATA_RESTRICTIONS_UNIVERSAL,
|
api_category=DATA_RESTRICTIONS_UNIVERSAL,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -13,10 +13,11 @@ import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
|
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ATTR_ID, ENTITY_CATEGORY_CONFIG
|
from homeassistant.const import ATTR_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 config_validation as cv, entity_platform
|
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||||
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
|
@ -181,7 +182,7 @@ async def async_setup_entry(
|
||||||
RainMachineSwitchDescription(
|
RainMachineSwitchDescription(
|
||||||
key=f"{kind}_{uid}_enabled",
|
key=f"{kind}_{uid}_enabled",
|
||||||
name=f"{data['name']} Enabled",
|
name=f"{data['name']} Enabled",
|
||||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
icon="mdi:cog",
|
icon="mdi:cog",
|
||||||
uid=uid,
|
uid=uid,
|
||||||
),
|
),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue