Exemple #1
0
def ButtonAction(data):
    "Action et description d'un bouton poussoir branché sur un port GPIO du RPi poussé par packet ButtonRPi"
    Constellation.WriteInfo('Packet ReveilISEN / Callback ButtonAction ; pin = ' + str(data.pin) + ' / event = ' + str(data.event))
    global currentDisplay

    # POSITION BOUTONS
    # [13]_____[16][19][20]_____[26]
    BUTTON_FARLEFT  = 13
    BUTTON_LEFT     = 16
    BUTTON_HOME     = 19
    BUTTON_RIGHT    = 20
    BUTTON_FARRIGHT = 26

    # Clics simples
    if data.event == "clicked":
        if data.pin == BUTTON_FARLEFT:      # Interface précédente
            currentDisplay = previousDisplay(currentDisplay)
            toDisplay(currentDisplay)
        if data.pin == BUTTON_LEFT:         # Volume moins
            Constellation.SendMessage(MUSIC_PACKAGE, "MusicControl", {"instruction":"TURNDOWN_VOLUME"})
        if data.pin == BUTTON_HOME:         # Lecture / pause
            Constellation.SendMessage(MUSIC_PACKAGE, "MusicControl", {"instruction":"PLAY_PAUSE"})
            Constellation.SendMessage(ALARM_PACKAGE, "StopRinging", alarmName)
            Constellation.WriteInfo("Stop la dernière alarme '%s' " % alarmName)
        if data.pin == BUTTON_RIGHT:        # Volume plus
            Constellation.SendMessage(MUSIC_PACKAGE, "MusicControl", {"instruction":"TURNUP_VOLUME"})
        if data.pin == BUTTON_FARRIGHT:     # Interface suivante
            currentDisplay = nextDisplay(currentDisplay)
            toDisplay(currentDisplay)
    # Clics doubles
    elif data.event == "doubleclicked":
        if data.pin == BUTTON_FARLEFT:      # Interface précédente
            currentDisplay = previousDisplay(currentDisplay)
            toDisplay(currentDisplay)
        if data.pin == BUTTON_LEFT:         # Volume moins
            Constellation.SendMessage(MUSIC_PACKAGE, "MusicControl", {"instruction":"TURNDOWN_VOLUME"})
        if data.pin == BUTTON_HOME:         # Lecture / pause
            Constellation.SendMessage(MUSIC_PACKAGE, "MusicControl", {"instruction":"PLAY_PAUSE"})
            Constellation.SendMessage(ALARM_PACKAGE, "StopRinging", alarmName)
            Constellation.WriteInfo("Stop la dernière alarme '%s' " % alarmName)
        if data.pin == BUTTON_RIGHT:        # Volume plus
            Constellation.SendMessage(MUSIC_PACKAGE, "MusicControl", {"instruction":"TURNUP_VOLUME"})
        if data.pin == BUTTON_FARRIGHT:     # Interface suivante
            currentDisplay = nextDisplay(currentDisplay)
            toDisplay(currentDisplay)
    # Clics longs 
    elif data.event == "longpressed":
        if data.pin == BUTTON_FARLEFT:      # Snooze
            snooze()
        if data.pin == BUTTON_LEFT:         # Titre précédent
            Constellation.SendMessage(MUSIC_PACKAGE, "MusicControl", {"instruction":"PREVIOUS_SONG"})
        if data.pin == BUTTON_HOME:         # Home
            currentDisplay = 0
            toDisplay(currentDisplay)
        if data.pin == BUTTON_RIGHT:        # Titre suivant
            Constellation.SendMessage(MUSIC_PACKAGE, "MusicControl", {"instruction":"NEXT_SONG"})
        if data.pin == BUTTON_FARRIGHT:     # Snooze
            snooze()
Exemple #2
0
def ClockUpdated(stateobject):
    global alarmName
    
    Constellation.WriteInfo("Check reveil %s" % stateobject.Name)
    if stateobject.Value.IsRinging == True:
        Constellation.WriteWarn("REVEIL '%s' en action !" % stateobject.Name)
        Constellation.SendMessage(MUSIC_PACKAGE, "MusicControl", {"instruction":"PLAY_PLAYLIST", "uri":"spotify:user:officiallifeisstrange:playlist:1f5ZzLDTXHTDR8CYIEddpW"})
        #time.sleep(10)
        #Constellation.SendMessage(MUSIC_PACKAGE, "MusicControl", {"instruction":"PLAY_PAUSE"})
        Constellation.SendMessage(DISPLAY_PACKAGE, "DisplayContent", {"icon":"musique", "text":stateobject.Name,"time":None,"matrix":None})
        alarmName = stateobject.Value.ClockName
def OnStart():
    # Register callback on package shutdown
    Constellation.OnExitCallback = OnExit   
    
    # Write log & common properties
    Constellation.WriteInfo("Hi I'm '%s' and I currently running on %s and %s to Constellation" % (Constellation.PackageName, Constellation.SentinelName if not Constellation.IsStandAlone else 'local sandbox', "connected" if Constellation.IsConnected else "disconnected"))
    
    #  GetSetting
    Constellation.WriteInfo("Demo1 = " + str(Constellation.GetSetting("Demo1"))) # If setting not exist, return None !
    
    # Send message without parameter 
    Constellation.SendMessage("DemoPackage", "HelloWorld", [], Constellation.MessageScope.package)    
    # Send message with 2 parameter
    Constellation.SendMessage("DemoPackage", "SendMessage", [ "+33123456789", "Hi" ], Constellation.MessageScope.package)
    # Send message with complex parameter 
    Constellation.SendMessage("DemoPackage", "DemoComplex", { "A": "This is a string", "B": 123, "C": True }, Constellation.MessageScope.package)
    # Send message "MessageCallbackWithComplexeResponse" with "123" as parameter to "Demo" pasckage and write the "A" property of the response
    Constellation.SendMessageWithSaga(lambda response: Constellation.WriteInfo("A=%s" % response.A), "Demo", "MessageCallbackWithComplexResponse", 123)
    
    # Push basic StateObject
    Constellation.PushStateObject("DemoStr", "Demo de seb") # StateObject with "String" as value
    Constellation.PushStateObject("DemoBool", False, lifetime=10) # StateObject with "Bool" as value and a lifetime (10 sec here)
    Constellation.PushStateObject("DemoInt", 123, metadatas={ "DeviceId":"RPi", "Serial":"123" }) # StateObject with "Int" as value and metadatas    
    Constellation.PushStateObject("DemoFloat", 12.45, metadatas={ "DeviceId":"RPi", "Serial":"123" }, lifetime=10) # StateObject with "Float" as value, metadatas and lifetime
    
    # Custom type descriptions
    Constellation.DescribeMessageCallbackType("CredentialInfo", "Credential information", [
        { 'Name':'Username', 'Type':'string', 'Description': 'The username' },
        { 'Name':'Password', 'Type':'string', 'Description': 'The password' },
    ])
    Constellation.DescribeStateObjectType("DemoType", "Demo type", [
        { 'Name':'Sender', 'Type':'string', 'Description': 'The demo' },        
        { 'Name':'Credential', 'Type':'CredentialInfo', 'Description': 'The credential nested demo' }
    ])
    Constellation.DeclarePackageDescriptor()
    
    # Push complex StateObject
    Constellation.PushStateObject("Demo", { "Sender": "DemoPython", "Credential": { "Username": "******", "Password":"******" } }, "DemoType", { "DeviceId": "RPi", "Serial":"123" }) # StateObject with custom type
    
    # WriteInfo, WriteWarn & WriteError
    Constellation.WriteInfo("Hello world from Python !")
    Constellation.WriteWarn("This is a warning !")
    Constellation.WriteError("This is an error !")
    
    # Last StateObjects of the previous instance
    if Constellation.LastStateObjects:
        for so in Constellation.LastStateObjects:
            Constellation.WriteInfo(" + %s @ %s" % (so.Name, so.LastUpdate))
def ProcessIncomingCall(call):
    Constellation.WriteInfo(
        "IncomingCall from '%s' (StatusCode: %s - CallID: %s)" %
        (call["Number"], call["StatusCode"], call["CallID"]))
    Constellation.SendMessage(
        Constellation.GetSetting("IncomingEventGroupName"), "IncomingCall",
        call['Number'], Constellation.MessageScope.group)
Exemple #5
0
def onButtonEvent(button, event):

    if event == BUTTON_LONGPRESSED:
        Constellation.SendMessage("ConstellationReveilISEN", "ButtonAction", {
            "pin": button.buttonPin,
            "event": "longpressed"
        }, Constellation.MessageScope.package)
    elif event == BUTTON_CLICKED:
        Constellation.SendMessage("ConstellationReveilISEN", "ButtonAction", {
            "pin": button.buttonPin,
            "event": "clicked"
        }, Constellation.MessageScope.package)
    elif event == BUTTON_DOUBLECLICKED:
        Constellation.SendMessage("ConstellationReveilISEN", "ButtonAction", {
            "pin": button.buttonPin,
            "event": "doubleclicked"
        }, Constellation.MessageScope.package)
def ProcessIncomingSMS(sms):
    Constellation.WriteInfo("IncomingSMS from '%s' : %s" %
                            (sms["Number"], sms["Text"]))
    Constellation.SendMessage(
        Constellation.GetSetting("IncomingEventGroupName"), "IncomingSMS", {
            'Number': sms['Number'],
            'Text': sms['Text']
        }, Constellation.MessageScope.group)
    sm.DeleteSMS(Location=sms['Location'], Folder=0)
Exemple #7
0
def snooze():
    global alarmName
    Constellation.SendMessage(ALARM_PACKAGE, "SnoozeAlarm", alarmName)
    Constellation.WriteInfo("Snooze de l'alarme %s" % alarmName)
    Constellation.SendMessage(MUSIC_PACKAGE, "MusicControl", {"instruction":"PLAY_PAUSE"})
Exemple #8
0
def displayMusic():
    Constellation.WriteWarn("DISPLAY MUSIQUE")
    Constellation.SendMessage(DISPLAY_PACKAGE, "DisplayContent", {"icon":"musique", "text":"Musique !","time":None,"matrix":None})   
Exemple #9
0
def displayTwitter():
    Constellation.WriteWarn("DISPLAY TWITTER")
    Constellation.SendMessage(DISPLAY_PACKAGE, "DisplayContent", {"icon":"twitter_oiseau", "text":twitterSO.followers_count,"time":None,"matrix":None})
Exemple #10
0
def displayWeather():
    Constellation.WriteWarn("DISPLAY FORECAST")
    Constellation.SendMessage(DISPLAY_PACKAGE, "DisplayContent", {"icon":"cloudy", "text":str(int(round(weatherForecastIO.temperature,0))) + 'C',"time":None,"matrix":None})
Exemple #11
0
def displayHome():
    # Si l'on se trouve sur l'écran du module, on update en live:
    if(displays[currentDisplay] == displayHome):
        Constellation.WriteWarn("DISPLAY HOME !")
        threading.Timer(10.0, displayHome).start()
        Constellation.SendMessage(DISPLAY_PACKAGE, "DisplayContent", {"icon":"horloge", "text":datetime.now().strftime('%H:%M'),"time":None,"matrix":None})