media_player

Go types for Home Assistant's media_player domain: control over HTTP.

Control: HTTP
import "github.com/taumatix/homeassistant-go/domains/mediaplayer"

Overview

Package mediaplayer is Home Assistant's media_player domain: its types.

Entity controls one media_player entity over HTTP.

No method for media_player.browse_media and media_player.search_media, which only answer with data: call api.Client.CallServiceForResponse.

Home Assistant documents the domain here:

Integration: https://www.home-assistant.io/integrations/media_player/

Entity model (developers): https://contributors.home-assistant.io/core/entities/media-player/

Control

// client is an *api.Client
target := mediaplayer.Get(client, "my_media_player")
state, err := target.State(ctx)
err = target.ClearPlaylist(ctx)

Commands

What each Entity method does on each transport. Home Assistant has no MQTT discovery for this domain.

MethodOver HTTP, calls
ClearPlaylist media_player.clear_playlist
Join media_player.join
MediaNextTrack media_player.media_next_track
MediaPause media_player.media_pause
MediaPlay media_player.media_play
MediaPlayPause media_player.media_play_pause
MediaPreviousTrack media_player.media_previous_track
MediaSeek media_player.media_seek
MediaStop media_player.media_stop
PlayMedia media_player.play_media
RepeatSet media_player.repeat_set
SelectSoundMode media_player.select_sound_mode
SelectSource media_player.select_source
ShuffleSet media_player.shuffle_set
Toggle media_player.toggle
TurnOff media_player.turn_off
TurnOn media_player.turn_on
Unjoin media_player.unjoin
VolumeDown media_player.volume_down
VolumeMute media_player.volume_mute
VolumeSet media_player.volume_set
VolumeUp media_player.volume_up

Services without a method

Call these with the REST or WebSocket client.

ServiceWhy
media_player.browse_mediait only answers with data
media_player.search_mediait only answers with data

Control

type Entity struct

Entity controls one media_player entity over HTTP (api.Client). State and Subscribe come from the embedded Handle.

Embeds entity.Handle[Attributes], whose methods it has too.

func Get(transport entity.Transport, id string) *Entity

Get returns the media_player entity with the given id: an entity id over HTTP (the "media_player." prefix may be omitted). It does no I/O.

func List(ctx context.Context, transport entity.Transport) ([]*Entity, error)

List returns every media_player entity the transport can see.

func (e *Entity) ClearPlaylist(ctx context.Context) error

ClearPlaylist calls media_player.clear_playlist. It has no MQTT equivalent. Core describes the service: Removes all items from a media player's playlist.

func (e *Entity) Join(ctx context.Context, options ...entity.ServiceOption) error

Join calls media_player.join. It has no MQTT equivalent. Core describes the service: Groups media players together for synchronous playback. Only works on supported multiroom audio systems.

func (e *Entity) MediaNextTrack(ctx context.Context) error

MediaNextTrack calls media_player.media_next_track. It has no MQTT equivalent. Core describes the service: Selects the next track on a media player.

func (e *Entity) MediaPause(ctx context.Context) error

MediaPause calls media_player.media_pause. It has no MQTT equivalent. Core describes the service: Pauses playback on a media player.

func (e *Entity) MediaPlay(ctx context.Context) error

MediaPlay calls media_player.media_play. It has no MQTT equivalent. Core describes the service: Starts playback on a media player.

func (e *Entity) MediaPlayPause(ctx context.Context) error

MediaPlayPause calls media_player.media_play_pause. It has no MQTT equivalent. Core describes the service: Toggles play/pause on a media player.

func (e *Entity) MediaPreviousTrack(ctx context.Context) error

MediaPreviousTrack calls media_player.media_previous_track. It has no MQTT equivalent. Core describes the service: Selects the previous track on a media player.

func (e *Entity) MediaSeek(ctx context.Context, options ...entity.ServiceOption) error

MediaSeek calls media_player.media_seek. It has no MQTT equivalent. Core describes the service: Allows you to go to a different part of the media that is currently playing on a media player.

func (e *Entity) MediaStop(ctx context.Context) error

MediaStop calls media_player.media_stop. It has no MQTT equivalent. Core describes the service: Stops playback on a media player.

func (e *Entity) PlayMedia(ctx context.Context, options ...entity.ServiceOption) error

PlayMedia calls media_player.play_media. It has no MQTT equivalent. Core describes the service: Starts playing specified media on a media player.

func (e *Entity) RepeatSet(ctx context.Context, options ...entity.ServiceOption) error

RepeatSet calls media_player.repeat_set. It has no MQTT equivalent. Core describes the service: Sets the repeat mode of a media player.

func (e *Entity) SelectSoundMode(ctx context.Context, options ...entity.ServiceOption) error

SelectSoundMode calls media_player.select_sound_mode. It has no MQTT equivalent. Core describes the service: Selects a specific sound mode of a media player.

func (e *Entity) SelectSource(ctx context.Context, options ...entity.ServiceOption) error

SelectSource calls media_player.select_source. It has no MQTT equivalent. Core describes the service: Sends a media player the command to change the input source.

func (e *Entity) ShuffleSet(ctx context.Context, options ...entity.ServiceOption) error

ShuffleSet calls media_player.shuffle_set. It has no MQTT equivalent. Core describes the service: Enables or disables the shuffle mode of a media player.

func (e *Entity) Toggle(ctx context.Context) error

Toggle calls media_player.toggle. It has no MQTT equivalent. Core describes the service: Toggles a media player on/off.

func (e *Entity) TurnOff(ctx context.Context) error

TurnOff calls media_player.turn_off. It has no MQTT equivalent. Core describes the service: Turns off the power of a media player.

func (e *Entity) TurnOn(ctx context.Context) error

TurnOn calls media_player.turn_on. It has no MQTT equivalent. Core describes the service: Turns on the power of a media player.

func (e *Entity) Unjoin(ctx context.Context) error

Unjoin calls media_player.unjoin. It has no MQTT equivalent. Core describes the service: Removes a media player from a group. Only works on platforms which support player groups.

func (e *Entity) VolumeDown(ctx context.Context) error

VolumeDown calls media_player.volume_down. It has no MQTT equivalent. Core describes the service: Turns down the volume of a media player.

func (e *Entity) VolumeMute(ctx context.Context, options ...entity.ServiceOption) error

VolumeMute calls media_player.volume_mute. It has no MQTT equivalent. Core describes the service: Mutes or unmutes a media player.

func (e *Entity) VolumeSet(ctx context.Context, options ...entity.ServiceOption) error

VolumeSet calls media_player.volume_set. It has no MQTT equivalent. Core describes the service: Sets the volume level of a media player.

func (e *Entity) VolumeUp(ctx context.Context) error

VolumeUp calls media_player.volume_up. It has no MQTT equivalent. Core describes the service: Turns up the volume of a media player.

type State = entity.State[Attributes]

State is a snapshot of one media_player entity.

func Announce(value bool) entity.ServiceOption

Announce sets the "announce" service data field.

func Enqueue(value string) entity.ServiceOption

Enqueue sets the "enqueue" service data field.

func GroupMembers(value []string) entity.ServiceOption

GroupMembers sets the "group_members" service data field.

func IsVolumeMuted(value bool) entity.ServiceOption

IsVolumeMuted sets the "is_volume_muted" service data field.

func Media(value map[string]any) entity.ServiceOption

Media sets the "media" service data field.

func Repeat(value string) entity.ServiceOption

Repeat sets the "repeat" service data field.

func SeekPosition(value float64) entity.ServiceOption

SeekPosition sets the "seek_position" service data field.

func Shuffle(value bool) entity.ServiceOption

Shuffle sets the "shuffle" service data field.

func SoundMode(value string) entity.ServiceOption

SoundMode sets the "sound_mode" service data field.

func Source(value string) entity.ServiceOption

Source sets the "source" service data field.

func VolumeLevel(value float64) entity.ServiceOption

VolumeLevel sets the "volume_level" service data field.

State and values

type Attributes struct

Attributes are the state attributes of a media_player entity, under the names Home Assistant publishes them with.

See: https://www.home-assistant.io/integrations/media_player/

FieldTypeWire keyDescription
AppId*stringapp_id

App ID.

AppName*stringapp_name

App.

DeviceClass*DeviceClassdevice_class
MediaImageLocal*stringentity_picture_local

Local accessible entity picture.

GroupMembers*[]stringgroup_members
IsVolumeMuted*boolis_volume_muted

Muted.

MediaAlbumArtist*stringmedia_album_artist

Album artist.

MediaAlbumName*stringmedia_album_name

Album.

MediaArtist*stringmedia_artist

Artist.

MediaChannel*stringmedia_channel

Channel.

MediaContentId*stringmedia_content_id

Content ID.

MediaContentType*stringmedia_content_type

Content type.

MediaDuration*intmedia_duration

Duration.

MediaEpisode*stringmedia_episode

Episode.

MediaPlaylist*stringmedia_playlist

Playlist.

MediaPosition*intmedia_position

Position.

MediaPositionUpdatedAt*ha.DateTimemedia_position_updated_at

Position updated.

MediaSeason*stringmedia_season

Season.

MediaSeriesTitle*stringmedia_series_title

Series.

MediaTitle*stringmedia_title

Title.

MediaTrack*intmedia_track

Track.

Repeat*stringrepeat

Repeat.

Shuffle*boolshuffle

Shuffle.

SoundMode*stringsound_mode

Sound mode.

SoundModeList*[]stringsound_mode_list

Available sound modes.

Source*stringsource

Source.

SourceList*[]stringsource_list

Available sources.

SupportedFeaturesFeaturesupported_features

A set of Feature flags.

VolumeLevel*float64volume_level

Volume.

DeviceClass

type DeviceClass string

DeviceClass is core's MediaPlayerDeviceClass.

ConstantValue
DeviceClassUnknown"Unknown"
DeviceClassTv"tv"
DeviceClassSpeaker"speaker"
DeviceClassReceiver"receiver"
DeviceClassProjector"projector"
func DeviceClassFromString(s string) DeviceClass

DeviceClassFromString returns the DeviceClass spelled s, by its value or by the name of core's member, and DeviceClassUnknown for anything else.

func (v *DeviceClass) UnmarshalJSON(data []byte) error

UnmarshalJSON reads any spelling DeviceClassFromString accepts.

Feature

type Feature uint64

Feature is a set of media_player supported features, with the values of core's MediaPlayerEntityFeature: the supported_features attribute decodes into it.

ConstantValue
FeatureUnknown0
FeaturePause1 << 0
FeatureSeek1 << 1
FeatureVolumeSet1 << 2
FeatureVolumeMute1 << 3
FeaturePreviousTrack1 << 4
FeatureNextTrack1 << 5
FeatureTurnOn1 << 7
FeatureTurnOff1 << 8
FeaturePlayMedia1 << 9
FeatureVolumeStep1 << 10
FeatureSelectSource1 << 11
FeatureStop1 << 12
FeatureClearPlaylist1 << 13
FeaturePlay1 << 14
FeatureShuffleSet1 << 15
FeatureSelectSoundMode1 << 16
FeatureBrowseMedia1 << 17
FeatureRepeatSet1 << 18
FeatureGrouping1 << 19
FeatureMediaAnnounce1 << 20
FeatureMediaEnqueue1 << 21
FeatureSearchMedia1 << 22
func FeatureFromString(s string) Feature

FeatureFromString returns the Feature spelled s, by its value or by the name of core's member, and FeatureUnknown for anything else.

MediaClass

type MediaClass string

MediaClass is core's MediaClass.

ConstantValue
MediaClassUnknown"Unknown"
MediaClassAlbum"album"
MediaClassApp"app"
MediaClassArtist"artist"
MediaClassChannel"channel"
MediaClassComposer"composer"
MediaClassContributingArtist"contributing_artist"
MediaClassDirectory"directory"
MediaClassEpisode"episode"
MediaClassGame"game"
MediaClassGenre"genre"
MediaClassImage"image"
MediaClassMovie"movie"
MediaClassMusic"music"
MediaClassPlaylist"playlist"
MediaClassPodcast"podcast"
MediaClassSeason"season"
MediaClassTrack"track"
MediaClassTvShow"tv_show"
MediaClassUrl"url"
MediaClassVideo"video"
func MediaClassFromString(s string) MediaClass

MediaClassFromString returns the MediaClass spelled s, by its value or by the name of core's member, and MediaClassUnknown for anything else.

func (v *MediaClass) UnmarshalJSON(data []byte) error

UnmarshalJSON reads any spelling MediaClassFromString accepts.

MediaContentType

type MediaContentType string

MediaContentType lists the built-in values of the media_content_type attribute, as Home Assistant translates them. Integrations may use others, which are kept as they are.

ConstantValue
MediaContentTypeUnknown"Unknown"
MediaContentTypeAlbum"album"
MediaContentTypeApp"app"
MediaContentTypeArtist"artist"
MediaContentTypeChannel"channel"
MediaContentTypeChannels"channels"
MediaContentTypeComposer"composer"
MediaContentTypeContributingArtist"contributing_artist"
MediaContentTypeEpisode"episode"
MediaContentTypeGame"game"
MediaContentTypeGenre"genre"
MediaContentTypeImage"image"
MediaContentTypeMovie"movie"
MediaContentTypeMusic"music"
MediaContentTypePlaylist"playlist"
MediaContentTypePodcast"podcast"
MediaContentTypeSeason"season"
MediaContentTypeTrack"track"
MediaContentTypeTvshow"tvshow"
MediaContentTypeUrl"url"
MediaContentTypeVideo"video"
func MediaContentTypeFromString(s string) MediaContentType

MediaContentTypeFromString returns s as a MediaContentType.

func (v *MediaContentType) UnmarshalJSON(data []byte) error

UnmarshalJSON reads any spelling MediaContentTypeFromString accepts.

MediaPlayerEnqueue

type MediaPlayerEnqueue string

MediaPlayerEnqueue is core's MediaPlayerEnqueue.

ConstantValue
MediaPlayerEnqueueUnknown"Unknown"
MediaPlayerEnqueueAdd"add"
MediaPlayerEnqueueNext"next"
MediaPlayerEnqueuePlay"play"
MediaPlayerEnqueueReplace"replace"
func MediaPlayerEnqueueFromString(s string) MediaPlayerEnqueue

MediaPlayerEnqueueFromString returns the MediaPlayerEnqueue spelled s, by its value or by the name of core's member, and MediaPlayerEnqueueUnknown for anything else.

func (v *MediaPlayerEnqueue) UnmarshalJSON(data []byte) error

UnmarshalJSON reads any spelling MediaPlayerEnqueueFromString accepts.

MediaType

type MediaType string

MediaType is core's MediaType.

ConstantValue
MediaTypeUnknown"Unknown"
MediaTypeAlbum"album"
MediaTypeApp"app"
MediaTypeApps"apps"
MediaTypeArtist"artist"
MediaTypeChannel"channel"
MediaTypeChannels"channels"
MediaTypeComposer"composer"
MediaTypeContributingArtist"contributing_artist"
MediaTypeEpisode"episode"
MediaTypeGame"game"
MediaTypeGenre"genre"
MediaTypeImage"image"
MediaTypeMovie"movie"
MediaTypeMusic"music"
MediaTypePlaylist"playlist"
MediaTypePodcast"podcast"
MediaTypeSeason"season"
MediaTypeTrack"track"
MediaTypeTvshow"tvshow"
MediaTypeUrl"url"
MediaTypeVideo"video"
func MediaTypeFromString(s string) MediaType

MediaTypeFromString returns the MediaType spelled s, by its value or by the name of core's member, and MediaTypeUnknown for anything else.

func (v *MediaType) UnmarshalJSON(data []byte) error

UnmarshalJSON reads any spelling MediaTypeFromString accepts.

RepeatMode

type RepeatMode string

RepeatMode is core's RepeatMode.

ConstantValue
RepeatModeUnknown"Unknown"
RepeatModeAll"all"
RepeatModeOff"off"
RepeatModeOne"one"
func RepeatModeFromString(s string) RepeatMode

RepeatModeFromString returns the RepeatMode spelled s, by its value or by the name of core's member, and RepeatModeUnknown for anything else.

func (v *RepeatMode) UnmarshalJSON(data []byte) error

UnmarshalJSON reads any spelling RepeatModeFromString accepts.

RepeatValue

type RepeatValue string

RepeatValue lists the built-in values of the repeat attribute, as Home Assistant translates them. Integrations may use others, which are kept as they are.

ConstantValue
RepeatValueUnknown"Unknown"
RepeatValueAll"all"
RepeatValueOff"off"
RepeatValueOne"one"
func RepeatValueFromString(s string) RepeatValue

RepeatValueFromString returns s as a RepeatValue.

func (v *RepeatValue) UnmarshalJSON(data []byte) error

UnmarshalJSON reads any spelling RepeatValueFromString accepts.

StateValue

type StateValue string

StateValue is core's MediaPlayerState.

ConstantValue
StateValueUnknown"Unknown"
StateValueOff"off"
StateValueOn"on"
StateValueIdle"idle"
StateValuePlaying"playing"
StateValuePaused"paused"
StateValueStandby"standby"
StateValueBuffering"buffering"
func StateValueFromString(s string) StateValue

StateValueFromString returns the StateValue spelled s, by its value or by the name of core's member, and StateValueUnknown for anything else.

func (v *StateValue) UnmarshalJSON(data []byte) error

UnmarshalJSON reads any spelling StateValueFromString accepts.