# Buggy code
def __init__(self, hass, config):
    """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]
    self._name = config[CONF_NAME]
    self.host = config[CONF_HOST]
    self.port = config[CONF_PORT]
    self.path = config[CONF_PATH]
    self.user = config[CONF_USERNAME]
    self.passwd = config[CONF_PASSWORD]

    hass.async_add_job(self._connect_to_client)


# Traceback (BrokenPipeError)
Traceback (most recent call last):
File "/usr/lib/python3.6/asyncio/tasks.py", line 179, in _step
result = coro.send(None)
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 474, in send_camera_still
image = await async_get_image(hass, msg['entity_id'])
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 124, in async_get_image
image = await camera.async_camera_image()
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/yi.py", line 122, in async_camera_image
url = await self._get_latest_video_url()
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/yi.py", line 96, in _get_latest_video_url
await self._ftp.change_directory(self.path)
File "/config/deps/lib/python3.6/site-packages/aioftp/client.py", line 555, in change_directory
await self.command(cmd, "2xx")
File "/config/deps/lib/python3.6/site-packages/aioftp/client.py", line 242, in command
await self.stream.write(message.encode(encoding=self.encoding))
File "/config/deps/lib/python3.6/site-packages/aioftp/common.py", line 549, in write
await super().write(data)
File "/usr/lib/python3.6/asyncio/tasks.py", line 333, in wait_for
return (yield from fut)
File "/config/deps/lib/python3.6/site-packages/aioftp/common.py", line 301, in write
await self.writer.drain()
File "/usr/lib/python3.6/asyncio/streams.py", line 323, in drain
raise exc
File "/usr/lib/python3.6/asyncio/tasks.py", line 179, in _step
result = coro.send(None)
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 474, in send_camera_still
image = await async_get_image(hass, msg['entity_id'])
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 124, in async_get_image
image = await camera.async_camera_image()
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/yi.py", line 122, in async_camera_image
url = await self._get_latest_video_url()
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/yi.py", line 96, in _get_latest_video_url
await self._ftp.change_directory(self.path)
File "/config/deps/lib/python3.6/site-packages/aioftp/client.py", line 555, in change_directory
await self.command(cmd, "2xx")
File "/config/deps/lib/python3.6/site-packages/aioftp/client.py", line 242, in command
await self.stream.write(message.encode(encoding=self.encoding))
File "/config/deps/lib/python3.6/site-packages/aioftp/common.py", line 549, in write
await super().write(data)
File "/usr/lib/python3.6/asyncio/tasks.py", line 333, in wait_for
return (yield from fut)
File "/config/deps/lib/python3.6/site-packages/aioftp/common.py", line 301, in write
await self.writer.drain()
File "/usr/lib/python3.6/asyncio/streams.py", line 323, in drain
raise exc
File "/usr/lib/python3.6/asyncio/tasks.py", line 179, in _step
result = coro.send(None)
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 474, in send_camera_still
image = await async_get_image(hass, msg['entity_id'])
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 124, in async_get_image
image = await camera.async_camera_image()
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/yi.py", line 122, in async_camera_image
url = await self._get_latest_video_url()
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/yi.py", line 96, in _get_latest_video_url
await self._ftp.change_directory(self.path)
File "/config/deps/lib/python3.6/site-packages/aioftp/client.py", line 555, in change_directory
await self.command(cmd, "2xx")
File "/config/deps/lib/python3.6/site-packages/aioftp/client.py", line 242, in command
await self.stream.write(message.encode(encoding=self.encoding))
File "/config/deps/lib/python3.6/site-packages/aioftp/common.py", line 549, in write
await super().write(data)
File "/usr/lib/python3.6/asyncio/tasks.py", line 333, in wait_for
return (yield from fut)
File "/config/deps/lib/python3.6/site-packages/aioftp/common.py", line 301, in write
await self.writer.drain()
File "/usr/lib/python3.6/asyncio/streams.py", line 323, in drain
raise exc
File "/usr/lib/python3.6/asyncio/tasks.py", line 179, in _step
result = coro.send(None)
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 474, in send_camera_still
image = await async_get_image(hass, msg['entity_id'])
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 124, in async_get_image
image = await camera.async_camera_image()
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/yi.py", line 122, in async_camera_image
url = await self._get_latest_video_url()
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/yi.py", line 96, in _get_latest_video_url
await self._ftp.change_directory(self.path)
File "/config/deps/lib/python3.6/site-packages/aioftp/client.py", line 555, in change_directory
await self.command(cmd, "2xx")
File "/config/deps/lib/python3.6/site-packages/aioftp/client.py", line 242, in command
await self.stream.write(message.encode(encoding=self.encoding))
File "/config/deps/lib/python3.6/site-packages/aioftp/common.py", line 549, in write
await super().write(data)
File "/usr/lib/python3.6/asyncio/tasks.py", line 333, in wait_for
return (yield from fut)
File "/config/deps/lib/python3.6/site-packages/aioftp/common.py", line 301, in write
await self.writer.drain()
File "/usr/lib/python3.6/asyncio/streams.py", line 323, in drain
raise exc
File "/usr/lib/python3.6/asyncio/tasks.py", line 179, in _step
result = coro.send(None)
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 474, in send_camera_still
image = await async_get_image(hass, msg['entity_id'])
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 124, in async_get_image
image = await camera.async_camera_image()
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/yi.py", line 122, in async_camera_image
url = await self._get_latest_video_url()
File "/usr/lib/python3.6/site-packages/homeassistant/components/camera/yi.py", line 96, in _get_latest_video_url
await self._ftp.change_directory(self.path)
File "/config/deps/lib/python3.6/site-packages/aioftp/client.py", line 555, in change_directory
await self.command(cmd, "2xx")
File "/config/deps/lib/python3.6/site-packages/aioftp/client.py", line 242, in command
await self.stream.write(message.encode(encoding=self.encoding))
File "/config/deps/lib/python3.6/site-packages/aioftp/common.py", line 549, in write
await super().write(data)
File "/usr/lib/python3.6/asyncio/tasks.py", line 333, in wait_for
return (yield from fut)
File "/config/deps/lib/python3.6/site-packages/aioftp/common.py", line 301, in write
await self.writer.drain()
File "/usr/lib/python3.6/asyncio/streams.py", line 323, in drain
raise exc
File "/usr/lib/python3.6/asyncio/selector_events.py", line 762, in write
n = self._sock.send(data)
BrokenPipeError: [Errno 32] Broken pipe

# Fixed code
def __init__(self, hass, config):
    """Initialize."""
    super().__init__()
    self._extra_arguments = config.get(CONF_FFMPEG_ARGUMENTS)
    self._last_image = None
    self._last_url = None
    self._manager = hass.data[DATA_FFMPEG]
    self._name = config[CONF_NAME]
    self.host = config[CONF_HOST]
    self.port = config[CONF_PORT]
    self.path = config[CONF_PATH]
    self.user = config[CONF_USERNAME]
    self.passwd = config[CONF_PASSWORD]