This file is indexed.

/usr/share/pyshared/coherence/backends/light.py is in python-coherence 0.6.6.2-8.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
# Licensed under the MIT license
# http://opensource.org/licenses/mit-license.php

# Copyright 2008, Frank Scholz <coherence@beebits.net>

import coherence.extern.louie as louie

from coherence.upnp.core.utils import generalise_boolean

from coherence.backend import Backend

class SimpleLight(Backend):

    """ this is a backend for a simple light
        that only can be switched on or off

        therefore we need to inform Coherence
        about the state, and a method to change it

        everything else is done by Coherence
    """

    implements = ['BinaryLight']
    logCategory = 'simple_light'

    def __init__(self, server, **kwargs):
        self.name = kwargs.get('name','SimpleLight')
        self.server = server
        self.state = 0 # we start switched off
        louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self)

    def upnp_init(self):
        if self.server:
            self.server.switch_power_server.set_variable(0, 'Target', self.state)
            self.server.switch_power_server.set_variable(0, 'Status', self.state)

    def upnp_SetTarget(self,**kwargs):
        self.info('upnp_SetTarget %r', kwargs)
        self.state = int(generalise_boolean(kwargs['NewTargetValue']))
        if self.server:
            self.server.switch_power_server.set_variable(0, 'Target', self.state)
            self.server.switch_power_server.set_variable(0, 'Status', self.state)
        print "we have been switched to state", self.state
        return {}


class BetterLight(Backend):

    implements = ['DimmableLight']
    logCategory = 'better_light'

    def __init__(self, server, **kwargs):
        self.name = kwargs.get('name','BetterLight')
        self.server = server
        self.state = 0 # we start switched off
        self.loadlevel = 50 # we start with 50% brightness

        louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self)

    def upnp_init(self):
        if self.server:
            self.server.switch_power_server.set_variable(0, 'Target', self.state)
            self.server.switch_power_server.set_variable(0, 'Status', self.state)
            self.server.dimming_server.set_variable(0, 'LoadLevelTarget', self.loadlevel)
            self.server.dimming_server.set_variable(0, 'LoadLevelStatus', self.loadlevel)

    def upnp_SetTarget(self,**kwargs):
        self.info('upnp_SetTarget %r', kwargs)
        self.state = int(generalise_boolean(kwargs['NewTargetValue']))
        if self.server:
            self.server.switch_power_server.set_variable(0, 'Target', self.state)
            self.server.switch_power_server.set_variable(0, 'Status', self.state)
        print "we have been switched to state", self.state
        return {}

    def upnp_SetLoadLevelTarget(self,**kwargs):
        self.info('SetLoadLevelTarget %r', kwargs)
        self.loadlevel = int(kwargs['NewLoadlevelTarget'])
        self.loadlevel = min(max(0,self.loadlevel),100)
        if self.server:
            self.server.dimming_server.set_variable(0, 'LoadLevelTarget', self.loadlevel)
            self.server.dimming_server.set_variable(0, 'LoadLevelStatus', self.loadlevel)
        print "we have been dimmed to level", self.loadlevel
        return {}


if __name__ == '__main__':

    from coherence.base import Coherence

    def main():
        config = {}
        config['logmode'] = 'warning'
        c = Coherence(config)
        f = c.add_plugin('SimpleLight')
        f = c.add_plugin('BetterLight')

    from twisted.internet import reactor
    reactor.callWhenRunning(main)
    reactor.run()