mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Move Renault service registration (#116459)
* Move Renault service registration * Hassfest
This commit is contained in:
parent
f9b1b371e9
commit
0005f8400d
@ -7,10 +7,20 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import CONF_LOCALE, DOMAIN, PLATFORMS
|
||||
from .renault_hub import RenaultHub
|
||||
from .services import SERVICE_AC_START, setup_services, unload_services
|
||||
from .services import setup_services
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Renault component."""
|
||||
setup_services(hass)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
@ -36,21 +46,9 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
||||
|
||||
if not hass.services.has_service(DOMAIN, SERVICE_AC_START):
|
||||
setup_services(hass)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||
config_entry, PLATFORMS
|
||||
)
|
||||
|
||||
if unload_ok:
|
||||
hass.data[DOMAIN].pop(config_entry.entry_id)
|
||||
if not hass.data[DOMAIN]:
|
||||
unload_services(hass)
|
||||
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)
|
||||
|
@ -141,9 +141,3 @@ def setup_services(hass: HomeAssistant) -> None:
|
||||
charge_set_schedules,
|
||||
schema=SERVICE_CHARGE_SET_SCHEDULES_SCHEMA,
|
||||
)
|
||||
|
||||
|
||||
def unload_services(hass: HomeAssistant) -> None:
|
||||
"""Unload Renault services."""
|
||||
for service in SERVICES:
|
||||
hass.services.async_remove(DOMAIN, service)
|
||||
|
@ -18,7 +18,6 @@ from homeassistant.components.renault.services import (
|
||||
SERVICE_AC_CANCEL,
|
||||
SERVICE_AC_START,
|
||||
SERVICE_CHARGE_SET_SCHEDULES,
|
||||
SERVICES,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
@ -60,25 +59,6 @@ def get_device_id(hass: HomeAssistant) -> str:
|
||||
return device.id
|
||||
|
||||
|
||||
async def test_service_registration(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
) -> None:
|
||||
"""Test entry setup and unload."""
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Check that all services are registered.
|
||||
for service in SERVICES:
|
||||
assert hass.services.has_service(DOMAIN, service)
|
||||
|
||||
# Unload the entry
|
||||
await hass.config_entries.async_unload(config_entry.entry_id)
|
||||
|
||||
# Check that all services are un-registered.
|
||||
for service in SERVICES:
|
||||
assert not hass.services.has_service(DOMAIN, service)
|
||||
|
||||
|
||||
async def test_service_set_ac_cancel(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user