Skip to content

Commit f5b843e

Browse files
authored
Merge pull request #102 from h4de5/feature/add-media_player-again
Add media_player in a 2025.11 compatible way.
2 parents 6e7a8ac + c0f5acb commit f5b843e

File tree

5 files changed

+27
-44
lines changed

5 files changed

+27
-44
lines changed

custom_components/vimar/const.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
DEVICE_TYPE_COVERS: "cover",
7878
DEVICE_TYPE_SWITCHES: "switch",
7979
DEVICE_TYPE_CLIMATES: "climate",
80-
# DEVICE_TYPE_MEDIA_PLAYERS: "media_player",
80+
DEVICE_TYPE_MEDIA_PLAYERS: "media_player",
8181
DEVICE_TYPE_SCENES: "scene",
8282
# DEVICE_TYPE_FANS: 'fan',
8383
DEVICE_TYPE_SENSORS: "sensor",
@@ -90,7 +90,7 @@
9090
DEVICE_TYPE_COVERS,
9191
DEVICE_TYPE_SWITCHES,
9292
DEVICE_TYPE_CLIMATES,
93-
# DEVICE_TYPE_MEDIA_PLAYERS,
93+
DEVICE_TYPE_MEDIA_PLAYERS,
9494
DEVICE_TYPE_SCENES,
9595
DEVICE_TYPE_SENSORS,
9696
]

custom_components/vimar/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"documentation": "https://github.com/h4de5/home-assistant-vimar",
88
"iot_class": "local_polling",
99
"issue_tracker": "https://github.com/h4de5/home-assistant-vimar/issues",
10-
"version": "2025.11.2"
10+
"version": "2025.11.3"
1111
}

custom_components/vimar/media_player.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,12 @@
22

33
import logging
44

5-
from homeassistant.components.media_player.const import (
6-
MEDIA_TYPE_CHANNEL,
7-
MEDIA_TYPE_MUSIC,
8-
SUPPORT_NEXT_TRACK,
9-
SUPPORT_SELECT_SOURCE,
10-
SUPPORT_TURN_OFF,
11-
SUPPORT_TURN_ON,
12-
SUPPORT_VOLUME_MUTE,
13-
SUPPORT_VOLUME_SET,
14-
SUPPORT_VOLUME_STEP,
15-
)
165
from homeassistant.const import STATE_OFF, STATE_PLAYING # STATE_IDLE,
17-
6+
from homeassistant.components.media_player import (
7+
MediaPlayerEntityFeature,
8+
MediaPlayerEntity,
9+
MediaType)
1810
from .vimar_entity import VimarEntity, vimar_setup_entry
19-
20-
try:
21-
from homeassistant.components.media_player import MediaPlayerEntity
22-
except ImportError:
23-
from homeassistant.components.media_player import MediaPlayerDevice as MediaPlayerEntity
24-
2511
from .const import DEVICE_TYPE_MEDIA_PLAYERS as CURR_PLATFORM
2612

2713
_LOGGER = logging.getLogger(__name__)
@@ -128,9 +114,9 @@ def media_content_type(self):
128114
"""Content type of current playing media."""
129115
# if self.has_state('source') and self.get_state('source') == self._channel_source_id:
130116
if self.has_state("channel") and self.get_state("channel") == self._channel_source_id:
131-
return MEDIA_TYPE_CHANNEL
117+
return MediaType.CHANNEL
132118
else:
133-
return MEDIA_TYPE_MUSIC
119+
return MediaType.MUSIC
134120

135121
@property
136122
def media_title(self):
@@ -158,12 +144,12 @@ def supported_features(self):
158144
"""Flag supported features."""
159145
flags = 0
160146
if self.has_state("on/off"):
161-
flags |= SUPPORT_TURN_ON | SUPPORT_TURN_OFF
147+
flags |= MediaPlayerEntityFeature.TURN_ON | MediaPlayerEntityFeature.TURN_OFF
162148
if self.has_state("volume"):
163-
flags |= SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_STEP
149+
flags |= MediaPlayerEntityFeature.VOLUME_SET | MediaPlayerEntityFeature.VOLUME_MUTE | MediaPlayerEntityFeature.VOLUME_STEP
164150
# if self.has_state('source'):
165151
if self.has_state("channel"):
166-
flags |= SUPPORT_SELECT_SOURCE
152+
flags |= MediaPlayerEntityFeature.SELECT_SOURCE
167153
# channel only available on source == 0 /
168154
# if self.get_state('source') == 0 and self.has_state('channel'):
169155
# if self.get_state('channel') == self._channel_source_id and self.has_state('source'):
@@ -172,7 +158,7 @@ def supported_features(self):
172158
if self.has_state("source"):
173159
# we can only do next track
174160
# flags |= SUPPORT_NEXT_TRACK | SUPPORT_PREVIOUS_TRACK
175-
flags |= SUPPORT_NEXT_TRACK
161+
flags |= MediaPlayerEntityFeature.NEXT_TRACK
176162

177163
# FIXED FIX ME - remove me in live
178164
# flags |= SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | SUPPORT_SELECT_SOURCE | SUPPORT_NEXT_TRACK | SUPPORT_PREVIOUS_TRACK

custom_components/vimar/vimar_device_customizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ def device_type_singolarize(self, device_type):
318318
return DEVICE_TYPE_COVERS
319319
if device_type == "lights":
320320
return DEVICE_TYPE_LIGHTS
321-
# if device_type == "media_players":
322-
# return DEVICE_TYPE_MEDIA_PLAYERS
321+
if device_type == "media_players":
322+
return DEVICE_TYPE_MEDIA_PLAYERS
323323
if device_type == "others":
324324
return DEVICE_TYPE_OTHERS
325325
if device_type == "scenes":

custom_components/vimar/vimarlink/vimarlink.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from ..const import (
1919
DEVICE_TYPE_COVERS,
2020
DEVICE_TYPE_LIGHTS,
21-
# DEVICE_TYPE_MEDIA_PLAYERS,
21+
DEVICE_TYPE_MEDIA_PLAYERS,
2222
DEVICE_TYPE_OTHERS,
2323
DEVICE_TYPE_SCENES,
2424
DEVICE_TYPE_SENSORS,
@@ -977,9 +977,6 @@ def parse_device_type(self, device):
977977
device_class = DEVICE_CLASS_SWITCH
978978
icon = ["mdi:fan", "mdi:fan-off"]
979979

980-
# device_type = DEVICE_TYPE_MEDIA_PLAYERS
981-
# icon = ["mdi:radio", "mdi:radio-off"]
982-
983980
# elif device["object_name"].find("LAMPE") != -1:
984981
elif any(x in device["object_name"].upper() for x in ["LAMPE"]):
985982
device_type = DEVICE_TYPE_LIGHTS
@@ -1145,17 +1142,17 @@ def parse_device_type(self, device):
11451142
device_type = DEVICE_TYPE_SENSORS
11461143
icon = "mdi:weather-partly-snowy-rainy"
11471144

1148-
# elif device["object_type"] in ["CH_Audio"]:
1149-
# device_type = DEVICE_TYPE_MEDIA_PLAYERS
1150-
# icon = ["mdi:radio", "mdi:radio-off"]
1151-
1152-
# _LOGGER.debug(
1153-
# "Audio object returned from web server: "
1154-
# + device["object_type"]
1155-
# + " / "
1156-
# + device["object_name"]
1157-
# )
1158-
# _LOGGER.debug("Audio object has states: " + str(device["status"]))
1145+
elif device["object_type"] in ["CH_Audio"]:
1146+
device_type = DEVICE_TYPE_MEDIA_PLAYERS
1147+
icon = ["mdi:radio", "mdi:radio-off"]
1148+
1149+
_LOGGER.debug(
1150+
"Audio object returned from web server: "
1151+
+ device["object_type"]
1152+
+ " / "
1153+
+ device["object_name"]
1154+
)
1155+
_LOGGER.debug("Audio object has states: " + str(device["status"]))
11591156

11601157
elif device["object_type"] in [
11611158
"CH_SAI",

0 commit comments

Comments
 (0)