Support multiple accounts in Tile, use device identifiers (#17108)

*  Update tile to support multiple accounts

* 🎨 fix indent

* 🐛 fix format string

* 🎨 use .format

* 🎨 fix line indent
pull/17122/head
Michael Wei 2018-10-03 16:22:21 -07:00 committed by Aaron Bach
parent cf0147098a
commit 2b3019bdf4
1 changed files with 9 additions and 6 deletions

View File

@ -29,6 +29,8 @@ ATTR_IS_DEAD = 'is_dead'
ATTR_IS_LOST = 'is_lost'
ATTR_RING_STATE = 'ring_state'
ATTR_VOIP_STATE = 'voip_state'
ATTR_TILE_ID = 'tile_identifier'
ATTR_TILE_NAME = 'tile_name'
CONF_SHOW_INACTIVE = 'show_inactive'
@ -50,8 +52,10 @@ async def async_setup_scanner(hass, config, async_see, discovery_info=None):
websession = aiohttp_client.async_get_clientsession(hass)
config_file = hass.config.path(".{}{}".format(
slugify(config[CONF_USERNAME]), CLIENT_UUID_CONFIG_FILE))
config_data = await hass.async_add_job(
load_json, hass.config.path(CLIENT_UUID_CONFIG_FILE))
load_json, config_file)
if config_data:
client = Client(
config[CONF_USERNAME],
@ -63,10 +67,7 @@ async def async_setup_scanner(hass, config, async_see, discovery_info=None):
config[CONF_USERNAME], config[CONF_PASSWORD], websession)
config_data = {'client_uuid': client.client_uuid}
config_saved = await hass.async_add_job(
save_json, hass.config.path(CLIENT_UUID_CONFIG_FILE), config_data)
if not config_saved:
_LOGGER.error('Failed to save the client UUID')
await hass.async_add_job(save_json, config_file, config_data)
scanner = TileScanner(
client, hass, async_see, config[CONF_MONITORED_VARIABLES],
@ -125,7 +126,7 @@ class TileScanner:
for tile in tiles:
await self._async_see(
dev_id='tile_{0}'.format(slugify(tile['name'])),
dev_id='tile_{0}'.format(slugify(tile['tile_uuid'])),
gps=(
tile['tileState']['latitude'],
tile['tileState']['longitude']
@ -138,5 +139,7 @@ class TileScanner:
ATTR_IS_LOST: tile['tileState']['is_lost'],
ATTR_RING_STATE: tile['tileState']['ring_state'],
ATTR_VOIP_STATE: tile['tileState']['voip_state'],
ATTR_TILE_ID: tile['tile_uuid'],
ATTR_TILE_NAME: tile['name']
},
icon=DEFAULT_ICON)