Exemplo n.º 1
0
 def onStart(self):
     if Parameters["Mode6"] == "Debug":
         Domoticz.Debugging(1)
     DumpConfigToLog()
     Domoticz.Transport(Transport="TCP/IP", Address=Parameters["Address"], Port=Parameters["Port"])
     Domoticz.Protocol("HTTP")
     Domoticz.Connect()
Exemplo n.º 2
0
def onHeartbeat():
    global isConnected, nextConnect, oustandingPings, playerID
    if (isConnected == True):
        if (oustandingPings > 6):
            Domoticz.Disconnect()
            nextConnect = 0
        else:
            if (playerID == -1):
                Domoticz.Send(
                    '{"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":1001}'
                )
            else:
                Domoticz.Send(
                    '{"jsonrpc":"2.0","method":"Player.GetProperties","id":1002,"params":{"playerid":'
                    + str(playerID) +
                    ',"properties":["live","percentage","speed"]}}')
            oustandingPings = oustandingPings + 1
    else:
        # if not connected try and reconnected every 3 heartbeats
        oustandingPings = 0
        nextConnect = nextConnect - 1
        if (nextConnect <= 0):
            nextConnect = 3
            Domoticz.Connect()
    return True
Exemplo n.º 3
0
def onStart():
    if Parameters["Mode6"] == "Debug":
        Domoticz.Debugging(1)
    if (len(Devices) == 0):
        Domoticz.Device(
            Name="Main Zone",
            Unit=1,
            Type=244,
            Subtype=62,
            Switchtype=18,
            Image=5,
            Options=
            "LevelActions:fHx8fHx8fHx8fHx8fA==;LevelNames:T2ZmfERWRHxWRFB8VFZ8Q0R8REJTfFR1bmVyfFBob25vfFZDUi0xfFZDUi0yfFYuQXV4fENEUi9UYXBlfEF1eE5ldHxBdXhJUG9k;LevelOffHidden:ZmFsc2U=;SelectorStyle:MQ=="
        ).Create()
        Domoticz.Device(Name="Main Volume",
                        Unit=2,
                        Type=244,
                        Subtype=73,
                        Switchtype=7,
                        Image=8).Create()
        Domoticz.Device(
            Name="Zone 2",
            Unit=3,
            Type=244,
            Subtype=62,
            Switchtype=18,
            Image=5,
            Options=
            "LevelActions:fHx8fHx8fHx8fHx8fA==;LevelNames:T2ZmfERWRHxWRFB8VFZ8Q0R8REJTfFR1bmVyfFBob25vfFZDUi0xfFZDUi0yfFYuQXV4fENEUi9UYXBlfEF1eE5ldHxBdXhJUG9k;LevelOffHidden:ZmFsc2U=;SelectorStyle:MQ=="
        ).Create()
        Domoticz.Device(Name="Volume 2",
                        Unit=4,
                        Type=244,
                        Subtype=73,
                        Switchtype=7,
                        Image=8).Create()
        Domoticz.Device(
            Name="Zone 3",
            Unit=5,
            Type=244,
            Subtype=62,
            Switchtype=18,
            Image=5,
            Options=
            "LevelActions:fHx8fHx8fHx8fHx8fA==;LevelNames:T2ZmfERWRHxWRFB8VFZ8Q0R8REJTfFR1bmVyfFBob25vfFZDUi0xfFZDUi0yfFYuQXV4fENEUi9UYXBlfEF1eE5ldHxBdXhJUG9k;LevelOffHidden:ZmFsc2U=;SelectorStyle:MQ=="
        ).Create()
        Domoticz.Device(Name="Volume 3",
                        Unit=6,
                        Type=244,
                        Subtype=73,
                        Switchtype=7,
                        Image=8).Create()
        Domoticz.Log("Devices created.")
    DumpConfigToLog()
    Domoticz.Transport("TCP/IP", Parameters["Address"], Parameters["Port"])
    Domoticz.Protocol("Line")
    Domoticz.Connect()
    return
    def onStart(self):
        if Parameters["Mode6"] == "Debug":
            Domoticz.Debugging(1)

        self.SourceOptions = {
            'LevelActions': '|' * Parameters["Mode3"].count('|'),
            'LevelNames': Parameters["Mode3"],
            'LevelOffHidden': 'false',
            'SelectorStyle': '1'
        }

        if (len(Devices) == 0):
            Domoticz.Device(Name="Power", Unit=1, TypeName="Switch",
                            Image=5).Create()
            Domoticz.Device(Name="Main Zone",
                            Unit=2,
                            TypeName="Selector Switch",
                            Switchtype=18,
                            Image=5,
                            Options=self.SourceOptions).Create()
            Domoticz.Device(Name="Main Volume",
                            Unit=3,
                            Type=244,
                            Subtype=73,
                            Switchtype=7,
                            Image=8).Create()
        else:
            if (2 in Devices and (len(Devices[2].sValue) > 0)):
                self.mainSource = int(Devices[2].sValue)
                self.mainOn = (Devices[2].nValue != 0)
            if (3 in Devices and (len(Devices[3].sValue) > 0)):
                self.mainVolume1 = int(Devices[3].sValue) if (
                    Devices[3].nValue != 0) else int(Devices[3].sValue) * -1
            if (4 in Devices and (len(Devices[4].sValue) > 0)):
                self.zone2Source = int(Devices[4].sValue)
                self.zone2On = (Devices[4].nValue != 0)
            if (5 in Devices and (len(Devices[5].sValue) > 0)):
                self.zone2Volume = int(Devices[5].sValue) if (
                    Devices[5].nValue != 0) else int(Devices[5].sValue) * -1
            if (6 in Devices and (len(Devices[6].sValue) > 0)):
                self.zone3Source = int(Devices[6].sValue)
                self.zone3On = (Devices[6].nValue != 0)
            if (7 in Devices and (len(Devices[7].sValue) > 0)):
                self.zone3Volume = int(Devices[7].sValue) if (
                    Devices[7].nValue != 0) else int(Devices[7].sValue) * -1
            if (1 in Devices):
                self.powerOn = (self.mainOn or self.zone2On or self.zone3On)

        DumpConfigToLog()
        dictValue = 0
        for item in Parameters["Mode3"].split('|'):
            self.selectorMap[dictValue] = item
            dictValue = dictValue + 10
        Domoticz.Transport("TCP/IP", Parameters["Address"], Parameters["Port"])
        Domoticz.Protocol("Line")
        Domoticz.Connect()
        return
Exemplo n.º 5
0
def onHeartbeat():
    if _avr_device.connected:
        log.debug('onHeartbeat called')
        Domoticz.Send(Message='?V\r')
        Domoticz.Send(Message='?FL\r')
        Domoticz.Send(Message='?S\r')
        Domoticz.Send(Message='?L\r')
    else:
        Domoticz.Connect()
Exemplo n.º 6
0
def onStart():
    global mainSource, mainVolume1, zone2Source, zone2Volume, zone3Source, zone3Volume

    if Parameters["Mode6"] == "Debug":
        Domoticz.Debugging(1)
    LevelActions = '|'*Parameters["Mode3"].count('|')
    # if Zone 3 required make sure at least themain device exists, otherwise suppress polling for it
    if (Parameters["Mode1"] > "2"):
        if (6 not in Devices):
            Domoticz.Device(Name="Zone 3", Unit=6, TypeName="Selector Switch", Switchtype=18, Image=5, \
                            Options="LevelActions:"+stringToBase64(LevelActions)+";LevelNames:"+stringToBase64(Parameters["Mode3"])+";LevelOffHidden:ZmFsc2U=;SelectorStyle:MQ==").Create()
            if (7 not in Devices): Domoticz.Device(Name="Volume 3", Unit=7, Type=244, Subtype=73, Switchtype=7,  Image=8).Create()
            Domoticz.Log("Created Zone 3 device(s) because zone requested in hardware setup but device not found.")
        else:
            zone3Source = Devices[6].nValue
            if (7 in Devices): zone3Volume = int(Devices[7].sValue)
    else:
        pollingDict.pop("Z3")
        pollingDict["Z2"] = "PW?\r"
    
    # if Zone 2 required make sure at least themain device exists, otherwise suppress polling for it
    if (Parameters["Mode1"] > "1"):
        if (4 not in Devices):
            Domoticz.Device(Name="Zone 2", Unit=4, TypeName="Selector Switch", Switchtype=18, Image=5, \
                            Options="LevelActions:"+stringToBase64(LevelActions)+";LevelNames:"+stringToBase64(Parameters["Mode3"])+";LevelOffHidden:ZmFsc2U=;SelectorStyle:MQ==").Create()
            if (5 not in Devices): Domoticz.Device(Name="Volume 2", Unit=5, Type=244, Subtype=73, Switchtype=7,  Image=8).Create()
            Domoticz.Log("Created Zone 2 device(s) because zone requested in hardware setup but device not found.")
        else:
            zone2Source = Devices[4].nValue
            if (5 in Devices): zone2Volume = int(Devices[5].sValue)
    else:
        pollingDict.pop("Z2")
        pollingDict["MU"] = "PW?\r"
        
    if (1 not in Devices):
        Domoticz.Device(Name="Power", Unit=1, TypeName="Switch",  Image=5).Create()
        if (2 not in Devices): Domoticz.Device(Name="Main Zone", Unit=2, TypeName="Selector Switch", Switchtype=18, Image=5, \
                        Options="LevelActions:"+stringToBase64(LevelActions)+";LevelNames:"+stringToBase64(Parameters["Mode3"])+";LevelOffHidden:ZmFsc2U=;SelectorStyle:MQ==").Create()
        if (3 not in Devices): Domoticz.Device(Name="Main Volume", Unit=3, Type=244, Subtype=73, Switchtype=7,  Image=8).Create()
        Domoticz.Log("Created Main Zone devices because they were not found.")
    else:
        mainSource = Devices[2].nValue
        if (3 in Devices): mainVolume1 = int(Devices[3].sValue)
        
    DumpConfigToLog()
    dictValue=0
    for item in Parameters["Mode3"].split('|'):
        selectorMap[dictValue] = item
        dictValue = dictValue + 10
    Domoticz.Transport("TCP/IP", Parameters["Address"], Parameters["Port"])
    Domoticz.Protocol("Line")
    Domoticz.Connect()
    return
Exemplo n.º 7
0
def onStart():
    global _avr_state
    global _avr_device

    if Parameters['Mode6'] == 'DEBUG':
        Domoticz.Debugging(1)
    else:
        Domoticz.Debugging(0)
    setup_logging(base_path=Parameters['HomeFolder'],
                  root_level=Parameters['Mode6'])

    log.debug('onStart called')

    options = {
        'volume_max': 185,
        'volume_min': 0,
        'volume_db_min': -80.5,
        'volume_db_step': 0.5,
        'volume_slider_max': 121,
        'volume_slider_min': 21,   # -70 dB
        }

    _avr_state = DomoticzAVR(UNITS, options, update_device)
    _avr_device = PioneerDevice(_avr_state)

    if UNITS['display'] not in Devices:
        Domoticz.Device(Name="Display",
                        Unit=UNITS['display'],
                        TypeName="Text",
                        Image=5).Create()
    if UNITS['listening_mode'] not in Devices:
        Domoticz.Device(Name="Listening Mode",
                        Unit=UNITS['listening_mode'],
                        TypeName="Text").Create()
    if UNITS['playing_mode'] not in Devices:
        Domoticz.Device(Name="Playing Listening Mode",
                        Unit=UNITS['playing_mode'],
                        TypeName="Text").Create()
    if UNITS['main_sound_level'] not in Devices:
        Domoticz.Device(Name="Sound Level Main Zone",
                        Unit=UNITS['main_sound_level'],
                        TypeName="Sound Level").Create()
    if UNITS['main_volume'] not in Devices:
        Domoticz.Device(Name="Volume Main Zone",
                        Unit=UNITS['main_volume'],
                        TypeName="Switch",
                        Switchtype=7,
                        Image=8).Create()
    dump_config_to_log()
    Domoticz.Transport('TCP/IP', Parameters['Address'], Parameters['Port'])
    Domoticz.Protocol('Line')
    Domoticz.Heartbeat(30)
    Domoticz.Connect()
Exemplo n.º 8
0
 def onStart(self):
     if Parameters["Mode6"] == "Debug":
         Domoticz.Debugging(1)
     if (len(Devices) == 0):
         Domoticz.Device(Name="Socket 1", Unit=1,
                         TypeName="Switch").Create()
         Domoticz.Log("Device created.")
     DumpConfigToLog()
     Domoticz.Transport(Transport="TCP/IP",
                        Address=Parameters["Address"],
                        Port=Parameters["Port"])
     Domoticz.Protocol("HTTP")
     Domoticz.Heartbeat(8)
     Domoticz.Connect()
     if (1 in Devices) and (Devices[1].nValue == 1):
         self.socketOn = "TRUE"
Exemplo n.º 9
0
def onHeartbeat():
    global isConnected, nextConnect, oustandingPings
    if (isConnected == True):
        if (oustandingPings > 5):
            Domoticz.Disconnect()
            nextConnect = 0
        else:
            Domoticz.Send('PW?\r')
            oustandingPings = oustandingPings + 1
    else:
        # if not connected try and reconnected every 3 heartbeats
        oustandingPings = 0
        nextConnect = nextConnect - 1
        if (nextConnect <= 0):
            nextConnect = 3
            Domoticz.Connect()
    return
Exemplo n.º 10
0
def onHeartbeat():
    global isConnected, nextConnect, oustandingPings, lastMessage, pollingDict
    if (isConnected == True):
        if (oustandingPings > 5):
            Domoticz.Disconnect()
            nextConnect = 0
        else:
            Domoticz.Send(pollingDict[lastMessage])
            Domoticz.Debug("onHeartbeat: lastMessage "+lastMessage+", Sending '"+pollingDict[lastMessage][0:2]+"'.")
            oustandingPings = oustandingPings + 1
    else:
        # if not connected try and reconnected every 3 heartbeats
        oustandingPings = 0
        nextConnect = nextConnect - 1
        if (nextConnect <= 0):
            nextConnect = 3
            Domoticz.Connect()
    return
Exemplo n.º 11
0
 def onHeartbeat(self):
     if (self.KodiConn.Connected() == True):
         if (self.oustandingPings > 6):
             Domoticz.Disconnect()
             self.nextConnect = 0
         else:
             if (self.playerID == -1):
                 self.KodiConn.Send('{"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":1001}')
             else:
                 self.KodiConn.Send('{"jsonrpc":"2.0","method":"Player.GetProperties","id":1002,"params":{"playerid":' + str(self.playerID) + ',"properties":["live","percentage","speed"]}}')
             self.oustandingPings = self.oustandingPings + 1
     else:
         # if not connected try and reconnected every 3 heartbeats
         self.oustandingPings = 0
         self.nextConnect = self.nextConnect - 1
         if (self.nextConnect <= 0):
             self.nextConnect = 3
             Domoticz.Connect()
     return True
Exemplo n.º 12
0
 def onHeartbeat(self):
     if (self.isConnected == True):
         if (self.oustandingPings > 5):
             Domoticz.Disconnect()
             self.nextConnect = 0
         else:
             Domoticz.Send(self.pollingDict[self.lastMessage])
             Domoticz.Debug("onHeartbeat: self.lastMessage "+self.lastMessage+", Sending '"+self.pollingDict[self.lastMessage][0:2]+"'.")
             self.oustandingPings = self.oustandingPings + 1
     else:
         # if not connected try and reconnected every 3 heartbeats
         self.oustandingPings = 0
         self.nextConnect = self.nextConnect - 1
         if (self.nextConnect <= 0):
             self.nextConnect = 3
             Domoticz.Connect()
             
     self.lastHeartbeat = datetime.datetime.now()
     return
Exemplo n.º 13
0
    def SendMessage(self, command):
        if (self.isConnected == False):
            self.Port = Parameters["Port"]
            Domoticz.Transport(Transport="TCP/IP",
                               Address=Parameters["Address"],
                               Port=self.Port)
            Domoticz.Protocol("HTTP")
            Domoticz.Connect()

            self.LastCommand = command
            Domoticz.Debug("Sending command: " + str(command))
            return

        try:
            Domoticz.Send("", "GET", command, self.Headers)
        except:
            Domoticz.Debug("Failed to communicate to system at ip " +
                           Parameters["Address"] + ". Command " + command)
            return False

        return True
Exemplo n.º 14
0
def onStart():
    if Parameters["Mode6"] == "Debug":
        Domoticz.Debugging(1)
    if (len(Devices) == 0):
        Domoticz.Device(Name="Usage",
                        Unit=1,
                        Type=243,
                        Subtype=29,
                        Switchtype=0,
                        Image=0,
                        Options="").Create()
        Domoticz.Device("Total", 2, 113).Create()
        Domoticz.Log("Devices created.")
    Domoticz.Log("Plugin has " + str(len(Devices)) +
                 " devices associated with it.")
    DumpConfigToLog()
    #    Domoticz.Heartbeat(900)
    Domoticz.Transport("Serial", Parameters["SerialPort"], 115200)
    Domoticz.Protocol("XML")
    Domoticz.Connect()
    return
Exemplo n.º 15
0
def onStart():
    global playerState, mediaLevel
    if Parameters["Mode6"] == "Debug":
        Domoticz.Debugging(1)
    if (len(Devices) == 0):
        Domoticz.Device(Name="Status", Unit=1, Type=17, Switchtype=17).Create()
        Options = "LevelActions:" + stringToBase64(
            "||||") + ";LevelNames:" + stringToBase64(
                "Off|Video|Music|TV Shows|Live TV"
            ) + ";LevelOffHidden:ZmFsc2U=;SelectorStyle:MA=="
        Domoticz.Device(Name="Source",
                        Unit=2,
                        Type=244,
                        Subtype=62,
                        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.")
    else:
        if (1 in Devices): playerState = Devices[1].nValue
        if (2 in Devices): mediaLevel = Devices[2].nValue
    DumpConfigToLog()
    Domoticz.Transport("TCP/IP", Parameters["Address"], Parameters["Port"])
    Domoticz.Protocol("JSON")
    Domoticz.Heartbeat(10)
    Domoticz.Connect()
    return True
Exemplo n.º 16
0
def onStart():
    global playerState, mediaLevel
    if Parameters["Mode6"] == "Debug":
        Domoticz.Debugging(1)
    if (len(Devices) == 0):
        Domoticz.Device(Name="Status", Unit=1, Type=17, Switchtype=17).Create()
        Domoticz.Device(
            Name="Source",
            Unit=2,
            Type=244,
            Subtype=62,
            Switchtype=18,
            Image=12,
            Options=
            "LevelActions:fHx8fA==;LevelNames:T2ZmfFZpZGVvfE11c2ljfFRWIFNob3dzfExpdmUgVFY=;LevelOffHidden:ZmFsc2U=;SelectorStyle:MA=="
        ).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.")
    else:
        if (1 in Devices): playerState = Devices[1].nValue
        if (2 in Devices): mediaLevel = Devices[2].nValue
    DumpConfigToLog()
    Domoticz.Transport("TCP/IP", Parameters["Address"], Parameters["Port"])
    Domoticz.Protocol("JSON")
    Domoticz.Heartbeat(10)
    Domoticz.Connect()
    return True
Exemplo n.º 17
0
 def onStart(self):
     if Parameters["Mode6"] == "Debug":
         Domoticz.Debugging(1)
     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.")
     else:
         if (1 in Devices): self.playerState = Devices[1].nValue
         if (2 in Devices): self.mediaLevel = Devices[2].nValue
     DumpConfigToLog()
     Domoticz.Transport(Transport="TCP/IP",
                        Address=Parameters["Address"],
                        Port=Parameters["Port"])
     Domoticz.Protocol("JSON")
     Domoticz.Heartbeat(10)
     Domoticz.Connect()
     return True
Exemplo n.º 18
0
 def onHeartbeat(self):
     Domoticz.Debug("onHeartbeat called")
     if (self.pluginState == "Not Ready"):
         Domoticz.Connect()
     elif (self.pluginState == "Ready"):
         self.GetSocketSettings()
Exemplo n.º 19
0
def onHeartbeat():
    global isConnected
    if (isConnected != True):
        Domoticz.Connect()
    return True
Exemplo n.º 20
0
 def onDisconnect(self):
     self.isConnected = False
     self.pluginState = "Not Ready"
     Domoticz.Log("Device has disconnected")
     Domoticz.Connect()