diff --git a/homeassistant/components/camera/yi.py b/homeassistant/components/camera/yi.py index 868c5afb447..93f526c2b96 100644 --- a/homeassistant/components/camera/yi.py +++ b/homeassistant/components/camera/yi.py @@ -53,7 +53,6 @@ class YiCamera(Camera): """Initialize.""" super().__init__() self._extra_arguments = config.get(CONF_FFMPEG_ARGUMENTS) - self._ftp = None self._last_image = None self._last_url = None self._manager = hass.data[DATA_FFMPEG] @@ -64,8 +63,6 @@ class YiCamera(Camera): self.user = config[CONF_USERNAME] self.passwd = config[CONF_PASSWORD] - hass.async_add_job(self._connect_to_client) - @property def brand(self): """Camera brand.""" @@ -76,38 +73,35 @@ class YiCamera(Camera): """Return the name of this camera.""" return self._name - async def _connect_to_client(self): - """Attempt to establish a connection via FTP.""" + async def _get_latest_video_url(self): + """Retrieve the latest video file from the customized Yi FTP server.""" from aioftp import Client, StatusCodeError ftp = Client() try: await ftp.connect(self.host) await ftp.login(self.user, self.passwd) - self._ftp = ftp except StatusCodeError as err: raise PlatformNotReady(err) - async def _get_latest_video_url(self): - """Retrieve the latest video file from the customized Yi FTP server.""" - from aioftp import StatusCodeError - try: - await self._ftp.change_directory(self.path) + await ftp.change_directory(self.path) dirs = [] - for path, attrs in await self._ftp.list(): + for path, attrs in await ftp.list(): if attrs['type'] == 'dir' and '.' not in str(path): dirs.append(path) latest_dir = dirs[-1] - await self._ftp.change_directory(latest_dir) + await ftp.change_directory(latest_dir) videos = [] - for path, _ in await self._ftp.list(): + for path, _ in await ftp.list(): videos.append(path) if not videos: _LOGGER.info('Video folder "%s" empty; delaying', latest_dir) return None + await ftp.quit() + return 'ftp://{0}:{1}@{2}:{3}{4}/{5}/{6}'.format( self.user, self.passwd, self.host, self.port, self.path, latest_dir, videos[-1])