Fix RainMachine bugs (#106231)

This commit is contained in:
kingy444 2023-12-27 22:38:37 +11:00 committed by GitHub
parent c19688e2d2
commit 25f9c5f34b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 45 additions and 7 deletions

View file

@ -38,6 +38,7 @@ from homeassistant.util.network import is_ip_address
from .config_flow import get_client_controller
from .const import (
CONF_ALLOW_INACTIVE_ZONES_TO_RUN,
CONF_DEFAULT_ZONE_RUN_TIME,
CONF_DURATION,
CONF_USE_APP_RUN_TIMES,
@ -48,6 +49,7 @@ from .const import (
DATA_RESTRICTIONS_CURRENT,
DATA_RESTRICTIONS_UNIVERSAL,
DATA_ZONES,
DEFAULT_ZONE_RUN,
DOMAIN,
LOGGER,
)
@ -249,8 +251,13 @@ async def async_setup_entry( # noqa: C901
**entry.options,
CONF_DEFAULT_ZONE_RUN_TIME: data.pop(CONF_DEFAULT_ZONE_RUN_TIME),
}
entry_updates["options"] = {**entry.options}
if CONF_USE_APP_RUN_TIMES not in entry.options:
entry_updates["options"] = {**entry.options, CONF_USE_APP_RUN_TIMES: False}
entry_updates["options"][CONF_USE_APP_RUN_TIMES] = False
if CONF_DEFAULT_ZONE_RUN_TIME not in entry.options:
entry_updates["options"][CONF_DEFAULT_ZONE_RUN_TIME] = DEFAULT_ZONE_RUN
if CONF_ALLOW_INACTIVE_ZONES_TO_RUN not in entry.options:
entry_updates["options"][CONF_ALLOW_INACTIVE_ZONES_TO_RUN] = False
if entry_updates:
hass.config_entries.async_update_entry(entry, **entry_updates)

View file

@ -17,6 +17,7 @@ from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers import aiohttp_client, config_validation as cv
from .const import (
CONF_ALLOW_INACTIVE_ZONES_TO_RUN,
CONF_DEFAULT_ZONE_RUN_TIME,
CONF_USE_APP_RUN_TIMES,
DEFAULT_PORT,
@ -188,6 +189,12 @@ class RainMachineOptionsFlowHandler(config_entries.OptionsFlow):
CONF_USE_APP_RUN_TIMES,
default=self.config_entry.options.get(CONF_USE_APP_RUN_TIMES),
): bool,
vol.Optional(
CONF_ALLOW_INACTIVE_ZONES_TO_RUN,
default=self.config_entry.options.get(
CONF_ALLOW_INACTIVE_ZONES_TO_RUN
),
): bool,
}
),
)

View file

@ -8,6 +8,7 @@ DOMAIN = "rainmachine"
CONF_DURATION = "duration"
CONF_DEFAULT_ZONE_RUN_TIME = "zone_run_time"
CONF_USE_APP_RUN_TIMES = "use_app_run_times"
CONF_ALLOW_INACTIVE_ZONES_TO_RUN = "allow_inactive_zones_to_run"
DATA_API_VERSIONS = "api.versions"
DATA_MACHINE_FIRMWARE_UPDATE_STATUS = "machine.firmware_update_status"

View file

@ -24,7 +24,8 @@
"title": "Configure RainMachine",
"data": {
"zone_run_time": "Default zone run time (in seconds)",
"use_app_run_times": "Use zone run times from RainMachine app"
"use_app_run_times": "Use zone run times from the RainMachine app",
"allow_inactive_zones_to_run": "Allow disabled zones to be run manually"
}
}
}

View file

@ -20,6 +20,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import RainMachineData, RainMachineEntity, async_update_programs_and_zones
from .const import (
CONF_ALLOW_INACTIVE_ZONES_TO_RUN,
CONF_DEFAULT_ZONE_RUN_TIME,
CONF_DURATION,
CONF_USE_APP_RUN_TIMES,
@ -300,7 +301,10 @@ class RainMachineActivitySwitch(RainMachineBaseSwitch):
The only way this could occur is if someone rapidly turns a disabled activity
off right after turning it on.
"""
if not self.coordinator.data[self.entity_description.uid]["active"]:
if (
not self._entry.options[CONF_ALLOW_INACTIVE_ZONES_TO_RUN]
and not self.coordinator.data[self.entity_description.uid]["active"]
):
raise HomeAssistantError(
f"Cannot turn off an inactive program/zone: {self.name}"
)
@ -314,7 +318,10 @@ class RainMachineActivitySwitch(RainMachineBaseSwitch):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the switch on."""
if not self.coordinator.data[self.entity_description.uid]["active"]:
if (
not self._entry.options[CONF_ALLOW_INACTIVE_ZONES_TO_RUN]
and not self.coordinator.data[self.entity_description.uid]["active"]
):
self._attr_is_on = False
self.async_write_ha_state()
raise HomeAssistantError(