Use push updates in Apple TV#6323
Conversation
|
Please remove |
|
Ouch, missed that one. Removed now. |
balloob
left a comment
There was a problem hiding this comment.
I see a mix of async and sync methods being used. Please make sure you annotate methods correctly and don't mix them.
There was a problem hiding this comment.
Please add annotation @callback or @asyncio.coroutine (or, if this is not an async method, do not use hass.async_add_job but instead use hass.add_job.
There was a problem hiding this comment.
Should be a @callback, yes. It is called as a callback from an async method (think "future"), so everything it performs must be synced with event loop.
There was a problem hiding this comment.
Instead of starting this here, consider adding this to async_added_to_hass
@asyncio.coroutine
def async_added_to_hass(self):
"""Called when entity is about to be added to HASS."""
self._atv.push_updater.start()There was a problem hiding this comment.
Are you sure that you should not use asyncio.TimeoutError ?
There was a problem hiding this comment.
After some thinking I believe I can remove this altogether. It was some experimenting I worked with first but I don't think it's needed.
There was a problem hiding this comment.
Why do an update if you're not changing any of the internal state ?
There was a problem hiding this comment.
What, I must have missed something here. It's supposed to reset self._playing. I'll add that, good spotting!
There was a problem hiding this comment.
Is this supposed to be run inside a thread?
There was a problem hiding this comment.
I do not think so. Doing "stop" is basically cancel on a future and that is not thread-safe, so it must be run in the event loop. So it should be OK?
There was a problem hiding this comment.
Are these methods async friendly ? (_set_power_off is marked as an async callback)
There was a problem hiding this comment.
Yes, they are from what I have gathered (with same reasoning as earlier regarding canceling a future - start effectively adds a future to the event loop).
There was a problem hiding this comment.
hass will be available as self.hass, no need to pass in reference yourself. If push_updater expects hass to be there, only make connection inside async_added_to_hass and you should be good 👍
There was a problem hiding this comment.
Ok, cool. Is this a new thing I have missed? I don't recognize async_added_to_hass 😄
There was a problem hiding this comment.
Yeah it's new, came in last release :)
|
Niiice 🐬 |
|
Hmm, just pulled from dev and restarted. I get the following error in the log file now: I have not seen this before and how can that even happen? |
Description:
This basically removes the need to poll for device state changes.
Checklist:
If the code communicates with devices, web services, or third-party tools:
toxrun successfully. Your PR cannot be merged unless tests passREQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py.