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:
parent
b56eabc35b
commit
ada1cff4b1
2 changed files with 12 additions and 18 deletions
|
@ -16,15 +16,9 @@ from homeassistant.components.media_player import (
|
||||||
MediaPlayerDeviceClass,
|
MediaPlayerDeviceClass,
|
||||||
MediaPlayerEntity,
|
MediaPlayerEntity,
|
||||||
MediaPlayerEntityFeature,
|
MediaPlayerEntityFeature,
|
||||||
|
MediaPlayerState,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
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.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
@ -35,9 +29,9 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
HK_TO_HA_STATE = {
|
HK_TO_HA_STATE = {
|
||||||
CurrentMediaStateValues.PLAYING: STATE_PLAYING,
|
CurrentMediaStateValues.PLAYING: MediaPlayerState.PLAYING,
|
||||||
CurrentMediaStateValues.PAUSED: STATE_PAUSED,
|
CurrentMediaStateValues.PAUSED: MediaPlayerState.PAUSED,
|
||||||
CurrentMediaStateValues.STOPPED: STATE_IDLE,
|
CurrentMediaStateValues.STOPPED: MediaPlayerState.IDLE,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,21 +157,21 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
|
||||||
return char.value
|
return char.value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self) -> str:
|
def state(self) -> MediaPlayerState:
|
||||||
"""State of the tv."""
|
"""State of the tv."""
|
||||||
active = self.service.value(CharacteristicsTypes.ACTIVE)
|
active = self.service.value(CharacteristicsTypes.ACTIVE)
|
||||||
if not active:
|
if not active:
|
||||||
return STATE_PROBLEM
|
return MediaPlayerState.OFF
|
||||||
|
|
||||||
homekit_state = self.service.value(CharacteristicsTypes.CURRENT_MEDIA_STATE)
|
homekit_state = self.service.value(CharacteristicsTypes.CURRENT_MEDIA_STATE)
|
||||||
if homekit_state is not None:
|
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:
|
async def async_media_play(self) -> None:
|
||||||
"""Send play command."""
|
"""Send play command."""
|
||||||
if self.state == STATE_PLAYING:
|
if self.state == MediaPlayerState.PLAYING:
|
||||||
_LOGGER.debug("Cannot play while already playing")
|
_LOGGER.debug("Cannot play while already playing")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -192,7 +186,7 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
|
||||||
|
|
||||||
async def async_media_pause(self) -> None:
|
async def async_media_pause(self) -> None:
|
||||||
"""Send pause command."""
|
"""Send pause command."""
|
||||||
if self.state == STATE_PAUSED:
|
if self.state == MediaPlayerState.PAUSED:
|
||||||
_LOGGER.debug("Cannot pause while already paused")
|
_LOGGER.debug("Cannot pause while already paused")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -207,7 +201,7 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
|
||||||
|
|
||||||
async def async_media_stop(self) -> None:
|
async def async_media_stop(self) -> None:
|
||||||
"""Send stop command."""
|
"""Send stop command."""
|
||||||
if self.state == STATE_IDLE:
|
if self.state == MediaPlayerState.IDLE:
|
||||||
_LOGGER.debug("Cannot stop when already idle")
|
_LOGGER.debug("Cannot stop when already idle")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ async def test_lg_tv(hass):
|
||||||
# The LG TV doesn't (at least at this patch level) report
|
# The LG TV doesn't (at least at this patch level) report
|
||||||
# its media state via CURRENT_MEDIA_STATE. Therefore "ok"
|
# its media state via CURRENT_MEDIA_STATE. Therefore "ok"
|
||||||
# is the best we can say.
|
# is the best we can say.
|
||||||
state="ok",
|
state="on",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue