mirror of
https://github.com/home-assistant/core.git
synced 2026-09-24 15:31:52 -05:00
Register Subaru unlock_specific_door action in async_setup (#181014)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
a22eb5f3e8
commit
8ba416558a
@@ -13,8 +13,9 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import aiohttp_client
|
||||
from homeassistant.helpers import aiohttp_client, config_validation as cv
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
@@ -38,9 +39,18 @@ from .coordinator import (
|
||||
SubaruDataUpdateCoordinator,
|
||||
SubaruRuntimeData,
|
||||
)
|
||||
from .services import async_setup_services
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Subaru integration."""
|
||||
async_setup_services(hass)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: SubaruConfigEntry) -> bool:
|
||||
"""Set up Subaru from a config entry."""
|
||||
|
||||
@@ -3,17 +3,12 @@
|
||||
import logging
|
||||
from typing import Any, override
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.lock import LockEntity
|
||||
from homeassistant.const import SERVICE_LOCK, SERVICE_UNLOCK
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .const import (
|
||||
ATTR_DOOR,
|
||||
SERVICE_UNLOCK_SPECIFIC_DOOR,
|
||||
UNLOCK_DOOR_ALL,
|
||||
UNLOCK_VALID_DOORS,
|
||||
VEHICLE_HAS_REMOTE_SERVICE,
|
||||
@@ -41,14 +36,6 @@ async def async_setup_entry(
|
||||
if vehicle[VEHICLE_HAS_REMOTE_SERVICE]
|
||||
)
|
||||
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_UNLOCK_SPECIFIC_DOOR,
|
||||
{vol.Required(ATTR_DOOR): vol.In(UNLOCK_VALID_DOORS)},
|
||||
"async_unlock_specific_door",
|
||||
)
|
||||
|
||||
|
||||
class SubaruLock(SubaruCoordinatorEntity, LockEntity):
|
||||
"""Representation of a Subaru door lock.
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
"""Services for the Subaru integration."""
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import service
|
||||
|
||||
from .const import ATTR_DOOR, DOMAIN, SERVICE_UNLOCK_SPECIFIC_DOOR, UNLOCK_VALID_DOORS
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Register the Subaru services."""
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_UNLOCK_SPECIFIC_DOOR,
|
||||
entity_domain=LOCK_DOMAIN,
|
||||
schema={vol.Required(ATTR_DOOR): vol.In(UNLOCK_VALID_DOORS)},
|
||||
func="async_unlock_specific_door",
|
||||
)
|
||||
@@ -8,7 +8,7 @@ from homeassistant.components.homeassistant import (
|
||||
DOMAIN as HA_DOMAIN,
|
||||
SERVICE_UPDATE_ENTITY,
|
||||
)
|
||||
from homeassistant.components.subaru.const import DOMAIN
|
||||
from homeassistant.components.subaru.const import DOMAIN, SERVICE_UNLOCK_SPECIFIC_DOOR
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -33,10 +33,10 @@ from .conftest import (
|
||||
|
||||
|
||||
async def test_setup_with_no_config(hass: HomeAssistant) -> None:
|
||||
"""Test DOMAIN is empty if there is no config."""
|
||||
"""Test the action is registered at integration setup, before any entry loads."""
|
||||
assert await async_setup_component(hass, DOMAIN, {})
|
||||
await hass.async_block_till_done()
|
||||
assert DOMAIN not in hass.config_entries.async_domains()
|
||||
assert hass.services.has_service(DOMAIN, SERVICE_UNLOCK_SPECIFIC_DOOR)
|
||||
|
||||
|
||||
async def test_setup_ev(hass: HomeAssistant, ev_entry) -> None:
|
||||
|
||||
Reference in New Issue
Block a user