use device name instead of ID
This commit is contained in:
@@ -15,7 +15,7 @@ type alarm struct {
|
||||
type MorningAlarmConfig struct {
|
||||
SpotifyClientID string `json:"spotifyClientId"`
|
||||
SpotifyClientSecret string `json:"spotifyClientSecret"`
|
||||
DeviceID string `json:"deviceId"`
|
||||
DeviceName string `json:"deviceName"`
|
||||
PlaylistID string `json:"wakeupContext"`
|
||||
RedirectURL string `json:"redirectUrl"`
|
||||
ListenAddr string `json:"listenAddr"`
|
||||
|
||||
@@ -114,7 +114,14 @@ func (ma *MorningAlarm) setupSpotify() error {
|
||||
// Can still return an error even if the playback was started successfully.
|
||||
func (ma *MorningAlarm) playWakeUpMusic() (bool, error) {
|
||||
playContextURI := spotify.URI("spotify:playlist:" + ma.config.PlaylistID)
|
||||
deviceID := spotify.ID(ma.config.DeviceID)
|
||||
|
||||
devID, err := ma.getDeviceIDFromName(ma.config.DeviceName)
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
deviceID := spotify.ID(devID)
|
||||
|
||||
playlist, err := ma.sp.GetPlaylistItems(context.Background(), spotify.ID(ma.config.PlaylistID))
|
||||
|
||||
@@ -160,3 +167,19 @@ func (ma *MorningAlarm) getAvailableDevices() ([]Device, error) {
|
||||
|
||||
return availableDevices, nil
|
||||
}
|
||||
|
||||
func (ma *MorningAlarm) getDeviceIDFromName(name string) (string, error) {
|
||||
dev, err := ma.getAvailableDevices()
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for _, device := range dev {
|
||||
if device.Name == name {
|
||||
return device.ID, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("device with name %s not found", name)
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func (ma *MorningAlarm) setupWebserver() {
|
||||
"timezoneOffsetInH": offset / 60 / 60,
|
||||
"alarms": len(ma.cr.Entries()),
|
||||
"wakeupPlaylist": ma.config.PlaylistID,
|
||||
"deviceId": ma.config.DeviceID,
|
||||
"deviceName": ma.config.DeviceName,
|
||||
}
|
||||
|
||||
if nextIn != nil {
|
||||
|
||||
Reference in New Issue
Block a user