From 8ce4d647c37efd2e3a5b37cb986427e65edba66c Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Thu, 15 Jul 2021 04:19:18 -0400 Subject: [PATCH] Use entity class attributes for arcam_fmj (#52675) * Use entity class attributes for arcam_fmj * fix --- .../components/arcam_fmj/media_player.py | 45 +++++-------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/homeassistant/components/arcam_fmj/media_player.py b/homeassistant/components/arcam_fmj/media_player.py index 8a119d020fe..89f0cc3b112 100644 --- a/homeassistant/components/arcam_fmj/media_player.py +++ b/homeassistant/components/arcam_fmj/media_player.py @@ -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()