mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Adds support for disabled Tiles and automatic session renewal (#11172)
* Adds support for disabled Tiles and automatic session renewal * Updated requirements * Collaborator-requested changes * Collaborator-requested changes
This commit is contained in:
parent
8c303bf48c
commit
5566ea8c81
@ -19,7 +19,7 @@ from homeassistant.util.json import load_json, save_json
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
REQUIREMENTS = ['pytile==1.0.0']
|
REQUIREMENTS = ['pytile==1.1.0']
|
||||||
|
|
||||||
CLIENT_UUID_CONFIG_FILE = '.tile.conf'
|
CLIENT_UUID_CONFIG_FILE = '.tile.conf'
|
||||||
DEFAULT_ICON = 'mdi:bluetooth'
|
DEFAULT_ICON = 'mdi:bluetooth'
|
||||||
@ -29,14 +29,15 @@ ATTR_ALTITUDE = 'altitude'
|
|||||||
ATTR_CONNECTION_STATE = 'connection_state'
|
ATTR_CONNECTION_STATE = 'connection_state'
|
||||||
ATTR_IS_DEAD = 'is_dead'
|
ATTR_IS_DEAD = 'is_dead'
|
||||||
ATTR_IS_LOST = 'is_lost'
|
ATTR_IS_LOST = 'is_lost'
|
||||||
ATTR_LAST_SEEN = 'last_seen'
|
|
||||||
ATTR_LAST_UPDATED = 'last_updated'
|
|
||||||
ATTR_RING_STATE = 'ring_state'
|
ATTR_RING_STATE = 'ring_state'
|
||||||
ATTR_VOIP_STATE = 'voip_state'
|
ATTR_VOIP_STATE = 'voip_state'
|
||||||
|
|
||||||
|
CONF_SHOW_INACTIVE = 'show_inactive'
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_USERNAME): cv.string,
|
vol.Required(CONF_USERNAME): cv.string,
|
||||||
vol.Required(CONF_PASSWORD): cv.string,
|
vol.Required(CONF_PASSWORD): cv.string,
|
||||||
|
vol.Optional(CONF_SHOW_INACTIVE, default=False): cv.boolean,
|
||||||
vol.Optional(CONF_MONITORED_VARIABLES):
|
vol.Optional(CONF_MONITORED_VARIABLES):
|
||||||
vol.All(cv.ensure_list, [vol.In(DEVICE_TYPES)]),
|
vol.All(cv.ensure_list, [vol.In(DEVICE_TYPES)]),
|
||||||
})
|
})
|
||||||
@ -79,6 +80,7 @@ class TileDeviceScanner(DeviceScanner):
|
|||||||
_LOGGER.debug('Client UUID: %s', self._client.client_uuid)
|
_LOGGER.debug('Client UUID: %s', self._client.client_uuid)
|
||||||
_LOGGER.debug('User UUID: %s', self._client.user_uuid)
|
_LOGGER.debug('User UUID: %s', self._client.user_uuid)
|
||||||
|
|
||||||
|
self._show_inactive = config.get(CONF_SHOW_INACTIVE)
|
||||||
self._types = config.get(CONF_MONITORED_VARIABLES)
|
self._types = config.get(CONF_MONITORED_VARIABLES)
|
||||||
|
|
||||||
self.devices = {}
|
self.devices = {}
|
||||||
@ -91,29 +93,25 @@ class TileDeviceScanner(DeviceScanner):
|
|||||||
|
|
||||||
def _update_info(self, now=None) -> None:
|
def _update_info(self, now=None) -> None:
|
||||||
"""Update the device info."""
|
"""Update the device info."""
|
||||||
device_data = self._client.get_tiles(type_whitelist=self._types)
|
self.devices = self._client.get_tiles(
|
||||||
|
type_whitelist=self._types, show_inactive=self._show_inactive)
|
||||||
|
|
||||||
try:
|
if not self.devices:
|
||||||
self.devices = device_data['result']
|
|
||||||
except KeyError:
|
|
||||||
_LOGGER.warning('No Tiles found')
|
_LOGGER.warning('No Tiles found')
|
||||||
_LOGGER.debug(device_data)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
for info in self.devices.values():
|
for dev in self.devices:
|
||||||
dev_id = 'tile_{0}'.format(slugify(info['name']))
|
dev_id = 'tile_{0}'.format(slugify(dev['name']))
|
||||||
lat = info['tileState']['latitude']
|
lat = dev['tileState']['latitude']
|
||||||
lon = info['tileState']['longitude']
|
lon = dev['tileState']['longitude']
|
||||||
|
|
||||||
attrs = {
|
attrs = {
|
||||||
ATTR_ALTITUDE: info['tileState']['altitude'],
|
ATTR_ALTITUDE: dev['tileState']['altitude'],
|
||||||
ATTR_CONNECTION_STATE: info['tileState']['connection_state'],
|
ATTR_CONNECTION_STATE: dev['tileState']['connection_state'],
|
||||||
ATTR_IS_DEAD: info['is_dead'],
|
ATTR_IS_DEAD: dev['is_dead'],
|
||||||
ATTR_IS_LOST: info['tileState']['is_lost'],
|
ATTR_IS_LOST: dev['tileState']['is_lost'],
|
||||||
ATTR_LAST_SEEN: info['tileState']['timestamp'],
|
ATTR_RING_STATE: dev['tileState']['ring_state'],
|
||||||
ATTR_LAST_UPDATED: device_data['timestamp_ms'],
|
ATTR_VOIP_STATE: dev['tileState']['voip_state'],
|
||||||
ATTR_RING_STATE: info['tileState']['ring_state'],
|
|
||||||
ATTR_VOIP_STATE: info['tileState']['voip_state'],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.see(
|
self.see(
|
||||||
|
@ -928,7 +928,7 @@ pythonegardia==1.0.22
|
|||||||
pythonwhois==2.4.3
|
pythonwhois==2.4.3
|
||||||
|
|
||||||
# homeassistant.components.device_tracker.tile
|
# homeassistant.components.device_tracker.tile
|
||||||
pytile==1.0.0
|
pytile==1.1.0
|
||||||
|
|
||||||
# homeassistant.components.device_tracker.trackr
|
# homeassistant.components.device_tracker.trackr
|
||||||
pytrackr==0.0.5
|
pytrackr==0.0.5
|
||||||
|
Loading…
x
Reference in New Issue
Block a user