<commit_before>//
//  SleepController.swift
//  Sleep
//
//  Created by <NAME> on 06/01/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit
import MediaPlayer

enum SleepError: String, ErrorType, CustomStringConvertible {

    case PlaylistNotFound = "Playlist not found"

    //MARK: CustomStringConvertible

    var description: String {
        return rawValue
    }
}

final class SleepController: UIViewController {

    //MARK: Properties

    @IBOutlet weak var sleepButton: UIButton!

    //MARK: Button Actions

    @IBAction func sleep(sender: UIButton) {
        do {
            try playSleepPlaylist()
        } catch {
            let alertController = UIAlertController(title: "Error", message: String(error), preferredStyle: .Alert)
            let alertAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
            alertController.addAction(alertAction)
            presentViewController(alertController, animated: true, completion: nil)
        }
    }

    private func playSleepPlaylist() throws {
        let playlistQuery = MPMediaQuery.playlistsQuery()
        playlistQuery.addFilterPredicate(MPMediaPropertyPredicate(value: "Sleep 😴", forProperty: MPMediaPlaylistPropertyName))
        guard let playlist = playlistQuery.collections?.first else {
            throw SleepError.PlaylistNotFound
        }

        let musicPlayer = MPMusicPlayerController.systemMusicPlayer()
        musicPlayer.setQueueWithItemCollection(playlist)
        musicPlayer.repeatMode = .None
        musicPlayer.shuffleMode = .Songs
        musicPlayer.play()
    }
}<commit_msg>Make sure Loxone credentials are set<commit_after>//
//  SleepController.swift
//  Sleep
//
//  Created by <NAME> on 06/01/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit
import MediaPlayer

enum SleepError: String, ErrorType, CustomStringConvertible {

    case PlaylistNotFound = "Playlist not found"
    case CredentialsNotSet = "Credentials not set"

    //MARK: CustomStringConvertible

    var description: String {
        return rawValue
    }
}

final class SleepController: UIViewController {

    //MARK: Properties

    @IBOutlet weak var sleepButton: UIButton!

    //MARK: Button Actions

    @IBAction func sleep(sender: UIButton) {
        do {
            try turnOnAmp()
            try playSleepPlaylist()
        } catch {
            let alertController = UIAlertController(title: "Error", message: String(error), preferredStyle: .Alert)
            let alertAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
            alertController.addAction(alertAction)
            presentViewController(alertController, animated: true, completion: nil)
        }
    }

    private func playSleepPlaylist() throws {
        let playlistQuery = MPMediaQuery.playlistsQuery()
        playlistQuery.addFilterPredicate(MPMediaPropertyPredicate(value: "Sleep 😴", forProperty: MPMediaPlaylistPropertyName))
        guard let playlist = playlistQuery.collections?.first else {
            throw SleepError.PlaylistNotFound
        }

        let musicPlayer = MPMusicPlayerController.systemMusicPlayer()
        musicPlayer.setQueueWithItemCollection(playlist)
        musicPlayer.repeatMode = .None
        musicPlayer.shuffleMode = .Songs
        musicPlayer.play()
    }

    private func turnOnAmp() throws {
        guard let loxoneCredentials = NSProcessInfo.processInfo().environment["LOXONE_CREDENTIALS"] where !loxoneCredentials.isEmpty else {
            throw SleepError.CredentialsNotSet
        }
    }
}
{'fraction_non_alphanumeric': 0.08519553072625698, 'fraction_numerical': 0.00558659217877095, 'mean_word_length': 2.9051254089422027, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1345286', 'n_tokens_mistral': 996, 'n_tokens_neox': 940, 'n_words': 241}