Ejemplo n.º 1
0
    def testNewSessionDropsPreviousSettingsOfOtherAttrs(self):
        
        c = Collector(MockSyncedGraph(PREFIX + '''

        udmx:c1 :connectedTo dev:colorStripRed .
        udmx:c2 :connectedTo dev:colorStripGreen .
        udmx:c3 :connectedTo dev:colorStripBlue .
        udmx:c4 :connectedTo dev:colorStripMode .

        dev:colorStrip a :Device, :ChauvetColorStrip;
          :red dev:colorStripRed;
          :green dev:colorStripGreen;
          :blue dev:colorStripBlue;
          :mode dev:colorStripMode .

        dmx0:c1 :connectedTo dev:inst1Brightness .
        dev:inst1 a :Device, :Dimmer;
          :brightness dev:inst1Brightness .
        '''), outputs=[self.dmx0, self.udmx])

        c.setAttrs('client1', 'sess1',
                   [(DEV['colorStrip'], L9['color'], '#ff0000')])
        c.setAttrs('client1', 'sess2',
                   [(DEV['colorStrip'], L9['color'], '#00ff00')])

        self.assertEqual([[255, 0, 0, 215], 'flush',
                          [0, 255, 0, 215], 'flush'], self.udmx.updates)
Ejemplo n.º 2
0
    def testRoutesColorOutput(self):
        c = Collector(self.config, outputs=[self.dmx0, self.udmx])

        c.setAttrs('client', 'sess1',
                   [(DEV['colorStrip'], L9['color'], '#00ff00')], t0)

        self.assertEqual([[215, 0, 255, 0], 'flush'], self.udmx.updates)
        self.assertEqual([[0, 0, 0, 0], 'flush'], self.dmx0.updates)
Ejemplo n.º 3
0
    def testNewSessionReplacesPreviousOutput(self):
        # ..as opposed to getting max'd with it
        c = Collector(self.config, outputs=[self.dmx0, self.udmx])

        c.setAttrs('client1', 'sess1', [(DEV['inst1'], L9['brightness'], .8)])
        c.setAttrs('client1', 'sess2', [(DEV['inst1'], L9['brightness'], .5)])

        self.assertEqual([[204], 'flush', [127], 'flush'], self.dmx0.updates)
Ejemplo n.º 4
0
    def testClientsOnDifferentOutputs(self):
        c = Collector(self.config, outputs=[self.dmx0, self.udmx])

        c.setAttrs('client1', 'sess1', [(DEV['colorStrip'], L9['color'], '#aa0000')])
        c.setAttrs('client2', 'sess1', [(DEV['inst1'], L9['brightness'], .5)])

        # ok that udmx is flushed twice- it can screen out its own duplicates
        self.assertEqual([[170, 0, 0, 215], 'flush',
                          [170, 0, 0, 215], 'flush'], self.udmx.updates)
        self.assertEqual([[127], 'flush'], self.dmx0.updates)
Ejemplo n.º 5
0
    def testOutputMaxOfTwoClients(self):
        c = Collector(self.config, outputs=[self.dmx0, self.udmx])

        c.setAttrs('client1', 'sess1',
                   [(DEV['colorStrip'], L9['color'], '#ff0000')])
        c.setAttrs('client2', 'sess1',
                   [(DEV['colorStrip'], L9['color'], '#333333')])

        self.assertEqual([[255, 0, 0, 215], 'flush',
                          [255, 51, 51, 215], 'flush'],
                         self.udmx.updates)
        self.assertEqual([], self.dmx0.updates)
Ejemplo n.º 6
0
    def testRepeatedAttributesInOneRequestGetResolved(self):
        c = Collector(self.config, outputs=[self.dmx0, self.udmx])
        
        c.setAttrs('client1', 'sess1', [
            (DEV['inst1'], L9['brightness'], .5),
            (DEV['inst1'], L9['brightness'], .3),
        ])
        self.assertEqual([[127], 'flush'], self.dmx0.updates)

        c.setAttrs('client1', 'sess1', [
            (DEV['inst1'], L9['brightness'], .3),
            (DEV['inst1'], L9['brightness'], .5),
        ])
        self.assertEqual([[127], 'flush', [127], 'flush'], self.dmx0.updates)
Ejemplo n.º 7
0
    def testClientUpdatesAreCollected(self):
        # second call to setAttrs doesn't forget the first
        c = Collector(self.config, outputs=[self.dmx0, self.udmx])

        c.setAttrs('client1', 'sess1', [(DEV['inst1'], L9['brightness'], .5)])
        c.setAttrs('client1', 'sess1', [(DEV['inst1'], L9['brightness'], 1)])
        c.setAttrs('client1', 'sess1', [(DEV['colorStrip'], L9['color'], '#00ff00')])

        self.assertEqual([[0, 255, 0, 215], 'flush'], self.udmx.updates)
        self.assertEqual([[127], 'flush', [255], 'flush', [255], 'flush'], self.dmx0.updates)
Ejemplo n.º 8
0
 def testClientIsForgottenAfterAWhile(self):
     with freeze_time(datetime.datetime.now()) as ft:
         c = Collector(self.config, outputs=[self.dmx0, self.udmx])
         c.setAttrs('cli1', 'sess1', [(DEV['inst1'], L9['brightness'], .5)])
         ft.tick(delta=datetime.timedelta(seconds=1))
         c.setAttrs('cli2', 'sess1', [(DEV['inst1'], L9['brightness'], .2)])
         ft.tick(delta=datetime.timedelta(seconds=9.1))
         c.setAttrs('cli2', 'sess1', [(DEV['inst1'], L9['brightness'], .4)])
         self.assertEqual([[127], 'flush', [127], 'flush', [102], 'flush'],
                          self.dmx0.updates)
Ejemplo n.º 9
0
    def testNewSessionDropsPreviousSettingsOfOtherAttrs(self):
        c = Collector(MockSyncedGraph(PREFIX + THEATER + '''

        dev:colorStrip a :Device, :ChauvetColorStrip;
          :dmxUniverse udmx:; :dmxBase 1;
          :red dev:colorStripRed;
          :green dev:colorStripGreen;
          :blue dev:colorStripBlue;
          :mode dev:colorStripMode .

        dev:inst1 a :Device, :SimpleDimmer;
          :dmxUniverse dmx0:; :dmxBase 0;
          :level dev:inst1Brightness .
        '''), outputs=[self.dmx0, self.udmx])

        c.setAttrs('client1', 'sess1',
                   [(DEV['colorStrip'], L9['color'], '#ff0000')], t0)
        c.setAttrs('client1', 'sess2',
                   [(DEV['colorStrip'], L9['color'], '#00ff00')], t0)

        self.assertEqual([[215, 255, 0, 0], 'flush',
                          [215, 0, 255, 0], 'flush'], self.udmx.updates)
Ejemplo n.º 10
0
    def testClientOnSameOutputIsRememberedOverCalls(self):
        c = Collector(self.config, outputs=[self.dmx0, self.udmx])

        c.setAttrs('client1', 'sess1',
                   [(DEV['colorStrip'], L9['color'], '#080000')])
        c.setAttrs('client2', 'sess1',
                   [(DEV['colorStrip'], L9['color'], '#060000')])
        c.setAttrs('client1', 'sess1',
                   [(DEV['colorStrip'], L9['color'], '#050000')])

        self.assertEqual([[8, 0, 0, 215], 'flush',
                          [8, 0, 0, 215], 'flush',
                          [6, 0, 0, 215], 'flush'],
                         self.udmx.updates)
        self.assertEqual([], self.dmx0.updates)
Ejemplo n.º 11
0
    def testClientUpdatesAreNotMerged(self):
        # second call to setAttrs forgets the first
        c = Collector(self.config, outputs=[self.dmx0, self.udmx])
        t0 = time.time()
        c.setAttrs('client1', 'sess1', [(DEV['inst1'], L9['brightness'], .5)], t0)
        c.setAttrs('client1', 'sess1', [(DEV['inst1'], L9['brightness'], 1)], t0)
        c.setAttrs('client1', 'sess1', [(DEV['colorStrip'], L9['color'], '#00ff00')], t0)

        self.assertEqual([[215, 0, 0, 0], 'flush',
                          [215, 0, 0, 0], 'flush',
                          [215, 0, 255, 0], 'flush'],
                         self.udmx.updates)
        self.assertEqual([[127, 0, 0, 0], 'flush',
                          [255, 0, 0, 0], 'flush',
                          [0, 0, 0, 0], 'flush'],
                         self.dmx0.updates)
Ejemplo n.º 12
0
 def testClientIsForgottenAfterAWhile(self):
     with freeze_time(datetime.datetime.now()) as ft:
         c = Collector(self.config, outputs=[self.dmx0, self.udmx])
         c.setAttrs('cli1', 'sess1', [(DEV['inst1'], L9['brightness'], .5)],
                    time.time())
         ft.tick(delta=datetime.timedelta(seconds=1))
         # this max's with cli1's value so we still see .5
         c.setAttrs('cli2', 'sess1', [(DEV['inst1'], L9['brightness'], .2)], 
                    time.time())
         ft.tick(delta=datetime.timedelta(seconds=9.1))
         # now cli1 is forgotten, so our value appears
         c.setAttrs('cli2', 'sess1', [(DEV['inst1'], L9['brightness'], .4)], 
                    time.time())
         self.assertEqual([[127, 0, 0, 0], 'flush',
                           [127, 0, 0, 0], 'flush',
                           [102, 0, 0, 0], 'flush'],
                          self.dmx0.updates)