Use more shorthand attributes in hyperion (#100213)

* Use more shorthand attributes in hyperion

There are likely some more here, but I only did the safe ones

* Update homeassistant/components/hyperion/switch.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Apply suggestions from code review

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
J. Nick Koston 2023-09-14 21:28:59 -05:00 committed by GitHub
parent 6a9c9ca735
commit b68ceb3ce4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 64 deletions

View file

@ -133,6 +133,8 @@ class HyperionComponentSwitch(SwitchEntity):
_attr_entity_category = EntityCategory.CONFIG
_attr_should_poll = False
_attr_has_entity_name = True
# These component controls are for advanced users and are disabled by default.
_attr_entity_registry_enabled_default = False
def __init__(
self,
@ -143,7 +145,7 @@ class HyperionComponentSwitch(SwitchEntity):
hyperion_client: client.HyperionClient,
) -> None:
"""Initialize the switch."""
self._unique_id = _component_to_unique_id(
self._attr_unique_id = _component_to_unique_id(
server_id, component_name, instance_num
)
self._device_id = get_hyperion_device_id(server_id, instance_num)
@ -154,17 +156,13 @@ class HyperionComponentSwitch(SwitchEntity):
self._client_callbacks = {
f"{KEY_COMPONENTS}-{KEY_UPDATE}": self._update_components
}
@property
def entity_registry_enabled_default(self) -> bool:
"""Whether or not the entity is enabled by default."""
# These component controls are for advanced users and are disabled by default.
return False
@property
def unique_id(self) -> str:
"""Return a unique id for this instance."""
return self._unique_id
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self._device_id)},
manufacturer=HYPERION_MANUFACTURER_NAME,
model=HYPERION_MODEL_NAME,
name=self._instance_name,
configuration_url=self._client.remote_url,
)
@property
def is_on(self) -> bool:
@ -179,17 +177,6 @@ class HyperionComponentSwitch(SwitchEntity):
"""Return server availability."""
return bool(self._client.has_loaded_state)
@property
def device_info(self) -> DeviceInfo:
"""Return device information."""
return DeviceInfo(
identifiers={(DOMAIN, self._device_id)},
manufacturer=HYPERION_MANUFACTURER_NAME,
model=HYPERION_MODEL_NAME,
name=self._instance_name,
configuration_url=self._client.remote_url,
)
async def _async_send_set_component(self, value: bool) -> None:
"""Send a component control request."""
await self._client.async_send_set_component(
@ -219,7 +206,7 @@ class HyperionComponentSwitch(SwitchEntity):
self.async_on_remove(
async_dispatcher_connect(
self.hass,
SIGNAL_ENTITY_REMOVE.format(self._unique_id),
SIGNAL_ENTITY_REMOVE.format(self._attr_unique_id),
functools.partial(self.async_remove, force_remove=True),
)
)