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
This commit is contained in:
ChristianKuehnel 2018-03-30 18:12:57 +02:00 committed by Martin Hjelmare
parent 6314aabc6f
commit 979a8f8772

View File

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