Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version v0.9.0 #57

Merged
merged 17 commits into from
Jan 6, 2025
Merged

Version v0.9.0 #57

merged 17 commits into from
Jan 6, 2025

Conversation

andrewsayre
Copy link
Owner

@andrewsayre andrewsayre commented Jan 6, 2025

Description:

Fixed

  • url is no longer quoted in play_url

New

General

  • Python 3.13 support
  • Updates for HEOS CLI 1.21

const module:

  • MediaType added to represent media types.
  • RepeatType added to represent repeat options.
  • AddCriteriaType added to represent queue add criteria.
  • PlayState added to represent play state.
  • MUSIC_SOURCE_CONNCECT for Tidal/Sonos connect
  • INPUT_SOURCE_1 through INPUT_SOURCE_18

media module:

  • New class Media represents a common base-type for music sources and media items.
  • MediaMusicSource represents a root-level music source, returned from Heos.get_music_sources and includes function browse to enumerate child items.
  • MediaItem represents non-root sources, and all other media types (containers, playlists, albums, stations, etc...). Function browse is used to enumerate child items when browsable=True
  • BrowseResult represents the result of a browse operation and includes the items returned as well as record count information.

Heos class:

  • New update_credential parameter to sign_in and sign_out to indicate that the set credential should be updated and used on a reconnect attempt. Defaults to True.
  • current_credentials property exposes the currently stored credentials, whether passed in through options, or updated as the result of a sign_in or sign_out call.
  • browse for browsing media item by identifiers.
  • browse_media for browsing a MediaMusicSource or MediaItem.
  • play_media for playing an instance of MediaItem. This function will call the correct underlying function to switch the input, play the stream, or add the item to the queue.
  • play_input_source to play an specific input source.
  • play_station to play a station
  • play_preset_station to play a favorite
  • play_url to play a URL
  • add_to_queue to add an item to the queue
  • reboot to reboot the connected device.
  • add_on_controller_event, add_on_heos_event, add_on_connected, add_on_disconnected, add_on_user_credentials_invalid for connecting event handlers.

MediaItem class:

  • play_media for playing the current item on a player. This function will call the correct underlying function to switch the input, play the stream, or add the item to the queue.

HeosPlayer class:

  • add_to_queue to add an item to the player queue
  • play_media for playing an instance of MediaItem. This function will call the correct underlying function to switch the input, play the stream, or add the item to the queue.
  • add_on_player_event for connecting event handlers

Breaking changes

The following items were changed or removed in the library and may represent a breaking change, depending on usage.

const module:

  • SOURCE_CONTROLS now uses enum values from const.MediaType instead of discrete music source constants.
  • Removed music source constants: TYPE_MUSIC_SERVICE, TYPE_STATION, TYPE_SONG, TYPE_HEOS_SERVICE, TYPE_PLAYLIST. Use const.MediaType instead.
  • Removed repeat constants: REPEAT_ON_ALL, REPEAT_ON_ONE, REPEAT_OFF, VALID_REPEAT_MODES. Use const.RepeatType instead.
  • Removed queue criteria constants: ADD_QUEUE_PLAY_NOW, ADD_QUEUE_PLAY_NEXT, ADD_QUEUE_ADD_TO_END, ADD_QUEUE_REPLACE_AND_PLAY, and VALID_ADD_QUEUE_OPTIONS. Use the new enum AddCriteriaType.
  • Removed player state constants: PLAY_STATE_PLAY, PLAY_STATE_PAUSE, PLAY_STATE_STOP, and VALID_PLAY_STATES. Use the new enum PlayState.

Heos class:

  • get_music_sources now returns dict[int, MediaMusicSource]
  • get_input_sources now returns Sequence[MediaItem]
  • get_favorites now returns dict[int, MediaItem]
  • get_playlists now returns Sequence[MediaItem]
  • music_sources now returns dict[int, MediaMusicSource]

HeosPlayer class:

  • set_play_mode method parameter repeat is now of type const.RepeatType
  • play_input_source method parameter input_source is now of type MediaItem
  • add_to_queue method parameter source renamed to media: MediaItem
  • repeat property is now of type const.RepeatType
  • Renamed play_input to play_input_source for consistency.
  • Renamed play_favorite to play_preset_station for consistency.

source module:

This entire module has been removed. The functionality has been replaced by the media module. In most cases, this represents a change to the class only -- property name and functions remain the same from their former counterparts.

  • Removed HeosSource. Root level music sources are now represented by MediaMusicSource. All other source and media types are now represented by MediaItem
  • Removed InputSource. Now represented by MediaItem.

Checklist:

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • Tests have been added/updated. No exclusions in .coveragerc permitted.
  • README.MD updated (if necessary)

andrewsayre and others added 17 commits December 27, 2024 14:42
* Create discrete HeosMusicSource type

* Add ability to browse and treverse media

* Add BrowseResult class

* Remove InputSource in favor of MediaItem

* Update get_favorites to use MediaItem

* Update get_playlists to return MediaContainer

* Remove HeosSource

* Fix test typing

* Collapse media types

* Update wrapper methods to use same base

* Add const.RepeatType and remove discrete constants

* Add const.ATTR_SHUFFLE

* MediaMusicSource tests

* Remainder of Media module tests

* Move coverage config to project file

* Use const.VALUE_ON

* Use const.VALUE_OFF

* Use const.ATTR_TYPE

* More const usage and refactoring

* Add tests for uncovered code browse code
* Add const.AddCriteriaType

* Add and standardize play methods

* media.play_media tests

* Move reused data to fixture

* Refactor browse commands

* Tests for play functions

* Some test clean-up

* Fix typing issues
* Add command decorator

* Define more consts

* Remove asyncio mark

* Cache fixture loads

* Update group tests

* Return unknown command from mock device

* Add calls_commands decorator and simplify group tests

* Move items to common

* Clean-up player tests

* Update browse tests

* Update heos tests

* Simplify event writing

* Simplified matching classes

* Correct test names

* Add command under process support
* Add browse mixin

* Player commands 4.2.1 - 4.2.14

* Remaining player commands

* Remove player commands reference

* Add PlayState enum

* Add test case for uncovered
Before this change, if I request to play the URL

    http://192.168.0.10/test.mp3?auth%3Dsomething

through Home Assistant, it will result in this message being sent:

    heos://browse/play_stream?sequence=498&pid=-646915758&url=http://192.168.0.10/test.mp3?auth%3Dsomething

but despite saying in CLI specification that special characters in
arguments need to be encoded, HEOS seems to take the url argument
and pass it to the stream server verbatim, as demonstrated by the
nginx log resulting from this command:

    Jan 04 12:03:27 lillia nginx[351316]: lillia nginx: 192.168.0.209 - - [04/Jan/2025:12:03:27 +0100] "GET /test.mp3?auth%3Dsomething HTTP/1.1" 404 146 "-" "AvegaMediaServer/2.0 Linux/2.6"

I've been playing URLs with ? in them for some months now by inserting
them into the HEOS command without quoting them, for example:

    heos://browse/play_stream?sequence=498&pid=-646915758&url=http://192.168.0.10/test.mp3?auth=something

This seems to be consistent with the requirement that url be the last
argument, because then the controller can treat the rest of the command
as URL without processing it.

This change introduces special handling of the url argument, so that it
bypasses quoting in addition to being the last argument.
* Refactored group commands

* Move command consts

* Move other specific consts

* HeosGroup is now a dataclass

* Move methods to mixins

* Refactoring

* Add tests

* Consistency in media class implementation

* HeosPlayer dataclass

* Make sure player availability is set based on connection
* Allow controls for TIDAL Connect

HEOS U34 added support for TIDAL Connect. When playing, the source id is
always `0`. All normal player controls are supported in this case.

* Merge conflic fixes

* Fix const

---------

Co-authored-by: Andrew Sayre <6730289+andrewsayre@users.noreply.github.com>
* Add python 3.13 and update deps

* Try UV

* Try UV

* Remove flag

* Try system

* Update publish action
* Add input/source1 - 18

* Add refresh option to get_music_sources

* Update readme

* Typo
* Raise event when command auth error occurs

* Test for command error event

* Use helper

* Tests and ensure dispatcher logs failed calls

* Test for dispatcher exception logging

* Undo change to Heos.disconnect
* Wait on dispatch calls

* Add Heos callbacks

* Move type defs to top

* Add add_on_player_event

* Add add_on_controller_event

* Made heos public

* Refactoring
This reverts commit 74305a5.
@andrewsayre andrewsayre marked this pull request as ready for review January 6, 2025 23:28
@andrewsayre andrewsayre merged commit ea86b51 into main Jan 6, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants