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
5 changed files with 39 additions and 25 deletions
|
@ -536,6 +536,8 @@ def get_media_url(
|
|||
class MotionEyeEntity(CoordinatorEntity):
|
||||
"""Base class for motionEye entities."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config_entry_id: str,
|
||||
|
|
|
@ -12,7 +12,6 @@ from motioneye_client.const import (
|
|||
DEFAULT_SURVEILLANCE_USERNAME,
|
||||
KEY_ACTION_SNAPSHOT,
|
||||
KEY_MOTION_DETECTION,
|
||||
KEY_NAME,
|
||||
KEY_STREAMING_AUTH_MODE,
|
||||
KEY_TEXT_OVERLAY_CAMERA_NAME,
|
||||
KEY_TEXT_OVERLAY_CUSTOM_TEXT,
|
||||
|
@ -144,8 +143,6 @@ async def async_setup_entry(
|
|||
class MotionEyeMjpegCamera(MotionEyeEntity, MjpegCamera):
|
||||
"""motionEye mjpeg camera."""
|
||||
|
||||
_name: str
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config_entry_id: str,
|
||||
|
@ -203,7 +200,7 @@ class MotionEyeMjpegCamera(MotionEyeEntity, MjpegCamera):
|
|||
streaming_url = self._client.get_camera_stream_url(camera)
|
||||
|
||||
return {
|
||||
CONF_NAME: camera[KEY_NAME],
|
||||
CONF_NAME: 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_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
|
||||
# MotionEye camera dictionary.
|
||||
properties = self._get_mjpeg_camera_properties_for_camera(camera)
|
||||
self._name = properties[CONF_NAME]
|
||||
self._username = properties[CONF_USERNAME]
|
||||
self._password = properties[CONF_PASSWORD]
|
||||
self._mjpeg_url = properties[CONF_MJPEG_URL]
|
||||
|
|
|
@ -6,7 +6,7 @@ from types import MappingProxyType
|
|||
from typing import Any
|
||||
|
||||
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.config_entries import ConfigEntry
|
||||
|
@ -48,6 +48,8 @@ async def async_setup_entry(
|
|||
class MotionEyeActionSensor(MotionEyeEntity, SensorEntity):
|
||||
"""motionEye action sensor camera."""
|
||||
|
||||
_attr_translation_key = "actions"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
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
|
||||
def native_value(self) -> StateType:
|
||||
"""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": {
|
||||
"set_text_overlay": {
|
||||
"name": "Set text overlay",
|
||||
|
|
|
@ -8,7 +8,6 @@ from motioneye_client.client import MotionEyeClient
|
|||
from motioneye_client.const import (
|
||||
KEY_MOTION_DETECTION,
|
||||
KEY_MOVIES,
|
||||
KEY_NAME,
|
||||
KEY_STILL_IMAGES,
|
||||
KEY_TEXT_OVERLAY,
|
||||
KEY_UPLOAD_ENABLED,
|
||||
|
@ -28,37 +27,37 @@ from .const import CONF_CLIENT, CONF_COORDINATOR, DOMAIN, TYPE_MOTIONEYE_SWITCH_
|
|||
MOTIONEYE_SWITCHES = [
|
||||
SwitchEntityDescription(
|
||||
key=KEY_MOTION_DETECTION,
|
||||
name="Motion Detection",
|
||||
translation_key="motion_detection",
|
||||
entity_registry_enabled_default=True,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
SwitchEntityDescription(
|
||||
key=KEY_TEXT_OVERLAY,
|
||||
name="Text Overlay",
|
||||
translation_key="text_overlay",
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
SwitchEntityDescription(
|
||||
key=KEY_VIDEO_STREAMING,
|
||||
name="Video Streaming",
|
||||
translation_key="video_streaming",
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
SwitchEntityDescription(
|
||||
key=KEY_STILL_IMAGES,
|
||||
name="Still Images",
|
||||
translation_key="still_images",
|
||||
entity_registry_enabled_default=True,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
SwitchEntityDescription(
|
||||
key=KEY_MOVIES,
|
||||
name="Movies",
|
||||
translation_key="movies",
|
||||
entity_registry_enabled_default=True,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
SwitchEntityDescription(
|
||||
key=KEY_UPLOAD_ENABLED,
|
||||
name="Upload Enabled",
|
||||
translation_key="upload_enabled",
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
|
@ -114,12 +113,6 @@ class MotionEyeSwitch(MotionEyeEntity, SwitchEntity):
|
|||
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
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if the switch is on."""
|
||||
|
|
Loading…
Add table
Reference in a new issue