Beispiel #1
0
    def onStart(self):
        if Parameters["Mode6"] == "Debug":
            Domoticz.Debugging(1)
            DumpConfigToLog()
        
        if ('Kodi'  not in Images): Domoticz.Image('Kodi Icons.zip').Create()
        if ('KodiBlack' not in Images): Domoticz.Image('KodiBlack Icons.zip').Create()
        if ('KodiRound' not in Images): Domoticz.Image('KodiRound Icons.zip').Create()

        if (len(Devices) == 0):
            Domoticz.Device(Name="Status",  Unit=1, Type=17,  Switchtype=17).Create()
            Options = {"LevelActions": "||||", 
                       "LevelNames": "Off|Video|Music|TV Shows|Live TV",
                       "LevelOffHidden": "false",
                       "SelectorStyle": "1"}
            Domoticz.Device(Name="Source",  Unit=2, TypeName="Selector Switch", Switchtype=18, Image=12, Options=Options).Create()
            Domoticz.Device(Name="Volume",  Unit=3, Type=244, Subtype=73, Switchtype=7, Image=8).Create()
            Domoticz.Device(Name="Playing", Unit=4, Type=244, Subtype=73, Switchtype=7, Image=12).Create()
            Domoticz.Log("Devices created.")
        if (1 in Devices):
            UpdateImage(1)
            self.playerState = Devices[1].nValue
        if (2 in Devices):
            UpdateImage(2)
            self.mediaLevel = Devices[2].nValue
        if (4 in Devices):
            UpdateImage(4)
            self.mediaLevel = Devices[2].nValue
        self.KodiConn = Domoticz.Connection(Name="KodiConn", Transport="TCP/IP", Protocol="JSON", Address=Parameters["Address"], Port=Parameters["Port"])
        self.KodiConn.Connect()
        if (Parameters["Mode3"] == "True"):
            Domoticz.Notifier(Parameters["Mode4"])
        Domoticz.Heartbeat(10)
        return True
    def onStart(self):
        global _tv
        
        if Parameters["Mode6"] == "Debug": 
            Domoticz.Debugging(1)
            self.debug = True

        #TODO: get number of inputs and apps to build list
        
        self.SourceOptions3 =   {   "LevelActions"  : "||||||", 
                                    "LevelNames"    : "Off|TV|HDMI1|HDMI2|HDMI3|Hulu|Netflix|Amazon|Youtube|iPlayer|Unknown",
                                    "LevelOffHidden": "true",
                                    "SelectorStyle" : "0"
                                }
                                    
        if (len(Devices) == 0):
            Domoticz.Device(Name="Status", Unit=1, Type=17, Image=2, Switchtype=17).Create()
            if Parameters["Mode3"] == "Volume": Domoticz.Device(Name="Volume", Unit=2, Type=244, Subtype=73, Switchtype=7, Image=8).Create()
            Domoticz.Device(Name="Source", Unit=3, TypeName="Selector Switch", Switchtype=18, Image=2, Options=self.SourceOptions3).Create()
            Domoticz.Log("Devices created")
        elif (Parameters["Mode3"] == "Volume" and 2 not in Devices):
            Domoticz.Device(Name="Volume", Unit=2, Type=244, Subtype=73, Switchtype=7, Image=8).Create()
            Domoticz.Log("Volume device created")
        elif (Parameters["Mode3"] != "Volume" and 2 in Devices):
            Devices[2].Delete()
            Domoticz.Log("Volume device deleted")
        elif 1 not in Devices:
            Domoticz.Device(Name="Status", Unit=1, Type=17, Image=2, Switchtype=17).Create()
            Domoticz.Log("TV device created")
        elif 3 not in Devices:
            Domoticz.Device(Name="Source", Unit=3, TypeName="Selector Switch", Switchtype=18, Image=2, Options=self.SourceOptions3).Create()
            Domoticz.Log("Source device created")
        else:
            if (1 in Devices): self.tvState = Devices[1].nValue    #--> of sValue
            if (2 in Devices): self.tvVolume = Devices[2].nValue   #--> of sValue
            if (3 in Devices): self.tvSource = Devices[3].sValue
        
        # Set update interval, values below 10 seconds are not allowed due to timeout of 5 seconds in bravia.py script
        updateInterval = int(Parameters["Mode5"])
        if updateInterval < 30:
            if updateInterval < 10: updateInterval == 10
            Domoticz.Log("Update interval set to " + str(updateInterval) + " (minimum is 10 seconds)")
            Domoticz.Heartbeat(updateInterval)
        else:
            Domoticz.Heartbeat(30)
        if self.debug == True:
            DumpConfigToLog()
        if Parameters["Mode4"] != "":
            Domoticz.Notifier(Parameters["Mode4"])
        else:
            Domoticz.Log("Notifications are off, add a Notifier Name to enable.")
        return #--> return True
Beispiel #3
0
    def onStart(self):
        if Parameters["Mode6"] != "Normal":
            Domoticz.Debugging(1)
            DumpConfigToLog()

        self.SourceOptions = {
            "LevelActions": "||||",
            "LevelNames": "Off|Previous|Play|Pause|Next|Snooze|Stop",
            "LevelOffHidden": "true",
            "SelectorStyle": "0"
        }

        # Check if images are in database
        if 'Sonos' not in Images: Domoticz.Image('Sonos.zip').Create()
        if 'Sonos1' not in Images: Domoticz.Image('Sonos1.zip').Create()
        if 'Sonos5' not in Images: Domoticz.Image('Sonos5.zip').Create()

        # Create devices if required
        if 1 not in Devices:
            Domoticz.Device(Name="Status",
                            Unit=1,
                            Type=17,
                            Switchtype=17,
                            Used=1).Create()
            Domoticz.Log("Status device created")
        if 2 not in Devices:
            Domoticz.Device(Name="Volume",
                            Unit=2,
                            Type=244,
                            Subtype=73,
                            Switchtype=7,
                            Image=8,
                            Used=1).Create()
            Domoticz.Log("Volume device created.")
        if 3 not in Devices:
            Domoticz.Device(Name="Control",
                            Unit=3,
                            TypeName="Selector Switch",
                            Switchtype=18,
                            Image=8,
                            Options=self.SourceOptions,
                            Used=1).Create()
            Domoticz.Log("Control device created")

        # Create or update radio stations selector switch
        self.sonos_GetFavorites()
        LogMessage("Number of radio stations in favorites: " +
                   str(len(self.radioFavorites)))
        sradioStations = sorted(list(self.radioFavorites.keys(
        )))  #get radiostations in sorted list, source is key in dict
        sradioStations = '|'.join(
            sradioStations
        )  #get radiostations in string, divided with | for selector switch
        LogMessage("Radio stations in favorites: " + str(sradioStations))
        self.SourceOptions2 = {
            "LevelActions": "|" * int(len(self.radioFavorites)),
            "LevelNames": "Off|" + sradioStations,
            "LevelOffHidden": "false",
            "SelectorStyle": "1"
        }
        if 4 not in Devices:
            Domoticz.Device(Name="Radio",
                            Unit=4,
                            TypeName="Selector Switch",
                            Switchtype=18,
                            Image=8,
                            Options=self.SourceOptions2,
                            Used=1).Create()
            Domoticz.Log("Radio device created")
        if 4 in Devices and Parameters["Mode5"] == "Refresh":
            Devices[4].Delete()
            Domoticz.Device(Name="Radio",
                            Unit=4,
                            TypeName="Selector Switch",
                            Switchtype=18,
                            Image=8,
                            Options=self.SourceOptions2,
                            Used=1).Create()
            Domoticz.Log(
                "Radio device updated (device will be on last position of Switches tab...)"
            )
            Domoticz.Log("Number of radio stations in favorites: " +
                         str(len(self.radioFavorites)))
            Domoticz.Log("Radio stations in favorites: " + str(sradioStations))

        # Update images and status
        if 1 in Devices:
            UpdateImage(1)
            self.playerState = Devices[1].nValue
        if 2 in Devices:
            self.mediaLevel = Devices[2].nValue
        if 3 in Devices:
            UpdateImage(3)
            self.sonosControl = Devices[3].sValue
        if 4 in Devices:
            UpdateImage(4)
            self.sonosControl = Devices[3].sValue

        # Add notifier if required
        if Parameters["Mode3"] == "True":
            notifierName = Devices[1].Name  #use hardware name from device name
            notifierName = notifierName.split(' -')[
                0]  #remove everything after -
            notifierName = notifierName.replace(
                ' ', '_')  #replace spaces by underscore
            notifierName = notifierName.lower()  #lower case
            Domoticz.Notifier(notifierName)  #add notifier
            Domoticz.Log("Notifier '" + notifierName + "' added")

        # Set refresh
        if is_number(Parameters["Mode1"]):
            if int(Parameters["Mode1"]) < 30:
                Domoticz.Log("Update interval set to " + Parameters["Mode1"])
                Domoticz.Heartbeat(int(Parameters["Mode1"]))
            else:
                Domoticz.Heartbeat(30)
        else:
            Domoticz.Heartbeat(30)
        return
Beispiel #4
0
    def onStart(self):
        #Get the variables
        self.debugging = Parameters["Mode6"].strip()
        self.dt = str(datetime.datetime.now().strftime("%Y%m%d-%H%M%S"))
        self.baudrate = Parameters["Mode1"].strip()
        self.pin = Parameters["Mode2"].strip()
        self.apn = Parameters["Mode3"].strip()
        self.auth_phones = Parameters["Address"].strip()
        self.port = Parameters["SerialPort"].strip()
        self.passkey = unidecode(Parameters["Mode4"].strip().replace(
            " ", "").lower())
        self.name_idx = unidecode(
            str(Parameters["Mode5"]).strip().replace(" ", "").lower())

        #HARDCODED
        if self.debugging == "true":
            Domoticz.Debugging(2)
        DumpConfigToLog()
        #Debug data values
        #HEartbeat
        Domoticz.Heartbeat(20)
        Domoticz.Notifier("OnBoard_GSM")
        #ReConfigure the config.json
        success = self.reWriteConfigFile()
        if not success:
            Domoticz.Log("Reconfigure config.json --> Failed")
            return 0
        #Create Variables and Devices
        if len(Devices) == 0:
            #SMS LOG Variable
            Domoticz.Device(Name="GSM Info",
                            TypeName="Text",
                            Unit=uid_GSMinfo,
                            DeviceID="gsm_info").Create()
            Domoticz.Device(Name="Received SMS",
                            TypeName="Text",
                            Unit=uid_SMS,
                            DeviceID="gsm_receivedsms").Create()
            Domoticz.Device(Name="GSM Network Status",
                            TypeName="Text",
                            Unit=uid_netstat,
                            DeviceID="gsm_attached").Create()
            Domoticz.Device(Name="GSM Jamming",
                            TypeName="Alert",
                            Unit=uid_jamming,
                            DeviceID="gsm_jamming").Create()
        #PinCode if set
        if self.pin != "":
            pin_status = os.popen(
                '/usr/bin/gammu --config /home/pi/.gammurc entersecuritycode PIN '
                + self.pin).read()
            if "Nothing to enter." in pin_status:
                Domoticz.Log("No Pin Code required !")
            elif "Security error":
                Domoticz.Log(
                    "Error PIN Code ! Please check in a phone (locked after 3 attempts"
                )
                return
        time.sleep(0.5)
        # global SerialConn
        global ser
        ser = serial.Serial(port=self.port,
                            baudrate=int(self.baudrate.split('at')[1]),
                            timeout=1)
        # ser = serial.Serial(port = '/dev/ttyUSB_ttyS1',baudrate=19200,timeout=1)
        try:
            ser.open()
            # SerialConn = Domoticz.Connection(Name="tty_GSM", Transport="Serial", Protocol="None", Address=self.port, Baud=int(self.baudrate))
            # SerialConn.Connect()
            # SerialConn.Send(b'AT+SJDR=1,0,255\r')
        except Exception as e:
            Domoticz.Debug("error open serial port: " + str(e))
        #Set the jamming detection option
        ser.write(b'AT+SJDR=1,0,255\r')
        ser.close()

        #Check that everything is running fine
        network_info = os.popen(
            '/usr/bin/gammu --config /home/pi/.gammurc networkinfo').read()
        if "Warning" in network_info or "Error" in network_info:
            success = 0

        if success == 1:
            #remove the backup file
            os.system("sudo rm " + self.backupfile)
        else:
            Domoticz.Log("Trying to revert the config file...")
            copy2(self.backupfile, self.path + "/config.json")
            success = self.startProcess()
        #Update the ID
        if success:
            #update the network info
            Devices[uid_GSMinfo].Update(sValue=str(network_info), nValue=0)