Skip to content

Commit

Permalink
fix deprecation of the media_player constants in HA 2024.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
litinoveweedle committed Jun 9, 2024
1 parent 9aae6e2 commit af3f1a9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
12 changes: 5 additions & 7 deletions custom_components/smartir/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@
CONF_POWER_SENSOR_DELAY = "power_sensor_delay"
CONF_POWER_SENSOR_RESTORE_STATE = "power_sensor_restore_state"

SUPPORT_FLAGS = (
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_ON
| ClimateEntityFeature.TURN_OFF
)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Optional(CONF_UNIQUE_ID): cv.string,
Expand Down Expand Up @@ -132,7 +126,11 @@ def __init__(self, hass, config, device_data):
self._on_by_remote = False
self._current_temperature = None
self._current_humidity = None
self._support_flags = SUPPORT_FLAGS
self._support_flags = (
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_ON
| ClimateEntityFeature.TURN_OFF
)
self._power_sensor_check_expect = None
self._power_sensor_check_cancel = None

Expand Down
35 changes: 20 additions & 15 deletions custom_components/smartir/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@

from homeassistant.components.media_player import MediaPlayerEntity, PLATFORM_SCHEMA
from homeassistant.components.media_player.const import (
SUPPORT_TURN_OFF,
SUPPORT_TURN_ON,
SUPPORT_PREVIOUS_TRACK,
SUPPORT_NEXT_TRACK,
SUPPORT_VOLUME_STEP,
SUPPORT_VOLUME_MUTE,
SUPPORT_PLAY_MEDIA,
SUPPORT_SELECT_SOURCE,
MediaPlayerEntityFeature,
MEDIA_TYPE_CHANNEL,
)
from homeassistant.const import CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN
Expand Down Expand Up @@ -114,34 +107,46 @@ def __init__(self, hass, config, device_data):

# Supported features
if "off" in self._commands and self._commands["off"] is not None:
self._support_flags = self._support_flags | SUPPORT_TURN_OFF
self._support_flags = (
self._support_flags | MediaPlayerEntityFeature.TURN_OFF
)

if "on" in self._commands and self._commands["on"] is not None:
self._support_flags = self._support_flags | SUPPORT_TURN_ON
self._support_flags = self._support_flags | MediaPlayerEntityFeature.TURN_ON

if (
"previousChannel" in self._commands
and self._commands["previousChannel"] is not None
):
self._support_flags = self._support_flags | SUPPORT_PREVIOUS_TRACK
self._support_flags = (
self._support_flags | MediaPlayerEntityFeature.PREVIOUS_TRACK
)

if (
"nextChannel" in self._commands
and self._commands["nextChannel"] is not None
):
self._support_flags = self._support_flags | SUPPORT_NEXT_TRACK
self._support_flags = (
self._support_flags | MediaPlayerEntityFeature.NEXT_TRACK
)

if (
"volumeDown" in self._commands and self._commands["volumeDown"] is not None
) or ("volumeUp" in self._commands and self._commands["volumeUp"] is not None):
self._support_flags = self._support_flags | SUPPORT_VOLUME_STEP
self._support_flags = (
self._support_flags | MediaPlayerEntityFeature.VOLUME_STEP
)

if "mute" in self._commands and self._commands["mute"] is not None:
self._support_flags = self._support_flags | SUPPORT_VOLUME_MUTE
self._support_flags = (
self._support_flags | MediaPlayerEntityFeature.VOLUME_MUTE
)

if "sources" in self._commands and self._commands["sources"] is not None:
self._support_flags = (
self._support_flags | SUPPORT_SELECT_SOURCE | SUPPORT_PLAY_MEDIA
self._support_flags
| MediaPlayerEntityFeature.SELECT_SOURCE
| MediaPlayerEntityFeature.PLAY_MEDIA
)

for source, new_name in config.get(CONF_SOURCE_NAMES, {}).items():
Expand Down

0 comments on commit af3f1a9

Please sign in to comment.