From 38ce4039c3c6580e13d9ad006f3390e2c9affd7a Mon Sep 17 00:00:00 2001 From: Gerard Date: Wed, 21 Aug 2019 09:11:06 +0200 Subject: [PATCH] Update bimmer_connected to 0.6.0 (#26098) * Update bimmer_connected to 0.6.0 * Correct file properties --- CODEOWNERS | 1 + .../bmw_connected_drive/__init__.py | 5 +- .../bmw_connected_drive/binary_sensor.py | 65 ++++++++++--------- .../bmw_connected_drive/manifest.json | 7 +- .../components/bmw_connected_drive/sensor.py | 13 ++-- requirements_all.txt | 2 +- 6 files changed, 50 insertions(+), 43 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index d08ac85941c..7a153b3ff82 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -40,6 +40,7 @@ homeassistant/components/azure_event_hub/* @eavanvalkenburg homeassistant/components/bitcoin/* @fabaff homeassistant/components/bizkaibus/* @UgaitzEtxebarria homeassistant/components/blink/* @fronzbot +homeassistant/components/bmw_connected_drive/* @gerard33 homeassistant/components/braviatv/* @robbiet480 homeassistant/components/broadlink/* @danielhiversen homeassistant/components/brunt/* @eavanvalkenburg diff --git a/homeassistant/components/bmw_connected_drive/__init__.py b/homeassistant/components/bmw_connected_drive/__init__.py index 9b44012e758..c257470bb2d 100644 --- a/homeassistant/components/bmw_connected_drive/__init__.py +++ b/homeassistant/components/bmw_connected_drive/__init__.py @@ -143,7 +143,10 @@ class BMWConnectedDriveAccount: for listener in self._update_listeners: listener() 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) def add_update_listener(self, listener): diff --git a/homeassistant/components/bmw_connected_drive/binary_sensor.py b/homeassistant/components/bmw_connected_drive/binary_sensor.py index d52bec330fb..418ccbabffe 100644 --- a/homeassistant/components/bmw_connected_drive/binary_sensor.py +++ b/homeassistant/components/bmw_connected_drive/binary_sensor.py @@ -9,17 +9,17 @@ from . import DOMAIN as BMW_DOMAIN _LOGGER = logging.getLogger(__name__) SENSOR_TYPES = { - "lids": ["Doors", "opening"], - "windows": ["Windows", "opening"], - "door_lock_state": ["Door lock state", "safety"], - "lights_parking": ["Parking lights", "light"], - "condition_based_services": ["Condition based services", "problem"], - "check_control_messages": ["Control messages", "problem"], + "lids": ["Doors", "opening", "mdi:car-door"], + "windows": ["Windows", "opening", "mdi:car-door"], + "door_lock_state": ["Door lock state", "safety", "mdi:car-key"], + "lights_parking": ["Parking lights", "light", "mdi:car-parking-lights"], + "condition_based_services": ["Condition based services", "problem", "mdi:wrench"], + "check_control_messages": ["Control messages", "problem", "mdi:car-tire-alert"], } SENSOR_TYPES_ELEC = { - "charging_status": ["Charging status", "power"], - "connection_status": ["Connection status", "plug"], + "charging_status": ["Charging status", "power", "mdi:ev-station"], + "connection_status": ["Connection status", "plug", "mdi:car-electric"], } 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: _LOGGER.debug("BMW with a high voltage battery") for key, value in sorted(SENSOR_TYPES_ELEC.items()): - device = BMWConnectedDriveSensor( - account, vehicle, key, value[0], value[1] - ) - devices.append(device) + if key in vehicle.available_attributes: + device = BMWConnectedDriveSensor( + account, vehicle, key, value[0], value[1], value[2] + ) + devices.append(device) elif vehicle.has_internal_combustion_engine: _LOGGER.debug("BMW with an internal combustion engine") for key, value in sorted(SENSOR_TYPES.items()): - device = BMWConnectedDriveSensor( - account, vehicle, key, value[0], value[1] - ) - devices.append(device) + if key in vehicle.available_attributes: + device = BMWConnectedDriveSensor( + account, vehicle, key, value[0], value[1], value[2] + ) + devices.append(device) add_entities(devices, True) class BMWConnectedDriveSensor(BinarySensorDevice): """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.""" self._account = account self._vehicle = vehicle @@ -61,6 +65,7 @@ class BMWConnectedDriveSensor(BinarySensorDevice): self._unique_id = "{}-{}".format(self._vehicle.vin, self._attribute) self._sensor_name = sensor_name self._device_class = device_class + self._icon = icon self._state = None @property @@ -81,6 +86,11 @@ class BMWConnectedDriveSensor(BinarySensorDevice): """Return the name of the binary sensor.""" return self._name + @property + def icon(self): + """Icon to use in the frontend, if any.""" + return self._icon + @property def device_class(self): """Return the class of the binary sensor.""" @@ -112,23 +122,19 @@ class BMWConnectedDriveSensor(BinarySensorDevice): for report in vehicle_state.condition_based_services: result.update(self._format_cbs_report(report)) elif self._attribute == "check_control_messages": - check_control_messages = vehicle_state.check_control_messages - if not check_control_messages: - result["check_control_messages"] = "OK" - else: + check_control_messages = vehicle_state.has_check_control_messages + if check_control_messages: cbs_list = [] for message in check_control_messages: cbs_list.append(message["ccmDescriptionShort"]) result["check_control_messages"] = cbs_list + else: + result["check_control_messages"] = "OK" elif self._attribute == "charging_status": result["charging_status"] = vehicle_state.charging_status.value - # pylint: disable=protected-access - result["last_charging_end_result"] = vehicle_state._attributes[ - "lastChargingEndResult" - ] - if self._attribute == "connection_status": - # pylint: disable=protected-access - result["connection_status"] = vehicle_state._attributes["connectionStatus"] + result["last_charging_end_result"] = vehicle_state.last_charging_end_result + elif self._attribute == "connection_status": + result["connection_status"] = vehicle_state.connection_status return sorted(result.items()) @@ -166,8 +172,7 @@ class BMWConnectedDriveSensor(BinarySensorDevice): # device class plug: On means device is plugged in, # Off means device is unplugged if self._attribute == "connection_status": - # pylint: disable=protected-access - self._state = vehicle_state._attributes["connectionStatus"] == "CONNECTED" + self._state = vehicle_state.connection_status == "CONNECTED" def _format_cbs_report(self, report): result = {} diff --git a/homeassistant/components/bmw_connected_drive/manifest.json b/homeassistant/components/bmw_connected_drive/manifest.json index eec81aa6525..0cc875c50f9 100644 --- a/homeassistant/components/bmw_connected_drive/manifest.json +++ b/homeassistant/components/bmw_connected_drive/manifest.json @@ -1,11 +1,12 @@ { "domain": "bmw_connected_drive", - "name": "Bmw connected drive", + "name": "BMW Connected Drive", "documentation": "https://www.home-assistant.io/components/bmw_connected_drive", "requirements": [ - "bimmer_connected==0.5.3" + "bimmer_connected==0.6.0" ], "dependencies": [], "codeowners": [ + "@gerard33" ] -} +} \ No newline at end of file diff --git a/homeassistant/components/bmw_connected_drive/sensor.py b/homeassistant/components/bmw_connected_drive/sensor.py index bc133fa4034..8248ded4f8b 100644 --- a/homeassistant/components/bmw_connected_drive/sensor.py +++ b/homeassistant/components/bmw_connected_drive/sensor.py @@ -51,14 +51,11 @@ def setup_platform(hass, config, add_entities, discovery_info=None): for account in accounts: for vehicle in account.account.vehicles: for attribute_name in vehicle.drive_train_attributes: - device = BMWConnectedDriveSensor( - account, vehicle, attribute_name, attribute_info - ) - devices.append(device) - device = BMWConnectedDriveSensor( - account, vehicle, "mileage", attribute_info - ) - devices.append(device) + if attribute_name in vehicle.available_attributes: + device = BMWConnectedDriveSensor( + account, vehicle, attribute_name, attribute_info + ) + devices.append(device) add_entities(devices, True) diff --git a/requirements_all.txt b/requirements_all.txt index 70378e90fda..bb12466cd71 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -266,7 +266,7 @@ beautifulsoup4==4.8.0 bellows-homeassistant==0.9.1 # homeassistant.components.bmw_connected_drive -bimmer_connected==0.5.3 +bimmer_connected==0.6.0 # homeassistant.components.bizkaibus bizkaibus==0.1.1