Eliminate duplicated run state logic in RainMachine (#70009)
parent
8e64ae8478
commit
6cf7973a49
|
@ -1,6 +1,8 @@
|
|||
"""Define constants for the SimpliSafe component."""
|
||||
import logging
|
||||
|
||||
from homeassistant.backports.enum import StrEnum
|
||||
|
||||
LOGGER = logging.getLogger(__package__)
|
||||
|
||||
DOMAIN = "rainmachine"
|
||||
|
@ -17,3 +19,18 @@ DATA_ZONES = "zones"
|
|||
|
||||
DEFAULT_PORT = 8080
|
||||
DEFAULT_ZONE_RUN = 60 * 10
|
||||
|
||||
|
||||
class RunStates(StrEnum):
|
||||
"""Define an enum for program/zone run states."""
|
||||
|
||||
NOT_RUNNING = "Not Running"
|
||||
QUEUED = "Queued"
|
||||
RUNNING = "Running"
|
||||
|
||||
|
||||
RUN_STATE_MAP = {
|
||||
0: RunStates.NOT_RUNNING,
|
||||
1: RunStates.RUNNING,
|
||||
2: RunStates.QUEUED,
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ from .const import (
|
|||
DATA_RESTRICTIONS_UNIVERSAL,
|
||||
DATA_ZONES,
|
||||
DOMAIN,
|
||||
RUN_STATE_MAP,
|
||||
RunStates,
|
||||
)
|
||||
from .model import (
|
||||
RainMachineDescriptionMixinApiCategory,
|
||||
|
@ -41,15 +43,6 @@ TYPE_FLOW_SENSOR_WATERING_CLICKS = "flow_sensor_watering_clicks"
|
|||
TYPE_FREEZE_TEMP = "freeze_protect_temp"
|
||||
TYPE_ZONE_RUN_COMPLETION_TIME = "zone_run_completion_time"
|
||||
|
||||
ZONE_STATE_NOT_RUNNING = "not_running"
|
||||
ZONE_STATE_PENDING = "pending"
|
||||
ZONE_STATE_RUNNING = "running"
|
||||
ZONE_STATE_MAP = {
|
||||
0: ZONE_STATE_NOT_RUNNING,
|
||||
1: ZONE_STATE_RUNNING,
|
||||
2: ZONE_STATE_PENDING,
|
||||
}
|
||||
|
||||
|
||||
@dataclass
|
||||
class RainMachineSensorDescriptionApiCategory(
|
||||
|
@ -219,7 +212,7 @@ class ZoneTimeRemainingSensor(RainMachineEntity, SensorEntity):
|
|||
data = self.coordinator.data[self.entity_description.uid]
|
||||
now = utcnow()
|
||||
|
||||
if ZONE_STATE_MAP.get(data["state"]) != ZONE_STATE_RUNNING:
|
||||
if RUN_STATE_MAP.get(data["state"]) != RunStates.RUNNING:
|
||||
# If the zone isn't actively running, return immediately:
|
||||
return
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ from .const import (
|
|||
DATA_ZONES,
|
||||
DEFAULT_ZONE_RUN,
|
||||
DOMAIN,
|
||||
RUN_STATE_MAP,
|
||||
)
|
||||
from .model import RainMachineDescriptionMixinUid
|
||||
|
||||
|
@ -55,8 +56,6 @@ ATTR_ZONES = "zones"
|
|||
|
||||
DAYS = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
|
||||
|
||||
RUN_STATUS_MAP = {0: "Not Running", 1: "Running", 2: "Queued"}
|
||||
|
||||
SOIL_TYPE_MAP = {
|
||||
0: "Not Set",
|
||||
1: "Clay Loam",
|
||||
|
@ -328,7 +327,7 @@ class RainMachineProgram(RainMachineActivitySwitch):
|
|||
ATTR_ID: self.entity_description.uid,
|
||||
ATTR_NEXT_RUN: next_run,
|
||||
ATTR_SOAK: data.get("soak"),
|
||||
ATTR_STATUS: RUN_STATUS_MAP[data["status"]],
|
||||
ATTR_STATUS: RUN_STATE_MAP[data["status"]],
|
||||
ATTR_ZONES: [z for z in data["wateringTimes"] if z["active"]],
|
||||
}
|
||||
)
|
||||
|
@ -402,7 +401,7 @@ class RainMachineZone(RainMachineActivitySwitch):
|
|||
ATTR_SLOPE: SLOPE_TYPE_MAP.get(data["slope"], 99),
|
||||
ATTR_SOIL_TYPE: SOIL_TYPE_MAP.get(data["soil"], 99),
|
||||
ATTR_SPRINKLER_TYPE: SPRINKLER_TYPE_MAP.get(data["group_id"], 99),
|
||||
ATTR_STATUS: RUN_STATUS_MAP[data["state"]],
|
||||
ATTR_STATUS: RUN_STATE_MAP[data["state"]],
|
||||
ATTR_SUN_EXPOSURE: SUN_EXPOSURE_MAP.get(data.get("sun")),
|
||||
ATTR_VEGETATION_TYPE: VEGETATION_MAP.get(data["type"], 99),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue