Remove previously-deprecated RainMachine sensors (#81053)

This commit is contained in:
Aaron Bach 2022-10-27 02:25:07 -06:00 committed by GitHub
parent 4e8e53f357
commit d72b8a025f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 76 deletions

View file

@ -12,12 +12,7 @@ from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import RainMachineData, RainMachineEntity
from .const import (
DATA_PROVISION_SETTINGS,
DATA_RESTRICTIONS_CURRENT,
DATA_RESTRICTIONS_UNIVERSAL,
DOMAIN,
)
from .const import DATA_PROVISION_SETTINGS, DATA_RESTRICTIONS_CURRENT, DOMAIN
from .model import (
RainMachineEntityDescription,
RainMachineEntityDescriptionMixinDataKey,
@ -30,8 +25,6 @@ from .util import (
TYPE_FLOW_SENSOR = "flow_sensor"
TYPE_FREEZE = "freeze"
TYPE_FREEZE_PROTECTION = "freeze_protection"
TYPE_HOT_DAYS = "extra_water_on_hot_days"
TYPE_HOURLY = "hourly"
TYPE_MONTH = "month"
TYPE_RAINDELAY = "raindelay"
@ -64,22 +57,6 @@ BINARY_SENSOR_DESCRIPTIONS = (
api_category=DATA_RESTRICTIONS_CURRENT,
data_key="freeze",
),
RainMachineBinarySensorDescription(
key=TYPE_FREEZE_PROTECTION,
name="Freeze protection",
icon="mdi:weather-snowy",
entity_category=EntityCategory.DIAGNOSTIC,
api_category=DATA_RESTRICTIONS_UNIVERSAL,
data_key="freezeProtectEnabled",
),
RainMachineBinarySensorDescription(
key=TYPE_HOT_DAYS,
name="Extra water on hot days",
icon="mdi:thermometer-lines",
entity_category=EntityCategory.DIAGNOSTIC,
api_category=DATA_RESTRICTIONS_UNIVERSAL,
data_key="hotDaysExtraWatering",
),
RainMachineBinarySensorDescription(
key=TYPE_HOURLY,
name="Hourly restrictions",
@ -139,14 +116,14 @@ async def async_setup_entry(
f"{data.controller.mac}_freeze_protection",
f"switch.{data.controller.name.lower()}_freeze_protect_enabled",
breaks_in_ha_version="2022.12.0",
remove_old_entity=False,
remove_old_entity=True,
),
EntityDomainReplacementStrategy(
BINARY_SENSOR_DOMAIN,
f"{data.controller.mac}_extra_water_on_hot_days",
f"switch.{data.controller.name.lower()}_hot_days_extra_watering",
breaks_in_ha_version="2022.12.0",
remove_old_entity=False,
remove_old_entity=True,
),
),
)
@ -154,7 +131,6 @@ async def async_setup_entry(
api_category_sensor_map = {
DATA_PROVISION_SETTINGS: ProvisionSettingsBinarySensor,
DATA_RESTRICTIONS_CURRENT: CurrentRestrictionsBinarySensor,
DATA_RESTRICTIONS_UNIVERSAL: UniversalRestrictionsBinarySensor,
}
async_add_entities(
@ -204,17 +180,3 @@ class ProvisionSettingsBinarySensor(RainMachineEntity, BinarySensorEntity):
self._attr_is_on = self.coordinator.data.get("system", {}).get(
"useFlowSensor"
)
class UniversalRestrictionsBinarySensor(RainMachineEntity, BinarySensorEntity):
"""Define a binary sensor that handles universal restrictions data."""
entity_description: RainMachineBinarySensorDescription
@callback
def update_from_latest_data(self) -> None:
"""Update the state."""
if self.entity_description.key == TYPE_FREEZE_PROTECTION:
self._attr_is_on = self.coordinator.data.get("freezeProtectEnabled")
elif self.entity_description.key == TYPE_HOT_DAYS:
self._attr_is_on = self.coordinator.data.get("hotDaysExtraWatering")

View file

@ -14,20 +14,14 @@ from homeassistant.components.sensor import (
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS, VOLUME_CUBIC_METERS, VOLUME_LITERS
from homeassistant.const import VOLUME_CUBIC_METERS, VOLUME_LITERS
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util.dt import utc_from_timestamp, utcnow
from . import RainMachineData, RainMachineEntity
from .const import (
DATA_PROGRAMS,
DATA_PROVISION_SETTINGS,
DATA_RESTRICTIONS_UNIVERSAL,
DATA_ZONES,
DOMAIN,
)
from .const import DATA_PROGRAMS, DATA_PROVISION_SETTINGS, DATA_ZONES, DOMAIN
from .model import (
RainMachineEntityDescription,
RainMachineEntityDescriptionMixinDataKey,
@ -49,7 +43,6 @@ TYPE_FLOW_SENSOR_LEAK_CLICKS = "flow_sensor_leak_clicks"
TYPE_FLOW_SENSOR_LEAK_VOLUME = "flow_sensor_leak_volume"
TYPE_FLOW_SENSOR_START_INDEX = "flow_sensor_start_index"
TYPE_FLOW_SENSOR_WATERING_CLICKS = "flow_sensor_watering_clicks"
TYPE_FREEZE_TEMP = "freeze_protect_temp"
TYPE_LAST_LEAK_DETECTED = "last_leak_detected"
TYPE_PROGRAM_RUN_COMPLETION_TIME = "program_run_completion_time"
TYPE_RAIN_SENSOR_RAIN_START = "rain_sensor_rain_start"
@ -140,17 +133,6 @@ SENSOR_DESCRIPTIONS = (
api_category=DATA_PROVISION_SETTINGS,
data_key="flowSensorWateringClicks",
),
RainMachineSensorDataDescription(
key=TYPE_FREEZE_TEMP,
name="Freeze protect temperature",
icon="mdi:thermometer",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=TEMP_CELSIUS,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
api_category=DATA_RESTRICTIONS_UNIVERSAL,
data_key="freezeProtectTemp",
),
RainMachineSensorDataDescription(
key=TYPE_LAST_LEAK_DETECTED,
name="Last leak detected",
@ -191,17 +173,16 @@ async def async_setup_entry(
f"{data.controller.mac}_freeze_protect_temp",
f"select.{data.controller.name.lower()}_freeze_protect_temperature",
breaks_in_ha_version="2022.12.0",
remove_old_entity=False,
remove_old_entity=True,
),
),
)
api_category_sensor_map = {
DATA_PROVISION_SETTINGS: ProvisionSettingsSensor,
DATA_RESTRICTIONS_UNIVERSAL: UniversalRestrictionsSensor,
}
sensors = [
sensors: list[ProvisionSettingsSensor | TimeRemainingSensor] = [
api_category_sensor_map[description.api_category](entry, data, description)
for description in SENSOR_DESCRIPTIONS
if (
@ -373,18 +354,6 @@ class ProvisionSettingsSensor(RainMachineEntity, SensorEntity):
self._attr_native_value = new_value
class UniversalRestrictionsSensor(RainMachineEntity, SensorEntity):
"""Define a sensor that handles universal restrictions data."""
entity_description: RainMachineSensorDataDescription
@callback
def update_from_latest_data(self) -> None:
"""Update the state."""
if self.entity_description.key == TYPE_FREEZE_TEMP:
self._attr_native_value = self.coordinator.data.get("freezeProtectTemp")
class ZoneTimeRemainingSensor(TimeRemainingSensor):
"""Define a sensor that shows the amount of time remaining for a zone."""