コード例 #1
0
 def __init__(self, ipadress, macadress, psk, apikey, jeedomadress):
     self._ipadress = ipadress
     self._macadress = macadress
     self._psk = psk
     self._apikey = apikey
     self._jeedomadress = jeedomadress
     self._braviainstance = BraviaRC(self._ipadress, self._psk,
                                     self._macadress)
コード例 #2
0
    def onStart(self):
        global _tv

        if Parameters["Mode6"] == "Debug":
            Domoticz.Debugging(1)

        self.SourceOptions3 = {
            "LevelActions": "||||||",
            "LevelNames": "Off|TV|HDMI1|HDMI2|HDMI3|HDMI4|Netflix",
            "LevelOffHidden": "true",
            "SelectorStyle": "0"
        }
        self.SourceOptions4 = {
            "LevelActions": "|||||",
            "LevelNames": "Off|Play|Stop|Pause|TV Pause|Exit",
            "LevelOffHidden": "true",
            "SelectorStyle": "0"
        }
        self.SourceOptions5 = {
            "LevelActions": "||||||||||",
            "LevelNames":
            "Off|CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8|CH9|--Choose a channel--",
            "LevelOffHidden": "true",
            "SelectorStyle": "1"
        }

        if Parameters["Mode3"] == "Volume" and 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 Parameters["Mode3"] != "Volume" and 2 in Devices:
            Devices[2].Delete()
            Domoticz.Log("Volume device deleted")
        # TODO : For some reason the first device entry in Devices is f****d and will weirdly toggle states
        #        This device itself, now sitting in Utility tab, is obsolete but prevents useful devices from being bugged
        if 1 not in Devices:
            Domoticz.Device(Name="Info", Unit=1, Type=243, Subtype=19,
                            Used=1).Create()
            Domoticz.Log("TV Status device created")
        if 3 not in Devices:
            Domoticz.Device(Name="Source",
                            Unit=3,
                            Type=244,
                            Subtype=62,
                            Switchtype=18,
                            Image=2,
                            Options=self.SourceOptions3,
                            Used=1).Create()
            Domoticz.Log("Source device created")
        if 4 not in Devices:
            Domoticz.Device(Name="Control",
                            Unit=4,
                            Type=244,
                            Subtype=62,
                            Switchtype=18,
                            Image=2,
                            Options=self.SourceOptions4,
                            Used=1).Create()
            Domoticz.Log("Control device created")
        if 5 not in Devices:
            Domoticz.Device(Name="Channel",
                            Unit=5,
                            Type=244,
                            Subtype=62,
                            Switchtype=18,
                            Image=2,
                            Options=self.SourceOptions5,
                            Used=1).Create()
            Domoticz.Log("Channel device created")
        if 7 not in Devices:
            Domoticz.Device(Name="Status",
                            Unit=7,
                            Type=244,
                            Subtype=73,
                            Switchtype=17,
                            Image=2,
                            Used=1).Create()

        if 2 in Devices: self.tvVolume = Devices[2].nValue  #--> of sValue
        if 3 in Devices: self.tvSource = Devices[3].sValue
        if 4 in Devices: self.tvControl = Devices[4].sValue
        if 5 in Devices: self.tvChannel = Devices[5].sValue

        self.HttpConn = Domoticz.Connection(Name="HttpConn",
                                            Transport="TCP/IP",
                                            Protocol="HTTP",
                                            Address=Parameters["Address"],
                                            Port="80")
        self.HttpConn.Connect()

        _tv = BraviaRC(self.HttpConn, Parameters["Address"],
                       Parameters["Mode1"])

        # 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: updateInterval = 30
        elif updateInterval < 10: updateInterval = 10
        Domoticz.Debug("Update interval set to " + str(updateInterval) +
                       " (minimum is 10 seconds)")
        Domoticz.Heartbeat(updateInterval)

        return True
コード例 #3
0
class SonyBravia:
    """ Fetch teleinformation datas and call user callback
	each time all data are collected
	"""
    def __init__(self, ipadress, macadress, psk, apikey, jeedomadress):
        self._ipadress = ipadress
        self._macadress = macadress
        self._psk = psk
        self._apikey = apikey
        self._jeedomadress = jeedomadress
        self._braviainstance = BraviaRC(self._ipadress, self._psk,
                                        self._macadress)

    def run(self):
        Donnees = {}
        _Donnees = {}
        _RAZ = datetime.now()
        Sources = {}
        Apps = {}
        _RazCalcul = 0
        _Separateur = "&"
        _SendData = ""

        def target():
            self.process = None
            #logger.debug("Thread started, timeout = " + str(timeout)+", command : "+str(self.cmd))
            self.process = subprocess.Popen(self.cmd + _SendData, shell=True)
            #print(self.cmd + _SendData)
            self.process.communicate()
            #logger.debug("Return code: " + str(self.process.returncode))
            #logger.debug("Thread finished")
            self.timer.cancel()

        def timer_callback():
            #logger.debug("Thread timeout, terminate it")
            if self.process.poll() is None:
                try:
                    self.process.kill()
                except OSError as error:
                    #logger.error("Error: %s " % error)
                    self._log.error("Error: %s " % error)
                self._log.warning("Thread terminated")
            else:
                self._log.warning("Thread not alive")

        tvstatus = ""
        try:
            Sources = self._braviainstance.load_source_list()
            Apps = self._braviainstance.load_app_list()
            for cle, valeur in Sources.items():
                _tmp += cle.replace(' ', '%20')
                _tmp += "|"
            #print (_tmp)
            Donnees["sources"] = _tmp
            _tmp = ""
            for cle, valeur in Apps.items():
                _tmp += cle.replace(' ', '%20') + "|"
            _tmp = _tmp.replace('&', '%26')
            _tmp = _tmp.replace('\'', '%27')
            Donnees["apps"] = _tmp
        except Exception:
            errorCom = "Connection error"
        while (1):
            _RazCalcul = datetime.now() - _RAZ
            if (_RazCalcul.seconds > 8):
                _RAZ = datetime.now()
                del Donnees
                del _Donnees
                Donnees = {}
                _Donnees = {}
            _SendData = ""
            try:
                tvstatus = self._braviainstance.get_power_status()
                Donnees["status"] = tvstatus
            except KeyError:
                print('TV not found')
                sys.exit()
            if tvstatus == 'active':
                try:
                    tvinfo = self._braviainstance.get_system_info()
                    Donnees["model"] = tvinfo['model']
                except:
                    print('Model not found')
                try:
                    vol = self._braviainstance.get_volume_info()
                    Donnees["volume"] = str(vol['volume'])
                except:
                    print('Volume not found')
                try:
                    tvPlaying = self._braviainstance.get_playing_info()
                    #print (tvPlaying)
                    if not tvPlaying:
                        Donnees["source"] = "Application"
                        Donnees["program"] = ""
                        Donnees["nom_chaine"] = ""
                        Donnees["debut"] = ""
                        Donnees["debut_p"] = ''
                        Donnees["fin_p"] = ''
                        Donnees["pourcent_p"] = '0'
                        Donnees["duree"] = ""
                        Donnees["chaine"] = ""
                    else:
                        Donnees["source"] = (
                            (tvPlaying['source'])[-4:]).upper() + (
                                tvPlaying['uri'])[-1:]
                        try:
                            if tvPlaying['dispNum'] is not None:
                                Donnees["chaine"] = tvPlaying['dispNum']
                        except:
                            print('num chaine not found')
                        try:
                            if tvPlaying['programTitle'] is not None:
                                Donnees["program"] = tvPlaying[
                                    'programTitle'].replace(' ',
                                                            '%20').replace(
                                                                'é', '%C3%A9')
                        except:
                            print('program info not found')
                        try:
                            if tvPlaying['title'] is not None:
                                Donnees["nom_chaine"] = tvPlaying[
                                    'title'].replace(' ', '%20')
                        except:
                            print('nom chaine not found')
                        try:
                            if tvPlaying['startDateTime'] is not None:
                                if tvPlaying['startDateTime'] != '':
                                    Donnees["debut"] = tvPlaying[
                                        'startDateTime']
                                    Donnees["debut_p"], Donnees["fin_p"], Donnees[
                                        "pourcent_p"] = self._braviainstance.playing_time(
                                            tvPlaying['startDateTime'],
                                            tvPlaying['durationSec'])
                                else:
                                    Donnees["debut_p"] = ''
                                    Donnees["fin_p"] = ''
                                    Donnees["pourcent_p"] = '0'
                        except:
                            print('start date not found')
                        try:
                            if tvPlaying['durationSec'] is not None:
                                if tvPlaying['durationSec'] != '':
                                    Donnees["duree"] = str(
                                        tvPlaying['durationSec'])
                                else:
                                    Donnees["duree"] = '0'
                        except:
                            print('duration not found')
                except:
                    print('Playing Info not found')
            self.cmd = "curl -L -s -G --max-time 15 " + self._jeedomadress + " -d 'apikey=" + self._apikey + "&mac=" + self._macadress
            for cle, valeur in Donnees.items():
                if (cle in _Donnees):
                    if (Donnees[cle] != _Donnees[cle]):
                        _SendData += _Separateur + cle + '=' + valeur
                        _Donnees[cle] = valeur
                else:
                    _SendData += _Separateur + cle + '=' + valeur
                    _Donnees[cle] = valeur
            _SendData += "'"
            if _SendData != "'":
                try:
                    thread = threading.Thread(target=target)
                    self.timer = threading.Timer(int(5), timer_callback)
                    self.timer.start()
                    thread.start()
                except Exception:
                    errorCom = "Connection error"
            time.sleep(2)

    def exit_handler(self, *args):
        self.terminate()
コード例 #4
0
    def onStart(self):
        global _tv

        if Parameters["Mode6"] == "Debug":
            Domoticz.Debugging(1)

        _tv = BraviaRC(Parameters["Address"], Parameters["Mode1"],
                       Parameters["Mode2"])  #IP, PSK, MAC

        Options = {
            "LevelActions": "|||||",
            "LevelNames": "Off|TV|HDMI1|HDMI2|HDMI3|HDMI4",
            "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=Options).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.")
        else:
            if (1 in Devices):
                self.tvState = Devices[1].nValue
            if (2 in Devices):
                self.tvVolume = Devices[2].nValue
            if (3 in Devices):
                self.tvSource = Devices[3].nValue

        # 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)

        DumpConfigToLog()

        return  #--> return True
コード例 #5
0
    def onStart(self):
        global _tv
        
        if Parameters["Mode6"] == "Debug":
            Domoticz.Debugging(1)
            DumpConfigToLog()
        
        _tv = BraviaRC(Parameters["Address"], Parameters["Mode1"], Parameters["Mode2"]) #IP, PSK, MAC
        
        self.SourceOptions3 =   {   "LevelActions"  : "||||||", 
                                    "LevelNames"    : "Off|TV|HDMI1|HDMI2|HDMI3|HDMI4|Netflix",
                                    "LevelOffHidden": "true",
                                    "SelectorStyle" : "0"
                                }
        self.SourceOptions4 =   {   "LevelActions"  : "|||||", 
                                    "LevelNames"    : "Off|Play|Stop|Pause|TV Pause|Exit",
                                    "LevelOffHidden": "true",
                                    "SelectorStyle" : "0"
                                }
        self.SourceOptions5 =   {   "LevelActions"  : "||||||||||", 
                                    "LevelNames"    : "Off|CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8|CH9|--Choose a channel--",
                                    "LevelOffHidden": "true",
                                    "SelectorStyle" : "1"
                                }
                                    
        if len(Devices) == 0:
            Domoticz.Device(Name="Status", Unit=1, Type=17, Image=2, Switchtype=17, Used=1).Create()
            if Parameters["Mode3"] == "Volume": Domoticz.Device(Name="Volume", Unit=2, Type=244, Subtype=73, Switchtype=7, Image=8, Used=1).Create()
            Domoticz.Device(Name="Source", Unit=3, TypeName="Selector Switch", Switchtype=18, Image=2, Options=self.SourceOptions3, Used=1).Create()
            Domoticz.Device(Name="Control", Unit=4, TypeName="Selector Switch", Switchtype=18, Image=2, Options=self.SourceOptions4, Used=1).Create()
            Domoticz.Device(Name="Channel", Unit=5, TypeName="Selector Switch", Switchtype=18, Image=2, Options=self.SourceOptions5, Used=1).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, Used=1).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, Used=1).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, Used=1).Create()
            Domoticz.Log("Source device created")
        elif 4 not in Devices:
            Domoticz.Device(Name="Control", Unit=4, TypeName="Selector Switch", Switchtype=18, Image=2, Options=self.SourceOptions4, Used=1).Create()
            Domoticz.Log("Control device created")
        elif 5 not in Devices:
            Domoticz.Device(Name="Channel", Unit=5, TypeName="Selector Switch", Switchtype=18, Image=2, Options=self.SourceOptions5, Used=1).Create()
            Domoticz.Log("Channel 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
            if 4 in Devices: self.tvControl = Devices[4].sValue
            if 5 in Devices: self.tvChannel = Devices[5].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)

        return #--> return True
コード例 #6
0
try:
    import Domoticz
except ImportError:
    import fakeDomoticz as Domoticz

import os
from bravia import BraviaRC
import sys

### Enter the IP address, PSK and MAC address of the TV below
ip = '192.168.1.191'
psk = 'sony'
mac = 'AA:BB:CC:DD:EE:FF'
###

x = BraviaRC(ip, psk, mac)

try:
    tvstatus = x.get_power_status()
    #print('Status TV:', tvstatus)
except KeyError:
    print('TV not found')
    sys.exit()

if tvstatus == 'active':
    #zet op NLD1
    #NLD1 = x.send_req_ircc(HOST, PSK, 'AAAAAQAAAAEAAAAAAw==')
    #NLD1 = x.send_req_ircc(x.get_command_code('Num1'))
    #print(NLD1)
    #zet op NLD2
    #NLD2 = x.send_req_ircc(HOST, PSK, 'AAAAAQAAAAEAAAABAw==')