-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
Make Yi platform async #14944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Yi platform async #14944
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty much good to me 👍. Just a few quick comments
latest_dir, videos[-1]) | ||
except (ConnectionRefusedError, StatusCodeError) as err: | ||
print('There was an issue: {0}'.format(err)) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent return - once you're returning False
, once a string and here None
. It does work but I would suggest switching both error cases to return None
.
self.user, self.passwd, self.host, self.port, self.path, | ||
latest_dir, videos[-1]) | ||
except (ConnectionRefusedError, StatusCodeError) as err: | ||
print('There was an issue: {0}'.format(err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use _LOGGER.error()
. Also, I don't think "there was an issue ..." Is not that great of a issue message :P
Maybe something like: "Error while fetching video URL: ..."
return 'ftp://{0}:{1}@{2}:{3}{4}/{5}/{6}'.format( | ||
self.user, self.passwd, self.host, self.port, self.path, | ||
latest_dir, videos[-1]) | ||
await ftp.connect(self.host) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe For a future PR if it's possible: Opening a whole new FTP session with a new socket for each new image is ... a bit inefficient I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great feedback; I think I should be able to address this easily. Hang tight.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah just realized that ffmpeg/whatever is passing on the video stream is opening a new socket for each image anyway... So this is probably not that big of a speedup in the end. Sorry about that!
I would just like to point out #14244 existence |
@dgomes To what end? Yi Technologies has split off from Xiaomi, so blending them together makes no sense. That PR looks like a near-exact copy of my original one (prior to this PR’s async work). EDIT: I’ve taken a deeper look at that PR. The connection between the Xiaofang and Yi platforms – if there is one – is how the videos are accessed: via FTP. There’s no overarching similarity between them beyond that. So, there are some options:
I honestly don’t think 3 makes sense: that’s consolidation for consolidation’s sake. 2 doesn’t feel quite right either. I’d recommend 1 and if there’s heartburn about code replication, we should move the FTP video-access logic into a helper via a separate PR. Lastly, no matter what, I’d still suggest the async changes: since we’re at a minimum of Python 3.5.3 and have |
First aioftp is very much welcomed! Now in relation to #14244: It looks almost equal to the original Yi Camera because that was the initial PR submitted. It was a blant copy&paste of the Yi Camera code as Xiaomi Camera with minor tweaks to accommodate Xiaofang. IMHO: If the platforms share >90% of the code they should be the same platform. To me what makes no sense is that the same code does not exist in two separate platforms. An FTPcamera actually makes more sense to me, not through a new component (#3) but through your proposal #2 (just renaming it Yi Camera -> FTP Camera and adding configuration options to accommodate various cameras). |
I disagree with this. If they are two different brands, they should be different platforms with their own code. Just like light and switch are very similar but still have their own code. Eventually these platforms will evolve and they will no longer have 90% overlap, splitting them up then is going to be a pain. |
On the other hand, if a bug/change is made to one of the platforms, the others will not get updated. Very hard to maintain code this way :( |
If you merge 2 platforms in one piece of code, each feature that is only supported by some models, will create more permutations that need to be tested and will be easier to have bugs. So if you have 2 simple implementations, it's easier to find and fix a bug. |
The only difference is the FTP path And my point is that the 90% of code shared is common to any camera with an FTP interface, therefore why I said an FTP Camera made more sense than 20+ different cameras where only the path changes. |
I don’t think that was the only change – didn’t he also mentioned that at that path, he couldn’t grab the latest file, but had to grab the one right before it? And any rate, combining these would require an architectural discussion – some platforms might point at a single folder, some platforms my point at folders of folders, various platforms will need to choose files with in those folders based on certain criteria, etc. |
* Conversion complete * Updated requirements * Got rid of 3.6-specific syntax * Removed more 3.6-specific syntax * Contributor-requested changes
* Conversion complete * Updated requirements * Got rid of 3.6-specific syntax * Removed more 3.6-specific syntax * Contributor-requested changes
Description:
This PR makes the Yi camera platform async.
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):Checklist:
tox
. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated in home-assistant.github.ioIf the code communicates with devices, web services, or third-party tools:
REQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
.- [ ] New files were added to.coveragerc
.