From b6da542296eec5ad7293664909055be635475f77 Mon Sep 17 00:00:00 2001 From: rikroe Date: Mon, 11 May 2020 16:54:34 +0200 Subject: [PATCH] Make device_tracker updateable, add hint of config source --- custom_components/bmw_connected_drive/config_flow.py | 5 +++-- custom_components/bmw_connected_drive/device_tracker.py | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/custom_components/bmw_connected_drive/config_flow.py b/custom_components/bmw_connected_drive/config_flow.py index fe1eca4..bbe0fd4 100644 --- a/custom_components/bmw_connected_drive/config_flow.py +++ b/custom_components/bmw_connected_drive/config_flow.py @@ -2,7 +2,7 @@ import logging from homeassistant import config_entries, core, exceptions -from homeassistant.const import CONF_USERNAME +from homeassistant.const import CONF_USERNAME, CONF_SOURCE from . import ACCOUNT_SCHEMA as DATA_SCHEMA, DOMAIN, setup_account from .const import CONF_REGION @@ -35,7 +35,7 @@ async def validate_input(hass: core.HomeAssistant, data): raise InvalidAuth # Return info that you want to store in the config entry. - return {"title": data[CONF_USERNAME]} + return {"title": f"{data[CONF_USERNAME]}{data.get(CONF_SOURCE, '')}"} class BMWConnectedDriveConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): @@ -71,6 +71,7 @@ async def async_step_user(self, user_input=None): async def async_step_import(self, user_input): """Handle import.""" + user_input[CONF_SOURCE] = " (configuration.yaml)" return await self.async_step_user(user_input) diff --git a/custom_components/bmw_connected_drive/device_tracker.py b/custom_components/bmw_connected_drive/device_tracker.py index 45f0471..2c63cf2 100644 --- a/custom_components/bmw_connected_drive/device_tracker.py +++ b/custom_components/bmw_connected_drive/device_tracker.py @@ -97,6 +97,10 @@ def source_type(self): def icon(self): return "mdi:car" + def update(self): + """Update state of the decvice tracker.""" + self._location = self._vehicle.state.gps_position + def update_callback(self): """Schedule a state update.""" self.schedule_update_ha_state(True)