#!/usr/bin/env python
# -*- coding:utf-8 -*

# Plugin for FSTA
# the main FSTA.installation object is named "maison"
# To add a new group :
#	maison.add_group(name = "mongroupe", hotword = "mongroupe.pmdl")
# 
# To add a new scenario (here or (better) in another file (ie my_rule.scenario))
#	maison.group("mongroupe").add_scenario(name = "monscenario", _
#											phrases = [u"do this",u"do that"], _ or phrases = u"éteint la lumière",
#											actions = [
#												action_mqtt(
#													topic = "T-HOME/SALON/LUMIERES",
#													payload = "ON",
#													text = "ON"),
#												action(callback_function, text = "Oooh"),
#												action_os(cmd="my_cmd_line", text = "cmd_line")]
from FSTA.action import *

def play_music():
	from soco import SoCo
	SoCo("192.168.0.14").play_uri('x-sonosapi-radio:pxIasSYsGYc?sid=151&flags=8300&sn=1')
def play_inter():
	from soco import SoCo
	SoCo("192.168.0.14").play_uri('x-sonosapi-stream:s24875?sid=254&flags=8224&sn=0','<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="-1" parentID="-1" restricted="true"><dc:title>France Inter</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON65031_</desc></item></DIDL-Lite>')
	
# Pour trouver les données SONOS :
# 
# from soco import SoCo
# from soco.snapshot import Snapshot
# zp = SoCo('192.168.0.14')
#snap = Snapshot(zp)
#snap.snapshot()
#print 'media_uri: ', snap.media_uri
#print 'media_metadata: ', snap.media_metadata
#	
	
maison.group("maison").add_scenario(name = "MUSIQUE ON",
									phrases = [u"musique",
												u"allume la musique",u"musique aléatoire"],
									actions = action(callback=play_music,text="Musique"))
maison.group("maison").add_scenario(name = "FRANCE INTER",
									phrases = [u"France Inter",
												u"Ecoutons France Inter",u"mettre France Inter"],
									actions = action(callback=play_inter,text="France Inter"))

maison.group("maison").add_scenario(name = "MUSIQUE PLAY",
									phrases = [u"musique play", u'musique joue'],
									actions = action_mqtt(
											topic = "T-EPINAL/SONOS",
											payload = '{"mode": "play"}',
											text = "Musique play"))
maison.group("maison").add_scenario(name = "MUSIQUE PAUSE",
									phrases = [u"musique pause", u'musique reprend', u'musique continue'],
									actions = action_mqtt(
											topic = "T-EPINAL/SONOS",
											payload = '{"mode": "pause"}',
											text = "Musique pause"))
maison.group("maison").add_scenario(name = "MUSIQUE OFF",
									phrases = [u"stop la musique",
												u"éteins la musique",
												u"arrête la musique"],
									actions = action_mqtt(
											topic = "T-EPINAL/SONOS",
											payload = '{"mode": "stop"}',
											text = "STOP"))
maison.group("maison").add_scenario(name = "MUSIQUE NEXT",
									phrases = [u"musique suivante",
												u"change la musique"],
									actions = action_mqtt(
											topic = "T-EPINAL/SONOS",
											payload = '{"mode": "next"}',
											text = "Next"))
