Fix SmartThings soundbar without media playback (#143170)

This commit is contained in:
Joost Lekkerkerker 2025-04-19 09:53:31 +02:00 committed by GitHub
parent 850d9a0254
commit d8d9449e2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 455 additions and 28 deletions

View File

@ -23,7 +23,6 @@ from .entity import SmartThingsEntity
MEDIA_PLAYER_CAPABILITIES = (
Capability.AUDIO_MUTE,
Capability.AUDIO_VOLUME,
Capability.MEDIA_PLAYBACK,
)
CONTROLLABLE_SOURCES = ["bluetooth", "wifi"]
@ -100,7 +99,12 @@ class SmartThingsMediaPlayer(SmartThingsEntity, MediaPlayerEntity):
)
def _determine_features(self) -> MediaPlayerEntityFeature:
flags = MediaPlayerEntityFeature(0)
flags = (
MediaPlayerEntityFeature.VOLUME_SET
| MediaPlayerEntityFeature.VOLUME_STEP
| MediaPlayerEntityFeature.VOLUME_MUTE
)
if self.supports_capability(Capability.MEDIA_PLAYBACK):
playback_commands = self.get_attribute_value(
Capability.MEDIA_PLAYBACK, Attribute.SUPPORTED_PLAYBACK_COMMANDS
)
@ -114,13 +118,6 @@ class SmartThingsMediaPlayer(SmartThingsEntity, MediaPlayerEntity):
flags |= MediaPlayerEntityFeature.PREVIOUS_TRACK
if "fastForward" in playback_commands:
flags |= MediaPlayerEntityFeature.NEXT_TRACK
if self.supports_capability(Capability.AUDIO_VOLUME):
flags |= (
MediaPlayerEntityFeature.VOLUME_SET
| MediaPlayerEntityFeature.VOLUME_STEP
)
if self.supports_capability(Capability.AUDIO_MUTE):
flags |= MediaPlayerEntityFeature.VOLUME_MUTE
if self.supports_capability(Capability.SWITCH):
flags |= (
MediaPlayerEntityFeature.TURN_ON | MediaPlayerEntityFeature.TURN_OFF
@ -270,6 +267,13 @@ class SmartThingsMediaPlayer(SmartThingsEntity, MediaPlayerEntity):
def state(self) -> MediaPlayerState | None:
"""State of the media player."""
if self.supports_capability(Capability.SWITCH):
if not self.supports_capability(Capability.MEDIA_PLAYBACK):
if (
self.get_attribute_value(Capability.SWITCH, Attribute.SWITCH)
== "on"
):
return MediaPlayerState.ON
return MediaPlayerState.OFF
if self.get_attribute_value(Capability.SWITCH, Attribute.SWITCH) == "on":
if (
self.source is not None

View File

@ -194,13 +194,7 @@ CAPABILITY_TO_SENSORS: dict[
native_unit_of_measurement=PERCENTAGE,
deprecated=(
lambda status: "media_player"
if all(
capability in status
for capability in (
Capability.AUDIO_MUTE,
Capability.MEDIA_PLAYBACK,
)
)
if Capability.AUDIO_MUTE in status
else None
),
)

View File

@ -38,7 +38,6 @@ AC_CAPABILITIES = (
MEDIA_PLAYER_CAPABILITIES = (
Capability.AUDIO_MUTE,
Capability.AUDIO_VOLUME,
Capability.MEDIA_PLAYBACK,
)

View File

@ -109,6 +109,7 @@ def mock_smartthings() -> Generator[AsyncMock]:
"da_ref_normal_01011",
"da_ref_normal_01001",
"vd_network_audio_002s",
"vd_network_audio_003s",
"vd_sensor_light_2023",
"iphone",
"da_sac_ehs_000001_sub",

View File

@ -0,0 +1,231 @@
{
"components": {
"main": {
"samsungvd.soundFrom": {
"mode": {
"value": 29,
"timestamp": "2025-04-05T13:51:47.865Z"
},
"detailName": {
"value": "None",
"timestamp": "2025-04-05T13:51:50.230Z"
}
},
"audioVolume": {
"volume": {
"value": 6,
"unit": "%",
"timestamp": "2025-04-17T11:17:25.272Z"
}
},
"samsungvd.audioGroupInfo": {
"role": {
"value": null
},
"channel": {
"value": null
},
"status": {
"value": null
}
},
"refresh": {},
"audioNotification": {},
"execute": {
"data": {
"value": null
}
},
"samsungvd.audioInputSource": {
"supportedInputSources": {
"value": ["D.IN", "BT", "WIFI"],
"timestamp": "2025-03-18T19:11:54.071Z"
},
"inputSource": {
"value": "D.IN",
"timestamp": "2025-04-17T11:18:02.048Z"
}
},
"switch": {
"switch": {
"value": "off",
"timestamp": "2025-04-17T14:42:04.704Z"
}
},
"sec.wifiConfiguration": {
"autoReconnection": {
"value": true,
"timestamp": "2025-03-18T19:11:54.484Z"
},
"minVersion": {
"value": "1.0",
"timestamp": "2025-03-18T19:11:54.484Z"
},
"supportedWiFiFreq": {
"value": ["2.4G", "5G"],
"timestamp": "2025-03-18T19:11:54.484Z"
},
"supportedAuthType": {
"value": [
"OPEN",
"WEP",
"WPA-PSK",
"WPA2-PSK",
"EAP",
"SAE",
"OWE",
"FT-PSK"
],
"timestamp": "2025-03-18T19:11:54.484Z"
},
"protocolType": {
"value": ["ble_ocf"],
"timestamp": "2025-03-18T19:11:54.484Z"
}
},
"ocf": {
"st": {
"value": "1970-01-01T00:00:47Z",
"timestamp": "2025-02-21T15:09:52.348Z"
},
"mndt": {
"value": "2024-01-01",
"timestamp": "2025-02-21T15:09:52.348Z"
},
"mnfv": {
"value": "SAT-MT8532D24WWC-1016.0",
"timestamp": "2025-02-21T16:47:38.134Z"
},
"mnhw": {
"value": "",
"timestamp": "2025-02-21T15:09:52.348Z"
},
"di": {
"value": "a75cb1e1-03fd-3c77-ca9f-d4e56c4096c6",
"timestamp": "2025-02-21T15:09:52.348Z"
},
"mnsl": {
"value": "",
"timestamp": "2025-02-21T15:09:52.348Z"
},
"dmv": {
"value": "res.1.1.0,sh.1.1.0",
"timestamp": "2025-02-21T15:09:52.348Z"
},
"n": {
"value": "Soundbar",
"timestamp": "2025-02-21T16:47:38.134Z"
},
"mnmo": {
"value": "HW-S60D",
"timestamp": "2025-02-21T15:09:52.348Z"
},
"vid": {
"value": "VD-NetworkAudio-003S",
"timestamp": "2025-02-21T15:09:52.348Z"
},
"mnmn": {
"value": "Samsung Electronics",
"timestamp": "2025-02-21T15:09:52.348Z"
},
"mnml": {
"value": "",
"timestamp": "2025-02-21T15:09:52.348Z"
},
"mnpv": {
"value": "8.0",
"timestamp": "2025-02-21T15:09:52.348Z"
},
"mnos": {
"value": "Tizen",
"timestamp": "2025-02-21T15:09:52.348Z"
},
"pi": {
"value": "a75cb1e1-03fd-3c77-ca9f-d4e56c4096c6",
"timestamp": "2025-02-21T15:09:52.348Z"
},
"icv": {
"value": "core.1.1.0",
"timestamp": "2025-02-21T15:09:52.348Z"
}
},
"samsungvd.supportsFeatures": {
"mediaOutputSupported": {
"value": null
},
"imeAdvSupported": {
"value": null
},
"wifiUpdateSupport": {
"value": true,
"timestamp": "2025-03-18T19:11:53.853Z"
},
"executableServiceList": {
"value": null
},
"remotelessSupported": {
"value": null
},
"artSupported": {
"value": null
},
"mobileCamSupported": {
"value": null
}
},
"sec.diagnosticsInformation": {
"logType": {
"value": ["errCode", "dump"],
"timestamp": "2025-03-18T19:11:54.336Z"
},
"endpoint": {
"value": "PIPER",
"timestamp": "2025-03-18T19:11:54.336Z"
},
"minVersion": {
"value": "3.0",
"timestamp": "2025-03-18T19:11:54.336Z"
},
"signinPermission": {
"value": null
},
"setupId": {
"value": "301",
"timestamp": "2025-03-18T19:11:54.336Z"
},
"protocolType": {
"value": "ble_ocf",
"timestamp": "2025-03-18T19:11:54.336Z"
},
"tsId": {
"value": "VD02",
"timestamp": "2025-03-18T19:11:54.336Z"
},
"mnId": {
"value": "0AJK",
"timestamp": "2025-03-18T19:11:54.336Z"
},
"dumpType": {
"value": "file",
"timestamp": "2025-03-18T19:11:54.336Z"
}
},
"audioMute": {
"mute": {
"value": "muted",
"timestamp": "2025-04-17T11:36:04.814Z"
}
},
"samsungvd.thingStatus": {
"updatedTime": {
"value": 1744900925,
"timestamp": "2025-04-17T14:42:04.770Z"
},
"status": {
"value": "Idle",
"timestamp": "2025-03-18T19:11:54.101Z"
}
}
}
}
}

View File

@ -0,0 +1,115 @@
{
"items": [
{
"deviceId": "a75cb1e1-03fd-3c77-ca9f-d4e56c4096c6",
"name": "Soundbar",
"label": "Soundbar",
"manufacturerName": "Samsung Electronics",
"presentationId": "VD-NetworkAudio-003S",
"deviceManufacturerCode": "Samsung Electronics",
"locationId": "6bdf6730-8167-488b-8645-d0c5046ff763",
"ownerId": "15f0ae72-da51-14e2-65cf-ef59ae867e7f",
"roomId": "3b0fe9a8-51d6-49cf-b64a-8a719013c0a7",
"deviceTypeName": "Samsung OCF Network Audio Player",
"components": [
{
"id": "main",
"label": "main",
"capabilities": [
{
"id": "ocf",
"version": 1
},
{
"id": "execute",
"version": 1
},
{
"id": "refresh",
"version": 1
},
{
"id": "switch",
"version": 1
},
{
"id": "audioVolume",
"version": 1
},
{
"id": "audioMute",
"version": 1
},
{
"id": "samsungvd.audioInputSource",
"version": 1
},
{
"id": "audioNotification",
"version": 1
},
{
"id": "samsungvd.soundFrom",
"version": 1
},
{
"id": "sec.diagnosticsInformation",
"version": 1
},
{
"id": "samsungvd.thingStatus",
"version": 1
},
{
"id": "samsungvd.supportsFeatures",
"version": 1
},
{
"id": "sec.wifiConfiguration",
"version": 1
},
{
"id": "samsungvd.audioGroupInfo",
"version": 1,
"ephemeral": true
}
],
"categories": [
{
"name": "NetworkAudio",
"categoryType": "manufacturer"
}
],
"optional": false
}
],
"createTime": "2025-02-21T14:25:21.843Z",
"profile": {
"id": "25504ad5-8563-3b07-8770-e52ad29a9c5a"
},
"ocf": {
"ocfDeviceType": "oic.d.networkaudio",
"name": "Soundbar",
"specVersion": "core.1.1.0",
"verticalDomainSpecVersion": "res.1.1.0,sh.1.1.0",
"manufacturerName": "Samsung Electronics",
"modelNumber": "HW-S60D",
"platformVersion": "8.0",
"platformOS": "Tizen",
"hwVersion": "",
"firmwareVersion": "SAT-MT8532D24WWC-1016.0",
"vendorId": "VD-NetworkAudio-003S",
"vendorResourceClientServerVersion": "4.0.26",
"lastSignupTime": "2025-03-18T19:11:51.176292902Z",
"transferCandidate": false,
"additionalAuthCodeRequired": false
},
"type": "OCF",
"restrictionTier": 0,
"allowed": null,
"executionContext": "CLOUD",
"relationships": []
}
],
"_links": {}
}

View File

@ -1685,6 +1685,39 @@
'via_device_id': None,
})
# ---
# name: test_devices[vd_network_audio_003s]
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'config_entries_subentries': <ANY>,
'configuration_url': 'https://account.smartthings.com',
'connections': set({
}),
'disabled_by': None,
'entry_type': None,
'hw_version': '',
'id': <ANY>,
'identifiers': set({
tuple(
'smartthings',
'a75cb1e1-03fd-3c77-ca9f-d4e56c4096c6',
),
}),
'is_new': False,
'labels': set({
}),
'manufacturer': 'Samsung Electronics',
'model': 'HW-S60D',
'model_id': None,
'name': 'Soundbar',
'name_by_user': None,
'primary_config_entry': <ANY>,
'serial_number': None,
'suggested_area': None,
'sw_version': 'SAT-MT8532D24WWC-1016.0',
'via_device_id': None,
})
# ---
# name: test_devices[vd_sensor_light_2023]
DeviceRegistryEntrySnapshot({
'area_id': None,

View File

@ -231,6 +231,56 @@
'state': 'on',
})
# ---
# name: test_all_entities[vd_network_audio_003s][media_player.soundbar-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'media_player',
'entity_category': None,
'entity_id': 'media_player.soundbar',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <MediaPlayerDeviceClass.SPEAKER: 'speaker'>,
'original_icon': None,
'original_name': None,
'platform': 'smartthings',
'previous_unique_id': None,
'supported_features': <MediaPlayerEntityFeature: 1420>,
'translation_key': None,
'unique_id': 'a75cb1e1-03fd-3c77-ca9f-d4e56c4096c6_main',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[vd_network_audio_003s][media_player.soundbar-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'speaker',
'friendly_name': 'Soundbar',
'supported_features': <MediaPlayerEntityFeature: 1420>,
}),
'context': <ANY>,
'entity_id': 'media_player.soundbar',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_all_entities[vd_stv_2017_k][media_player.tv_samsung_8_series_49-entry]
EntityRegistryEntrySnapshot({
'aliases': set({