Help Prepping for Deprecation of Media Player Code

Nothing complicated here, I think. I just don’t know how to do it. I’m getting this log message:

Entity None (<class 'custom_components.htd_lync12.media_player.HtdDevice'>) is using deprecated supported features values which will be removed in HA Core 2025.1. Instead it should use <MediaPlayerEntityFeature.VOLUME_SET|VOLUME_MUTE|TURN_ON|TURN_OFF|SELECT_SOURCE: 2444>, please report it to the author of the 'htd_lync12' custom integration and reference https://developers.home-assistant.io/blog/2023/12/28/support-feature-magic-numbers-deprecation

Fortunately there is another log message with more specifics:

Logger: homeassistant.components.media_player.const
Source: helpers/deprecation.py:222
integration: Media player (documentation, issues)
First occurred: 1:21:24 PM (5 occurrences)
Last logged: 1:21:24 PM

SUPPORT_SELECT_SOURCE was used from htd_lync12, this is a deprecated constant which will be removed in HA Core 2025.10. Use MediaPlayerEntityFeature.SELECT_SOURCE instead, please report it to the author of the 'htd_lync12' custom integration
SUPPORT_TURN_OFF was used from htd_lync12, this is a deprecated constant which will be removed in HA Core 2025.10. Use MediaPlayerEntityFeature.TURN_OFF instead, please report it to the author of the 'htd_lync12' custom integration
SUPPORT_TURN_ON was used from htd_lync12, this is a deprecated constant which will be removed in HA Core 2025.10. Use MediaPlayerEntityFeature.TURN_ON instead, please report it to the author of the 'htd_lync12' custom integration
SUPPORT_VOLUME_MUTE was used from htd_lync12, this is a deprecated constant which will be removed in HA Core 2025.10. Use MediaPlayerEntityFeature.VOLUME_MUTE instead, please report it to the author of the 'htd_lync12' custom integration
SUPPORT_VOLUME_SET was used from htd_lync12, this is a deprecated constant which will be removed in HA Core 2025.10. Use MediaPlayerEntityFeature.VOLUME_SET instead, please report it to the author of the 'htd_lync12' custom integration

The code in question comes from the HTD Lync integration. It’s not really supported and I had to modify it for make it work for the Lync 6 instead of the Lync 12. This is the code:

import logging

_LOGGER = logging.getLogger(__name__)

"""Support for HTD Lync12 Series"""
from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity

from homeassistant.components.media_player.const import (
    SUPPORT_SELECT_SOURCE,
    SUPPORT_TURN_OFF,
    SUPPORT_TURN_ON,
    SUPPORT_VOLUME_MUTE,
    SUPPORT_VOLUME_SET,
    #SUPPORT_VOLUME_STEP,
)

from homeassistant.const import (
    CONF_HOST,
    CONF_NAME,
    STATE_OFF,
    STATE_ON,
    STATE_UNKNOWN,
)

from . import DOMAIN, CONF_ZONES
from .htd_lync12 import HtdLync12Client, MAX_HTD_VOLUME
SUPPORT_HTD_Lync12 = (
    SUPPORT_SELECT_SOURCE
    | SUPPORT_TURN_OFF
    | SUPPORT_TURN_ON
    | SUPPORT_VOLUME_MUTE
    | SUPPORT_VOLUME_SET
    #| SUPPORT_VOLUME_STEP
)


def setup_platform(hass, config, add_entities, discovery_info=None):
    htd_configs = hass.data[DOMAIN]
    entities = []

    for k in range(len(htd_configs)):
        config = htd_configs[k]
        zones = config["zones"]
        client = config["client"]
        sources = config["sources"]

        for i in range(len(zones)):
            entities.append(HtdDevice(k, client, sources, i + 1, zones[i]))

    add_entities(entities)


class HtdDevice(MediaPlayerEntity):
    def __init__(self, id, client,  sources, zone, zone_name):
        self.zone = zone
        self.id = id
        self.zone_name = zone_name
        self.sources = sources
        self.client = client
        self.update()

    @property
    def supported_features(self):
        return SUPPORT_HTD_Lync12

    @property
    def unique_id(self):
        return f"media_player.htd_lync12_zone_{self.id}_{self.zone}"

    @property
    def name(self):
        return self.zone_name

    def update(self):
        self.zone_info = self.client.query_zone(self.zone)

    @property
    def state(self):
        if self.zone_info['power'] == 'unknown':
            return STATE_UNKNOWN

        return STATE_ON if self.zone_info['power'] == 'on' else STATE_OFF

    def turn_on(self):
        self.client.set_power(self.zone, 1)

    def turn_off(self):
        self.client.set_power(self.zone, 0)

    @property
    def volume_level(self):
        return self.zone_info['vol'] / MAX_HTD_VOLUME

    def set_volume_level(self, new_volume):
        #_LOGGER.warning(f"New Vol {new_volume} ")   
        new_vol = int(100 * new_volume)
        #new_vol = int(new_volume)        
        self.client.set_volume(self.zone, new_vol)

    @property
    def is_volume_muted(self):
        return self.zone_info["mute"] == "on"

    def mute_volume(self, zone):
        #_LOGGER.warning(f"Set Mute" )
        if self.zone_info["mute"] == "on":
            return self.client.toggle_mute_off(self.zone)
        else:
            return self.client.toggle_mute_on(self.zone)            

    @property
    def source(self):
        return self.sources[self.zone_info["source"] - 1]

    @property
    def source_list(self):
        return self.sources

    @property
    def media_title(self):
        return self.source

    def select_source(self, source):
        index = self.sources.index(source)
        self.client.set_source(self.zone, index + 1)

    @property
    def icon(self):
        return "mdi:disc-player"

I tried to update the code but I seem to have made a mistake. Should it be just a simple as replacing SUPPORT_SELECT_SOURCE with MediaPlayerEntityFeature.SELECT_SOURCE (and similar to the other similarly listed items). Sorry, I’m not great with Python.

This is the message I get when I try to update it:

  File "/config/custom_components/htd_lync12/media_player.py", line 9
    MediaPlayerEntityFeature.SELECT_SOURCE, #SUPPORT_SELECT_SOURCE,
                            ^
SyntaxError: invalid syntax

Hi Noobitious,

That is the action you should need to take. If the author is already aware, there may be a fix there already.

(At least that’s how it is supposed to work…)

In case this helps anyone, thanks to the help of others and ChatGPT, I managed to make a new fork that works for HTD Lync6 and addresses the deprecated coding issue: Noobitious/htd-lync6-home-assistant: An integration for the HTD Lync6 Series for Home Assistant