mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 05:47:10 +00:00
Use shorthand attributes in yi camera (#145276)
This commit is contained in:
parent
fd1ddbd93d
commit
502574e86f
@ -66,36 +66,22 @@ async def async_setup_platform(
|
|||||||
class YiCamera(Camera):
|
class YiCamera(Camera):
|
||||||
"""Define an implementation of a Yi Camera."""
|
"""Define an implementation of a Yi Camera."""
|
||||||
|
|
||||||
def __init__(self, hass, config):
|
_attr_brand = DEFAULT_BRAND
|
||||||
|
|
||||||
|
def __init__(self, hass: HomeAssistant, config: ConfigType) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._extra_arguments = config.get(CONF_FFMPEG_ARGUMENTS)
|
self._extra_arguments = config.get(CONF_FFMPEG_ARGUMENTS)
|
||||||
self._last_image = None
|
self._last_image: bytes | None = None
|
||||||
self._last_url = None
|
self._last_url = None
|
||||||
self._manager = get_ffmpeg_manager(hass)
|
self._manager = get_ffmpeg_manager(hass)
|
||||||
self._name = config[CONF_NAME]
|
self._attr_name = config[CONF_NAME]
|
||||||
self._is_on = True
|
|
||||||
self.host = config[CONF_HOST]
|
self.host = config[CONF_HOST]
|
||||||
self.port = config[CONF_PORT]
|
self.port = config[CONF_PORT]
|
||||||
self.path = config[CONF_PATH]
|
self.path = config[CONF_PATH]
|
||||||
self.user = config[CONF_USERNAME]
|
self.user = config[CONF_USERNAME]
|
||||||
self.passwd = config[CONF_PASSWORD]
|
self.passwd = config[CONF_PASSWORD]
|
||||||
|
|
||||||
@property
|
|
||||||
def brand(self):
|
|
||||||
"""Camera brand."""
|
|
||||||
return DEFAULT_BRAND
|
|
||||||
|
|
||||||
@property
|
|
||||||
def is_on(self):
|
|
||||||
"""Determine whether the camera is on."""
|
|
||||||
return self._is_on
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of this camera."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
async def _get_latest_video_url(self):
|
async def _get_latest_video_url(self):
|
||||||
"""Retrieve the latest video file from the customized Yi FTP server."""
|
"""Retrieve the latest video file from the customized Yi FTP server."""
|
||||||
ftp = Client()
|
ftp = Client()
|
||||||
@ -122,14 +108,14 @@ class YiCamera(Camera):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
await ftp.quit()
|
await ftp.quit()
|
||||||
self._is_on = True
|
self._attr_is_on = True
|
||||||
return (
|
return (
|
||||||
f"ftp://{self.user}:{self.passwd}@{self.host}:"
|
f"ftp://{self.user}:{self.passwd}@{self.host}:"
|
||||||
f"{self.port}{self.path}/{latest_dir}/{videos[-1]}"
|
f"{self.port}{self.path}/{latest_dir}/{videos[-1]}"
|
||||||
)
|
)
|
||||||
except (ConnectionRefusedError, StatusCodeError) as err:
|
except (ConnectionRefusedError, StatusCodeError) as err:
|
||||||
_LOGGER.error("Error while fetching video: %s", err)
|
_LOGGER.error("Error while fetching video: %s", err)
|
||||||
self._is_on = False
|
self._attr_is_on = False
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def async_camera_image(
|
async def async_camera_image(
|
||||||
@ -151,7 +137,7 @@ class YiCamera(Camera):
|
|||||||
|
|
||||||
async def handle_async_mjpeg_stream(self, request):
|
async def handle_async_mjpeg_stream(self, request):
|
||||||
"""Generate an HTTP MJPEG stream from the camera."""
|
"""Generate an HTTP MJPEG stream from the camera."""
|
||||||
if not self._is_on:
|
if not self._attr_is_on:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
stream = CameraMjpeg(self._manager.binary)
|
stream = CameraMjpeg(self._manager.binary)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user