mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Use shorthand attributes in Songpal (#99849)
This commit is contained in:
parent
1ca505c228
commit
1cf2f2f8b8
@ -110,14 +110,14 @@ class SongpalEntity(MediaPlayerEntity):
|
|||||||
self._model = None
|
self._model = None
|
||||||
|
|
||||||
self._state = False
|
self._state = False
|
||||||
self._available = False
|
self._attr_available = False
|
||||||
self._initialized = False
|
self._initialized = False
|
||||||
|
|
||||||
self._volume_control = None
|
self._volume_control = None
|
||||||
self._volume_min = 0
|
self._volume_min = 0
|
||||||
self._volume_max = 1
|
self._volume_max = 1
|
||||||
self._volume = 0
|
self._volume = 0
|
||||||
self._is_muted = False
|
self._attr_is_volume_muted = False
|
||||||
|
|
||||||
self._active_source = None
|
self._active_source = None
|
||||||
self._sources = {}
|
self._sources = {}
|
||||||
@ -137,7 +137,7 @@ class SongpalEntity(MediaPlayerEntity):
|
|||||||
async def _volume_changed(volume: VolumeChange):
|
async def _volume_changed(volume: VolumeChange):
|
||||||
_LOGGER.debug("Volume changed: %s", volume)
|
_LOGGER.debug("Volume changed: %s", volume)
|
||||||
self._volume = volume.volume
|
self._volume = volume.volume
|
||||||
self._is_muted = volume.mute
|
self._attr_is_volume_muted = volume.mute
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
async def _source_changed(content: ContentChange):
|
async def _source_changed(content: ContentChange):
|
||||||
@ -161,13 +161,13 @@ class SongpalEntity(MediaPlayerEntity):
|
|||||||
self._dev.endpoint,
|
self._dev.endpoint,
|
||||||
)
|
)
|
||||||
_LOGGER.debug("Disconnected: %s", connect.exception)
|
_LOGGER.debug("Disconnected: %s", connect.exception)
|
||||||
self._available = False
|
self._attr_available = False
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
# Try to reconnect forever, a successful reconnect will initialize
|
# Try to reconnect forever, a successful reconnect will initialize
|
||||||
# the websocket connection again.
|
# the websocket connection again.
|
||||||
delay = INITIAL_RETRY_DELAY
|
delay = INITIAL_RETRY_DELAY
|
||||||
while not self._available:
|
while not self._attr_available:
|
||||||
_LOGGER.debug("Trying to reconnect in %s seconds", delay)
|
_LOGGER.debug("Trying to reconnect in %s seconds", delay)
|
||||||
await asyncio.sleep(delay)
|
await asyncio.sleep(delay)
|
||||||
|
|
||||||
@ -220,11 +220,6 @@ class SongpalEntity(MediaPlayerEntity):
|
|||||||
sw_version=self._sysinfo.version,
|
sw_version=self._sysinfo.version,
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def available(self):
|
|
||||||
"""Return availability of the device."""
|
|
||||||
return self._available
|
|
||||||
|
|
||||||
async def async_set_sound_setting(self, name, value):
|
async def async_set_sound_setting(self, name, value):
|
||||||
"""Change a setting on the device."""
|
"""Change a setting on the device."""
|
||||||
_LOGGER.debug("Calling set_sound_setting with %s: %s", name, value)
|
_LOGGER.debug("Calling set_sound_setting with %s: %s", name, value)
|
||||||
@ -243,7 +238,7 @@ class SongpalEntity(MediaPlayerEntity):
|
|||||||
volumes = await self._dev.get_volume_information()
|
volumes = await self._dev.get_volume_information()
|
||||||
if not volumes:
|
if not volumes:
|
||||||
_LOGGER.error("Got no volume controls, bailing out")
|
_LOGGER.error("Got no volume controls, bailing out")
|
||||||
self._available = False
|
self._attr_available = False
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(volumes) > 1:
|
if len(volumes) > 1:
|
||||||
@ -256,7 +251,7 @@ class SongpalEntity(MediaPlayerEntity):
|
|||||||
self._volume_min = volume.minVolume
|
self._volume_min = volume.minVolume
|
||||||
self._volume = volume.volume
|
self._volume = volume.volume
|
||||||
self._volume_control = volume
|
self._volume_control = volume
|
||||||
self._is_muted = self._volume_control.is_muted
|
self._attr_is_volume_muted = self._volume_control.is_muted
|
||||||
|
|
||||||
status = await self._dev.get_power()
|
status = await self._dev.get_power()
|
||||||
self._state = status.status
|
self._state = status.status
|
||||||
@ -273,11 +268,11 @@ class SongpalEntity(MediaPlayerEntity):
|
|||||||
|
|
||||||
_LOGGER.debug("Active source: %s", self._active_source)
|
_LOGGER.debug("Active source: %s", self._active_source)
|
||||||
|
|
||||||
self._available = True
|
self._attr_available = True
|
||||||
|
|
||||||
except SongpalException as ex:
|
except SongpalException as ex:
|
||||||
_LOGGER.error("Unable to update: %s", ex)
|
_LOGGER.error("Unable to update: %s", ex)
|
||||||
self._available = False
|
self._attr_available = False
|
||||||
|
|
||||||
async def async_select_source(self, source: str) -> None:
|
async def async_select_source(self, source: str) -> None:
|
||||||
"""Select source."""
|
"""Select source."""
|
||||||
@ -309,8 +304,7 @@ class SongpalEntity(MediaPlayerEntity):
|
|||||||
@property
|
@property
|
||||||
def volume_level(self):
|
def volume_level(self):
|
||||||
"""Return volume level."""
|
"""Return volume level."""
|
||||||
volume = self._volume / self._volume_max
|
return self._volume / self._volume_max
|
||||||
return volume
|
|
||||||
|
|
||||||
async def async_set_volume_level(self, volume: float) -> None:
|
async def async_set_volume_level(self, volume: float) -> None:
|
||||||
"""Set volume level."""
|
"""Set volume level."""
|
||||||
@ -354,8 +348,3 @@ class SongpalEntity(MediaPlayerEntity):
|
|||||||
"""Mute or unmute the device."""
|
"""Mute or unmute the device."""
|
||||||
_LOGGER.debug("Set mute: %s", mute)
|
_LOGGER.debug("Set mute: %s", mute)
|
||||||
return await self._volume_control.set_mute(mute)
|
return await self._volume_control.set_mute(mute)
|
||||||
|
|
||||||
@property
|
|
||||||
def is_volume_muted(self):
|
|
||||||
"""Return whether the device is muted."""
|
|
||||||
return self._is_muted
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user