示例#1
0
 def __init__(self, pluginId, pluginDisplayName, pluginVersion,
              pluginPrefs):
     indigo.PluginBase.__init__(self, pluginId, pluginDisplayName,
                                pluginVersion, pluginPrefs)
     self.plexApi = PlexApi(pluginPrefs.get('address'),
                            pluginPrefs.get('port'))
     self.debug = pluginPrefs.get('showDebugInfo', False)
示例#2
0
    def testGetClientMachineIds_no_results(self):
        real = PlexApi("foo", "bar")
        real.getStatusSession = Mock(return_value='''
                <MediaContainer size="0">
                </MediaContainer>
            ''')

        machineIds = real.getClientMachineIds()
        assert isinstance(machineIds, list)
        self.assertEqual(0, len(machineIds))
示例#3
0
    def testGetClientMachineIds(self):
        real = PlexApi("foo", "bar")
        machineId1 = '''TestMI1'''
        machineId2 = '''TestMI2'''
        real.getStatusSession = Mock(return_value=('''
                <MediaContainer size="1">
                    <Video>
                        <Player machineIdentifier="%s" platform="Plex Home Theater" product="Plex Home Theater" state="paused" title="HTPC" />
                        <Player machineIdentifier="%s" platform="Plex Home Theater" product="Plex Home Theater" state="paused" title="HTPC" />
                    </Video>
                </MediaContainer>
            ''' % (machineId1, machineId2)))

        machineIds = real.getClientMachineIds()
        assert isinstance(machineIds, list)
        self.assertEqual(2, len(machineIds))
        self.assertEqual(machineId1, machineIds[0])
        self.assertEqual(machineId2, machineIds[1])
示例#4
0
    def testGetClientState(self):
        real = PlexApi("foo", "bar")
        machineId1 = 'TestMI1'
        machineId2 = 'TestMI2'
        real.getStatusSession = Mock(return_value=('''
                <MediaContainer size="1">
                    <Video>
                        <Player machineIdentifier="%s" platform="Plex Home Theater" product="Plex Home Theater" state="paused" title="HTPC" />
                        <Player machineIdentifier="%s" platform="Plex Home Theater" product="Plex Home Theater" state="playing" title="HTPC" />
                    </Video>
                </MediaContainer>
            ''' % (machineId1, machineId2)))

        state = real.getClientState(machineId1)
        self.assertEqual('paused', state)
        state = real.getClientState(machineId2)
        self.assertEqual('playing', state)
        state = real.getClientState('unknownMI')
        self.assertEqual('client_offline', state)
示例#5
0
 def closedPrefsConfigUi(self, valuesDict, userCancelled):
     if not userCancelled:
         address = valuesDict.get(u"address")
         port = valuesDict.get(u"port")
         self.debugLog(u"Plex Server " + address + ":" + port)
         self.plexApi = PlexApi(address, port)
示例#6
0
class Plugin(indigo.PluginBase):
    ########################################
    def __init__(self, pluginId, pluginDisplayName, pluginVersion,
                 pluginPrefs):
        indigo.PluginBase.__init__(self, pluginId, pluginDisplayName,
                                   pluginVersion, pluginPrefs)
        self.plexApi = PlexApi(pluginPrefs.get('address'),
                               pluginPrefs.get('port'))
        self.debug = pluginPrefs.get('showDebugInfo', False)

    def __del__(self):
        indigo.PluginBase.__del__(self)

    ########################################
    def startup(self):
        self.debugLog(u"startup called")

    def shutdown(self):
        self.debugLog(u"shutdown called")

    def deviceStartComm(self, device):
        self.debugLog(u"Starting device: " + device.name)

    def closedPrefsConfigUi(self, valuesDict, userCancelled):
        if not userCancelled:
            address = valuesDict.get(u"address")
            port = valuesDict.get(u"port")
            self.debugLog(u"Plex Server " + address + ":" + port)
            self.plexApi = PlexApi(address, port)

#######################################

    def clientListGenerator(self,
                            filter="",
                            valuesDict=None,
                            typeId="",
                            targetId=0):
        return self.plexApi.getClientMachineIds()

    def runConcurrentThread(self):
        try:
            while True:
                for dev in indigo.devices.iter("self"):
                    if not dev.enabled or not dev.configured:
                        continue

                    if dev.deviceTypeId == u"plexClient":
                        clientId = dev.pluginProps.get('clientId', None)
                        state = self.plexApi.getClientState(clientId)
                        # self.debugLog(u"runConcurrentThread loop! " + state)
                        self.updateDeviceState(dev, 'mode', state)

                self.sleep(1)
        except self.StopThread:
            pass

    def updateDeviceState(self, device, state, newValue):
        if newValue != device.states[state]:
            try:
                self.debugLog(u"updateDeviceState: Updating device " +
                              device.name + u" state: " + str(state) + u" = " +
                              str(newValue))
            except Exception, e:
                self.debugLog(
                    u"updateDeviceState: Updating device " + device.name +
                    u" state: (Unable to display state due to error: " +
                    str(e) + u")")

            device.updateStateOnServer(key=state, value=newValue)