Use attributes in xiaomi-tv media player (#82842)

pull/82845/head
epenet 2022-11-28 12:26:24 +01:00 committed by GitHub
parent a747a8f936
commit e8a03ea870
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 21 deletions

View File

@ -58,6 +58,7 @@ def setup_platform(
class XiaomiTV(MediaPlayerEntity):
"""Represent the Xiaomi TV for Home Assistant."""
_attr_assumed_state = True
_attr_supported_features = (
MediaPlayerEntityFeature.VOLUME_STEP
| MediaPlayerEntityFeature.TURN_ON
@ -70,23 +71,8 @@ class XiaomiTV(MediaPlayerEntity):
# Initialize the Xiaomi TV.
self._tv = pymitv.TV(ip)
# Default name value, only to be overridden by user.
self._name = name
self._state = MediaPlayerState.OFF
@property
def name(self):
"""Return the display name of this TV."""
return self._name
@property
def state(self):
"""Return _state variable, containing the appropriate constant."""
return self._state
@property
def assumed_state(self):
"""Indicate that state is assumed."""
return True
self._attr_name = name
self._attr_state = MediaPlayerState.OFF
def turn_off(self) -> None:
"""
@ -96,17 +82,17 @@ class XiaomiTV(MediaPlayerEntity):
because the TV won't accept any input when turned off. Thus, the user
would be unable to turn the TV back on, unless it's done manually.
"""
if self._state != MediaPlayerState.OFF:
if self.state != MediaPlayerState.OFF:
self._tv.sleep()
self._state = MediaPlayerState.OFF
self._attr_state = MediaPlayerState.OFF
def turn_on(self) -> None:
"""Wake the TV back up from sleep."""
if self._state != MediaPlayerState.ON:
if self.state != MediaPlayerState.ON:
self._tv.wake()
self._state = MediaPlayerState.ON
self._attr_state = MediaPlayerState.ON
def volume_up(self) -> None:
"""Increase volume by one."""