Пример #1
0
    def poll(self):
        _host = None if __addon__.getSetting("lg_host") == "" else __addon__.getSetting("lg_host")
        try:
            tools.notifyLog("Service running (%s, %s)" % (self.lg_protocol, self.lg_pairing_key))

            while not self.Mon.abortRequested:
                _cycle = POLL_INTERVAL if self.sessionEstablished else WAIT_FOR_NEXT_CONNECT
                if self.Mon.waitForAbort(_cycle):
                    break
                if self.Mon.settingsChanged:
                    self.readSettings()
                if not self.sessionEstablished:
                    self.getSettings(init=False)

        except interface.Interface.LGinNetworkNotFoundException:
            tools.notifyLog("LG Devices not found in network.", level=xbmc.LOGERROR)
            tools.dialogOSD(__LS__(30050))
        except interface.Interface.LGProtocolWebOSException:
            tools.notifyLog("Device use WebOS on port 3000. Not supported.", level=xbmc.LOGERROR)
            tools.dialogOSD(__LS__(30051))
        except interface.Interface.LGProtocollNotAcceptedException:
            tools.notifyLog("Protocol not supported.", level=xbmc.LOGERROR)
            tools.dialogOSD(__LS__(30052))
        except interface.Interface.NoConnectionToHostException:
            tools.notifyLog("No connection to host.", level=xbmc.LOGERROR)
            tools.dialogOSD(__LS__(30053) % (_host))
        except Exception, e:
            pass
Пример #2
0
    def reswitch3D(self, auto_pause):
        mode = self.lgtv.get_3D_Mode()

        if mode == Display3dMode.ERROR:
            tools.notifyLog("Could not get current 3D mode")
            if not self.lgtv.toast("Could not get current 3D mode",
                                   icon_file=__IconKodi__):
                tools.notifyOSD(__addonname__,
                                "Could not get current 3D mode",
                                icon=__IconError__)

        if mode == self.mode3D:
            return

        if auto_pause:
            # pause playback until 3D mode is switched
            self.pause()
        success, msg = self.lgtv.set_3D_Mode(self.mode3D)
        if not success:
            tools.notifyLog(msg)
            if not self.lgtv.toast(msg, icon_file=__IconKodi__):
                tools.notifyOSD(__addonname__, msg, icon=__IconError__)
        if auto_pause:
            # resume
            self.pause()
Пример #3
0
    def poll(self):
        _host = None if __addon__.getSetting(
            'lg_host') == '' else __addon__.getSetting('lg_host')
        try:
            tools.notifyLog('Service running (%s, %s)' %
                            (self.lg_protocol, self.lg_pairing_key))

            while not self.Mon.abortRequested:
                _cycle = POLL_INTERVAL if self.sessionEstablished else WAIT_FOR_NEXT_CONNECT
                if self.Mon.waitForAbort(_cycle): break
                if self.Mon.settingsChanged: self.readSettings()
                if not self.sessionEstablished: self.getSettings(init=False)

        except interface.Interface.LGinNetworkNotFoundException:
            tools.notifyLog('LG Devices not found in network.',
                            level=xbmc.LOGERROR)
            tools.dialogOSD(__LS__(30050))
        except interface.Interface.LGProtocolWebOSException:
            tools.notifyLog('Device use WebOS on port 3000. Not supported.',
                            level=xbmc.LOGERROR)
            tools.dialogOSD(__LS__(30051))
        except interface.Interface.LGProtocollNotAcceptedException:
            tools.notifyLog('Protocol not supported.', level=xbmc.LOGERROR)
            tools.dialogOSD(__LS__(30052))
        except interface.Interface.NoConnectionToHostException:
            tools.notifyLog('No connection to host.', level=xbmc.LOGERROR)
            tools.dialogOSD(__LS__(30053) % (_host))
        except Exception, e:
            pass
Пример #4
0
 def getSettings(self, init=True):
     if init: self.readSettings()
     if self.lg_host is not None:
         if self.Remote is None:
             try:
                 self.Remote = interface.Interface(self.lg_host,
                                                   self.lg_port,
                                                   self.lg_protocol)
                 if not self.Remote.session_id:
                     self.Remote.get_session_id(self.lg_pairing_key)
                     self.sessionEstablished = True
                     tools.notifyLog(
                         'Session established. Using session id %s.' %
                         (self.Remote.session_id),
                         level=xbmc.LOGDEBUG)
             except self.Remote.NoConnectionToHostException:
                 self.sessionEstablished = False
                 self.Remote = None
                 tools.notifyLog('No connection to host on %s' %
                                 (self.lg_host),
                                 level=xbmc.LOGERROR)
                 if init:
                     tools.notifyOSD(__addonname__,
                                     __LS__(30054),
                                     icon=__IconError__)
Пример #5
0
    def onPlayBackEnded(self):
        _currentMode = self.mode3D
        if self.getStereoscopicMode() and self.isPlaying3D and self.mode3D == "OFF":
            tools.notifyLog("Turn 3D %s mode off" % (_currentMode), level=xbmc.LOGDEBUG)
            if _currentMode == "SBS":
                __mode3D_off__ = __mode3DSBS_off__
            elif _currentMode == "TAB":
                __mode3D_off__ = __mode3DTAB_off__
            else:
                return

            self.sendCommand(__mode3D_off__[self.lg_protocol], self.lg_seq_3D_off)
            self.isPlaying3D = False
Пример #6
0
    def readSettings(self):
        self.lg_host = __addon__.getSetting("lg_host")
        self.lg_host = None if self.lg_host == "" else self.lg_host
        self.lg_port = __addon__.getSetting("lg_port")
        self.lg_protocol = __addon__.getSetting("lg_protocol")
        self.lg_protocol = None if self.lg_protocol == __LS__(30017) else self.lg_protocol.lower()
        self.lg_pairing_key = __addon__.getSetting("lg_pairing_key")

        self.lg_key_delay = int(re.match("\d+", __addon__.getSetting("lg_delay")).group())
        self.lg_own_seqs_enabled = True if __addon__.getSetting("use_own_seq").upper() == "TRUE" else False
        self.lg_seq_3D_on = " ".join(__addon__.getSetting("lg_3D_on").replace(",", " ").split()).split()
        self.lg_seq_3D_off = " ".join(__addon__.getSetting("lg_3D_off").replace(",", " ").split()).split()

        self.Mon.settingsChanged = False
        tools.notifyLog("Settings reloaded", level=xbmc.LOGDEBUG)
Пример #7
0
    def onPlayBackEnded(self):
        _currentMode = self.mode3D
        if self.getStereoscopicMode(
        ) and self.isPlaying3D and self.mode3D == 'OFF':
            tools.notifyLog('Turn 3D %s mode off' % (_currentMode),
                            level=xbmc.LOGDEBUG)
            if _currentMode == 'SBS':
                __mode3D_off__ = __mode3DSBS_off__
            elif _currentMode == 'TAB':
                __mode3D_off__ = __mode3DTAB_off__
            else:
                return

            self.sendCommand(__mode3D_off__[self.lg_protocol],
                             self.lg_seq_3D_off)
            self.isPlaying3D = False
Пример #8
0
    def onPlayBackStarted(self):
        if self.isPlayingVideo() and self.lg_protocol is not None:
            _file = os.path.basename(self.getPlayingFile().decode("utf-8"))
            if re.search(__pattern3D__, _file, re.IGNORECASE):
                if self.getStereoscopicMode():
                    if self.mode3D == "SBS":
                        __mode3D_on__ = __mode3DSBS_on__
                    elif self.mode3D == "TAB":
                        __mode3D_on__ = __mode3DTAB_on__
                    else:
                        return

                tools.notifyLog("Playing '%s'" % (_file), level=xbmc.LOGDEBUG)
                tools.notifyLog("sending sequence for 3D %s" % (self.mode3D), level=xbmc.LOGDEBUG)
                self.sendCommand(__mode3D_on__[self.lg_protocol], self.lg_seq_3D_on)
                self.isPlaying3D = True
Пример #9
0
    def onPlayBackStarted(self):
        if self.isPlayingVideo() and self.lg_protocol is not None:
            _file = os.path.basename(self.getPlayingFile().decode('utf-8'))
            if re.search(__pattern3D__, _file, re.IGNORECASE):
                if self.getStereoscopicMode():
                    if self.mode3D == 'SBS': __mode3D_on__ = __mode3DSBS_on__
                    elif self.mode3D == 'TAB': __mode3D_on__ = __mode3DTAB_on__
                    else:
                        return

                tools.notifyLog('Playing \'%s\'' % (_file),
                                level=xbmc.LOGDEBUG)
                tools.notifyLog('sending sequence for 3D %s' % (self.mode3D),
                                level=xbmc.LOGDEBUG)
                self.sendCommand(__mode3D_on__[self.lg_protocol],
                                 self.lg_seq_3D_on)
                self.isPlaying3D = True
Пример #10
0
 def getSettings(self, init=True):
     if init:
         self.readSettings()
     if self.lg_host is not None:
         if self.Remote is None:
             try:
                 self.Remote = interface.Interface(self.lg_host, self.lg_port, self.lg_protocol)
                 if not self.Remote.session_id:
                     self.Remote.get_session_id(self.lg_pairing_key)
                     self.sessionEstablished = True
                     tools.notifyLog(
                         "Session established. Using session id %s." % (self.Remote.session_id), level=xbmc.LOGDEBUG
                     )
             except self.Remote.NoConnectionToHostException:
                 self.sessionEstablished = False
                 self.Remote = None
                 tools.notifyLog("No connection to host on %s" % (self.lg_host), level=xbmc.LOGERROR)
                 if init:
                     tools.notifyOSD(__addonname__, __LS__(30054), icon=__IconError__)
Пример #11
0
    def getStereoscopicMode(self):
        for _ in range(
                int(WAIT_FOR_MODE_SELECT / WAIT_FOR_MODE_SELECT_INTERVAL)):
            try:
                # VideoPlayer.StereoscopicMode returns the _currently played_ video's 3D mode as a string (left_right etc.)
                # However, if the video is rendered in another mode (e.g. SBS video rendered as TAB by Kodi), this will
                # result in a wrong 3D mode switch.
                # System.StereoscopicMode returns a str(int) giving the GUI's _current_ 3D mode, which is exactly what we need.
                mode = self.THREE_D_MODE_MAPPING[int(
                    xbmc.getInfoLabel("System.StereoscopicMode"))]
                if self.mode3D != mode:
                    self.mode3D = mode
                    tools.notifyLog('Stereoscopic mode has changed to %s' %
                                    (Display3dMode.to_string(self.mode3D)))
                    return True
                if self.monitor.waitForAbort(WAIT_FOR_MODE_SELECT_INTERVAL):
                    raise SystemExit
            except SystemExit:
                tools.notifyLog(
                    'System will terminate this script, closing it.',
                    level=xbmc.LOGERROR)
                return False
            except Exception as e:
                tools.notifyLog("Could not determine stereoscopic mode: %s" %
                                e,
                                level=xbmc.LOGERROR)
                return False

        # no 3D mode change happened
        return False
Пример #12
0
    def readSettings(self):
        self.lg_host = __addon__.getSetting('lg_host')
        self.lg_host = None if self.lg_host == '' else self.lg_host
        self.lg_port = __addon__.getSetting('lg_port')
        self.lg_protocol = __addon__.getSetting('lg_protocol')
        self.lg_protocol = None if self.lg_protocol == __LS__(
            30017) else self.lg_protocol.lower()
        self.lg_pairing_key = __addon__.getSetting('lg_pairing_key')

        self.lg_key_delay = int(
            re.match('\d+', __addon__.getSetting('lg_delay')).group())
        self.lg_own_seqs_enabled = True if __addon__.getSetting(
            'use_own_seq').upper() == 'TRUE' else False
        self.lg_seq_3D_on = ' '.join(
            __addon__.getSetting('lg_3D_on').replace(',',
                                                     ' ').split()).split()
        self.lg_seq_3D_off = ' '.join(
            __addon__.getSetting('lg_3D_off').replace(',',
                                                      ' ').split()).split()

        self.Mon.settingsChanged = False
        tools.notifyLog('Settings reloaded', level=xbmc.LOGDEBUG)
Пример #13
0
    def switch3D(self, auto_pause):
        if self.getStereoscopicMode():
            tools.notifyLog('Switching to 3D mode %s' %
                            Display3dMode.to_string(self.mode3D))
            if auto_pause:
                # pause playback during switching
                self.pause()
            try:
                success, msg = self.lgtv.set_3D_Mode(self.mode3D)
                if success:
                    return

                # in case something _seriously_ failed during previous communication, try clean reconnect
                if not self.lgtv.is_connected():
                    tools.notifyLog("Not connected, attempting reconnect")
                    success = self.lgtv.connect(self.lg_host, __addonname__)
                    if not success:
                        tools.notifyLog("Reconnect failed")
                        tools.notifyOSD(__addonname__,
                                        __LS__(30100) % self.lg_host,
                                        icon=__IconError__)
                        return

                    tools.notifyLog("Reconnected to TV at %s" % self.lg_host)
                    #tools.notifyOSD(__addonname__, __LS__(30102) % self.lg_host, icon=__IconConnected__)
                    self.lgtv.toast(__LS__(30104), icon_file=__IconKodi__)

                success, msg = self.lgtv.set_3D_Mode(self.mode3D)
                if not success:
                    tools.notifyLog(msg)
                    if not self.lgtv.toast(msg, icon_file=__IconKodi__):
                        tools.notifyOSD(__addonname__, msg, icon=__IconError__)
            finally:
                if auto_pause:
                    # resume playback after switching
                    self.pause()
Пример #14
0
def main():
    tools.notifyLog("Scanning for LG Smart TV Devices running WebOS...", level=xbmc.LOGDEBUG)

    ip = LGTV(log=tools.simpleLog).discover_ip(tries=5)

    if ip is None:
        tools.notifyLog("No LG Smart TV found.")
        tools.dialogOSD(__LS__(30050))
        return

    __addon__.setSetting('lg_host', ip)
    tools.notifyLog('Found LG Smart TV at %s' % ip)
    tools.dialogOSD(__LS__(30051) % ip)
Пример #15
0
 def getStereoscopicMode(self):
     mode = {
         "off": 'OFF',
         "split_vertical": 'SBS',
         "split_horizontal": 'TAB',
         "row_interleaved": 'INTERLEAVE',
         "hardware_based": 'HW',
         "anaglyph_cyan_red": 'CR',
         "anaglyph_green_magenta": 'GM',
         "monoscopic": 'MONO'
     }
     query = {
         "jsonrpc": "2.0",
         "method": "GUI.GetProperties",
         "params": {
             "properties": ["stereoscopicmode"]
         },
         "id": 1
     }
     _poll = WAIT_FOR_MODE_SELECT
     while _poll > 0:
         try:
             res = json.loads(
                 xbmc.executeJSONRPC(json.dumps(query, encoding='utf-8')))
             if 'result' in res and 'stereoscopicmode' in res['result']:
                 res = res['result']['stereoscopicmode'].get('mode')
                 if self.mode3D != mode[res]:
                     tools.notifyLog('Stereoscopic mode has changed to %s' %
                                     (mode[res]))
                     self.mode3D = mode[res]
                     return True
                 _poll -= 1
                 xbmc.sleep(1000)
             else:
                 break
         except SystemExit:
             tools.notifyLog(
                 'System will terminate this script, closing it.',
                 level=xbmc.LOGERROR)
             break
     tools.notifyLog('Could not determine steroscopic mode',
                     level=xbmc.LOGERROR)
     return False
Пример #16
0
    def sendCommand(self, sequence, own_sequence):
        try:
            self.getSettings()
            if self.lg_own_seqs_enabled:
                sequence = own_sequence
                tools.notifyLog("Sending user sequence %s" % (sequence), level=xbmc.LOGDEBUG)

            for code in sequence:
                if self.Remote.session_id is None:
                    self.Remote.get_session_id(self.lg_pairing_key)
                # let smart models time for response ;)
                xbmc.sleep(self.lg_key_delay)
                tools.notifyLog(
                    "%s msec delayed, sending keycode %s. Response: %s."
                    % (self.lg_key_delay, code, self.Remote.handle_key_input(code)),
                    level=xbmc.LOGDEBUG,
                )

        except self.Remote.NoConnectionToHostException:
            self.sessionEstablished = False
            tools.notifyLog("No connection to host on %s" % (self.lg_host), level=xbmc.LOGERROR)
Пример #17
0
    def sendCommand(self, sequence, own_sequence):
        try:
            self.getSettings()
            if self.lg_own_seqs_enabled:
                sequence = own_sequence
                tools.notifyLog('Sending user sequence %s' % (sequence),
                                level=xbmc.LOGDEBUG)

            for code in sequence:
                if self.Remote.session_id is None:
                    self.Remote.get_session_id(self.lg_pairing_key)
                # let smart models time for response ;)
                xbmc.sleep(self.lg_key_delay)
                tools.notifyLog(
                    '%s msec delayed, sending keycode %s. Response: %s.' %
                    (self.lg_key_delay, code,
                     self.Remote.handle_key_input(code)),
                    level=xbmc.LOGDEBUG)

        except self.Remote.NoConnectionToHostException:
            self.sessionEstablished = False
            tools.notifyLog('No connection to host on %s' % (self.lg_host),
                            level=xbmc.LOGERROR)
Пример #18
0
 def getStereoscopicMode(self):
     mode = {
         "off": "OFF",
         "split_vertical": "SBS",
         "split_horizontal": "TAB",
         "row_interleaved": "INTERLEAVE",
         "hardware_based": "HW",
         "anaglyph_cyan_red": "CR",
         "anaglyph_green_magenta": "GM",
         "monoscopic": "MONO",
     }
     query = {
         "jsonrpc": "2.0",
         "method": "GUI.GetProperties",
         "params": {"properties": ["stereoscopicmode"]},
         "id": 1,
     }
     _poll = WAIT_FOR_MODE_SELECT
     while _poll > 0:
         try:
             res = json.loads(xbmc.executeJSONRPC(json.dumps(query, encoding="utf-8")))
             if "result" in res and "stereoscopicmode" in res["result"]:
                 res = res["result"]["stereoscopicmode"].get("mode")
                 if self.mode3D != mode[res]:
                     tools.notifyLog("Stereoscopic mode has changed to %s" % (mode[res]))
                     self.mode3D = mode[res]
                     return True
                 _poll -= 1
                 xbmc.sleep(1000)
             else:
                 break
         except SystemExit:
             tools.notifyLog("System will terminate this script, closing it.", level=xbmc.LOGERROR)
             break
     tools.notifyLog("Could not determine steroscopic mode", level=xbmc.LOGERROR)
     return False
Пример #19
0
                            (self.lg_protocol, self.lg_pairing_key))

            while not self.Mon.abortRequested:
                _cycle = POLL_INTERVAL if self.sessionEstablished else WAIT_FOR_NEXT_CONNECT
                if self.Mon.waitForAbort(_cycle): break
                if self.Mon.settingsChanged: self.readSettings()
                if not self.sessionEstablished: self.getSettings(init=False)

        except interface.Interface.LGinNetworkNotFoundException:
            tools.notifyLog('LG Devices not found in network.',
                            level=xbmc.LOGERROR)
            tools.dialogOSD(__LS__(30050))
        except interface.Interface.LGProtocolWebOSException:
            tools.notifyLog('Device use WebOS on port 3000. Not supported.',
                            level=xbmc.LOGERROR)
            tools.dialogOSD(__LS__(30051))
        except interface.Interface.LGProtocollNotAcceptedException:
            tools.notifyLog('Protocol not supported.', level=xbmc.LOGERROR)
            tools.dialogOSD(__LS__(30052))
        except interface.Interface.NoConnectionToHostException:
            tools.notifyLog('No connection to host.', level=xbmc.LOGERROR)
            tools.dialogOSD(__LS__(30053) % (_host))
        except Exception, e:
            pass


RemoteService = Service()
RemoteService.poll()
del RemoteService
tools.notifyLog('Service finished')
Пример #20
0
__addonname__ = __addon__.getAddonInfo('name')
__addonID__ = __addon__.getAddonInfo('id')
__path__ = __addon__.getAddonInfo('path')
__version__ = __addon__.getAddonInfo('version')
__LS__ = __addon__.getLocalizedString

__IconConnected__ = xbmc.translatePath(
    os.path.join(__path__, 'resources', 'media', 'ok.png'))
__IconError__ = xbmc.translatePath(
    os.path.join(__path__, 'resources', 'media', 'fail.png'))
__IconDefault__ = xbmc.translatePath(
    os.path.join(__path__, 'resources', 'media', 'default.png'))

try:
    if sys.argv[1] == 'scan':
        tools.notifyLog("Scanning for LG Smart TV Devices...",
                        level=xbmc.LOGDEBUG)

        _host = None if __addon__.getSetting(
            'lg_host') == '' else __addon__.getSetting('lg_host')
        _port = 8080 if __addon__.getSetting('lg_port') == '' else int(
            __addon__.getSetting('lg_port'))
        Remote = interface.Interface(host=_host, port=_port, protocol=None)
        _host = Remote.host
        _protocol = Remote._protocol
        tools.notifyLog('Device (IP %s protocol %s) found' %
                        (_host, _protocol.upper()),
                        level=xbmc.LOGDEBUG)
        #
        # input pairing key if not exists
        #
        _pairing_key = None if __addon__.getSetting(
Пример #21
0
            while not self.Mon.abortRequested:
                _cycle = POLL_INTERVAL if self.sessionEstablished else WAIT_FOR_NEXT_CONNECT
                if self.Mon.waitForAbort(_cycle):
                    break
                if self.Mon.settingsChanged:
                    self.readSettings()
                if not self.sessionEstablished:
                    self.getSettings(init=False)

        except interface.Interface.LGinNetworkNotFoundException:
            tools.notifyLog("LG Devices not found in network.", level=xbmc.LOGERROR)
            tools.dialogOSD(__LS__(30050))
        except interface.Interface.LGProtocolWebOSException:
            tools.notifyLog("Device use WebOS on port 3000. Not supported.", level=xbmc.LOGERROR)
            tools.dialogOSD(__LS__(30051))
        except interface.Interface.LGProtocollNotAcceptedException:
            tools.notifyLog("Protocol not supported.", level=xbmc.LOGERROR)
            tools.dialogOSD(__LS__(30052))
        except interface.Interface.NoConnectionToHostException:
            tools.notifyLog("No connection to host.", level=xbmc.LOGERROR)
            tools.dialogOSD(__LS__(30053) % (_host))
        except Exception, e:
            pass


RemoteService = Service()
RemoteService.poll()
del RemoteService
tools.notifyLog("Service finished")
Пример #22
0
from resources.lib import tools

__addon__ = xbmcaddon.Addon()
__addonname__ = __addon__.getAddonInfo('name')
__addonID__ = __addon__.getAddonInfo('id')
__path__ = __addon__.getAddonInfo('path')
__version__ = __addon__.getAddonInfo('version')
__LS__ = __addon__.getLocalizedString

__IconConnected__ = xbmc.translatePath(os.path.join( __path__,'resources', 'media', 'ok.png'))
__IconError__ = xbmc.translatePath(os.path.join( __path__,'resources', 'media', 'fail.png'))
__IconDefault__ = xbmc.translatePath(os.path.join( __path__,'resources', 'media', 'default.png'))

try:
    if sys.argv[1] == 'scan':
        tools.notifyLog("Scanning for LG Smart TV Devices...", level=xbmc.LOGDEBUG)

        _host = None if __addon__.getSetting('lg_host') == '' else __addon__.getSetting('lg_host')
        _port = 8080 if __addon__.getSetting('lg_port') == '' else int(__addon__.getSetting('lg_port'))
        Remote = interface.Interface(host=_host, port=_port, protocol=None)
        _host = Remote.host
        _protocol = Remote._protocol
        tools.notifyLog('Device (IP %s protocol %s) found' % (_host, _protocol.upper()), level=xbmc.LOGDEBUG)
        #
        # input pairing key if not exists
        #
        _pairing_key = None if __addon__.getSetting('lg_pairing_key') == '' else __addon__.getSetting('lg_pairing_key')
        if _pairing_key is None:
            kb = xbmc.Keyboard('', __LS__(30030))
            kb.doModal()
            if kb.isConfirmed() and kb.getText() != '':  _pairing_key = kb.getText()
Пример #23
0
    def readSettings(self):
        self.lg_host = __addon__.getSetting('lg_host')
        self.lg_host = None if self.lg_host == '' else self.lg_host
        self.lg_pairing_key = __addon__.getSetting('lg_pairing_key')
        self.enable_discovery = __addon__.getSetting(
            'lg_enable_discovery') == 'true'
        self.force_discovery = __addon__.getSetting(
            'lg_force_discovery') == 'true'
        self.switch_on_pause = __addon__.getSetting(
            'lg_switch_on_pause') == 'true'
        self.switch_on_resume = __addon__.getSetting(
            'lg_switch_on_resume') == 'true'
        self.pause_while_switching = __addon__.getSetting(
            'lg_pause_while_switching') == 'true'

        host_was_empty = self.lg_host is None or self.force_discovery
        if host_was_empty and self.enable_discovery:
            self.discover()

        if self.lg_host is None:
            # no host found
            tools.notifyLog(
                "No LG TV found on network and no TV is configured in settings",
                level=xbmc.LOGWARNING)
            tools.notifyOSD(__addonname__, __LS__(30101), icon=__IconError__)
            self.abortRequested = True
            return

        try:
            success = self.lgtv.connect(self.lg_host, __addonname__)
            if not success:
                raise Exception("LGTV.connect() failed")
            tools.notifyLog("Connected to TV at %s" % self.lg_host)
            #tools.notifyOSD(__addonname__, __LS__(30102) % self.lg_host, icon=__IconConnected__)
            self.lgtv.toast(__LS__(30103), icon_file=__IconKodi__)
        except Exception as e:
            # try new discovery
            if not host_was_empty and self.enable_discovery:
                # we didn't discover before
                self.discover()

                # try this newly discovered host
                if self.lg_host is not None:
                    try:
                        success = self.lgtv.connect(self.lg_host,
                                                    __addonname__)
                        if not success:
                            raise Exception("LGTV.connect() failed")
                        tools.notifyLog("Connected to TV at %s" % self.lg_host)
                        #tools.notifyOSD(__addonname__, __LS__(30102) % self.lg_host, icon=__IconConnected__)
                        self.lgtv.toast(__LS__(30103), icon_file=__IconKodi__)
                    except Exception as e:
                        tools.notifyLog("Could not connect to TV at %s: %s" %
                                        (self.lg_host, str(e)),
                                        level=xbmc.LOGERROR)
                        tools.notifyOSD(__addonname__,
                                        __LS__(30100) % self.lg_host,
                                        icon=__IconError__)
                        self.abortRequested = True
            else:
                # host found via recovery could not be connected to
                tools.notifyLog("Could not connect to TV at %s: %s" %
                                (self.lg_host, str(e)),
                                level=xbmc.LOGERROR)
                tools.notifyOSD(__addonname__,
                                __LS__(30100) % self.lg_host,
                                icon=__IconError__)
                self.abortRequested = True