mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Fix socket bug with Yi in 0.72 (#15109)
* Fixes BrokenPipeError exceptions with Yi (#15108) * Make sure to close the socket
This commit is contained in:
parent
1c8b52f630
commit
893e0f8db6
@ -53,7 +53,6 @@ class YiCamera(Camera):
|
|||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._extra_arguments = config.get(CONF_FFMPEG_ARGUMENTS)
|
self._extra_arguments = config.get(CONF_FFMPEG_ARGUMENTS)
|
||||||
self._ftp = None
|
|
||||||
self._last_image = None
|
self._last_image = None
|
||||||
self._last_url = None
|
self._last_url = None
|
||||||
self._manager = hass.data[DATA_FFMPEG]
|
self._manager = hass.data[DATA_FFMPEG]
|
||||||
@ -64,8 +63,6 @@ class YiCamera(Camera):
|
|||||||
self.user = config[CONF_USERNAME]
|
self.user = config[CONF_USERNAME]
|
||||||
self.passwd = config[CONF_PASSWORD]
|
self.passwd = config[CONF_PASSWORD]
|
||||||
|
|
||||||
hass.async_add_job(self._connect_to_client)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brand(self):
|
def brand(self):
|
||||||
"""Camera brand."""
|
"""Camera brand."""
|
||||||
@ -76,38 +73,35 @@ class YiCamera(Camera):
|
|||||||
"""Return the name of this camera."""
|
"""Return the name of this camera."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
async def _connect_to_client(self):
|
async def _get_latest_video_url(self):
|
||||||
"""Attempt to establish a connection via FTP."""
|
"""Retrieve the latest video file from the customized Yi FTP server."""
|
||||||
from aioftp import Client, StatusCodeError
|
from aioftp import Client, StatusCodeError
|
||||||
|
|
||||||
ftp = Client()
|
ftp = Client()
|
||||||
try:
|
try:
|
||||||
await ftp.connect(self.host)
|
await ftp.connect(self.host)
|
||||||
await ftp.login(self.user, self.passwd)
|
await ftp.login(self.user, self.passwd)
|
||||||
self._ftp = ftp
|
|
||||||
except StatusCodeError as err:
|
except StatusCodeError as err:
|
||||||
raise PlatformNotReady(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:
|
try:
|
||||||
await self._ftp.change_directory(self.path)
|
await ftp.change_directory(self.path)
|
||||||
dirs = []
|
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):
|
if attrs['type'] == 'dir' and '.' not in str(path):
|
||||||
dirs.append(path)
|
dirs.append(path)
|
||||||
latest_dir = dirs[-1]
|
latest_dir = dirs[-1]
|
||||||
await self._ftp.change_directory(latest_dir)
|
await ftp.change_directory(latest_dir)
|
||||||
|
|
||||||
videos = []
|
videos = []
|
||||||
for path, _ in await self._ftp.list():
|
for path, _ in await ftp.list():
|
||||||
videos.append(path)
|
videos.append(path)
|
||||||
if not videos:
|
if not videos:
|
||||||
_LOGGER.info('Video folder "%s" empty; delaying', latest_dir)
|
_LOGGER.info('Video folder "%s" empty; delaying', latest_dir)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
await ftp.quit()
|
||||||
|
|
||||||
return 'ftp://{0}:{1}@{2}:{3}{4}/{5}/{6}'.format(
|
return 'ftp://{0}:{1}@{2}:{3}{4}/{5}/{6}'.format(
|
||||||
self.user, self.passwd, self.host, self.port, self.path,
|
self.user, self.passwd, self.host, self.port, self.path,
|
||||||
latest_dir, videos[-1])
|
latest_dir, videos[-1])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user