Remove monitored conditions from RainMachine (#31066)
* Remove monitored conditions from RainMachine
* Migrate config entry
* Revert "Migrate config entry"
This reverts commit 84fcf5120f
.
* Code review comments
* Disable some entities by default
This commit is contained in:
parent
3fc86988fa
commit
73a55825af
3 changed files with 114 additions and 159 deletions
|
@ -10,27 +10,75 @@ from . import (
|
|||
PROVISION_SETTINGS,
|
||||
RESTRICTIONS_UNIVERSAL,
|
||||
SENSOR_UPDATE_TOPIC,
|
||||
SENSORS,
|
||||
TYPE_FLOW_SENSOR_CLICK_M3,
|
||||
TYPE_FLOW_SENSOR_CONSUMED_LITERS,
|
||||
TYPE_FLOW_SENSOR_START_INDEX,
|
||||
TYPE_FLOW_SENSOR_WATERING_CLICKS,
|
||||
TYPE_FREEZE_TEMP,
|
||||
RainMachineEntity,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
TYPE_FLOW_SENSOR_CLICK_M3 = "flow_sensor_clicks_cubic_meter"
|
||||
TYPE_FLOW_SENSOR_CONSUMED_LITERS = "flow_sensor_consumed_liters"
|
||||
TYPE_FLOW_SENSOR_START_INDEX = "flow_sensor_start_index"
|
||||
TYPE_FLOW_SENSOR_WATERING_CLICKS = "flow_sensor_watering_clicks"
|
||||
TYPE_FREEZE_TEMP = "freeze_protect_temp"
|
||||
|
||||
SENSORS = {
|
||||
TYPE_FLOW_SENSOR_CLICK_M3: (
|
||||
"Flow Sensor Clicks",
|
||||
"mdi:water-pump",
|
||||
"clicks/m^3",
|
||||
None,
|
||||
False,
|
||||
),
|
||||
TYPE_FLOW_SENSOR_CONSUMED_LITERS: (
|
||||
"Flow Sensor Consumed Liters",
|
||||
"mdi:water-pump",
|
||||
"liter",
|
||||
None,
|
||||
False,
|
||||
),
|
||||
TYPE_FLOW_SENSOR_START_INDEX: (
|
||||
"Flow Sensor Start Index",
|
||||
"mdi:water-pump",
|
||||
"index",
|
||||
None,
|
||||
False,
|
||||
),
|
||||
TYPE_FLOW_SENSOR_WATERING_CLICKS: (
|
||||
"Flow Sensor Clicks",
|
||||
"mdi:water-pump",
|
||||
"clicks",
|
||||
None,
|
||||
False,
|
||||
),
|
||||
TYPE_FREEZE_TEMP: (
|
||||
"Freeze Protect Temperature",
|
||||
"mdi:thermometer",
|
||||
"°C",
|
||||
"temperature",
|
||||
True,
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
async def async_setup_entry(hass, entry, async_add_entities):
|
||||
"""Set up RainMachine sensors based on a config entry."""
|
||||
rainmachine = hass.data[RAINMACHINE_DOMAIN][DATA_CLIENT][entry.entry_id]
|
||||
|
||||
sensors = []
|
||||
for sensor_type in rainmachine.sensor_conditions:
|
||||
name, icon, unit, device_class = SENSORS[sensor_type]
|
||||
for (
|
||||
sensor_type,
|
||||
(name, icon, unit, device_class, enabled_by_default),
|
||||
) in SENSORS.items():
|
||||
sensors.append(
|
||||
RainMachineSensor(rainmachine, sensor_type, name, icon, unit, device_class)
|
||||
RainMachineSensor(
|
||||
rainmachine,
|
||||
sensor_type,
|
||||
name,
|
||||
icon,
|
||||
unit,
|
||||
device_class,
|
||||
enabled_by_default,
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(sensors, True)
|
||||
|
@ -39,17 +87,32 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||
class RainMachineSensor(RainMachineEntity):
|
||||
"""A sensor implementation for raincloud device."""
|
||||
|
||||
def __init__(self, rainmachine, sensor_type, name, icon, unit, device_class):
|
||||
def __init__(
|
||||
self,
|
||||
rainmachine,
|
||||
sensor_type,
|
||||
name,
|
||||
icon,
|
||||
unit,
|
||||
device_class,
|
||||
enabled_by_default,
|
||||
):
|
||||
"""Initialize."""
|
||||
super().__init__(rainmachine)
|
||||
|
||||
self._device_class = device_class
|
||||
self._enabled_by_default = enabled_by_default
|
||||
self._icon = icon
|
||||
self._name = name
|
||||
self._sensor_type = sensor_type
|
||||
self._state = None
|
||||
self._unit = unit
|
||||
|
||||
@property
|
||||
def entity_registry_enabled_default(self):
|
||||
"""Determine whether an entity is enabled by default."""
|
||||
return self._enabled_by_default
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
"""Return the icon."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue