Update bimmer_connected to 0.6.0 (#26098)

* Update bimmer_connected to 0.6.0

* Correct file properties
This commit is contained in:
Gerard 2019-08-21 09:11:06 +02:00 committed by Pascal Vizeli
parent 2fbe01fb33
commit 38ce4039c3
6 changed files with 50 additions and 43 deletions

View File

@ -40,6 +40,7 @@ homeassistant/components/azure_event_hub/* @eavanvalkenburg
homeassistant/components/bitcoin/* @fabaff homeassistant/components/bitcoin/* @fabaff
homeassistant/components/bizkaibus/* @UgaitzEtxebarria homeassistant/components/bizkaibus/* @UgaitzEtxebarria
homeassistant/components/blink/* @fronzbot homeassistant/components/blink/* @fronzbot
homeassistant/components/bmw_connected_drive/* @gerard33
homeassistant/components/braviatv/* @robbiet480 homeassistant/components/braviatv/* @robbiet480
homeassistant/components/broadlink/* @danielhiversen homeassistant/components/broadlink/* @danielhiversen
homeassistant/components/brunt/* @eavanvalkenburg homeassistant/components/brunt/* @eavanvalkenburg

View File

@ -143,7 +143,10 @@ class BMWConnectedDriveAccount:
for listener in self._update_listeners: for listener in self._update_listeners:
listener() listener()
except IOError as exception: except IOError as exception:
_LOGGER.error("Error updating the vehicle state") _LOGGER.error(
"Could not connect to the BMW Connected Drive portal. "
"The vehicle state could not be updated."
)
_LOGGER.exception(exception) _LOGGER.exception(exception)
def add_update_listener(self, listener): def add_update_listener(self, listener):

View File

@ -9,17 +9,17 @@ from . import DOMAIN as BMW_DOMAIN
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
SENSOR_TYPES = { SENSOR_TYPES = {
"lids": ["Doors", "opening"], "lids": ["Doors", "opening", "mdi:car-door"],
"windows": ["Windows", "opening"], "windows": ["Windows", "opening", "mdi:car-door"],
"door_lock_state": ["Door lock state", "safety"], "door_lock_state": ["Door lock state", "safety", "mdi:car-key"],
"lights_parking": ["Parking lights", "light"], "lights_parking": ["Parking lights", "light", "mdi:car-parking-lights"],
"condition_based_services": ["Condition based services", "problem"], "condition_based_services": ["Condition based services", "problem", "mdi:wrench"],
"check_control_messages": ["Control messages", "problem"], "check_control_messages": ["Control messages", "problem", "mdi:car-tire-alert"],
} }
SENSOR_TYPES_ELEC = { SENSOR_TYPES_ELEC = {
"charging_status": ["Charging status", "power"], "charging_status": ["Charging status", "power", "mdi:ev-station"],
"connection_status": ["Connection status", "plug"], "connection_status": ["Connection status", "plug", "mdi:car-electric"],
} }
SENSOR_TYPES_ELEC.update(SENSOR_TYPES) SENSOR_TYPES_ELEC.update(SENSOR_TYPES)
@ -35,24 +35,28 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
if vehicle.has_hv_battery: if vehicle.has_hv_battery:
_LOGGER.debug("BMW with a high voltage battery") _LOGGER.debug("BMW with a high voltage battery")
for key, value in sorted(SENSOR_TYPES_ELEC.items()): for key, value in sorted(SENSOR_TYPES_ELEC.items()):
device = BMWConnectedDriveSensor( if key in vehicle.available_attributes:
account, vehicle, key, value[0], value[1] device = BMWConnectedDriveSensor(
) account, vehicle, key, value[0], value[1], value[2]
devices.append(device) )
devices.append(device)
elif vehicle.has_internal_combustion_engine: elif vehicle.has_internal_combustion_engine:
_LOGGER.debug("BMW with an internal combustion engine") _LOGGER.debug("BMW with an internal combustion engine")
for key, value in sorted(SENSOR_TYPES.items()): for key, value in sorted(SENSOR_TYPES.items()):
device = BMWConnectedDriveSensor( if key in vehicle.available_attributes:
account, vehicle, key, value[0], value[1] device = BMWConnectedDriveSensor(
) account, vehicle, key, value[0], value[1], value[2]
devices.append(device) )
devices.append(device)
add_entities(devices, True) add_entities(devices, True)
class BMWConnectedDriveSensor(BinarySensorDevice): class BMWConnectedDriveSensor(BinarySensorDevice):
"""Representation of a BMW vehicle binary sensor.""" """Representation of a BMW vehicle binary sensor."""
def __init__(self, account, vehicle, attribute: str, sensor_name, device_class): def __init__(
self, account, vehicle, attribute: str, sensor_name, device_class, icon
):
"""Constructor.""" """Constructor."""
self._account = account self._account = account
self._vehicle = vehicle self._vehicle = vehicle
@ -61,6 +65,7 @@ class BMWConnectedDriveSensor(BinarySensorDevice):
self._unique_id = "{}-{}".format(self._vehicle.vin, self._attribute) self._unique_id = "{}-{}".format(self._vehicle.vin, self._attribute)
self._sensor_name = sensor_name self._sensor_name = sensor_name
self._device_class = device_class self._device_class = device_class
self._icon = icon
self._state = None self._state = None
@property @property
@ -81,6 +86,11 @@ class BMWConnectedDriveSensor(BinarySensorDevice):
"""Return the name of the binary sensor.""" """Return the name of the binary sensor."""
return self._name return self._name
@property
def icon(self):
"""Icon to use in the frontend, if any."""
return self._icon
@property @property
def device_class(self): def device_class(self):
"""Return the class of the binary sensor.""" """Return the class of the binary sensor."""
@ -112,23 +122,19 @@ class BMWConnectedDriveSensor(BinarySensorDevice):
for report in vehicle_state.condition_based_services: for report in vehicle_state.condition_based_services:
result.update(self._format_cbs_report(report)) result.update(self._format_cbs_report(report))
elif self._attribute == "check_control_messages": elif self._attribute == "check_control_messages":
check_control_messages = vehicle_state.check_control_messages check_control_messages = vehicle_state.has_check_control_messages
if not check_control_messages: if check_control_messages:
result["check_control_messages"] = "OK"
else:
cbs_list = [] cbs_list = []
for message in check_control_messages: for message in check_control_messages:
cbs_list.append(message["ccmDescriptionShort"]) cbs_list.append(message["ccmDescriptionShort"])
result["check_control_messages"] = cbs_list result["check_control_messages"] = cbs_list
else:
result["check_control_messages"] = "OK"
elif self._attribute == "charging_status": elif self._attribute == "charging_status":
result["charging_status"] = vehicle_state.charging_status.value result["charging_status"] = vehicle_state.charging_status.value
# pylint: disable=protected-access result["last_charging_end_result"] = vehicle_state.last_charging_end_result
result["last_charging_end_result"] = vehicle_state._attributes[ elif self._attribute == "connection_status":
"lastChargingEndResult" result["connection_status"] = vehicle_state.connection_status
]
if self._attribute == "connection_status":
# pylint: disable=protected-access
result["connection_status"] = vehicle_state._attributes["connectionStatus"]
return sorted(result.items()) return sorted(result.items())
@ -166,8 +172,7 @@ class BMWConnectedDriveSensor(BinarySensorDevice):
# device class plug: On means device is plugged in, # device class plug: On means device is plugged in,
# Off means device is unplugged # Off means device is unplugged
if self._attribute == "connection_status": if self._attribute == "connection_status":
# pylint: disable=protected-access self._state = vehicle_state.connection_status == "CONNECTED"
self._state = vehicle_state._attributes["connectionStatus"] == "CONNECTED"
def _format_cbs_report(self, report): def _format_cbs_report(self, report):
result = {} result = {}

View File

@ -1,11 +1,12 @@
{ {
"domain": "bmw_connected_drive", "domain": "bmw_connected_drive",
"name": "Bmw connected drive", "name": "BMW Connected Drive",
"documentation": "https://www.home-assistant.io/components/bmw_connected_drive", "documentation": "https://www.home-assistant.io/components/bmw_connected_drive",
"requirements": [ "requirements": [
"bimmer_connected==0.5.3" "bimmer_connected==0.6.0"
], ],
"dependencies": [], "dependencies": [],
"codeowners": [ "codeowners": [
"@gerard33"
] ]
} }

View File

@ -51,14 +51,11 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
for account in accounts: for account in accounts:
for vehicle in account.account.vehicles: for vehicle in account.account.vehicles:
for attribute_name in vehicle.drive_train_attributes: for attribute_name in vehicle.drive_train_attributes:
device = BMWConnectedDriveSensor( if attribute_name in vehicle.available_attributes:
account, vehicle, attribute_name, attribute_info device = BMWConnectedDriveSensor(
) account, vehicle, attribute_name, attribute_info
devices.append(device) )
device = BMWConnectedDriveSensor( devices.append(device)
account, vehicle, "mileage", attribute_info
)
devices.append(device)
add_entities(devices, True) add_entities(devices, True)

View File

@ -266,7 +266,7 @@ beautifulsoup4==4.8.0
bellows-homeassistant==0.9.1 bellows-homeassistant==0.9.1
# homeassistant.components.bmw_connected_drive # homeassistant.components.bmw_connected_drive
bimmer_connected==0.5.3 bimmer_connected==0.6.0
# homeassistant.components.bizkaibus # homeassistant.components.bizkaibus
bizkaibus==0.1.1 bizkaibus==0.1.1