mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
BMW Connected drive: option to disable the services (#15993)
* Update __init__.py * Update bmw_connected_drive.py * Update __init__.py * Update bmw_connected_drive.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update bmw_connected_drive.py
This commit is contained in:
parent
bc21a1b944
commit
e9e5bce10c
@ -20,6 +20,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
DOMAIN = 'bmw_connected_drive'
|
DOMAIN = 'bmw_connected_drive'
|
||||||
CONF_REGION = 'region'
|
CONF_REGION = 'region'
|
||||||
|
CONF_READ_ONLY = 'read_only'
|
||||||
ATTR_VIN = 'vin'
|
ATTR_VIN = 'vin'
|
||||||
|
|
||||||
ACCOUNT_SCHEMA = vol.Schema({
|
ACCOUNT_SCHEMA = vol.Schema({
|
||||||
@ -27,6 +28,7 @@ ACCOUNT_SCHEMA = vol.Schema({
|
|||||||
vol.Required(CONF_PASSWORD): cv.string,
|
vol.Required(CONF_PASSWORD): cv.string,
|
||||||
vol.Required(CONF_REGION): vol.Any('north_america', 'china',
|
vol.Required(CONF_REGION): vol.Any('north_america', 'china',
|
||||||
'rest_of_world'),
|
'rest_of_world'),
|
||||||
|
vol.Optional(CONF_READ_ONLY, default=False): cv.boolean,
|
||||||
})
|
})
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
@ -82,8 +84,10 @@ def setup_account(account_config: dict, hass, name: str) \
|
|||||||
username = account_config[CONF_USERNAME]
|
username = account_config[CONF_USERNAME]
|
||||||
password = account_config[CONF_PASSWORD]
|
password = account_config[CONF_PASSWORD]
|
||||||
region = account_config[CONF_REGION]
|
region = account_config[CONF_REGION]
|
||||||
|
read_only = account_config[CONF_READ_ONLY]
|
||||||
_LOGGER.debug('Adding new account %s', name)
|
_LOGGER.debug('Adding new account %s', name)
|
||||||
cd_account = BMWConnectedDriveAccount(username, password, region, name)
|
cd_account = BMWConnectedDriveAccount(username, password, region, name,
|
||||||
|
read_only)
|
||||||
|
|
||||||
def execute_service(call):
|
def execute_service(call):
|
||||||
"""Execute a service for a vehicle.
|
"""Execute a service for a vehicle.
|
||||||
@ -99,13 +103,13 @@ def setup_account(account_config: dict, hass, name: str) \
|
|||||||
function_name = _SERVICE_MAP[call.service]
|
function_name = _SERVICE_MAP[call.service]
|
||||||
function_call = getattr(vehicle.remote_services, function_name)
|
function_call = getattr(vehicle.remote_services, function_name)
|
||||||
function_call()
|
function_call()
|
||||||
|
if not read_only:
|
||||||
# register the remote services
|
# register the remote services
|
||||||
for service in _SERVICE_MAP:
|
for service in _SERVICE_MAP:
|
||||||
hass.services.register(
|
hass.services.register(
|
||||||
DOMAIN, service,
|
DOMAIN, service,
|
||||||
execute_service,
|
execute_service,
|
||||||
schema=SERVICE_SCHEMA)
|
schema=SERVICE_SCHEMA)
|
||||||
|
|
||||||
# update every UPDATE_INTERVAL minutes, starting now
|
# update every UPDATE_INTERVAL minutes, starting now
|
||||||
# this should even out the load on the servers
|
# this should even out the load on the servers
|
||||||
@ -122,13 +126,14 @@ class BMWConnectedDriveAccount:
|
|||||||
"""Representation of a BMW vehicle."""
|
"""Representation of a BMW vehicle."""
|
||||||
|
|
||||||
def __init__(self, username: str, password: str, region_str: str,
|
def __init__(self, username: str, password: str, region_str: str,
|
||||||
name: str) -> None:
|
name: str, read_only) -> None:
|
||||||
"""Constructor."""
|
"""Constructor."""
|
||||||
from bimmer_connected.account import ConnectedDriveAccount
|
from bimmer_connected.account import ConnectedDriveAccount
|
||||||
from bimmer_connected.country_selector import get_region_from_name
|
from bimmer_connected.country_selector import get_region_from_name
|
||||||
|
|
||||||
region = get_region_from_name(region_str)
|
region = get_region_from_name(region_str)
|
||||||
|
|
||||||
|
self.read_only = read_only
|
||||||
self.account = ConnectedDriveAccount(username, password, region)
|
self.account = ConnectedDriveAccount(username, password, region)
|
||||||
self.name = name
|
self.name = name
|
||||||
self._update_listeners = []
|
self._update_listeners = []
|
||||||
|
@ -23,9 +23,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
', '.join([a.name for a in accounts]))
|
', '.join([a.name for a in accounts]))
|
||||||
devices = []
|
devices = []
|
||||||
for account in accounts:
|
for account in accounts:
|
||||||
for vehicle in account.account.vehicles:
|
if not account.read_only:
|
||||||
device = BMWLock(account, vehicle, 'lock', 'BMW lock')
|
for vehicle in account.account.vehicles:
|
||||||
devices.append(device)
|
device = BMWLock(account, vehicle, 'lock', 'BMW lock')
|
||||||
|
devices.append(device)
|
||||||
add_devices(devices, True)
|
add_devices(devices, True)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user