mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Convert @property to _attr_variable for hdmi_sec (#53816)
Convert @property to _attr_variable. Break __init__ with a local function. Make _attr_should_poll a class variable. Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
8500afa5d9
commit
bb11dc19d3
@ -371,13 +371,32 @@ def setup(hass: HomeAssistant, base_config): # noqa: C901
|
|||||||
class CecEntity(Entity):
|
class CecEntity(Entity):
|
||||||
"""Representation of a HDMI CEC device entity."""
|
"""Representation of a HDMI CEC device entity."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, device, logical) -> None:
|
def __init__(self, device, logical) -> None:
|
||||||
"""Initialize the device."""
|
"""Initialize the device."""
|
||||||
self._device = device
|
self._device = device
|
||||||
self._icon = None
|
|
||||||
self._state: str | None = None
|
self._state: str | None = None
|
||||||
self._logical_address = logical
|
self._logical_address = logical
|
||||||
self.entity_id = "%s.%d" % (DOMAIN, self._logical_address)
|
self.entity_id = "%s.%d" % (DOMAIN, self._logical_address)
|
||||||
|
self._set_attr_name()
|
||||||
|
if self._device.type in ICONS_BY_TYPE:
|
||||||
|
self._attr_icon = ICONS_BY_TYPE[self._device.type]
|
||||||
|
else:
|
||||||
|
self._attr_icon = ICON_UNKNOWN
|
||||||
|
|
||||||
|
def _set_attr_name(self):
|
||||||
|
"""Set name."""
|
||||||
|
if (
|
||||||
|
self._device.osd_name is not None
|
||||||
|
and self.vendor_name is not None
|
||||||
|
and self.vendor_name != "Unknown"
|
||||||
|
):
|
||||||
|
self._attr_name = f"{self.vendor_name} {self._device.osd_name}"
|
||||||
|
elif self._device.osd_name is None:
|
||||||
|
self._attr_name = f"{self._device.type_name} {self._logical_address}"
|
||||||
|
else:
|
||||||
|
self._attr_name = f"{self._device.type_name} {self._logical_address} ({self._device.osd_name})"
|
||||||
|
|
||||||
def _hdmi_cec_unavailable(self, callback_event):
|
def _hdmi_cec_unavailable(self, callback_event):
|
||||||
# Change state to unavailable. Without this, entity would remain in
|
# Change state to unavailable. Without this, entity would remain in
|
||||||
@ -412,31 +431,6 @@ class CecEntity(Entity):
|
|||||||
"""Device status changed, schedule an update."""
|
"""Device status changed, schedule an update."""
|
||||||
self.schedule_update_ha_state(True)
|
self.schedule_update_ha_state(True)
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""
|
|
||||||
Return false.
|
|
||||||
|
|
||||||
CecEntity.update() is called by the HDMI network when there is new data.
|
|
||||||
"""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the device."""
|
|
||||||
return (
|
|
||||||
f"{self.vendor_name} {self._device.osd_name}"
|
|
||||||
if (
|
|
||||||
self._device.osd_name is not None
|
|
||||||
and self.vendor_name is not None
|
|
||||||
and self.vendor_name != "Unknown"
|
|
||||||
)
|
|
||||||
else "%s %d" % (self._device.type_name, self._logical_address)
|
|
||||||
if self._device.osd_name is None
|
|
||||||
else "%s %d (%s)"
|
|
||||||
% (self._device.type_name, self._logical_address, self._device.osd_name)
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def vendor_id(self):
|
def vendor_id(self):
|
||||||
"""Return the ID of the device's vendor."""
|
"""Return the ID of the device's vendor."""
|
||||||
@ -462,17 +456,6 @@ class CecEntity(Entity):
|
|||||||
"""Return the type ID of device."""
|
"""Return the type ID of device."""
|
||||||
return self._device.type
|
return self._device.type
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Return the icon for device by its type."""
|
|
||||||
return (
|
|
||||||
self._icon
|
|
||||||
if self._icon is not None
|
|
||||||
else ICONS_BY_TYPE.get(self._device.type)
|
|
||||||
if self._device.type in ICONS_BY_TYPE
|
|
||||||
else ICON_UNKNOWN
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user