mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 14:57:09 +00:00
Improve type hint in foscam camera entity (#77166)
This commit is contained in:
parent
e3210291a5
commit
03ed552ca9
@ -94,18 +94,17 @@ async def async_setup_entry(
|
|||||||
class HassFoscamCamera(Camera):
|
class HassFoscamCamera(Camera):
|
||||||
"""An implementation of a Foscam IP camera."""
|
"""An implementation of a Foscam IP camera."""
|
||||||
|
|
||||||
def __init__(self, camera, config_entry):
|
def __init__(self, camera: FoscamCamera, config_entry: ConfigEntry) -> None:
|
||||||
"""Initialize a Foscam camera."""
|
"""Initialize a Foscam camera."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self._foscam_session = camera
|
self._foscam_session = camera
|
||||||
self._name = config_entry.title
|
self._attr_name = config_entry.title
|
||||||
self._username = config_entry.data[CONF_USERNAME]
|
self._username = config_entry.data[CONF_USERNAME]
|
||||||
self._password = config_entry.data[CONF_PASSWORD]
|
self._password = config_entry.data[CONF_PASSWORD]
|
||||||
self._stream = config_entry.data[CONF_STREAM]
|
self._stream = config_entry.data[CONF_STREAM]
|
||||||
self._unique_id = config_entry.entry_id
|
self._attr_unique_id = config_entry.entry_id
|
||||||
self._rtsp_port = config_entry.data[CONF_RTSP_PORT]
|
self._rtsp_port = config_entry.data[CONF_RTSP_PORT]
|
||||||
self._motion_status = False
|
|
||||||
if self._rtsp_port:
|
if self._rtsp_port:
|
||||||
self._attr_supported_features = CameraEntityFeature.STREAM
|
self._attr_supported_features = CameraEntityFeature.STREAM
|
||||||
|
|
||||||
@ -119,21 +118,16 @@ class HassFoscamCamera(Camera):
|
|||||||
if ret == -3:
|
if ret == -3:
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
"Can't get motion detection status, camera %s configured with non-admin user",
|
"Can't get motion detection status, camera %s configured with non-admin user",
|
||||||
self._name,
|
self.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
elif ret != 0:
|
elif ret != 0:
|
||||||
LOGGER.error(
|
LOGGER.error(
|
||||||
"Error getting motion detection status of %s: %s", self._name, ret
|
"Error getting motion detection status of %s: %s", self.name, ret
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self._motion_status = response == 1
|
self._attr_motion_detection_enabled = response == 1
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return the entity unique ID."""
|
|
||||||
return self._unique_id
|
|
||||||
|
|
||||||
def camera_image(
|
def camera_image(
|
||||||
self, width: int | None = None, height: int | None = None
|
self, width: int | None = None, height: int | None = None
|
||||||
@ -147,18 +141,13 @@ class HassFoscamCamera(Camera):
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
async def stream_source(self):
|
async def stream_source(self) -> str | None:
|
||||||
"""Return the stream source."""
|
"""Return the stream source."""
|
||||||
if self._rtsp_port:
|
if self._rtsp_port:
|
||||||
return f"rtsp://{self._username}:{self._password}@{self._foscam_session.host}:{self._rtsp_port}/video{self._stream}"
|
return f"rtsp://{self._username}:{self._password}@{self._foscam_session.host}:{self._rtsp_port}/video{self._stream}"
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
|
||||||
def motion_detection_enabled(self):
|
|
||||||
"""Camera Motion Detection Status."""
|
|
||||||
return self._motion_status
|
|
||||||
|
|
||||||
def enable_motion_detection(self) -> None:
|
def enable_motion_detection(self) -> None:
|
||||||
"""Enable motion detection in camera."""
|
"""Enable motion detection in camera."""
|
||||||
try:
|
try:
|
||||||
@ -168,15 +157,15 @@ class HassFoscamCamera(Camera):
|
|||||||
if ret == -3:
|
if ret == -3:
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
"Can't set motion detection status, camera %s configured with non-admin user",
|
"Can't set motion detection status, camera %s configured with non-admin user",
|
||||||
self._name,
|
self.name,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
self._motion_status = True
|
self._attr_motion_detection_enabled = True
|
||||||
except TypeError:
|
except TypeError:
|
||||||
LOGGER.debug(
|
LOGGER.debug(
|
||||||
"Failed enabling motion detection on '%s'. Is it supported by the device?",
|
"Failed enabling motion detection on '%s'. Is it supported by the device?",
|
||||||
self._name,
|
self.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
def disable_motion_detection(self) -> None:
|
def disable_motion_detection(self) -> None:
|
||||||
@ -188,27 +177,27 @@ class HassFoscamCamera(Camera):
|
|||||||
if ret == -3:
|
if ret == -3:
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
"Can't set motion detection status, camera %s configured with non-admin user",
|
"Can't set motion detection status, camera %s configured with non-admin user",
|
||||||
self._name,
|
self.name,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
self._motion_status = False
|
self._attr_motion_detection_enabled = False
|
||||||
except TypeError:
|
except TypeError:
|
||||||
LOGGER.debug(
|
LOGGER.debug(
|
||||||
"Failed disabling motion detection on '%s'. Is it supported by the device?",
|
"Failed disabling motion detection on '%s'. Is it supported by the device?",
|
||||||
self._name,
|
self.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_perform_ptz(self, movement, travel_time):
|
async def async_perform_ptz(self, movement, travel_time):
|
||||||
"""Perform a PTZ action on the camera."""
|
"""Perform a PTZ action on the camera."""
|
||||||
LOGGER.debug("PTZ action '%s' on %s", movement, self._name)
|
LOGGER.debug("PTZ action '%s' on %s", movement, self.name)
|
||||||
|
|
||||||
movement_function = getattr(self._foscam_session, MOVEMENT_ATTRS[movement])
|
movement_function = getattr(self._foscam_session, MOVEMENT_ATTRS[movement])
|
||||||
|
|
||||||
ret, _ = await self.hass.async_add_executor_job(movement_function)
|
ret, _ = await self.hass.async_add_executor_job(movement_function)
|
||||||
|
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
LOGGER.error("Error moving %s '%s': %s", movement, self._name, ret)
|
LOGGER.error("Error moving %s '%s': %s", movement, self.name, ret)
|
||||||
return
|
return
|
||||||
|
|
||||||
await asyncio.sleep(travel_time)
|
await asyncio.sleep(travel_time)
|
||||||
@ -218,12 +207,12 @@ class HassFoscamCamera(Camera):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
LOGGER.error("Error stopping movement on '%s': %s", self._name, ret)
|
LOGGER.error("Error stopping movement on '%s': %s", self.name, ret)
|
||||||
return
|
return
|
||||||
|
|
||||||
async def async_perform_ptz_preset(self, preset_name):
|
async def async_perform_ptz_preset(self, preset_name):
|
||||||
"""Perform a PTZ preset action on the camera."""
|
"""Perform a PTZ preset action on the camera."""
|
||||||
LOGGER.debug("PTZ preset '%s' on %s", preset_name, self._name)
|
LOGGER.debug("PTZ preset '%s' on %s", preset_name, self.name)
|
||||||
|
|
||||||
preset_function = getattr(self._foscam_session, PTZ_GOTO_PRESET_COMMAND)
|
preset_function = getattr(self._foscam_session, PTZ_GOTO_PRESET_COMMAND)
|
||||||
|
|
||||||
@ -231,11 +220,6 @@ class HassFoscamCamera(Camera):
|
|||||||
|
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
LOGGER.error(
|
LOGGER.error(
|
||||||
"Error moving to preset %s on '%s': %s", preset_name, self._name, ret
|
"Error moving to preset %s on '%s': %s", preset_name, self.name, ret
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of this camera."""
|
|
||||||
return self._name
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user