mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Add entity translations to MotionEye (#96740)
* Add entity translations to MotionEye * Fix name * Explicit device name
This commit is contained in:
parent
34f1b2b71d
commit
8937884e33
@ -536,6 +536,8 @@ def get_media_url(
|
|||||||
class MotionEyeEntity(CoordinatorEntity):
|
class MotionEyeEntity(CoordinatorEntity):
|
||||||
"""Base class for motionEye entities."""
|
"""Base class for motionEye entities."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
config_entry_id: str,
|
config_entry_id: str,
|
||||||
|
@ -12,7 +12,6 @@ from motioneye_client.const import (
|
|||||||
DEFAULT_SURVEILLANCE_USERNAME,
|
DEFAULT_SURVEILLANCE_USERNAME,
|
||||||
KEY_ACTION_SNAPSHOT,
|
KEY_ACTION_SNAPSHOT,
|
||||||
KEY_MOTION_DETECTION,
|
KEY_MOTION_DETECTION,
|
||||||
KEY_NAME,
|
|
||||||
KEY_STREAMING_AUTH_MODE,
|
KEY_STREAMING_AUTH_MODE,
|
||||||
KEY_TEXT_OVERLAY_CAMERA_NAME,
|
KEY_TEXT_OVERLAY_CAMERA_NAME,
|
||||||
KEY_TEXT_OVERLAY_CUSTOM_TEXT,
|
KEY_TEXT_OVERLAY_CUSTOM_TEXT,
|
||||||
@ -144,8 +143,6 @@ async def async_setup_entry(
|
|||||||
class MotionEyeMjpegCamera(MotionEyeEntity, MjpegCamera):
|
class MotionEyeMjpegCamera(MotionEyeEntity, MjpegCamera):
|
||||||
"""motionEye mjpeg camera."""
|
"""motionEye mjpeg camera."""
|
||||||
|
|
||||||
_name: str
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
config_entry_id: str,
|
config_entry_id: str,
|
||||||
@ -203,7 +200,7 @@ class MotionEyeMjpegCamera(MotionEyeEntity, MjpegCamera):
|
|||||||
streaming_url = self._client.get_camera_stream_url(camera)
|
streaming_url = self._client.get_camera_stream_url(camera)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
CONF_NAME: camera[KEY_NAME],
|
CONF_NAME: None,
|
||||||
CONF_USERNAME: self._surveillance_username if auth is not None else None,
|
CONF_USERNAME: self._surveillance_username if auth is not None else None,
|
||||||
CONF_PASSWORD: self._surveillance_password if auth is not None else "",
|
CONF_PASSWORD: self._surveillance_password if auth is not None else "",
|
||||||
CONF_MJPEG_URL: streaming_url or "",
|
CONF_MJPEG_URL: streaming_url or "",
|
||||||
@ -218,7 +215,6 @@ class MotionEyeMjpegCamera(MotionEyeEntity, MjpegCamera):
|
|||||||
# Sets the state of the underlying (inherited) MjpegCamera based on the updated
|
# Sets the state of the underlying (inherited) MjpegCamera based on the updated
|
||||||
# MotionEye camera dictionary.
|
# MotionEye camera dictionary.
|
||||||
properties = self._get_mjpeg_camera_properties_for_camera(camera)
|
properties = self._get_mjpeg_camera_properties_for_camera(camera)
|
||||||
self._name = properties[CONF_NAME]
|
|
||||||
self._username = properties[CONF_USERNAME]
|
self._username = properties[CONF_USERNAME]
|
||||||
self._password = properties[CONF_PASSWORD]
|
self._password = properties[CONF_PASSWORD]
|
||||||
self._mjpeg_url = properties[CONF_MJPEG_URL]
|
self._mjpeg_url = properties[CONF_MJPEG_URL]
|
||||||
|
@ -6,7 +6,7 @@ from types import MappingProxyType
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from motioneye_client.client import MotionEyeClient
|
from motioneye_client.client import MotionEyeClient
|
||||||
from motioneye_client.const import KEY_ACTIONS, KEY_NAME
|
from motioneye_client.const import KEY_ACTIONS
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
|
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -48,6 +48,8 @@ async def async_setup_entry(
|
|||||||
class MotionEyeActionSensor(MotionEyeEntity, SensorEntity):
|
class MotionEyeActionSensor(MotionEyeEntity, SensorEntity):
|
||||||
"""motionEye action sensor camera."""
|
"""motionEye action sensor camera."""
|
||||||
|
|
||||||
|
_attr_translation_key = "actions"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
config_entry_id: str,
|
config_entry_id: str,
|
||||||
@ -69,12 +71,6 @@ class MotionEyeActionSensor(MotionEyeEntity, SensorEntity):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
camera_prepend = f"{self._camera[KEY_NAME]} " if self._camera else ""
|
|
||||||
return f"{camera_prepend}Actions"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> StateType:
|
def native_value(self) -> StateType:
|
||||||
"""Return the value reported by the sensor."""
|
"""Return the value reported by the sensor."""
|
||||||
|
@ -37,6 +37,33 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"entity": {
|
||||||
|
"sensor": {
|
||||||
|
"actions": {
|
||||||
|
"name": "Actions"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"switch": {
|
||||||
|
"motion_detection": {
|
||||||
|
"name": "Motion detection"
|
||||||
|
},
|
||||||
|
"text_overlay": {
|
||||||
|
"name": "Text overlay"
|
||||||
|
},
|
||||||
|
"video_streaming": {
|
||||||
|
"name": "Video streaming"
|
||||||
|
},
|
||||||
|
"still_images": {
|
||||||
|
"name": "Still images"
|
||||||
|
},
|
||||||
|
"movies": {
|
||||||
|
"name": "Movies"
|
||||||
|
},
|
||||||
|
"upload_enabled": {
|
||||||
|
"name": "Upload enabled"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"services": {
|
"services": {
|
||||||
"set_text_overlay": {
|
"set_text_overlay": {
|
||||||
"name": "Set text overlay",
|
"name": "Set text overlay",
|
||||||
|
@ -8,7 +8,6 @@ from motioneye_client.client import MotionEyeClient
|
|||||||
from motioneye_client.const import (
|
from motioneye_client.const import (
|
||||||
KEY_MOTION_DETECTION,
|
KEY_MOTION_DETECTION,
|
||||||
KEY_MOVIES,
|
KEY_MOVIES,
|
||||||
KEY_NAME,
|
|
||||||
KEY_STILL_IMAGES,
|
KEY_STILL_IMAGES,
|
||||||
KEY_TEXT_OVERLAY,
|
KEY_TEXT_OVERLAY,
|
||||||
KEY_UPLOAD_ENABLED,
|
KEY_UPLOAD_ENABLED,
|
||||||
@ -28,37 +27,37 @@ from .const import CONF_CLIENT, CONF_COORDINATOR, DOMAIN, TYPE_MOTIONEYE_SWITCH_
|
|||||||
MOTIONEYE_SWITCHES = [
|
MOTIONEYE_SWITCHES = [
|
||||||
SwitchEntityDescription(
|
SwitchEntityDescription(
|
||||||
key=KEY_MOTION_DETECTION,
|
key=KEY_MOTION_DETECTION,
|
||||||
name="Motion Detection",
|
translation_key="motion_detection",
|
||||||
entity_registry_enabled_default=True,
|
entity_registry_enabled_default=True,
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
),
|
),
|
||||||
SwitchEntityDescription(
|
SwitchEntityDescription(
|
||||||
key=KEY_TEXT_OVERLAY,
|
key=KEY_TEXT_OVERLAY,
|
||||||
name="Text Overlay",
|
translation_key="text_overlay",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
),
|
),
|
||||||
SwitchEntityDescription(
|
SwitchEntityDescription(
|
||||||
key=KEY_VIDEO_STREAMING,
|
key=KEY_VIDEO_STREAMING,
|
||||||
name="Video Streaming",
|
translation_key="video_streaming",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
),
|
),
|
||||||
SwitchEntityDescription(
|
SwitchEntityDescription(
|
||||||
key=KEY_STILL_IMAGES,
|
key=KEY_STILL_IMAGES,
|
||||||
name="Still Images",
|
translation_key="still_images",
|
||||||
entity_registry_enabled_default=True,
|
entity_registry_enabled_default=True,
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
),
|
),
|
||||||
SwitchEntityDescription(
|
SwitchEntityDescription(
|
||||||
key=KEY_MOVIES,
|
key=KEY_MOVIES,
|
||||||
name="Movies",
|
translation_key="movies",
|
||||||
entity_registry_enabled_default=True,
|
entity_registry_enabled_default=True,
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
),
|
),
|
||||||
SwitchEntityDescription(
|
SwitchEntityDescription(
|
||||||
key=KEY_UPLOAD_ENABLED,
|
key=KEY_UPLOAD_ENABLED,
|
||||||
name="Upload Enabled",
|
translation_key="upload_enabled",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
),
|
),
|
||||||
@ -114,12 +113,6 @@ class MotionEyeSwitch(MotionEyeEntity, SwitchEntity):
|
|||||||
entity_description,
|
entity_description,
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name of the switch."""
|
|
||||||
camera_prepend = f"{self._camera[KEY_NAME]} " if self._camera else ""
|
|
||||||
return f"{camera_prepend}{self.entity_description.name}"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return true if the switch is on."""
|
"""Return true if the switch is on."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user