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:
Alexxander0 2018-08-16 22:19:29 +02:00 committed by Paulus Schoutsen
parent bc21a1b944
commit e9e5bce10c
2 changed files with 18 additions and 12 deletions

View File

@ -20,6 +20,7 @@ _LOGGER = logging.getLogger(__name__)
DOMAIN = 'bmw_connected_drive'
CONF_REGION = 'region'
CONF_READ_ONLY = 'read_only'
ATTR_VIN = 'vin'
ACCOUNT_SCHEMA = vol.Schema({
@ -27,6 +28,7 @@ ACCOUNT_SCHEMA = vol.Schema({
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_REGION): vol.Any('north_america', 'china',
'rest_of_world'),
vol.Optional(CONF_READ_ONLY, default=False): cv.boolean,
})
CONFIG_SCHEMA = vol.Schema({
@ -82,8 +84,10 @@ def setup_account(account_config: dict, hass, name: str) \
username = account_config[CONF_USERNAME]
password = account_config[CONF_PASSWORD]
region = account_config[CONF_REGION]
read_only = account_config[CONF_READ_ONLY]
_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):
"""Execute a service for a vehicle.
@ -99,7 +103,7 @@ def setup_account(account_config: dict, hass, name: str) \
function_name = _SERVICE_MAP[call.service]
function_call = getattr(vehicle.remote_services, function_name)
function_call()
if not read_only:
# register the remote services
for service in _SERVICE_MAP:
hass.services.register(
@ -122,13 +126,14 @@ class BMWConnectedDriveAccount:
"""Representation of a BMW vehicle."""
def __init__(self, username: str, password: str, region_str: str,
name: str) -> None:
name: str, read_only) -> None:
"""Constructor."""
from bimmer_connected.account import ConnectedDriveAccount
from bimmer_connected.country_selector import get_region_from_name
region = get_region_from_name(region_str)
self.read_only = read_only
self.account = ConnectedDriveAccount(username, password, region)
self.name = name
self._update_listeners = []

View File

@ -23,6 +23,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
', '.join([a.name for a in accounts]))
devices = []
for account in accounts:
if not account.read_only:
for vehicle in account.account.vehicles:
device = BMWLock(account, vehicle, 'lock', 'BMW lock')
devices.append(device)