Add entity translations to Hyperion (#98635)
This commit is contained in:
parent
baf32658e5
commit
a1d554d1cb
5 changed files with 46 additions and 34 deletions
|
@ -44,7 +44,6 @@ from .const import (
|
|||
DOMAIN,
|
||||
HYPERION_MANUFACTURER_NAME,
|
||||
HYPERION_MODEL_NAME,
|
||||
NAME_SUFFIX_HYPERION_CAMERA,
|
||||
SIGNAL_ENTITY_REMOVE,
|
||||
TYPE_HYPERION_CAMERA,
|
||||
)
|
||||
|
@ -107,6 +106,9 @@ async def async_setup_entry(
|
|||
class HyperionCamera(Camera):
|
||||
"""ComponentBinarySwitch switch class."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
_attr_name = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
server_id: str,
|
||||
|
@ -120,7 +122,6 @@ class HyperionCamera(Camera):
|
|||
self._unique_id = get_hyperion_unique_id(
|
||||
server_id, instance_num, TYPE_HYPERION_CAMERA
|
||||
)
|
||||
self._name = f"{instance_name} {NAME_SUFFIX_HYPERION_CAMERA}".strip()
|
||||
self._device_id = get_hyperion_device_id(server_id, instance_num)
|
||||
self._instance_name = instance_name
|
||||
self._client = hyperion_client
|
||||
|
@ -140,11 +141,6 @@ class HyperionCamera(Camera):
|
|||
"""Return a unique id for this instance."""
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the switch."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if the camera is on."""
|
||||
|
|
|
@ -21,9 +21,6 @@ HYPERION_MODEL_NAME = f"{HYPERION_MANUFACTURER_NAME}-NG"
|
|||
HYPERION_RELEASES_URL = "https://github.com/hyperion-project/hyperion.ng/releases"
|
||||
HYPERION_VERSION_WARN_CUTOFF = "2.0.0-alpha.9"
|
||||
|
||||
NAME_SUFFIX_HYPERION_COMPONENT_SWITCH = "Component"
|
||||
NAME_SUFFIX_HYPERION_CAMERA = ""
|
||||
|
||||
SIGNAL_INSTANCE_ADD = f"{DOMAIN}_instance_add_signal.{{}}"
|
||||
SIGNAL_INSTANCE_REMOVE = f"{DOMAIN}_instance_remove_signal.{{}}"
|
||||
SIGNAL_ENTITY_REMOVE = f"{DOMAIN}_entity_remove_signal.{{}}"
|
||||
|
|
|
@ -116,6 +116,8 @@ async def async_setup_entry(
|
|||
class HyperionLight(LightEntity):
|
||||
"""A Hyperion light that acts as a client for the configured priority."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
_attr_name = None
|
||||
_attr_color_mode = ColorMode.HS
|
||||
_attr_should_poll = False
|
||||
_attr_supported_color_modes = {ColorMode.HS}
|
||||
|
@ -131,7 +133,6 @@ class HyperionLight(LightEntity):
|
|||
) -> None:
|
||||
"""Initialize the light."""
|
||||
self._unique_id = self._compute_unique_id(server_id, instance_num)
|
||||
self._name = self._compute_name(instance_name)
|
||||
self._device_id = get_hyperion_device_id(server_id, instance_num)
|
||||
self._instance_name = instance_name
|
||||
self._options = options
|
||||
|
@ -157,20 +158,11 @@ class HyperionLight(LightEntity):
|
|||
"""Compute a unique id for this instance."""
|
||||
return get_hyperion_unique_id(server_id, instance_num, TYPE_HYPERION_LIGHT)
|
||||
|
||||
def _compute_name(self, instance_name: str) -> str:
|
||||
"""Compute the name of the light."""
|
||||
return f"{instance_name}".strip()
|
||||
|
||||
@property
|
||||
def entity_registry_enabled_default(self) -> bool:
|
||||
"""Whether or not the entity is enabled by default."""
|
||||
return True
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the light."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def brightness(self) -> int:
|
||||
"""Return the brightness of this light between 0..255."""
|
||||
|
|
|
@ -50,5 +50,33 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"switch": {
|
||||
"all": {
|
||||
"name": "Component all"
|
||||
},
|
||||
"smoothing": {
|
||||
"name": "Component smoothing"
|
||||
},
|
||||
"blackbar_detection": {
|
||||
"name": "Component blackbar detection"
|
||||
},
|
||||
"forwarder": {
|
||||
"name": "Component forwarder"
|
||||
},
|
||||
"boblight_server": {
|
||||
"name": "Component boblight server"
|
||||
},
|
||||
"platform_capture": {
|
||||
"name": "Component platform capture"
|
||||
},
|
||||
"led_device": {
|
||||
"name": "Component LED device"
|
||||
},
|
||||
"usb_capture": {
|
||||
"name": "Component USB capture"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,6 @@ from .const import (
|
|||
DOMAIN,
|
||||
HYPERION_MANUFACTURER_NAME,
|
||||
HYPERION_MODEL_NAME,
|
||||
NAME_SUFFIX_HYPERION_COMPONENT_SWITCH,
|
||||
SIGNAL_ENTITY_REMOVE,
|
||||
TYPE_HYPERION_COMPONENT_SWITCH_BASE,
|
||||
)
|
||||
|
@ -74,13 +73,17 @@ def _component_to_unique_id(server_id: str, component: str, instance_num: int) -
|
|||
)
|
||||
|
||||
|
||||
def _component_to_switch_name(component: str, instance_name: str) -> str:
|
||||
"""Convert a component to a switch name."""
|
||||
return (
|
||||
f"{instance_name} "
|
||||
f"{NAME_SUFFIX_HYPERION_COMPONENT_SWITCH} "
|
||||
f"{KEY_COMPONENTID_TO_NAME.get(component, component.capitalize())}"
|
||||
)
|
||||
def _component_to_translation_key(component: str) -> str:
|
||||
return {
|
||||
KEY_COMPONENTID_ALL: "all",
|
||||
KEY_COMPONENTID_SMOOTHING: "smoothing",
|
||||
KEY_COMPONENTID_BLACKBORDER: "blackbar_detection",
|
||||
KEY_COMPONENTID_FORWARDER: "forwarder",
|
||||
KEY_COMPONENTID_BOBLIGHTSERVER: "boblight_server",
|
||||
KEY_COMPONENTID_GRABBER: "platform_capture",
|
||||
KEY_COMPONENTID_LEDDEVICE: "led_device",
|
||||
KEY_COMPONENTID_V4L: "usb_capture",
|
||||
}[component]
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
@ -129,6 +132,7 @@ class HyperionComponentSwitch(SwitchEntity):
|
|||
|
||||
_attr_entity_category = EntityCategory.CONFIG
|
||||
_attr_should_poll = False
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -143,7 +147,7 @@ class HyperionComponentSwitch(SwitchEntity):
|
|||
server_id, component_name, instance_num
|
||||
)
|
||||
self._device_id = get_hyperion_device_id(server_id, instance_num)
|
||||
self._name = _component_to_switch_name(component_name, instance_name)
|
||||
self._attr_translation_key = _component_to_translation_key(component_name)
|
||||
self._instance_name = instance_name
|
||||
self._component_name = component_name
|
||||
self._client = hyperion_client
|
||||
|
@ -162,11 +166,6 @@ class HyperionComponentSwitch(SwitchEntity):
|
|||
"""Return a unique id for this instance."""
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the switch."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if the switch is on."""
|
||||
|
|
Loading…
Add table
Reference in a new issue