Xiaomi Cameras - multiple models#14244
Conversation
|
|
||
| return 'ftp://{0}:{1}@{2}:{3}{4}/{5}/{6}/{7}'.format( | ||
| self.user, self.passwd, self.host, self.port, self.path, | ||
| first_dir,latest_dir, videos[-2]) |
| return DEFAULT_BRAND | ||
|
|
||
| def get_latest_video_url(self): | ||
| """Retrieve the latest video file from the customized Xiaofang FTP server.""" |
|
I saw your previous PR (#14238), and I'm wandering: how different is this camera from the Yi ? The code is almost identical, since they are from the same vendor can we have a single platform that covers both cameras with a configuration option indicating the model ? |
|
The folder structure is different than yi model. The folder structure to retrieve in yi model is 2018Y05M01D01H/41M00S.mp4 where as in xiaofang it is 20180501/01/41.mp4. And the latest file writing by the camera is not recognizable by the ffmpeg, so the program has to read last but one file, which is 1 minute lag of live video. |
|
I think those differences could fit in the same platform and we would avoid the duplication of much of the 90% of the code... |
|
I agree, will try to modify the yi.py code and test it on my end before publishing. |
|
Please create a new camera platform "xiaomi" that merges both. But leave "Yi" alone for now, so we don't break users install right away. |
|
I don't get it, this pull is a new platform, how to do it? |
|
|
Added Xiaomi Camera to accommodate multiple models like Yi, Xiaofang, etc.
| _LOGGER.error('Unable to find path: %s', first_dir) | ||
| _LOGGER.debug(exc) | ||
| return False | ||
| if self._model == 'xiaofang': |
There was a problem hiding this comment.
Define constants at the beginning of the file for all the fixed strings
There was a problem hiding this comment.
you mean to store 'xiaofang' and 'yi' as constants?
| ftp.cwd(first_dir) | ||
| except error_perm as exc: | ||
| _LOGGER.error('Unable to find path: %s', first_dir) | ||
| _LOGGER.debug(exc) |
There was a problem hiding this comment.
I think both logging are different, 1st one is level 1 and next is level 2.
There was a problem hiding this comment.
yet both will log the same issue, just leave one of them
There was a problem hiding this comment.
but 1st will report if 20180503 directory exists and 2nd will report if 15 directory exists, there may be cases where the 2nd level will not be there when the camera option was set to only record when there is an motion detection.
There was a problem hiding this comment.
they will both appear when log level is debug, and since they are in the same except clause they are reporting the same issue.
There was a problem hiding this comment.
I do have both models and tested both and worked fine.
There was a problem hiding this comment.
Have a look at existing tests:
create a new file for your platform
There was a problem hiding this comment.
Do I need to create a test?. I don't see it was created for yi already. And it is just a few modification over yi which was already released.
There was a problem hiding this comment.
Yi camera had no options.
I would mock the FTP server, and validade the existence of the image file in a different path depending on the configured model.
There was a problem hiding this comment.
This camera has same options like Yi camera, and am not sure how to do testing, as I am not an expert in python. The code of this one is same as Yi Camera, except one directory above.
| PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
| vol.Required(CONF_NAME): cv.string, | ||
| vol.Required(CONF_HOST): cv.string, | ||
| vol.Required(CONF_MODEL): cv.string, |
| self._manager = hass.data[DATA_FFMPEG] | ||
| self._name = config.get(CONF_NAME) | ||
| self.host = config.get(CONF_HOST) | ||
| self._model = config.get(CONF_MODEL) |
There was a problem hiding this comment.
Required configuration parameters should be retrieved with config[CONF_PARAMETER]
There was a problem hiding this comment.
Could you please let me know how to do it?
There was a problem hiding this comment.
config[CONF_MODEL] and alike for name and host
There was a problem hiding this comment.
only for required options and options with default value
| ftp.cwd(first_dir) | ||
| except error_perm as exc: | ||
| _LOGGER.error('Unable to find path: %s', first_dir) | ||
| _LOGGER.debug(exc) |
There was a problem hiding this comment.
You should also implement:
@property
def model(self):
"""Return the camera model."""
return None
vaidyasr
left a comment
There was a problem hiding this comment.
Fixed the code per review
| ftp.login(self.user, self.passwd) | ||
| except error_perm as exc: | ||
| _LOGGER.error('There was an error while logging into the camera') | ||
| _LOGGER.debug(exc) |
There was a problem hiding this comment.
Still the double logging issue... just merge the two
There was a problem hiding this comment.
Even though double logging is already there in some of the official released codes, am fixing it
|
I don't understand the failure of continuous-integration. The version of attrs library conflict it seems, can someone confirm. |
|
There is currently a PR #14281 related to the issue, wait until it gets merged and then rebase. |
|
I have seen the PR has been merged, how do I rebase? please help. |
|
There is no need to rebase (CI is already passing) What is currently missing is a test so coverage doesn't decrease. |
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| DEFAULT_BRAND = 'Xiaomi Home Camera' | ||
| DEFAULT_PASSWORD = '' |
| async_add_devices, | ||
| discovery_info=None): | ||
| """Set up a Xiaomi Camera.""" | ||
| _LOGGER.debug('Received configuration: %s', config) |
| try: | ||
| ftp.login(self.user, self.passwd) | ||
| except error_perm as exc: | ||
| _LOGGER.error('There was an error while logging: %s', exc) |
There was a problem hiding this comment.
Write at least: "... while logging in:".
Or rephrase to eg: "Camera login failed:".
| return False | ||
|
|
||
| if self._model == MODEL_XIAOFANG: | ||
| dirs = [d for d in ftp.nlst() if '.' not in d] |
There was a problem hiding this comment.
This is the same for both models. Can it be moved up?
Changes made per comment
|
|
||
|
|
||
| dirs = [d for d in ftp.nlst() if '.' not in d] | ||
| if not dirs: |
There was a problem hiding this comment.
IndentationError: unexpected indent
indentation is not a multiple of four
unexpected indentation
| return False | ||
|
|
||
|
|
||
| dirs = [d for d in ftp.nlst() if '.' not in d] |
| _LOGGER.error('Unable to find path: %s - %s', self.path, exc) | ||
| return False | ||
|
|
||
|
|
|
@vaidyasr is this supposed to work with the https://github.com/samtap/fang-hacks cfw? do I need to configure anything there since it looks like this component works with mjpeg whereas fang-hacks by default opens a rtsp stream? |
|
This component works with saved mp4 streams and not the live rtsp stream. For live rtsp stream, you may need to use the ffmpeg camera component. |
|
I didn't realize that this was for alternative firmware. In that case, the integration should be called after the alternative firmware, not the product. |
Description:
Adds support for Xiaomi Cameras running the alternate firmwares.
Related issue (if applicable): N/A
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5290
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:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.