Use entity class attributes for arcam_fmj (#52675)
* Use entity class attributes for arcam_fmj * fixpull/53052/head
parent
eee3aa3b6f
commit
8ce4d647c3
|
@ -63,6 +63,8 @@ async def async_setup_entry(
|
||||||
class ArcamFmj(MediaPlayerEntity):
|
class ArcamFmj(MediaPlayerEntity):
|
||||||
"""Representation of a media device."""
|
"""Representation of a media device."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
device_name,
|
device_name,
|
||||||
|
@ -72,9 +74,9 @@ class ArcamFmj(MediaPlayerEntity):
|
||||||
"""Initialize device."""
|
"""Initialize device."""
|
||||||
self._state = state
|
self._state = state
|
||||||
self._device_name = device_name
|
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._uuid = uuid
|
||||||
self._support = (
|
self._attr_supported_features = (
|
||||||
SUPPORT_SELECT_SOURCE
|
SUPPORT_SELECT_SOURCE
|
||||||
| SUPPORT_PLAY_MEDIA
|
| SUPPORT_PLAY_MEDIA
|
||||||
| SUPPORT_BROWSE_MEDIA
|
| SUPPORT_BROWSE_MEDIA
|
||||||
|
@ -85,7 +87,9 @@ class ArcamFmj(MediaPlayerEntity):
|
||||||
| SUPPORT_TURN_ON
|
| SUPPORT_TURN_ON
|
||||||
)
|
)
|
||||||
if state.zn == 1:
|
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):
|
def _get_2ch(self):
|
||||||
"""Return if source is 2 channel or not."""
|
"""Return if source is 2 channel or not."""
|
||||||
|
@ -101,14 +105,11 @@ class ArcamFmj(MediaPlayerEntity):
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def entity_registry_enabled_default(self) -> bool:
|
def state(self):
|
||||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
"""Return the state of the device."""
|
||||||
return self._state.zn == 1
|
if self._state.get_power():
|
||||||
|
return STATE_ON
|
||||||
@property
|
return STATE_OFF
|
||||||
def unique_id(self):
|
|
||||||
"""Return unique identifier if known."""
|
|
||||||
return f"{self._uuid}-{self._state.zn}"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self):
|
def device_info(self):
|
||||||
|
@ -123,28 +124,6 @@ class ArcamFmj(MediaPlayerEntity):
|
||||||
"manufacturer": "Arcam",
|
"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):
|
async def async_added_to_hass(self):
|
||||||
"""Once registered, add listener for events."""
|
"""Once registered, add listener for events."""
|
||||||
await self._state.start()
|
await self._state.start()
|
||||||
|
|
Loading…
Reference in New Issue