Add selectors to BMW Connected Drive service definitions (#47065)

Co-authored-by: rikroe <rikroe@users.noreply.github.com>
This commit is contained in:
rikroe 2021-06-15 00:56:14 +02:00 committed by GitHub
parent e1538594cd
commit dfe21eb78f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 23 deletions

View File

@ -11,6 +11,7 @@ from homeassistant.components.notify import DOMAIN as NOTIFY_DOMAIN
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
ATTR_ATTRIBUTION, ATTR_ATTRIBUTION,
CONF_DEVICE_ID,
CONF_NAME, CONF_NAME,
CONF_PASSWORD, CONF_PASSWORD,
CONF_REGION, CONF_REGION,
@ -18,7 +19,7 @@ from homeassistant.const import (
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import discovery from homeassistant.helpers import device_registry, discovery
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import DeviceInfo, Entity from homeassistant.helpers.entity import DeviceInfo, Entity
from homeassistant.helpers.event import track_utc_time_change from homeassistant.helpers.event import track_utc_time_change
@ -51,7 +52,12 @@ ACCOUNT_SCHEMA = vol.Schema(
CONFIG_SCHEMA = vol.Schema({DOMAIN: {cv.string: ACCOUNT_SCHEMA}}, extra=vol.ALLOW_EXTRA) CONFIG_SCHEMA = vol.Schema({DOMAIN: {cv.string: ACCOUNT_SCHEMA}}, extra=vol.ALLOW_EXTRA)
SERVICE_SCHEMA = vol.Schema({vol.Required(ATTR_VIN): cv.string}) SERVICE_SCHEMA = vol.Schema(
vol.Any(
{vol.Required(ATTR_VIN): cv.string},
{vol.Required(CONF_DEVICE_ID): cv.string},
)
)
DEFAULT_OPTIONS = { DEFAULT_OPTIONS = {
CONF_READ_ONLY: False, CONF_READ_ONLY: False,
@ -207,8 +213,15 @@ def setup_account(entry: ConfigEntry, hass, name: str) -> BMWConnectedDriveAccou
def execute_service(call): def execute_service(call):
"""Execute a service for a vehicle.""" """Execute a service for a vehicle."""
vin = call.data[ATTR_VIN] vin = call.data.get(ATTR_VIN)
device_id = call.data.get(CONF_DEVICE_ID)
vehicle = None vehicle = None
if not vin and device_id:
device = device_registry.async_get(hass).async_get(device_id)
vin = next(iter(device.identifiers))[1]
# Double check for read_only accounts as another account could create the services # Double check for read_only accounts as another account could create the services
for entry_data in [ for entry_data in [
e e

View File

@ -6,14 +6,20 @@
light_flash: light_flash:
name: Flash lights name: Flash lights
description: > description: >
Flash the lights of the vehicle. The vehicle is identified via the vin Flash the lights of the vehicle. The vehicle is identified either via its
(see below). device entry or the VIN. If a VIN is specified, the device entry will be ignored.
fields: fields:
device_id:
name: Car
description: The BMW Connected Drive device
selector:
device:
integration: bmw_connected_drive
vin: vin:
name: VIN name: VIN
description: > description: The vehicle identification number (VIN) of the vehicle, 17 characters
The vehicle identification number (VIN) of the vehicle, 17 characters advanced: true
required: true required: false
example: WBANXXXXXX1234567 example: WBANXXXXXX1234567
selector: selector:
text: text:
@ -21,14 +27,20 @@ light_flash:
sound_horn: sound_horn:
name: Sound horn name: Sound horn
description: > description: >
Sound the horn of the vehicle. The vehicle is identified via the vin Sound the horn of the vehicle. The vehicle is identified either via its
(see below). device entry or the VIN. If a VIN is specified, the device entry will be ignored.
fields: fields:
device_id:
name: Car
description: The BMW Connected Drive device
selector:
device:
integration: bmw_connected_drive
vin: vin:
name: VIN name: VIN
description: > description: The vehicle identification number (VIN) of the vehicle, 17 characters
The vehicle identification number (VIN) of the vehicle, 17 characters advanced: true
required: true required: false
example: WBANXXXXXX1234567 example: WBANXXXXXX1234567
selector: selector:
text: text:
@ -38,14 +50,20 @@ activate_air_conditioning:
description: > description: >
Start the air conditioning of the vehicle. What exactly is started here Start the air conditioning of the vehicle. What exactly is started here
depends on the type of vehicle. It might range from just ventilation over depends on the type of vehicle. It might range from just ventilation over
auxiliary heating to real air conditioning. The vehicle is identified via auxiliary heating to real air conditioning. The vehicle is identified either via its
the vin (see below). device entry or the VIN. If a VIN is specified, the device entry will be ignored.
fields: fields:
device_id:
name: Car
description: The BMW Connected Drive device
selector:
device:
integration: bmw_connected_drive
vin: vin:
name: VIN name: VIN
description: > description: The vehicle identification number (VIN) of the vehicle, 17 characters
The vehicle identification number (VIN) of the vehicle, 17 characters advanced: true
required: true required: false
example: WBANXXXXXX1234567 example: WBANXXXXXX1234567
selector: selector:
text: text:
@ -53,14 +71,20 @@ activate_air_conditioning:
find_vehicle: find_vehicle:
name: Find vehicle name: Find vehicle
description: > description: >
Request vehicle to update the gps location. The vehicle is identified via the vin Request vehicle to update the GPS location. The vehicle is identified either via its
(see below). device entry or the VIN. If a VIN is specified, the device entry will be ignored.
fields: fields:
device_id:
name: Car
description: The BMW Connected Drive device
selector:
device:
integration: bmw_connected_drive
vin: vin:
name: VIN name: VIN
description: > description: The vehicle identification number (VIN) of the vehicle, 17 characters
The vehicle identification number (VIN) of the vehicle, 17 characters advanced: true
required: true required: false
example: WBANXXXXXX1234567 example: WBANXXXXXX1234567
selector: selector:
text: text: