Use attributes in xiaomi-tv media player (#82842)
parent
a747a8f936
commit
e8a03ea870
|
@ -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."""
|
||||
|
|
Loading…
Reference in New Issue