Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions homeassistant/components/binary_sensor/bmw_connected_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import asyncio
import logging

from homeassistant.components.bmw_connected_drive import DOMAIN as BMW_DOMAIN
from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.components.bmw_connected_drive import DOMAIN as BMW_DOMAIN

DEPENDENCIES = ['bmw_connected_drive']

Expand Down Expand Up @@ -45,7 +45,7 @@ def __init__(self, account, vehicle, attribute: str, sensor_name,
self._account = account
self._vehicle = vehicle
self._attribute = attribute
self._name = '{} {}'.format(self._vehicle.modelName, self._attribute)
self._name = '{} {}'.format(self._vehicle.name, self._attribute)
self._sensor_name = sensor_name
self._device_class = device_class
self._state = None
Expand Down Expand Up @@ -75,7 +75,7 @@ def device_state_attributes(self):
"""Return the state attributes of the binary sensor."""
vehicle_state = self._vehicle.state
result = {
'car': self._vehicle.modelName
'car': self._vehicle.name
}

if self._attribute == 'lids':
Expand All @@ -91,6 +91,7 @@ def device_state_attributes(self):

def update(self):
"""Read new state data from the library."""
from bimmer_connected.state import LockState
vehicle_state = self._vehicle.state

# device class opening: On means open, Off means closed
Expand All @@ -101,9 +102,9 @@ def update(self):
self._state = not vehicle_state.all_windows_closed
# device class safety: On means unsafe, Off means safe
if self._attribute == 'door_lock_state':
# Possible values: LOCKED, SECURED, SELECTIVELOCKED, UNLOCKED
self._state = bool(vehicle_state.door_lock_state.value
in ('SELECTIVELOCKED', 'UNLOCKED'))
# Possible values: LOCKED, SECURED, SELECTIVE_LOCKED, UNLOCKED
self._state = vehicle_state.door_lock_state not in \
[LockState.LOCKED, LockState.SECURED]

def update_callback(self):
"""Schedule a state update."""
Expand Down
28 changes: 15 additions & 13 deletions homeassistant/components/bmw_connected_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,29 @@
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/bmw_connected_drive/
"""
import logging
import datetime
import logging

import voluptuous as vol

from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
from homeassistant.helpers import discovery
from homeassistant.helpers.event import track_utc_time_change

import homeassistant.helpers.config_validation as cv
from homeassistant.const import (
CONF_USERNAME, CONF_PASSWORD
)

REQUIREMENTS = ['bimmer_connected==0.4.1']
REQUIREMENTS = ['bimmer_connected==0.5.0']

_LOGGER = logging.getLogger(__name__)

DOMAIN = 'bmw_connected_drive'
CONF_VALUES = 'values'
CONF_COUNTRY = 'country'
CONF_REGION = 'region'


ACCOUNT_SCHEMA = vol.Schema({
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_COUNTRY): cv.string,
vol.Required(CONF_REGION): vol.Any('north_america', 'china',
'rest_of_world'),
})

CONFIG_SCHEMA = vol.Schema({
Expand All @@ -47,9 +46,9 @@ def setup(hass, config):
for name, account_config in config[DOMAIN].items():
username = account_config[CONF_USERNAME]
password = account_config[CONF_PASSWORD]
country = account_config[CONF_COUNTRY]
region = account_config[CONF_REGION]
_LOGGER.debug('Adding new account %s', name)
bimmer = BMWConnectedDriveAccount(username, password, country, name)
bimmer = BMWConnectedDriveAccount(username, password, region, name)
accounts.append(bimmer)

# update every UPDATE_INTERVAL minutes, starting now
Expand All @@ -75,12 +74,15 @@ def setup(hass, config):
class BMWConnectedDriveAccount(object):
"""Representation of a BMW vehicle."""

def __init__(self, username: str, password: str, country: str,
def __init__(self, username: str, password: str, region_str: str,
name: str) -> 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.account = ConnectedDriveAccount(username, password, country)
self.account = ConnectedDriveAccount(username, password, region)
self.name = name
self._update_listeners = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ def __init__(self, see, vehicle):

def update(self) -> None:
"""Update the device info."""
dev_id = slugify(self.vehicle.modelName)
dev_id = slugify(self.vehicle.name)
_LOGGER.debug('Updating %s', dev_id)
attrs = {
'trackr_id': dev_id,
'id': dev_id,
'name': self.vehicle.modelName
'name': self.vehicle.name
}
self._see(
dev_id=dev_id, host_name=self.vehicle.modelName,
dev_id=dev_id, host_name=self.vehicle.name,
gps=self.vehicle.state.gps_position, attributes=attrs,
icon='mdi:car'
)
20 changes: 12 additions & 8 deletions homeassistant/components/lock/bmw_connected_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, account, vehicle, attribute: str, sensor_name):
self._account = account
self._vehicle = vehicle
self._attribute = attribute
self._name = '{} {}'.format(self._vehicle.modelName, self._attribute)
self._name = '{} {}'.format(self._vehicle.name, self._attribute)
self._sensor_name = sensor_name
self._state = None

Expand All @@ -59,7 +59,7 @@ def device_state_attributes(self):
"""Return the state attributes of the lock."""
vehicle_state = self._vehicle.state
return {
'car': self._vehicle.modelName,
'car': self._vehicle.name,
'door_lock_state': vehicle_state.door_lock_state.value
}

Expand All @@ -70,7 +70,7 @@ def is_locked(self):

def lock(self, **kwargs):
"""Lock the car."""
_LOGGER.debug("%s: locking doors", self._vehicle.modelName)
_LOGGER.debug("%s: locking doors", self._vehicle.name)
# Optimistic state set here because it takes some time before the
# update callback response
self._state = STATE_LOCKED
Expand All @@ -79,7 +79,7 @@ def lock(self, **kwargs):

def unlock(self, **kwargs):
"""Unlock the car."""
_LOGGER.debug("%s: unlocking doors", self._vehicle.modelName)
_LOGGER.debug("%s: unlocking doors", self._vehicle.name)
# Optimistic state set here because it takes some time before the
# update callback response
self._state = STATE_UNLOCKED
Expand All @@ -88,13 +88,17 @@ def unlock(self, **kwargs):

def update(self):
"""Update state of the lock."""
_LOGGER.debug("%s: updating data for %s", self._vehicle.modelName,
from bimmer_connected.state import LockState

_LOGGER.debug("%s: updating data for %s", self._vehicle.name,
self._attribute)
vehicle_state = self._vehicle.state

# Possible values: LOCKED, SECURED, SELECTIVELOCKED, UNLOCKED
self._state = (STATE_LOCKED if vehicle_state.door_lock_state.value
in ('LOCKED', 'SECURED') else STATE_UNLOCKED)
# Possible values: LOCKED, SECURED, SELECTIVE_LOCKED, UNLOCKED
self._state = STATE_LOCKED \
if vehicle_state.door_lock_state \
in [LockState.LOCKED, LockState.SECURED] \
else STATE_UNLOCKED

def update_callback(self):
"""Schedule a state update."""
Expand Down
12 changes: 6 additions & 6 deletions homeassistant/components/sensor/bmw_connected_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.bmw_connected_drive/
"""
import logging
import asyncio
import logging

from homeassistant.components.bmw_connected_drive import DOMAIN as BMW_DOMAIN
from homeassistant.helpers.entity import Entity
Expand Down Expand Up @@ -51,7 +51,7 @@ def __init__(self, account, vehicle, attribute: str, sensor_name, icon):
self._attribute = attribute
self._state = None
self._unit_of_measurement = None
self._name = '{} {}'.format(self._vehicle.modelName, self._attribute)
self._name = '{} {}'.format(self._vehicle.name, self._attribute)
self._sensor_name = sensor_name
self._icon = icon

Expand Down Expand Up @@ -88,19 +88,19 @@ def unit_of_measurement(self) -> str:
def device_state_attributes(self):
"""Return the state attributes of the binary sensor."""
return {
'car': self._vehicle.modelName
'car': self._vehicle.name
}

def update(self) -> None:
"""Read new state data from the library."""
_LOGGER.debug('Updating %s', self._vehicle.modelName)
_LOGGER.debug('Updating %s', self._vehicle.name)
vehicle_state = self._vehicle.state
self._state = getattr(vehicle_state, self._attribute)

if self._attribute in LENGTH_ATTRIBUTES:
self._unit_of_measurement = vehicle_state.unit_of_length
self._unit_of_measurement = 'km'
elif self._attribute == 'remaining_fuel':
self._unit_of_measurement = vehicle_state.unit_of_volume
self._unit_of_measurement = 'l'
else:
self._unit_of_measurement = None

Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ beautifulsoup4==4.6.0
bellows==0.5.1

# homeassistant.components.bmw_connected_drive
bimmer_connected==0.4.1
bimmer_connected==0.5.0

# homeassistant.components.blink
blinkpy==0.6.0
Expand Down