Skip to content
23 changes: 14 additions & 9 deletions homeassistant/components/bmw_connected_drive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

DOMAIN = 'bmw_connected_drive'
CONF_REGION = 'region'
CONF_ENABLE_SERVICES = 'services'

@balloob balloob Aug 16, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename the option to read_only and default it to False

@Alexxander0 Alexxander0 Aug 16, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean CONF_READ_ONLY = 'services' ? This wouldnt make it consistent, because there is always a negation needed. I could do CONF_READ_ONLY = 'services_disabled' and set the default to false ?
Or CONF_READ_ONLY = 'read_only'

ATTR_VIN = 'vin'

ACCOUNT_SCHEMA = vol.Schema({
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_REGION): vol.Any('north_america', 'china',
'rest_of_world'),
vol.Optional(CONF_ENABLE_SERVICES, default=True): cv.boolean,
})

CONFIG_SCHEMA = vol.Schema({
Expand Down Expand Up @@ -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]
enable_services = account_config[CONF_ENABLE_SERVICES]
_LOGGER.debug('Adding new account %s', name)
cd_account = BMWConnectedDriveAccount(username, password, region, name)
cd_account = BMWConnectedDriveAccount(username, password, region, name,
enable_services)

def execute_service(call):
"""Execute a service for a vehicle.
Expand All @@ -99,13 +103,13 @@ def execute_service(call):
function_name = _SERVICE_MAP[call.service]
function_call = getattr(vehicle.remote_services, function_name)
function_call()

# register the remote services
for service in _SERVICE_MAP:
hass.services.register(
DOMAIN, service,
execute_service,
schema=SERVICE_SCHEMA)
if enable_services:
# register the remote services
for service in _SERVICE_MAP:
hass.services.register(
DOMAIN, service,
execute_service,
schema=SERVICE_SCHEMA)

# update every UPDATE_INTERVAL minutes, starting now
# this should even out the load on the servers
Expand All @@ -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, enable_services=True) -> 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.enable_services = enable_services
self.account = ConnectedDriveAccount(username, password, region)
self.name = name
self._update_listeners = []
Expand Down
7 changes: 4 additions & 3 deletions homeassistant/components/lock/bmw_connected_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
', '.join([a.name for a in accounts]))
devices = []
for account in accounts:
for vehicle in account.account.vehicles:
device = BMWLock(account, vehicle, 'lock', 'BMW lock')
devices.append(device)
if account.enable_services:
for vehicle in account.account.vehicles:
device = BMWLock(account, vehicle, 'lock', 'BMW lock')
devices.append(device)
add_devices(devices, True)


Expand Down