Use entity class attributes for arcam_fmj (#52675)

* Use entity class attributes for arcam_fmj

* fix
pull/53052/head
Robert Hillis 2021-07-15 04:19:18 -04:00 committed by GitHub
parent eee3aa3b6f
commit 8ce4d647c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 33 deletions

View File

@ -63,6 +63,8 @@ async def async_setup_entry(
class ArcamFmj(MediaPlayerEntity):
"""Representation of a media device."""
_attr_should_poll = False
def __init__(
self,
device_name,
@ -72,9 +74,9 @@ class ArcamFmj(MediaPlayerEntity):
"""Initialize device."""
self._state = state
self._device_name = device_name
self._name = f"{device_name} - Zone: {state.zn}"
self._attr_name = f"{device_name} - Zone: {state.zn}"
self._uuid = uuid
self._support = (
self._attr_supported_features = (
SUPPORT_SELECT_SOURCE
| SUPPORT_PLAY_MEDIA
| SUPPORT_BROWSE_MEDIA
@ -85,7 +87,9 @@ class ArcamFmj(MediaPlayerEntity):
| SUPPORT_TURN_ON
)
if state.zn == 1:
self._support |= SUPPORT_SELECT_SOUND_MODE
self._attr_supported_features |= SUPPORT_SELECT_SOUND_MODE
self._attr_unique_id = f"{uuid}-{state.zn}"
self._attr_entity_registry_enabled_default = state.zn == 1
def _get_2ch(self):
"""Return if source is 2 channel or not."""
@ -101,14 +105,11 @@ class ArcamFmj(MediaPlayerEntity):
)
@property
def entity_registry_enabled_default(self) -> bool:
"""Return if the entity should be enabled when first added to the entity registry."""
return self._state.zn == 1
@property
def unique_id(self):
"""Return unique identifier if known."""
return f"{self._uuid}-{self._state.zn}"
def state(self):
"""Return the state of the device."""
if self._state.get_power():
return STATE_ON
return STATE_OFF
@property
def device_info(self):
@ -123,28 +124,6 @@ class ArcamFmj(MediaPlayerEntity):
"manufacturer": "Arcam",
}
@property
def should_poll(self) -> bool:
"""No need to poll."""
return False
@property
def name(self):
"""Return the name of the controlled device."""
return self._name
@property
def state(self):
"""Return the state of the device."""
if self._state.get_power():
return STATE_ON
return STATE_OFF
@property
def supported_features(self):
"""Flag media player features that are supported."""
return self._support
async def async_added_to_hass(self):
"""Once registered, add listener for events."""
await self._state.start()