Add entity translations to kaleidescape (#95625)
parent
2aff138b92
commit
2807b6cabc
|
@ -3,7 +3,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import TYPE_CHECKING, cast
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
|
@ -19,18 +19,19 @@ _LOGGER = logging.getLogger(__name__)
|
|||
class KaleidescapeEntity(Entity):
|
||||
"""Defines a base Kaleidescape entity."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, device: KaleidescapeDevice) -> None:
|
||||
"""Initialize entity."""
|
||||
self._device = device
|
||||
|
||||
self._attr_should_poll = False
|
||||
self._attr_unique_id = device.serial_number
|
||||
self._attr_name = f"{KALEIDESCAPE_NAME} {device.system.friendly_name}"
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(KALEIDESCAPE_DOMAIN, self._device.serial_number)},
|
||||
# Instead of setting the device name to the entity name, kaleidescape
|
||||
# should be updated to set has_entity_name = True
|
||||
name=cast(str | None, self.name),
|
||||
name=f"{KALEIDESCAPE_NAME} {device.system.friendly_name}",
|
||||
model=self._device.system.type,
|
||||
manufacturer=KALEIDESCAPE_NAME,
|
||||
sw_version=f"{self._device.system.kos_version}",
|
||||
|
|
|
@ -56,6 +56,7 @@ class KaleidescapeMediaPlayer(KaleidescapeEntity, MediaPlayerEntity):
|
|||
| MediaPlayerEntityFeature.NEXT_TRACK
|
||||
| MediaPlayerEntityFeature.PREVIOUS_TRACK
|
||||
)
|
||||
_attr_name = None
|
||||
|
||||
async def async_turn_on(self) -> None:
|
||||
"""Send leave standby command."""
|
||||
|
|
|
@ -47,6 +47,8 @@ VALID_COMMANDS = {
|
|||
class KaleidescapeRemote(KaleidescapeEntity, RemoteEntity):
|
||||
"""Representation of a Kaleidescape device."""
|
||||
|
||||
_attr_name = None
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if device is on."""
|
||||
|
|
|
@ -39,67 +39,67 @@ class KaleidescapeSensorEntityDescription(
|
|||
SENSOR_TYPES: tuple[KaleidescapeSensorEntityDescription, ...] = (
|
||||
KaleidescapeSensorEntityDescription(
|
||||
key="media_location",
|
||||
name="Media Location",
|
||||
translation_key="media_location",
|
||||
icon="mdi:monitor",
|
||||
value_fn=lambda device: device.automation.movie_location,
|
||||
),
|
||||
KaleidescapeSensorEntityDescription(
|
||||
key="play_status",
|
||||
name="Play Status",
|
||||
translation_key="play_status",
|
||||
icon="mdi:monitor",
|
||||
value_fn=lambda device: device.movie.play_status,
|
||||
),
|
||||
KaleidescapeSensorEntityDescription(
|
||||
key="play_speed",
|
||||
name="Play Speed",
|
||||
translation_key="play_speed",
|
||||
icon="mdi:monitor",
|
||||
value_fn=lambda device: device.movie.play_speed,
|
||||
),
|
||||
KaleidescapeSensorEntityDescription(
|
||||
key="video_mode",
|
||||
name="Video Mode",
|
||||
translation_key="video_mode",
|
||||
icon="mdi:monitor-screenshot",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda device: device.automation.video_mode,
|
||||
),
|
||||
KaleidescapeSensorEntityDescription(
|
||||
key="video_color_eotf",
|
||||
name="Video Color EOTF",
|
||||
translation_key="video_color_eotf",
|
||||
icon="mdi:monitor-eye",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda device: device.automation.video_color_eotf,
|
||||
),
|
||||
KaleidescapeSensorEntityDescription(
|
||||
key="video_color_space",
|
||||
name="Video Color Space",
|
||||
translation_key="video_color_space",
|
||||
icon="mdi:monitor-eye",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda device: device.automation.video_color_space,
|
||||
),
|
||||
KaleidescapeSensorEntityDescription(
|
||||
key="video_color_depth",
|
||||
name="Video Color Depth",
|
||||
translation_key="video_color_depth",
|
||||
icon="mdi:monitor-eye",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda device: device.automation.video_color_depth,
|
||||
),
|
||||
KaleidescapeSensorEntityDescription(
|
||||
key="video_color_sampling",
|
||||
name="Video Color Sampling",
|
||||
translation_key="video_color_sampling",
|
||||
icon="mdi:monitor-eye",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda device: device.automation.video_color_sampling,
|
||||
),
|
||||
KaleidescapeSensorEntityDescription(
|
||||
key="screen_mask_ratio",
|
||||
name="Screen Mask Ratio",
|
||||
translation_key="screen_mask_ratio",
|
||||
icon="mdi:monitor-screenshot",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda device: device.automation.screen_mask_ratio,
|
||||
),
|
||||
KaleidescapeSensorEntityDescription(
|
||||
key="screen_mask_top_trim_rel",
|
||||
name="Screen Mask Top Trim Rel",
|
||||
translation_key="screen_mask_top_trim_rel",
|
||||
icon="mdi:monitor-screenshot",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
|
@ -107,7 +107,7 @@ SENSOR_TYPES: tuple[KaleidescapeSensorEntityDescription, ...] = (
|
|||
),
|
||||
KaleidescapeSensorEntityDescription(
|
||||
key="screen_mask_bottom_trim_rel",
|
||||
name="Screen Mask Bottom Trim Rel",
|
||||
translation_key="screen_mask_bottom_trim_rel",
|
||||
icon="mdi:monitor-screenshot",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
|
@ -115,14 +115,14 @@ SENSOR_TYPES: tuple[KaleidescapeSensorEntityDescription, ...] = (
|
|||
),
|
||||
KaleidescapeSensorEntityDescription(
|
||||
key="screen_mask_conservative_ratio",
|
||||
name="Screen Mask Conservative Ratio",
|
||||
translation_key="screen_mask_conservative_ratio",
|
||||
icon="mdi:monitor-screenshot",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda device: device.automation.screen_mask_conservative_ratio,
|
||||
),
|
||||
KaleidescapeSensorEntityDescription(
|
||||
key="screen_mask_top_mask_abs",
|
||||
name="Screen Mask Top Mask Abs",
|
||||
translation_key="screen_mask_top_mask_abs",
|
||||
icon="mdi:monitor-screenshot",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
|
@ -130,7 +130,7 @@ SENSOR_TYPES: tuple[KaleidescapeSensorEntityDescription, ...] = (
|
|||
),
|
||||
KaleidescapeSensorEntityDescription(
|
||||
key="screen_mask_bottom_mask_abs",
|
||||
name="Screen Mask Bottom Mask Abs",
|
||||
translation_key="screen_mask_bottom_mask_abs",
|
||||
icon="mdi:monitor-screenshot",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
|
@ -138,14 +138,14 @@ SENSOR_TYPES: tuple[KaleidescapeSensorEntityDescription, ...] = (
|
|||
),
|
||||
KaleidescapeSensorEntityDescription(
|
||||
key="cinemascape_mask",
|
||||
name="Cinemascape Mask",
|
||||
translation_key="cinemascape_mask",
|
||||
icon="mdi:monitor-star",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda device: device.automation.cinemascape_mask,
|
||||
),
|
||||
KaleidescapeSensorEntityDescription(
|
||||
key="cinemascape_mode",
|
||||
name="Cinemascape Mode",
|
||||
translation_key="cinemascape_mode",
|
||||
icon="mdi:monitor-star",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda device: device.automation.cinemascape_mode,
|
||||
|
@ -177,7 +177,6 @@ class KaleidescapeSensor(KaleidescapeEntity, SensorEntity):
|
|||
super().__init__(device)
|
||||
self.entity_description = entity_description
|
||||
self._attr_unique_id = f"{self._attr_unique_id}-{entity_description.key}"
|
||||
self._attr_name = f"{self._attr_name} {entity_description.name}"
|
||||
|
||||
@property
|
||||
def native_value(self) -> StateType:
|
||||
|
|
|
@ -21,5 +21,57 @@
|
|||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"unsupported": "Unsupported device"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"media_location": {
|
||||
"name": "Media location"
|
||||
},
|
||||
"play_status": {
|
||||
"name": "Play status"
|
||||
},
|
||||
"play_speed": {
|
||||
"name": "Play speed"
|
||||
},
|
||||
"video_mode": {
|
||||
"name": "Video mode"
|
||||
},
|
||||
"video_color_eotf": {
|
||||
"name": "Video color EOTF"
|
||||
},
|
||||
"video_color_space": {
|
||||
"name": "Video color space"
|
||||
},
|
||||
"video_color_depth": {
|
||||
"name": "Video color depth"
|
||||
},
|
||||
"video_color_sampling": {
|
||||
"name": "Video color sampling"
|
||||
},
|
||||
"screen_mask_ratio": {
|
||||
"name": "Screen mask ratio"
|
||||
},
|
||||
"screen_mask_top_trim_rel": {
|
||||
"name": "Screen mask top trim relative"
|
||||
},
|
||||
"screen_mask_bottom_trim_rel": {
|
||||
"name": "Screen mask bottom trim relative"
|
||||
},
|
||||
"screen_mask_conservative_ratio": {
|
||||
"name": "Screen mask conservative ratio"
|
||||
},
|
||||
"screen_mask_top_mask_abs": {
|
||||
"name": "Screen mask top mask absolute"
|
||||
},
|
||||
"screen_mask_bottom_mask_abs": {
|
||||
"name": "Screen mask bottom mask absolute"
|
||||
},
|
||||
"cinemascape_mask": {
|
||||
"name": "Cinemascape mask"
|
||||
},
|
||||
"cinemascape_mode": {
|
||||
"name": "Cinemascape mode"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ async def test_sensors(
|
|||
assert entity
|
||||
assert entity.state == "none"
|
||||
assert (
|
||||
entity.attributes.get(ATTR_FRIENDLY_NAME) == f"{FRIENDLY_NAME} Media Location"
|
||||
entity.attributes.get(ATTR_FRIENDLY_NAME) == f"{FRIENDLY_NAME} Media location"
|
||||
)
|
||||
assert entry
|
||||
assert entry.unique_id == f"{MOCK_SERIAL}-media_location"
|
||||
|
@ -36,7 +36,7 @@ async def test_sensors(
|
|||
entry = er.async_get(hass).async_get(f"{ENTITY_ID}_play_status")
|
||||
assert entity
|
||||
assert entity.state == "none"
|
||||
assert entity.attributes.get(ATTR_FRIENDLY_NAME) == f"{FRIENDLY_NAME} Play Status"
|
||||
assert entity.attributes.get(ATTR_FRIENDLY_NAME) == f"{FRIENDLY_NAME} Play status"
|
||||
assert entry
|
||||
assert entry.unique_id == f"{MOCK_SERIAL}-play_status"
|
||||
|
||||
|
|
Loading…
Reference in New Issue