def onConnect(Status, Description): global isConnected, playerState if (Status == 0): isConnected = True Domoticz.Log("Connected successfully to: " + Parameters["Address"] + ":" + Parameters["Port"]) playerState = 1 Domoticz.Send( '{"jsonrpc":"2.0","method":"System.GetProperties","params":{"properties":["canhibernate","cansuspend","canshutdown"]},"id":1007}' ) Domoticz.Send( '{"jsonrpc":"2.0","method":"Application.GetProperties","id":1011,"params":{"properties":["volume","muted"]}}' ) Domoticz.Send( '{"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":1001}') else: isConnected = False Domoticz.Log("Failed to connect (" + str(Status) + ") to: " + Parameters["Address"] + ":" + Parameters["Port"]) Domoticz.Debug("Failed to connect (" + str(Status) + ") to: " + Parameters["Address"] + ":" + Parameters["Port"] + " with error: " + Description) # Turn devices off in Domoticz for Key in Devices: UpdateDevice(Key, 0, Devices[Key].sValue) return True
def SetSocketSettings(self, power): timestamp = str(int(time.time())) encdata = hmac.new( self.privateKey, (timestamp + '"http://purenetworks.com/HNAP1/SetSocketSettings"').encode(), hashlib.md5) hnapauth = encdata.hexdigest().upper() + ' ' + timestamp data = '<?xml version="1.0" encoding="utf-8"?>' + \ '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' + \ '<soap:Body>' + \ '<SetSocketSettings xmlns="http://purenetworks.com/HNAP1/">' + \ '<ModuleID>1</ModuleID>' + \ '<NickName>Socket 1</NickName>' + \ '<Description>Socket 1</Description>' + \ '<OPStatus>' + power + '</OPStatus>' + \ '<Controller>1</Controller>' + \ '</SetSocketSettings>' + \ '</soap:Body>' + \ '</soap:Envelope>' headers = {'Content-Type': 'text/xml; charset=utf-8', 'Accept': 'Content-Type: text/html; charset=UTF-8', \ 'Connection': 'keep-alive', \ 'Host': Parameters["Address"]+":"+Parameters["Port"], \ 'User-Agent':'Domoticz/1.0', \ 'SOAPAction' : '"http://purenetworks.com/HNAP1/SetSocketSettings"', 'HNAP_AUTH' : hnapauth, 'Content-Length' : "%d"%(len(data)), 'Cookie' : 'uid=' + self.sessionCookie } # The device resets the connection every 2 minutes, if its not READY assume that is happening and delay the send by 2 seconds to allow reconnection if (self.pluginState == "Ready"): Domoticz.Send(data, 'POST', '/HNAP1/', headers) else: Domoticz.Send(data, 'POST', '/HNAP1/', headers, 2)
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
def TurnOff(): global canShutdown, canSuspend, canHibernate if (Parameters["Mode2"] == "Ignore"): Domoticz.Log("'Off' command ignored as configured.") elif (Parameters["Mode2"] == "Hibernate"): if (canHibernate == True): Domoticz.Send( '{"jsonrpc":"2.0","method":"System.Hibernate","id":1008}') else: Domoticz.Error( "Configured Shutdown option: 'Hibernate' not support by attached Kodi." ) elif (Parameters["Mode2"] == "Suspend"): if (canHibernate == True): Domoticz.Send( '{"jsonrpc":"2.0","method":"System.Suspend","id":1008}') else: Domoticz.Error( "Configured Shutdown option: 'Suspend' not support by attached Kodi." ) elif (Parameters["Mode2"] == "Shutdown"): if (canHibernate == True): Domoticz.Send( '{"jsonrpc":"2.0","method":"System.Shutdown","id":1008}') else: Domoticz.Error( "Configured Shutdown option: 'Shutdown' not support by attached Kodi." ) else: Domoticz.Error("Unknown Shutdown option, ID:" + str(Parameters["Mode2"]) + ".") return
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()
def onConnect(self, Status, Description): if (Status == 0): self.isConnected = True Domoticz.Log("Connected successfully to: "+Parameters["Address"]+":"+Parameters["Port"]) Domoticz.Send('PW?\r') Domoticz.Send('ZM?\r', Delay=1) Domoticz.Send('Z2?\r', Delay=2) Domoticz.Send('Z3?\r', Delay=3) else: self.isConnected = False self.powerOn = False Domoticz.Log("Failed to connect ("+str(Status)+") to: "+Parameters["Address"]+":"+Parameters["Port"]) Domoticz.Debug("Failed to connect ("+str(Status)+") to: "+Parameters["Address"]+":"+Parameters["Port"]+" with error: "+Description) self.SyncDevices() return
def onConnect(self, Status, Description): if (Status == 0): Domoticz.Debug("Smart plug connected successfully.") data = '<?xml version="1.0" encoding="utf-8"?>' + \ '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' + \ '<soap:Body>' \ '<Login xmlns="http://purenetworks.com/HNAP1/">' + \ '<Action>request</Action>' + \ '<Username>'+Parameters["Mode1"]+'</Username>' + \ '<LoginPassword></LoginPassword>' + \ '<Captcha></Captcha>' + \ '</Login>' + \ '</soap:Body>' + \ '</soap:Envelope>' headers = { 'Content-Type': 'text/xml; charset=utf-8', \ 'Connection': 'keep-alive', \ 'Accept': 'Content-Type: text/html; charset=UTF-8', \ 'Host': Parameters["Address"]+":"+Parameters["Port"], \ 'User-Agent':'Domoticz/1.0', \ 'SOAPAction' : '"http://purenetworks.com/HNAP1/Login"', \ 'Content-Length' : "%d"%(len(data)) } Domoticz.Send(data, 'POST', '/HNAP1/', headers) self.pluginState = "GetAuth" else: self.pluginState = "Not Ready" Domoticz.Log("Failed to connect (" + str(Status) + ") to: " + Parameters["Address"] + ":" + Parameters["Port"]) Domoticz.Debug("Failed to connect (" + str(Status) + ") to: " + Parameters["Address"] + ":" + Parameters["Port"] + " with error: " + Description)
def GetSocketSettings(self): timestamp = str(int(time.time())) encdata = hmac.new( self.privateKey, (timestamp + '"http://purenetworks.com/HNAP1/GetSocketSettings"').encode(), hashlib.md5) hnapauth = encdata.hexdigest().upper() + ' ' + timestamp data = '<?xml version="1.0" encoding="utf-8"?>' + \ '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' + \ '<soap:Body>' + \ '<GetSocketSettings xmlns="http://purenetworks.com/HNAP1/">' + \ '<ModuleID>1</ModuleID>' + \ '</GetSocketSettings>' + \ '</soap:Body>' + \ '</soap:Envelope>' headers = {'Content-Type': 'text/xml; charset=utf-8', 'Accept': 'Content-Type: text/html; charset=UTF-8', \ 'Connection': 'keep-alive', \ 'Host': Parameters["Address"]+":"+Parameters["Port"], \ 'User-Agent':'Domoticz/1.0', \ 'SOAPAction' : '"http://purenetworks.com/HNAP1/GetSocketSettings"', 'HNAP_AUTH' : hnapauth, 'Content-Length' : "%d"%(len(data)), 'Cookie' : 'uid=' + self.sessionCookie } Domoticz.Send(data, 'POST', '/HNAP1/', headers)
def onConnect(Status, Description): log.debug('onConnect called\nStatus: %s\nDescription: %s', Status, Description) if Status == 0: _avr_device.connected = True Domoticz.Send(Message='?P\r') onHeartbeat() else: _avr_device.connected = False
def onConnect(self, Status, Description): if (Status == 0): Domoticz.Debug("Google connected successfully.") data = '' headers = { 'Content-Type': 'text/xml; charset=utf-8', \ 'Connection': 'keep-alive', \ 'Accept': 'Content-Type: text/html; charset=UTF-8', \ 'Host': Parameters["Address"]+":"+Parameters["Port"], \ 'User-Agent':'Domoticz/1.0', \ 'Content-Length' : "%d"%(len(data)) } Domoticz.Send(data, 'GET', '/', headers) else: Domoticz.Log("Failed to connect ("+str(Status)+") to: "+Parameters["Address"]+":"+Parameters["Port"]+" with error: "+Description)
def onConnect(Status, Description): global isConnected, powerOn if (Status == 0): isConnected = True Domoticz.Log("Connected successfully to: "+Parameters["Address"]+":"+Parameters["Port"]) Domoticz.Send('PW?\r') else: isConnected = False powerOn = False Domoticz.Log("Failed to connect ("+str(Status)+") to: "+Parameters["Address"]+":"+Parameters["Port"]) Domoticz.Debug("Failed to connect ("+str(Status)+") to: "+Parameters["Address"]+":"+Parameters["Port"]+" with error: "+Description) SyncDevices() return
def onConnect(Status, Description): global isConnected if (Status == 0): isConnected = True Domoticz.Log("Connected successfully to: " + Parameters["SerialPort"]) Domoticz.Send("<Command>\n <Name>get_device_info</Name>\n</Command>") else: Domoticz.Log("Failed to connect (" + str(Status) + ") to: " + Parameters["SerialPort"]) Domoticz.Debug("Failed to connect (" + str(Status) + ") to: " + Parameters["SerialPort"] + " with error: " + Description) return True
def onHeartbeat(self): if (self.isConnected == True): if (self.oustandingPings > 6): Domoticz.Disconnect() self.nextConnect = 0 else: if (self.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(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
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
def onConnect(Status, Description): global isConnected if (Status == 0): isConnected = True Domoticz.Log("Connected successfully to: " + Parameters["Address"] + ":" + Parameters["Port"]) Domoticz.Send('PW?\r') else: isConnected = False Domoticz.Log("Failed to connect (" + str(Status) + ") to: " + Parameters["Address"] + ":" + Parameters["Port"]) Domoticz.Debug("Failed to connect (" + str(Status) + ") to: " + Parameters["Address"] + ":" + Parameters["Port"] + " with error: " + Description) # Turn devices off in Domoticz for Key in Devices: UpdateDevice(Key, 0, Devices[Key].sValue) return True
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
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
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
def onMessage(self, Data, Status, Extra): strData = Data.decode("utf-8", "ignore") Domoticz.Log("onMessage: Status="+str(Status)) Domoticz.Log("Headers:") for x in Extra: Domoticz.Log(" '" + x + "':'" + str(Extra[x])) if (Status == 200): Domoticz.Log("Good Response received from Google.") elif (Status == 302): Domoticz.Log("Google returned a Page Moved Error.") headers = { 'Content-Type': 'text/xml; charset=utf-8', \ 'Connection': 'keep-alive', \ 'Accept': 'Content-Type: text/html; charset=UTF-8', \ 'Host': Parameters["Address"]+":"+Parameters["Port"], \ 'User-Agent':'Domoticz/1.0', \ 'Content-Length' : "0" } Domoticz.Send("", "GET", Extra["Location"], headers) elif (Status == 400): Domoticz.Error("Google returned a Bad Request Error.") elif (Status == 500): Domoticz.Error("Google returned a Server Error.") else: Domoticz.Error("Google returned a status: "+str(Status))
def onMessage(self, Data, Status, Extra): strData = Data.decode("utf-8", "ignore") if (Status == 200): Domoticz.Debug("Good Response received for '" + self.pluginState + "'.") if (self.pluginState == "GetAuth"): challenge = extractTagValue('Challenge', strData).encode() self.sessionCookie = extractTagValue('Cookie', strData) publickey = extractTagValue('PublicKey', strData) loginresult = extractTagValue('LoginResult', strData) encdata = hmac.new((publickey + Parameters["Mode2"]).encode(), challenge, hashlib.md5) self.privateKey = encdata.hexdigest().upper().encode() encdata = hmac.new(self.privateKey, challenge, hashlib.md5) loginpassword = encdata.hexdigest().upper() data = '<?xml version="1.0" encoding="utf-8"?>' + \ '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' + \ '<soap:Body>' + \ '<Login xmlns="http://purenetworks.com/HNAP1/">' + \ '<Action>login</Action>' + \ '<Username>Admin</Username>' + \ '<LoginPassword>' + loginpassword + '</LoginPassword>' + \ '<Captcha></Captcha>' + \ '</Login>' + \ '</soap:Body>' + \ '</soap:Envelope>' headers = { 'Content-Type': 'text/xml; charset=utf-8', 'Accept': 'Content-Type: text/html; charset=UTF-8', \ 'Host': Parameters["Address"]+":"+Parameters["Port"], \ 'User-Agent':'Domoticz/1.0', \ 'SOAPAction' : '"http://purenetworks.com/HNAP1/Login"', \ 'Content-Length' : "%d"%(len(data)), \ 'Cookie' : 'uid=' + self.sessionCookie } Domoticz.Send(data, 'POST', '/HNAP1/', headers) self.pluginState = "Login" elif (self.pluginState == "Login"): loginresult = extractTagValue('LoginResult', strData) if (loginresult.upper() != "SUCCESS"): Domoticz.Error( "Login failed, check username and password in Hardware page" ) else: Domoticz.Log("Smart plug authentication successful.") self.pluginState = "Ready" elif (self.pluginState == "Ready"): if (strData.find('GetSocketSettingsResult') > 0): opStatus = extractTagValue('OPStatus', strData).upper() if (len(opStatus) and (self.socketOn != opStatus)): self.socketOn = opStatus Domoticz.Log("Socket State has changed, Now: " + self.socketOn) if (self.socketOn == "TRUE"): if (1 in Devices): Devices[1].Update(1, "100") else: if (1 in Devices): Devices[1].Update(0, "0") elif (strData.find('SetSocketSettingsResult') > 0): self.GetSocketSettings() Domoticz.Debug(self.pluginState + ": " + strData) else: Domoticz.Debug(self.pluginState + ": " + strData) elif (Status == 400): Domoticz.Error("Smart plug returned a Bad Request Error.") elif (Status == 500): Domoticz.Error("Smart plug returned a Server Error.")
def onCommand(Unit, Command, Level, Hue): global selectorMap, powerOn Domoticz.Log("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level)) Command = Command.strip() action, sep, params = Command.partition(' ') delay = 0 if (powerOn == False): Domoticz.Send('PWON\r') # Any commands sent within 4 seconds of this will potentially be ignored delay = int(Parameters["Mode2"]) if (action == "On"): if (Unit == 1): Domoticz.Send(Message='ZMON\r', Delay=delay) elif (Unit == 2): Domoticz.Send(Message='ZMON\r', Delay=delay) elif (Unit == 3): Domoticz.Send(Message='MUOFF\r', Delay=delay) elif (Unit == 4): Domoticz.Send(Message='Z2ON\r', Delay=delay) elif (Unit == 5): Domoticz.Send(Message='Z2MUOFF\r', Delay=delay) elif (Unit == 6): Domoticz.Send(Message='Z3ON\r', Delay=delay) elif (Unit == 7): Domoticz.Send(Message='Z3MUOFF\r', Delay=delay) else: Domoticz.Error( "Unknown Unit number in command "+str(Unit)+".") elif (action == "Set"): if (params.capitalize() == 'Level') or (Command.lower() == 'Volume'): if (Unit == 2): # Main selector Domoticz.Send(Message='SI'+selectorMap[Level]+'\r', Delay=delay) elif (Unit == 3): # Volume control Domoticz.Send(Message='MV'+str(Level)+'\r', Delay=delay) elif (Unit == 4): # Zone 2 selector Domoticz.Send(Message='Z2'+selectorMap[Level]+'\r', Delay=delay) elif (Unit == 5): # Zone 2 Volume control Domoticz.Send(Message='Z2'+str(Level)+'\r', Delay=delay) elif (Unit == 6): # Zone 3 selector Domoticz.Send(Message='Z3'+selectorMap[Level]+'\r', Delay=delay) elif (Unit == 7): # Zone 3 Volume control Domoticz.Send(Message='Z3'+str(Level)+'\r', Delay=delay) SyncDevices() elif (action == "Off"): if (Unit == 1): Domoticz.Send(Message='ZMOFF\r', Delay=delay) elif (Unit == 2): Domoticz.Send(Message='ZMOFF\r', Delay=delay) elif (Unit == 3): Domoticz.Send(Message='MUON\r', Delay=delay) elif (Unit == 4): Domoticz.Send(Message='Z2OFF\r', Delay=delay) elif (Unit == 5): Domoticz.Send(Message='Z2MUON\r', Delay=delay) elif (Unit == 6): Domoticz.Send(Message='Z3OFF\r', Delay=delay) elif (Unit == 7): Domoticz.Send(Message='Z3MUON\r', Delay=delay) else: Domoticz.Error( "Unknown Unit number in command "+str(Unit)+".") else: Domoticz.Error("Unhandled action '"+action+"' ignored, options are On/Set/Off") return
def onMessage(Data): global connectStatus, fScale, summation Domoticz.Debug(Data) xmltree = ET.fromstring(Data) if xmltree.tag == 'DeviceInfo': Domoticz.Log("Manufacturer: %s, Device ID: %s, Install Code: %s" % (xmltree.find('Manufacturer').text, xmltree.find('DeviceMacId').text, xmltree.find('InstallCode').text)) Domoticz.Log( "Hardware: Version %s, Firmware Version: %s, Model: %s" % (xmltree.find('HWVersion').text, xmltree.find('FWVersion').text, xmltree.find('ModelId').text)) Domoticz.Send( "<Command>\n <Name>get_network_info</Name>\n</Command>\n") elif xmltree.tag == 'NetworkInfo': Domoticz.Debug( "NetworkInfo response, Status = '%s' - %s, Link Strength = %d" % (xmltree.find('Status').text, xmltree.find('Description').text, int(xmltree.find('LinkStrength').text, 16))) Domoticz.Send( "<Command>\n <Name>get_connection_status</Name>\n</Command>\n") elif xmltree.tag == 'ConnectionStatus': if connectStatus != 'Connected': Domoticz.Send( "<Command>\n <Name>get_meter_list</Name>\n</Command>\n") connectStatus = xmltree.find('Status').text Domoticz.Log( "MeterMacId: %s, Connection Status, Status = '%s' - %s, Link Strength = %d" % (xmltree.find('MeterMacId').text, xmltree.find('Status').text, xmltree.find('Description').text, int(xmltree.find('LinkStrength').text, 16))) elif xmltree.tag == 'MeterList': for meter in xmltree.iter('MeterMacId'): Domoticz.Debug("MeterMacId: %s, MeterList response" % meter.text) Domoticz.Send( "<Command>\n <Name>get_meter_info</Name>\n <MeterMacId>" + meter.text + "</MeterMacId>\n</Command>\n") elif xmltree.tag == 'MeterInfo': Domoticz.Debug( "MeterMacId: %s, MeterInfo response, Enabled = %s" % (xmltree.find('MeterMacId').text, xmltree.find('Enabled').text)) Domoticz.Send( "<Command>\n <Name>get_schedule</Name>\n <MeterMacId>" + xmltree.find('MeterMacId').text + "</MeterMacId>\n</Command>\n") elif xmltree.tag == 'ScheduleInfo': iFreq = int(xmltree.find('Frequency').text, 16) Domoticz.Debug( "MeterMacId: %s, ScheduleInfo response: Type '%s', Frequency %d, Enabled %s" % (xmltree.find('MeterMacId').text, xmltree.find('Event').text, iFreq, xmltree.find('Enabled').text)) if (xmltree.find('Event').text == 'demand') and (iFreq != demandFreq): Domoticz.Debug( "MeterMacId: %s, Setting 'demand' schedule to: Frequency %d" % (xmltree.find('MeterMacId').text, demandFreq)) Domoticz.Send( "<Command>\n <Name>set_schedule</Name>\n <MeterMacId>" + xmltree.find('MeterMacId').text + "</MeterMacId>\n <Event>demand</Event>\n <Frequency>" + str(hex(demandFreq)) + "</Frequency>\n <Enabled>Y</Enabled>\n</Command>\n") if (xmltree.find('Event').text == 'summation') and (iFreq != summaryFreq): Domoticz.Debug( "MeterMacId: %s, Setting 'summation' schedule to: Frequency %d" % (xmltree.find('MeterMacId').text, summaryFreq)) Domoticz.Send( "<Command>\n <Name>set_schedule</Name>\n <MeterMacId>" + xmltree.find('MeterMacId').text + "</MeterMacId>\n <Event>summation</Event>\n <Frequency>" + str(hex(summaryFreq)) + "</Frequency>\n <Enabled>Y</Enabled>\n</Command>\n") if (xmltree.find('Event').text == 'summation'): Domoticz.Send( "<Command>\n <Name>get_current_summation_delivered</Name>\n <MeterMacId>" + xmltree.find('MeterMacId').text + "</MeterMacId>\n <Refresh>Y</Refresh>\n</Command>\n") elif xmltree.tag == 'InstantaneousDemand': demand = float(getInstantDemandKWh(xmltree)) if (summation == 0.0): Domoticz.Log( "MeterMacId: %s, Instantaneous Demand = %f, NO SUMMARY DATA" % (xmltree.find('MeterMacId').text, demand)) else: delta = fScale * demand summation = summation + delta Domoticz.Log( "MeterMacId: %s, Instantaneous Demand = %.3f, Summary Total = %.3f, Delta = %f" % (xmltree.find('MeterMacId').text, demand, summation, delta)) sValue = "%.3f;%.3f" % (demand, summation) Devices[1].Update(0, sValue.replace('.', '')) elif xmltree.tag == 'CurrentSummationDelivered': total = float(getCurrentSummationKWh(xmltree)) if (total > summation): summation = total sValue = "%.3f" % (total) Devices[2].Update(0, sValue.replace('.', '')) Domoticz.Log("MeterMacId: %s, Current Summation = %.3f" % (xmltree.find('MeterMacId').text, total)) elif xmltree.tag == 'TimeCluster': Domoticz.Debug(xmltree.tag + " response") elif xmltree.tag == 'PriceCluster': Domoticz.Debug(xmltree.tag + " response") elif xmltree.tag == 'CurrentPeriodUsage': Domoticz.Debug(xmltree.tag + " response") elif xmltree.tag == 'LastPeriodUsage': Domoticz.Debug(xmltree.tag + " response") elif xmltree.tag == 'ProfileData': Domoticz.Debug(xmltree.tag + " response") else: Domoticz.Error("Unrecognised (not implemented) XML Fragment (" + xmltree.tag + ").") return
def onCommand(self, Unit, Command, Level, Hue): Domoticz.Log("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level)) Command = Command.strip() action, sep, params = Command.partition(' ') action = action.capitalize() params = params.capitalize() delay = 0 if (self.powerOn == False): delay = int(Parameters["Mode2"]) else: # Amp will ignore commands if it is responding to a heartbeat so delay send lastHeartbeatDelta = (datetime.datetime.now()-self.lastHeartbeat).total_seconds() if (lastHeartbeatDelta < 0.5): delay = 1 Domoticz.Log("Last heartbeat was "+str(lastHeartbeatDelta)+" seconds ago, delaying command send.") if (Unit == 1): # Main power switch if (action == "On"): Domoticz.Send(Message='PWON\r') elif (action == "Off"): Domoticz.Send(Message='PWSTANDBY\r', Delay=delay) # Main Zone devices elif (Unit == 2): # Main selector if (action == "On"): Domoticz.Send(Message='ZMON\r') elif (action == "Set"): if (self.powerOn == False): Domoticz.Send(Message='PWON\r') Domoticz.Send(Message='SI'+self.selectorMap[Level]+'\r', Delay=delay) elif (action == "Off"): Domoticz.Send(Message='ZMOFF\r', Delay=delay) elif (Unit == 3): # Main Volume control if (self.powerOn == False): Domoticz.Send(Message='PWON\r') if (action == "On"): Domoticz.Send(Message='MUOFF\r', Delay=delay) elif (action == "Set"): Domoticz.Send(Message='MV'+str(Level)+'\r', Delay=delay) elif (action == "Off"): Domoticz.Send(Message='MUON\r', Delay=delay) # Zone 2 devices elif (Unit == 4): # Zone 2 selector if (action == "On"): if (self.powerOn == False): Domoticz.Send(Message='PWON\r') Domoticz.Send(Message='Z2ON\r', Delay=delay) elif (action == "Set"): if (self.powerOn == False): Domoticz.Send(Message='PWON\r') if (self.zone2On == False): Domoticz.Send(Message='Z2ON\r', Delay=delay) delay += 1 Domoticz.Send(Message='Z2'+self.selectorMap[Level]+'\r', Delay=delay) delay += 1 Domoticz.Send(Message='Z2?\r', Delay=delay) elif (action == "Off"): Domoticz.Send(Message='Z2OFF\r', Delay=delay) elif (Unit == 5): # Zone 2 Volume control if (self.powerOn == False): Domoticz.Send(Message='PWON\r') if (self.zone2On == False): Domoticz.Send(Message='Z2ON\r', Delay=delay) delay += 1 if (action == "On"): Domoticz.Send(Message='Z2MUOFF\r', Delay=delay) elif (action == "Set"): Domoticz.Send(Message='Z2'+str(Level)+'\r', Delay=delay) elif (action == "Off"): Domoticz.Send(Message='Z2MUON\r', Delay=delay) # Zone 3 devices elif (Unit == 6): # Zone 3 selector if (action == "On"): if (self.powerOn == False): Domoticz.Send(Message='PWON\r') Domoticz.Send(Message='Z3ON\r', Delay=delay) elif (action == "Set"): if (self.powerOn == False): Domoticz.Send(Message='PWON\r') if (self.zone3On == False): Domoticz.Send(Message='Z3ON\r', Delay=delay) delay += 1 Domoticz.Send(Message='Z3'+self.selectorMap[Level]+'\r', Delay=delay) delay += 1 Domoticz.Send(Message='Z3?\r', Delay=delay) elif (action == "Off"): Domoticz.Send(Message='Z3OFF\r', Delay=delay) elif (Unit == 7): # Zone 3 Volume control if (self.powerOn == False): Domoticz.Send(Message='PWON\r') if (self.zone3On == False): Domoticz.Send(Message='Z3ON\r', Delay=delay) delay += 1 if (action == "On"): Domoticz.Send(Message='Z3MUOFF\r', Delay=delay) elif (action == "Set"): Domoticz.Send(Message='Z3'+str(Level)+'\r', Delay=delay) elif (action == "Off"): Domoticz.Send(Message='Z3MUON\r', Delay=delay) return
def onMessage(Data): global oustandingPings, isStarting global selectorMap, powerOn, mainSource, mainVolume1, zone2Source, zone2Volume, zone3Source, zone3Volume oustandingPings = oustandingPings - 1 Domoticz.Debug("onMessage (" + str(isStarting) + ") called with Data: '" + str(Data) + "'") Data = Data.strip() action = Data[0:2] detail = Data[2:] if (action == "PW"): # Power Status if (detail == "STANDBY"): powerOn = False elif (detail == "ON"): if (powerOn == False): Domoticz.Send('ZM?\r') isStarting = True powerOn = True else: Domoticz.Debug("Unknown: Action " + action + ", Detail '" + detail + "' ignored.") elif (action == "ZM"): # Main Zone on/off if (detail == "ON"): Domoticz.Send('SI?\r') mainVolume1 = abs(mainVolume1) elif (detail == "OFF"): mainSource = 0 mainVolume1 = abs(mainVolume1) * -1 if (isStarting == True): Domoticz.Send('MU?\r') else: Domoticz.Debug("Unknown: Action " + action + ", Detail '" + detail + "' ignored.") elif (action == "SI"): # Main Zone Source Input for key, value in selectorMap.items(): if (detail == value): mainSource = key if (isStarting == True): Domoticz.Send('MV?\r') elif (action == "MV"): # Master Volume if (detail.isdigit()): mainVolume1 = int(detail) Domoticz.Send('MU?\r') elif (detail[0:3] == "MAX"): Domoticz.Debug("Unknown: Action " + action + ", Detail '" + detail + "' ignored.") else: Domoticz.Log("Unknown: Action " + action + ", Detail '" + detail + "' ignored.") elif (action == "MU"): # Overall Mute if (detail == "ON"): mainVolume1 = abs(mainVolume1) * -1 elif (detail == "OFF"): mainVolume1 = abs(mainVolume1) else: Domoticz.Debug("Unknown: Action " + action + ", Detail '" + detail + "' ignored.") if (isStarting == True): Domoticz.Send('Z2?\r') elif (action == "Z2"): # Zone 2 if (detail.isdigit()): zone2Volume = int(detail) else: for key, value in selectorMap.items(): if (detail == value): zone2Source = key if (zone2Source == 0): zone2Volume = abs(zone2Volume) * -1 else: zone2Volume = abs(zone2Volume) * -1 if (isStarting == True): Domoticz.Send('Z3?\r') elif (action == "Z3"): # Zone 3 isStarting = False if (detail.isdigit()): zone3Volume = int(detail) else: for key, value in selectorMap.items(): if (detail == value): zone3Source = key if (zone3Source == 0): zone3Volume = abs(zone3Volume) * -1 else: zone3Volume = abs(zone3Volume) * -1 elif (action == "SS"): Domoticz.Debug("Message '" + action + "' ignored.") else: Domoticz.Error("Unknown message '" + action + "' ignored.") SyncDevices() return
def onCommand(Unit, Command, Level, Hue): global isConnected global playerID, mediaLevel, playlistName, playlistPos Domoticz.Debug("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level) + ", Connected: " + str(isConnected)) Command = Command.strip() action, sep, params = Command.partition(' ') action = action.capitalize() if (isConnected == False): TurnOn() else: if (action == 'On'): if (Unit == 3): # Volume control Domoticz.Send( '{"jsonrpc":"2.0","method":"Application.SetMute","params":{"mute":false}}' ) elif (Unit == 4): # Position control if (playerID != -1): Domoticz.Send( '{"jsonrpc":"2.0","method":"Player.PlayPause","params":{"playerid":' + str(playerID) + ',"play":true}}') Domoticz.Send( '{"jsonrpc":"2.0","method":"Player.GetItem","id":1003,"params":{"playerid":' + str(playerID) + ',"properties":["artist","album","year","channel","showtitle","season","episode","title"]}}' ) else: if (Parameters["Mode1"] == ""): Domoticz.Log( "'On' command ignored, No MAC address configured.") elif (action == 'Set'): if (params.capitalize() == 'Level') or (Command.lower() == 'Volume'): if (Unit == 2): # Source selector mediaLevel = Level # valid windows name list http://kodi.wiki/view/JSON-RPC_API/v6#GUI.Window if (mediaLevel == 10): Domoticz.Send( '{"jsonrpc":"2.0","method":"GUI.ActivateWindow","params":{"window":"music"}}' ) if (mediaLevel == 20): Domoticz.Send( '{"jsonrpc":"2.0","method":"GUI.ActivateWindow","params":{"window":"videos"}}' ) if (mediaLevel == 30): Domoticz.Send( '{"jsonrpc":"2.0","method":"GUI.ActivateWindow","params":{"window":"video"}}' ) if (mediaLevel == 40): Domoticz.Send( '{"jsonrpc":"2.0","method":"GUI.ActivateWindow","params":{"window":"pictures"}}' ) if (mediaLevel == 50): Domoticz.Send( '{"jsonrpc":"2.0","method":"GUI.ActivateWindow","params":{"window":"pvr"}}' ) SyncDevices() elif (Unit == 3): # Volume control Domoticz.Send( '{"jsonrpc":"2.0","method":"Application.SetVolume","params":{"volume":' + str(Level) + '}}') elif (Unit == 4): # Position control Domoticz.Send( '{"jsonrpc":"2.0","method":"Player.Seek","params":{"playerid":' + str(playerID) + ',"value":' + str(Level) + '}}') else: Domoticz.Error("Unknown Unit number in command " + str(Unit) + ".") elif (action == 'Play') or (action == 'Pause'): if (playerID != -1): Domoticz.Send( '{"jsonrpc":"2.0","method":"Player.PlayPause","params":{"playerid":' + str(playerID) + ',"play":false}}') elif (action == 'Stop'): Domoticz.Send( '{"jsonrpc":"2.0","method":"Input.ExecuteAction","params":{"action":"stop"},"id":1006}' ) elif (action == 'Trigger'): Domoticz.Send( '{"jsonrpc":"2.0","method":"Input.ExecuteAction","params":{"action":"stop"},"id":1006}' ) Domoticz.Send( '{"jsonrpc":"2.0","method":"Playlist.Clear","params":{"playlistid":0},"id":2000}' ) Domoticz.Send( '{"jsonrpc":"2.0","method":"Playlist.Clear","params":{"playlistid":1},"id":2000}' ) action, sep, params = params.partition(' ') action = action.capitalize() playlistName = "" playlistPos = 0 if (action == 'Playlist'): # Command formats: 'Trigger Playlist ActionMovies', 'Trigger Playlist ActionMovies 15' playlistName, sep, params = params.partition(' ') if (params.isdigit()): playlistPos = int(params) Domoticz.Send( '{"jsonrpc":"2.0","method":"Playlist.Add","params":{"playlistid":0,"item":{"directory":"special://profile/playlists/music/' + playlistName + '.xsp\", "media":"music"}},"id":2002}') elif (action == 'Favorites') or (action == 'Favourites'): # Command formats: 'Trigger Favorites', 'Trigger Favorites 3' if (params.isdigit()): playlistPos = int(params) Domoticz.Send( '{"jsonrpc":"2.0","method":"Favourites.GetFavourites","params":{"properties":["path"]},"id":2100}' ) else: Domoticz.Error("Trigger, Unknown target: " + str(action) + ", expected Playlist/Favorites.") elif (action == 'Run'): Domoticz.Send( '{"jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"addonid":"' + params + '"},"id":1010}') elif (action == 'Off'): if (Unit == 1) or (Unit == 2): # Source Selector or Status Domoticz.Send( '{"jsonrpc":"2.0","method":"Input.ExecuteAction","params":{"action":"stop"},"id":1006}' ) Domoticz.Send( '{"jsonrpc":"2.0","method":"GUI.ActivateWindow","params":{"window":"home"}}' ) TurnOff() elif (Unit == 3): # Volume control Domoticz.Send( '{"jsonrpc":"2.0","method":"Application.SetMute","params":{"mute":true}}' ) elif (Unit == 4): # Position control if (playerID != -1): Domoticz.Send( '{"jsonrpc":"2.0","method":"Player.PlayPause","params":{"playerid":' + str(playerID) + ',"play":false}}') else: Domoticz.Error("Unknown Unit number in command " + str(Unit) + ".") else: Domoticz.Error( "Unhandled action '" + action + "' ignored, options are On/Set/Play/Pause/Stop/Trigger/Run/Off" ) return True
def onMessage(Data): global oustandingPings global canShutdown, canSuspend, canHibernate global playerState, playerID, mediaLevel, mediaDescrption, percentComplete, playlistName, playlistPos Response = json.loads(Data) if ('error' in Response): # Kodi has signalled and error if (Response["id"] == 1010): Domoticz.Log("Addon execution request failed: " + Data) elif (Response["id"] == 2002): Domoticz.Send( '{"jsonrpc":"2.0","method":"Playlist.Add","params":{"playlistid":1,"item":{"directory":"special://profile/playlists/music/' + playlistName + '.xsp\", "media":"music"}},"id":2003}') elif (Response["id"] == 2003): Domoticz.Error("Playlist '" + playlistName + "' could not be added, probably does not exist.") else: Domoticz.Error("Unhandled error response: " + Data) elif ('id' not in Response): # Events do not have an 'id' because we didn't request them if (Response["method"] == "Application.OnVolumeChanged"): Domoticz.Debug("Application.OnVolumeChanged recieved.") if (Response["params"]["data"]["muted"] == True): UpdateDevice(3, 0, int(Response["params"]["data"]["volume"])) else: UpdateDevice(3, 2, int(Response["params"]["data"]["volume"])) elif (Response["method"] == "Player.OnStop") or (Response["method"] == "System.OnWake"): Domoticz.Debug("Player.OnStop recieved.") ClearDevices() elif (Response["method"] == "Player.OnPlay"): Domoticz.Debug("Player.OnPlay recieved, Player ID: " + str(playerID)) playerID = Response["params"]["data"]["player"]["playerid"] if (Response["params"]["data"]["item"]["type"] == "picture"): playerState = 6 elif (Response["params"]["data"]["item"]["type"] == "episode"): playerState = 4 elif (Response["params"]["data"]["item"]["type"] == "channel"): playerState = 4 elif (Response["params"]["data"]["item"]["type"] == "movie"): playerState = 4 elif (Response["params"]["data"]["item"]["type"] == "song"): playerState = 5 elif (Response["params"]["data"]["item"]["type"] == "musicvideo"): playerState = 4 else: playerState = 9 if (playerID != -1): Domoticz.Send( '{"jsonrpc":"2.0","method":"Player.GetItem","id":1003,"params":{"playerid":' + str(playerID) + ',"properties":["artist","album","year","channel","showtitle","season","episode","title"]}}' ) elif (Response["method"] == "Player.OnPause"): Domoticz.Debug("Player.OnPause recieved, Player ID: " + str(playerID)) playerState = 2 SyncDevices() elif (Response["method"] == "Player.OnSeek"): if (playerID != -1): Domoticz.Send( '{"jsonrpc":"2.0","method":"Player.GetProperties","id":1002,"params":{"playerid":' + str(playerID) + ',"properties":["live","percentage","speed"]}}') else: Domoticz.Send( '{"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":1005}' ) Domoticz.Debug("Player.OnSeek recieved, Player ID: " + str(playerID)) elif (Response["method"] == "System.OnQuit") or ( Response["method"] == "System.OnSleep") or (Response["method"] == "System.OnRestart"): Domoticz.Debug("System.OnQuit recieved.") ClearDevices() else: Domoticz.Debug("Unhandled unsolicited response: " + Data) else: Domoticz.Debug(str(Response["id"]) + " response received: " + Data) # Responses to requests made by the plugin if (Response["id"] == 1001): # PING call when nothing is playing if playerState == 0: playerState = 1 oustandingPings = oustandingPings - 1 if (len(Response["result"]) > 0) and ('playerid' in Response["result"][0]): playerID = Response["result"][0]["playerid"] Domoticz.Send( '{"jsonrpc":"2.0","method":"Player.GetItem","id":1003,"params":{"playerid":' + str(playerID) + ',"properties":["artist","album","year","channel","showtitle","season","episode","title"]}}' ) else: ClearDevices() elif (Response["id"] == 1002): # PING call when something is playing # {"id":1002,"jsonrpc":"2.0","result":{"live":false,"percentage":0.044549804180860519409,"speed":1}} oustandingPings = oustandingPings - 1 if ("live" in Response["result"]) and (Response["result"]["live"] == True): mediaLevel = 40 if (playerState == 2) and ("speed" in Response["result"]) and ( Response["result"]["speed"] != 0): Domoticz.Send( '{"jsonrpc":"2.0","method":"Player.GetItem","id":1003,"params":{"playerid":' + str(playerID) + ',"properties":["artist","album","year","channel","showtitle","season","episode","title"]}}' ) if ("speed" in Response["result"]) and (Response["result"]["speed"] == 0): playerState = 2 if ("percentage" in Response["result"]): percentComplete = round(Response["result"]["percentage"]) elif (Response["id"] == 1003): if ("item" in Response["result"]): playerState = 9 mediaLevel = 0 if ("type" in Response["result"]["item"]): mediaType = Response["result"]["item"]["type"] if (mediaType == "song"): playerState = 5 mediaLevel = 20 elif (mediaType == "movie"): playerState = 4 mediaLevel = 10 elif (mediaType == "unknown"): playerState = 4 mediaLevel = 10 elif (mediaType == "episode"): playerState = 4 mediaLevel = 30 elif (mediaType == "channel"): playerState = 4 mediaLevel = 40 elif (mediaType == "picture"): playerState = 6 mediaLevel = 50 else: Domoticz.Error("Unknown media type encountered: " + str(mediaType)) playerState = 9 mediaDescrption = "" if ("artist" in Response["result"]["item"]) and (len( Response["result"]["item"]["artist"])): mediaDescrption = mediaDescrption + Response["result"][ "item"]["artist"][0] + ", " if ("album" in Response["result"]["item"]) and ( Response["result"]["item"]["album"] != ""): mediaDescrption = mediaDescrption + "(" + Response[ "result"]["item"]["album"] + ") " if ("showtitle" in Response["result"]["item"]) and ( Response["result"]["item"]["showtitle"] != ""): mediaDescrption = mediaDescrption + Response["result"][ "item"]["showtitle"] + ", " mediaDescrption = mediaDescrption + ": " if ("season" in Response["result"]["item"]) and ( Response["result"]["item"]["season"] > 0) and ("episode" in Response["result"]["item"]) and ( Response["result"]["item"]["episode"] > 0): mediaDescrption = mediaDescrption + "[S" + str( Response["result"]["item"]["season"]) + "E" + str( Response["result"]["item"]["episode"]) + "] " if ("title" in Response["result"]["item"]) and ( Response["result"]["item"]["title"] != ""): mediaDescrption = mediaDescrption + Response["result"][ "item"]["title"] + ", " if ("channel" in Response["result"]["item"]) and ( Response["result"]["item"]["channel"] != ""): mediaDescrption = mediaDescrption + "(" + Response[ "result"]["item"]["channel"] + ") " mediaLevel = 30 if ("label" in Response["result"]["item"]) and ( Response["result"]["item"]["label"] != ""): if (mediaDescrption.find( Response["result"]["item"]["label"]) == -1): mediaDescrption = mediaDescrption + Response["result"][ "item"]["label"] + ", " if ("year" in Response["result"]["item"]) and ( Response["result"]["item"]["year"] > 0): mediaDescrption = mediaDescrption + " (" + str( Response["result"]["item"]["year"]) + ")" # Now tidy up and compress the string mediaDescrption = mediaDescrption.lstrip(":") mediaDescrption = mediaDescrption.rstrip(", :") mediaDescrption = mediaDescrption.replace(" ", " ") mediaDescrption = mediaDescrption.replace(", :", ":") mediaDescrption = mediaDescrption.replace(", (", " (") if (len(mediaDescrption) > 40): mediaDescrption = mediaDescrption.replace(", ", ",") if (len(mediaDescrption) > 40): mediaDescrption = mediaDescrption.replace(" (", "(") if (len(mediaDescrption) > 40): mediaDescrption = mediaDescrption.replace(") ", ")") if (len(mediaDescrption) > 40): mediaDescrption = mediaDescrption.replace(": ", ":") if (len(mediaDescrption) > 40): mediaDescrption = mediaDescrption.replace(" [", "[") if (len(mediaDescrption) > 40): mediaDescrption = mediaDescrption.replace("] ", "]") mediaDescrption = mediaDescrption.replace(",(", "(") while (mediaDescrption.rfind(")") != -1) and (len(mediaDescrption) > 40): mediaDescrption = mediaDescrption.replace( mediaDescrption[mediaDescrption. rfind("("):mediaDescrption.rfind(")") + 1], "") if (mediaType != "picture"): Domoticz.Send( '{"jsonrpc":"2.0","method":"Player.GetProperties","id":1002,"params":{"playerid":' + str(playerID) + ',"properties":["live","percentage","speed"]}}') else: ClearDevices() elif (Response["id"] == 1006): if (Response["result"] != "OK"): Domoticz.Error("Remote command unsuccessful, response: '" + str(Response["result"]) + "'") elif (Response["id"] == 1007): canShutdown = Response["result"]["canshutdown"] canSuspend = Response["result"]["cansuspend"] canHibernate = Response["result"]["canhibernate"] Domoticz.Debug("Kodi shutdown options response processed.") elif (Response["id"] == 1008): if (Response["result"] == "OK"): Domoticz.Log("Shutdown command accepted.") else: Domoticz.Error("Shutdown command unsuccerssful response: '" + str(Response["result"]) + "'") elif (Response["id"] == 1010): Domoticz.Log("Executed Addon successfully") elif (Response["id"] == 1011): if (Response["result"]["muted"] == False): UpdateDevice(3, 2, Response["result"]["volume"]) else: UpdateDevice(3, 0, Response["result"]["volume"]) elif (Response["id"] == 2000): if (Response["result"] != "OK"): Domoticz.Error( "Playlist Clear command unsuccessful, response: '" + str(Response["result"]) + "'") elif (Response["id"] == 2002): Domoticz.Send( '{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"playlistid":0,"position":' + playlistPos + '}},"id":2004}') elif (Response["id"] == 2003): Domoticz.Send( '{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"playlistid":1,"position":' + playlistPos + '}},"id":2004}') elif (Response["id"] == 2004): if (Response["result"] != "OK"): Domoticz.Error( "Playlist Open command unsuccessful, response: '" + str(Response["result"]) + "'") elif (Response["id"] == 2100): if ('favourites' in Response["result"]) and ( 'limits' in Response["result"]) and ( 'total' in Response["result"]["limits"]): iFavCount = Response["result"]["limits"]["total"] if (playlistPos < 0): playlistPos = 0 if (playlistPos >= iFavCount): playlistPos = iFavCount - 1 i = 0 for Favourite in Response["result"]["favourites"]: Domoticz.Debug("Favourites #" + str(i) + " is '" + Favourite["title"] + "', type '" + Favourite["type"] + "'.") if (i == playlistPos): if (Favourite["type"] == "media"): Domoticz.Log("Favourites #" + str(i) + " has path '" + Favourite["path"] + "' and will be played.") Domoticz.Send( '{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"' + Favourite["path"] + '"}},"id":2101}') break else: Domoticz.Log( "Requested Favourite ('" + Favourite["title"] + "') is not playable, next playable item will be selected." ) playlistPos = playlistPos + 1 i = i + 1 else: Domoticz.Log("No Favourites returned.") elif (Response["id"] == 2101): Domoticz.Log("2101: To be handled: " + Data) else: Domoticz.Debug("Unknown Response: " + Data) SyncDevices() return True
def onConnect(self, Status, Description): Domoticz.Log("onConnect called") self.isConnected = True Domoticz.Send("", "GET", self.LastCommand, self.Headers)