Only unload RainMachine services if the last config entry is loaded (#60805)

pull/60809/head
Aaron Bach 2021-12-01 16:59:33 -07:00 committed by GitHub
parent 12cd87d230
commit 344cd0d71f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 4 deletions

View File

@ -11,7 +11,7 @@ from regenmaschine.controller import Controller
from regenmaschine.errors import RainMachineError
import voluptuous as vol
from homeassistant.config_entries import ConfigEntry
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
from homeassistant.const import (
CONF_DEVICE_ID,
CONF_IP_ADDRESS,
@ -313,9 +313,14 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)
if len(hass.config_entries.async_entries(DOMAIN)) == 1:
# If this is the last instance of RainMachine, deregister any services defined
# during integration setup:
loaded_entries = [
entry
for entry in hass.config_entries.async_entries(DOMAIN)
if entry.state == ConfigEntryState.LOADED
]
if len(loaded_entries) == 1:
# If this is the last loaded instance of RainMachine, deregister any services
# defined during integration setup:
for service_name in (
SERVICE_NAME_PAUSE_WATERING,
SERVICE_NAME_PUSH_WEATHER_DATA,