Use new media player enums in homekit_controller (#78105)

* Use new media player enums in homekit_controller

* Replace OK/PROBLEM with ON/OFF

* Fix tests
This commit is contained in:
epenet 2022-09-15 12:00:52 +02:00 committed by GitHub
parent b56eabc35b
commit ada1cff4b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 18 deletions

View file

@ -16,15 +16,9 @@ from homeassistant.components.media_player import (
MediaPlayerDeviceClass,
MediaPlayerEntity,
MediaPlayerEntityFeature,
MediaPlayerState,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
STATE_IDLE,
STATE_OK,
STATE_PAUSED,
STATE_PLAYING,
STATE_PROBLEM,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -35,9 +29,9 @@ _LOGGER = logging.getLogger(__name__)
HK_TO_HA_STATE = {
CurrentMediaStateValues.PLAYING: STATE_PLAYING,
CurrentMediaStateValues.PAUSED: STATE_PAUSED,
CurrentMediaStateValues.STOPPED: STATE_IDLE,
CurrentMediaStateValues.PLAYING: MediaPlayerState.PLAYING,
CurrentMediaStateValues.PAUSED: MediaPlayerState.PAUSED,
CurrentMediaStateValues.STOPPED: MediaPlayerState.IDLE,
}
@ -163,21 +157,21 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
return char.value
@property
def state(self) -> str:
def state(self) -> MediaPlayerState:
"""State of the tv."""
active = self.service.value(CharacteristicsTypes.ACTIVE)
if not active:
return STATE_PROBLEM
return MediaPlayerState.OFF
homekit_state = self.service.value(CharacteristicsTypes.CURRENT_MEDIA_STATE)
if homekit_state is not None:
return HK_TO_HA_STATE.get(homekit_state, STATE_OK)
return HK_TO_HA_STATE.get(homekit_state, MediaPlayerState.ON)
return STATE_OK
return MediaPlayerState.ON
async def async_media_play(self) -> None:
"""Send play command."""
if self.state == STATE_PLAYING:
if self.state == MediaPlayerState.PLAYING:
_LOGGER.debug("Cannot play while already playing")
return
@ -192,7 +186,7 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
async def async_media_pause(self) -> None:
"""Send pause command."""
if self.state == STATE_PAUSED:
if self.state == MediaPlayerState.PAUSED:
_LOGGER.debug("Cannot pause while already paused")
return
@ -207,7 +201,7 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
async def async_media_stop(self) -> None:
"""Send stop command."""
if self.state == STATE_IDLE:
if self.state == MediaPlayerState.IDLE:
_LOGGER.debug("Cannot stop when already idle")
return