Update to new "b2vapi" of BMW ConnectedDrive (#13305)

* updated to new "b2vapi" of bimmer_connected

* updated requirements_all.txt

* updated 2 more vehicle names after rebase

* cleanup of import statements

* found one more broken name...

* removed unused constant

* cleanup of import statements 2
This commit is contained in:
ChristianKuehnel 2018-03-24 12:16:49 +01:00 committed by Martin Hjelmare
parent 8bd5f66c57
commit 4d52875229
6 changed files with 44 additions and 37 deletions

View file

@ -7,8 +7,8 @@ https://home-assistant.io/components/binary_sensor.bmw_connected_drive/
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']
@ -45,7 +45,7 @@ class BMWConnectedDriveSensor(BinarySensorDevice):
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
@ -75,7 +75,7 @@ class BMWConnectedDriveSensor(BinarySensorDevice):
"""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':
@ -91,6 +91,7 @@ class BMWConnectedDriveSensor(BinarySensorDevice):
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
@ -101,9 +102,9 @@ class BMWConnectedDriveSensor(BinarySensorDevice):
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."""

View file

@ -4,30 +4,29 @@ Reads vehicle status from BMW connected drive portal.
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({
@ -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
@ -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
self.account = ConnectedDriveAccount(username, password, country)
region = get_region_from_name(region_str)
self.account = ConnectedDriveAccount(username, password, region)
self.name = name
self._update_listeners = []

View file

@ -37,15 +37,15 @@ class BMWDeviceTracker(object):
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'
)

View file

@ -37,7 +37,7 @@ class BMWLock(LockDevice):
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
@ -59,7 +59,7 @@ class BMWLock(LockDevice):
"""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
}
@ -70,7 +70,7 @@ class BMWLock(LockDevice):
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
@ -79,7 +79,7 @@ class BMWLock(LockDevice):
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
@ -88,13 +88,17 @@ class BMWLock(LockDevice):
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."""

View file

@ -4,8 +4,8 @@ Reads vehicle status from BMW connected drive portal.
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
@ -51,7 +51,7 @@ class BMWConnectedDriveSensor(Entity):
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
@ -88,19 +88,19 @@ class BMWConnectedDriveSensor(Entity):
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

View file

@ -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