Skip to content

Commit

Permalink
[ 1.0.47 ] * Added configuration option to hide specified device name…
Browse files Browse the repository at this point in the history
…s from the HA media player UI source list.
  • Loading branch information
thlucas1 committed Aug 5, 2024
1 parent f8ecf4e commit 557bf8c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Change are listed in reverse chronological order (newest to oldest).

<span class="changelog">

###### [ 1.0.47 ] - 2024/08/05

* Added configuration option to hide specified device names from the HA media player UI source list.

###### [ 1.0.46 ] - 2024/08/04

* Updated service `player_transfer_playback` to transfer the Spotify users queue (20 items max) to the Sonos device (instead of just the currently playing track). See the [Sonos Limitations](https://github.com/thlucas1/homeassistantcomponent_spotifyplus/wiki/Spotify-Connect-Brand-Notes#sonos) wiki documentation for further details about Sonos-related issues.
Expand Down
5 changes: 5 additions & 0 deletions custom_components/spotifyplus/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
CONF_OPTION_DEVICE_USERNAME,
CONF_OPTION_SCRIPT_TURN_OFF,
CONF_OPTION_SCRIPT_TURN_ON,
CONF_OPTION_SOURCE_LIST_HIDE,
DOMAIN,
DOMAIN_SCRIPT,
SPOTIFY_SCOPES
Expand Down Expand Up @@ -371,6 +372,7 @@ async def async_step_init(self, user_input:dict[str,Any]=None) -> FlowResult:
self._Options[CONF_OPTION_DEVICE_PASSWORD] = user_input.get(CONF_OPTION_DEVICE_PASSWORD, None)
self._Options[CONF_OPTION_SCRIPT_TURN_OFF] = user_input.get(CONF_OPTION_SCRIPT_TURN_OFF, None)
self._Options[CONF_OPTION_SCRIPT_TURN_ON] = user_input.get(CONF_OPTION_SCRIPT_TURN_ON, None)
self._Options[CONF_OPTION_SOURCE_LIST_HIDE] = user_input.get(CONF_OPTION_SOURCE_LIST_HIDE, None)

# validations.
# if device username was entered then device password is required.
Expand Down Expand Up @@ -438,6 +440,9 @@ async def async_step_init(self, user_input:dict[str,Any]=None) -> FlowResult:
): selector.EntitySelector(selector.EntitySelectorConfig(integration=DOMAIN_SCRIPT,
multiple=False),
),
vol.Optional(CONF_OPTION_SOURCE_LIST_HIDE,
description={"suggested_value": self._Options.get(CONF_OPTION_SOURCE_LIST_HIDE)},
): cv.string,
}
)

Expand Down
1 change: 1 addition & 0 deletions custom_components/spotifyplus/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
CONF_OPTION_DEVICE_USERNAME = "device_username"
CONF_OPTION_SCRIPT_TURN_ON = "script_turn_on"
CONF_OPTION_SCRIPT_TURN_OFF = "script_turn_off"
CONF_OPTION_SOURCE_LIST_HIDE = "source_list_hide"

# security scopes required by various Spotify Web API endpoints.
SPOTIFY_SCOPES:list = \
Expand Down
22 changes: 21 additions & 1 deletion custom_components/spotifyplus/instancedata_spotifyplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
CONF_OPTION_DEVICE_USERNAME,
CONF_OPTION_SCRIPT_TURN_OFF,
CONF_OPTION_SCRIPT_TURN_ON,
CONF_OPTION_SOURCE_LIST_HIDE,
)

@dataclass
Expand Down Expand Up @@ -98,4 +99,23 @@ def OptionScriptTurnOn(self) -> str | None:
Script entity id that will be called to power on the device that plays media content.
"""
return self.options.get(CONF_OPTION_SCRIPT_TURN_ON, None)


@property
def OptionSourceListHide(self) -> list:
"""
The list of devices to hide from the source list.
"""
result:list = []

# get option value.
value:str = self.options.get(CONF_OPTION_SOURCE_LIST_HIDE, None)

# build a list from the semi-colon delimited string.
if value is not None:
result = value.split(';')
for idx in range(0, len(result)):
result[idx] = result[idx].strip().lower()

# return result.
return result

2 changes: 1 addition & 1 deletion custom_components/spotifyplus/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"urllib3>=1.21.1,<1.27",
"zeroconf>=0.132.2"
],
"version": "1.0.46",
"version": "1.0.47",
"zeroconf": [ "_spotify-connect._tcp.local." ]
}
7 changes: 6 additions & 1 deletion custom_components/spotifyplus/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,16 @@ def source_list(self) -> list[str] | None:
# get spotify client cached device list.
if "GetSpotifyConnectDevices" in self.data.spotifyClient.ConfigurationCache:
result:SpotifyConnectDevices = self.data.spotifyClient.ConfigurationCache["GetSpotifyConnectDevices"]

# get the list of device names to hide (omit) in the list.
sourceListHide:list = self.data.OptionSourceListHide

# build list of device names for the source list.
deviceNames:list[str] = []
device:PlayerDevice
for device in result.GetDeviceList():
deviceNames.append(device.Name)
if (device.Name.lower() not in sourceListHide):
deviceNames.append(device.Name)
return deviceNames

return None
Expand Down
3 changes: 2 additions & 1 deletion custom_components/spotifyplus/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"device_password": "Spotify Connect password to use when connecting to an inactive device.",
"device_username": "Spotify Connect username to use when connecting to an inactive device.",
"script_turn_on": "Script called to turn on device that plays media content.",
"script_turn_off": "Script called to turn off device that plays media content."
"script_turn_off": "Script called to turn off device that plays media content.",
"source_list_hide": "The semi-colon delimited list of device names to hide in the source list."
},
"submit": "Save"
}
Expand Down
3 changes: 2 additions & 1 deletion custom_components/spotifyplus/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"device_password": "Spotify Connect password to use when connecting to an inactive device.",
"device_username": "Spotify Connect username to use when connecting to an inactive device.",
"script_turn_on": "Script called to turn on device that plays media content.",
"script_turn_off": "Script called to turn off device that plays media content."
"script_turn_off": "Script called to turn off device that plays media content.",
"source_list_hide": "The semi-colon delimited list of device names to hide in the source list."
},
"submit": "Save"
}
Expand Down

0 comments on commit 557bf8c

Please sign in to comment.