Skip to content

Update Tile platform to be async#15073

Merged
bachya merged 12 commits into
home-assistant:devfrom
bachya:tile
Jul 4, 2018
Merged

Update Tile platform to be async#15073
bachya merged 12 commits into
home-assistant:devfrom
bachya:tile

Conversation

@bachya
Copy link
Copy Markdown
Contributor

@bachya bachya commented Jun 21, 2018

Description:

This PR:

  • Updates the Tile device tracker to be async
  • Re-architects the platform to be cleaner, more consistent, and easier to understand.

Related issue (if applicable): N/A

Pull request in home-assistant.github.io with documentation (if applicable): N/A

Example entry for configuration.yaml (if applicable):

device_tracker:
  - platform: tile
    username: email@address.com
    password: password_123

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated in home-assistant.github.io

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
    - [ ] New files were added to .coveragerc.

If the code does not interact with devices:
- [ ] Tests have been added to verify that the new code works.

ATTR_VOIP_STATE: tile['tileState']['voip_state'],
},
icon=DEFAULT_ICON)
except SessionExpiredError:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only wrap the call that you expect to error with try... except. I think that's await self._client.tiles.all in this case.


try:
await self._client.get_session()
await self._async_update()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's a TileError inside _async_update it won't bubble up here since it's caught inside the method. Does that matter or are we only expecting _client.get_session to error?

self._hass, self._async_update, DEFAULT_SCAN_INTERVAL)

return True
except TileError as err:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this up to only wrap the call(s) that we expect to error.

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, default=list(DEVICE_TYPES)):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why copy to new list?

gps=(
tile['tileState']['latitude'],
tile['tileState']['longitude']),
attributes={
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing whitespace around operator

for tile in tiles:
await self._async_see(
dev_id='tile_{0}'.format(slugify(tile['name'])),
gps=(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing whitespace around operator

)
for tile in tiles:
await self._async_see(
dev_id='tile_{0}'.format(slugify(tile['name'])),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected indentation
missing whitespace around operator

attributes=attrs,
icon=DEFAULT_ICON
)
for tile in tiles:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line under-indented for visual indent

return

if not self.devices:
if not tiles:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line under-indented for visual indent

except SessionExpiredError:
_LOGGER.info('Session expired; trying again shortly')
return
except TileError as err:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line under-indented for visual indent

await self._client.asayn_init()
tiles = await self._client.tiles.all(
whitelist=self._types, show_inactive=self._show_inactive))
except SessionExpiredError:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line under-indented for visual indent

try:
await self._client.asayn_init()
tiles = await self._client.tiles.all(
whitelist=self._types, show_inactive=self._show_inactive))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SyntaxError: invalid syntax

@bachya bachya merged commit 2525fc5 into home-assistant:dev Jul 4, 2018
@ghost ghost removed the in progress label Jul 4, 2018
@bachya bachya deleted the tile branch July 4, 2018 02:42
@bachya bachya added this to the 0.73 milestone Jul 4, 2018
awarecan pushed a commit to awarecan/home-assistant that referenced this pull request Jul 16, 2018
* Updated

* Updated requirements

* Added expired session handling

* Changes

* Member-requested changes

* Bump to 2.0.2

* Bumping requirements

* Better exception handling and tidying

* Move asyncio stuff to HASS built-ins

* Revising re-initi

* Hound

* Hound
girlpunk pushed a commit to girlpunk/home-assistant that referenced this pull request Sep 4, 2018
* Updated

* Updated requirements

* Added expired session handling

* Changes

* Member-requested changes

* Bump to 2.0.2

* Bumping requirements

* Better exception handling and tidying

* Move asyncio stuff to HASS built-ins

* Revising re-initi

* Hound

* Hound
@home-assistant home-assistant locked and limited conversation to collaborators Dec 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants