From 979a8f87728b23ffeef78159deb1fa6570ac628a Mon Sep 17 00:00:00 2001 From: ChristianKuehnel Date: Fri, 30 Mar 2018 18:12:57 +0200 Subject: [PATCH] Fix BMW device tracker toggling state if vehicle tracking is disabled (#12999) * if tracking is disabled, the position is not set in the device tracker. This fixes an issue with a toggling vehicle state. * removed useless attributes --- .../device_tracker/bmw_connected_drive.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/device_tracker/bmw_connected_drive.py b/homeassistant/components/device_tracker/bmw_connected_drive.py index 1e501c0e199..2267bb51944 100644 --- a/homeassistant/components/device_tracker/bmw_connected_drive.py +++ b/homeassistant/components/device_tracker/bmw_connected_drive.py @@ -36,16 +36,20 @@ class BMWDeviceTracker(object): self.vehicle = vehicle def update(self) -> None: - """Update the device info.""" + """Update the device info. + + Only update the state in home assistant if tracking in + the car is enabled. + """ dev_id = slugify(self.vehicle.name) + + if not self.vehicle.state.is_vehicle_tracking_enabled: + _LOGGER.debug('Tracking is disabled for vehicle %s', dev_id) + return + _LOGGER.debug('Updating %s', dev_id) - attrs = { - 'trackr_id': dev_id, - 'id': dev_id, - 'name': self.vehicle.name - } + self._see( dev_id=dev_id, host_name=self.vehicle.name, - gps=self.vehicle.state.gps_position, attributes=attrs, - icon='mdi:car' + gps=self.vehicle.state.gps_position, icon='mdi:car' )