Add entity translations to kaleidescape (#95625)

pull/95794/head
Joost Lekkerkerker 2023-07-02 19:35:05 +02:00 committed by GitHub
parent 2aff138b92
commit 2807b6cabc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 78 additions and 23 deletions

View File

@ -3,7 +3,7 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import TYPE_CHECKING, cast from typing import TYPE_CHECKING
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.entity import DeviceInfo, Entity from homeassistant.helpers.entity import DeviceInfo, Entity
@ -19,18 +19,19 @@ _LOGGER = logging.getLogger(__name__)
class KaleidescapeEntity(Entity): class KaleidescapeEntity(Entity):
"""Defines a base Kaleidescape entity.""" """Defines a base Kaleidescape entity."""
_attr_has_entity_name = True
_attr_should_poll = False
def __init__(self, device: KaleidescapeDevice) -> None: def __init__(self, device: KaleidescapeDevice) -> None:
"""Initialize entity.""" """Initialize entity."""
self._device = device self._device = device
self._attr_should_poll = False
self._attr_unique_id = device.serial_number self._attr_unique_id = device.serial_number
self._attr_name = f"{KALEIDESCAPE_NAME} {device.system.friendly_name}"
self._attr_device_info = DeviceInfo( self._attr_device_info = DeviceInfo(
identifiers={(KALEIDESCAPE_DOMAIN, self._device.serial_number)}, identifiers={(KALEIDESCAPE_DOMAIN, self._device.serial_number)},
# Instead of setting the device name to the entity name, kaleidescape # Instead of setting the device name to the entity name, kaleidescape
# should be updated to set has_entity_name = True # 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, model=self._device.system.type,
manufacturer=KALEIDESCAPE_NAME, manufacturer=KALEIDESCAPE_NAME,
sw_version=f"{self._device.system.kos_version}", sw_version=f"{self._device.system.kos_version}",

View File

@ -56,6 +56,7 @@ class KaleidescapeMediaPlayer(KaleidescapeEntity, MediaPlayerEntity):
| MediaPlayerEntityFeature.NEXT_TRACK | MediaPlayerEntityFeature.NEXT_TRACK
| MediaPlayerEntityFeature.PREVIOUS_TRACK | MediaPlayerEntityFeature.PREVIOUS_TRACK
) )
_attr_name = None
async def async_turn_on(self) -> None: async def async_turn_on(self) -> None:
"""Send leave standby command.""" """Send leave standby command."""

View File

@ -47,6 +47,8 @@ VALID_COMMANDS = {
class KaleidescapeRemote(KaleidescapeEntity, RemoteEntity): class KaleidescapeRemote(KaleidescapeEntity, RemoteEntity):
"""Representation of a Kaleidescape device.""" """Representation of a Kaleidescape device."""
_attr_name = None
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true if device is on.""" """Return true if device is on."""

View File

@ -39,67 +39,67 @@ class KaleidescapeSensorEntityDescription(
SENSOR_TYPES: tuple[KaleidescapeSensorEntityDescription, ...] = ( SENSOR_TYPES: tuple[KaleidescapeSensorEntityDescription, ...] = (
KaleidescapeSensorEntityDescription( KaleidescapeSensorEntityDescription(
key="media_location", key="media_location",
name="Media Location", translation_key="media_location",
icon="mdi:monitor", icon="mdi:monitor",
value_fn=lambda device: device.automation.movie_location, value_fn=lambda device: device.automation.movie_location,
), ),
KaleidescapeSensorEntityDescription( KaleidescapeSensorEntityDescription(
key="play_status", key="play_status",
name="Play Status", translation_key="play_status",
icon="mdi:monitor", icon="mdi:monitor",
value_fn=lambda device: device.movie.play_status, value_fn=lambda device: device.movie.play_status,
), ),
KaleidescapeSensorEntityDescription( KaleidescapeSensorEntityDescription(
key="play_speed", key="play_speed",
name="Play Speed", translation_key="play_speed",
icon="mdi:monitor", icon="mdi:monitor",
value_fn=lambda device: device.movie.play_speed, value_fn=lambda device: device.movie.play_speed,
), ),
KaleidescapeSensorEntityDescription( KaleidescapeSensorEntityDescription(
key="video_mode", key="video_mode",
name="Video Mode", translation_key="video_mode",
icon="mdi:monitor-screenshot", icon="mdi:monitor-screenshot",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda device: device.automation.video_mode, value_fn=lambda device: device.automation.video_mode,
), ),
KaleidescapeSensorEntityDescription( KaleidescapeSensorEntityDescription(
key="video_color_eotf", key="video_color_eotf",
name="Video Color EOTF", translation_key="video_color_eotf",
icon="mdi:monitor-eye", icon="mdi:monitor-eye",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda device: device.automation.video_color_eotf, value_fn=lambda device: device.automation.video_color_eotf,
), ),
KaleidescapeSensorEntityDescription( KaleidescapeSensorEntityDescription(
key="video_color_space", key="video_color_space",
name="Video Color Space", translation_key="video_color_space",
icon="mdi:monitor-eye", icon="mdi:monitor-eye",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda device: device.automation.video_color_space, value_fn=lambda device: device.automation.video_color_space,
), ),
KaleidescapeSensorEntityDescription( KaleidescapeSensorEntityDescription(
key="video_color_depth", key="video_color_depth",
name="Video Color Depth", translation_key="video_color_depth",
icon="mdi:monitor-eye", icon="mdi:monitor-eye",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda device: device.automation.video_color_depth, value_fn=lambda device: device.automation.video_color_depth,
), ),
KaleidescapeSensorEntityDescription( KaleidescapeSensorEntityDescription(
key="video_color_sampling", key="video_color_sampling",
name="Video Color Sampling", translation_key="video_color_sampling",
icon="mdi:monitor-eye", icon="mdi:monitor-eye",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda device: device.automation.video_color_sampling, value_fn=lambda device: device.automation.video_color_sampling,
), ),
KaleidescapeSensorEntityDescription( KaleidescapeSensorEntityDescription(
key="screen_mask_ratio", key="screen_mask_ratio",
name="Screen Mask Ratio", translation_key="screen_mask_ratio",
icon="mdi:monitor-screenshot", icon="mdi:monitor-screenshot",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda device: device.automation.screen_mask_ratio, value_fn=lambda device: device.automation.screen_mask_ratio,
), ),
KaleidescapeSensorEntityDescription( KaleidescapeSensorEntityDescription(
key="screen_mask_top_trim_rel", key="screen_mask_top_trim_rel",
name="Screen Mask Top Trim Rel", translation_key="screen_mask_top_trim_rel",
icon="mdi:monitor-screenshot", icon="mdi:monitor-screenshot",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
@ -107,7 +107,7 @@ SENSOR_TYPES: tuple[KaleidescapeSensorEntityDescription, ...] = (
), ),
KaleidescapeSensorEntityDescription( KaleidescapeSensorEntityDescription(
key="screen_mask_bottom_trim_rel", key="screen_mask_bottom_trim_rel",
name="Screen Mask Bottom Trim Rel", translation_key="screen_mask_bottom_trim_rel",
icon="mdi:monitor-screenshot", icon="mdi:monitor-screenshot",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
@ -115,14 +115,14 @@ SENSOR_TYPES: tuple[KaleidescapeSensorEntityDescription, ...] = (
), ),
KaleidescapeSensorEntityDescription( KaleidescapeSensorEntityDescription(
key="screen_mask_conservative_ratio", key="screen_mask_conservative_ratio",
name="Screen Mask Conservative Ratio", translation_key="screen_mask_conservative_ratio",
icon="mdi:monitor-screenshot", icon="mdi:monitor-screenshot",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda device: device.automation.screen_mask_conservative_ratio, value_fn=lambda device: device.automation.screen_mask_conservative_ratio,
), ),
KaleidescapeSensorEntityDescription( KaleidescapeSensorEntityDescription(
key="screen_mask_top_mask_abs", key="screen_mask_top_mask_abs",
name="Screen Mask Top Mask Abs", translation_key="screen_mask_top_mask_abs",
icon="mdi:monitor-screenshot", icon="mdi:monitor-screenshot",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
@ -130,7 +130,7 @@ SENSOR_TYPES: tuple[KaleidescapeSensorEntityDescription, ...] = (
), ),
KaleidescapeSensorEntityDescription( KaleidescapeSensorEntityDescription(
key="screen_mask_bottom_mask_abs", key="screen_mask_bottom_mask_abs",
name="Screen Mask Bottom Mask Abs", translation_key="screen_mask_bottom_mask_abs",
icon="mdi:monitor-screenshot", icon="mdi:monitor-screenshot",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
@ -138,14 +138,14 @@ SENSOR_TYPES: tuple[KaleidescapeSensorEntityDescription, ...] = (
), ),
KaleidescapeSensorEntityDescription( KaleidescapeSensorEntityDescription(
key="cinemascape_mask", key="cinemascape_mask",
name="Cinemascape Mask", translation_key="cinemascape_mask",
icon="mdi:monitor-star", icon="mdi:monitor-star",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda device: device.automation.cinemascape_mask, value_fn=lambda device: device.automation.cinemascape_mask,
), ),
KaleidescapeSensorEntityDescription( KaleidescapeSensorEntityDescription(
key="cinemascape_mode", key="cinemascape_mode",
name="Cinemascape Mode", translation_key="cinemascape_mode",
icon="mdi:monitor-star", icon="mdi:monitor-star",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda device: device.automation.cinemascape_mode, value_fn=lambda device: device.automation.cinemascape_mode,
@ -177,7 +177,6 @@ class KaleidescapeSensor(KaleidescapeEntity, SensorEntity):
super().__init__(device) super().__init__(device)
self.entity_description = entity_description self.entity_description = entity_description
self._attr_unique_id = f"{self._attr_unique_id}-{entity_description.key}" self._attr_unique_id = f"{self._attr_unique_id}-{entity_description.key}"
self._attr_name = f"{self._attr_name} {entity_description.name}"
@property @property
def native_value(self) -> StateType: def native_value(self) -> StateType:

View File

@ -21,5 +21,57 @@
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"unsupported": "Unsupported device" "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"
}
}
} }
} }

View File

@ -27,7 +27,7 @@ async def test_sensors(
assert entity assert entity
assert entity.state == "none" assert entity.state == "none"
assert ( 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
assert entry.unique_id == f"{MOCK_SERIAL}-media_location" 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") entry = er.async_get(hass).async_get(f"{ENTITY_ID}_play_status")
assert entity assert entity
assert entity.state == "none" 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
assert entry.unique_id == f"{MOCK_SERIAL}-play_status" assert entry.unique_id == f"{MOCK_SERIAL}-play_status"