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."""