コード例 #1
0
class MoistureReducing(module.Base):
    public_name = 'Humidite automatique'

    fan_actuator = use_module('FanActuator')
    moisture_sensor = use_module('MoistureSensor')

    moisture = fields.proxy.readable('moisture', 'MoistureSensor', 'sensor')
    fan = fields.proxy.readable('fan', 'FanActuator', 'fan')

    class moisture_value_limit(fields.syntax.Percentage, fields.io.Writable,
                               fields.io.Readable, fields.syntax.Numeric,
                               fields.persistant.Volatile, fields.Base):
        update_rate = 421337
        public_name = 'Humidité maximale autorisée'
        init_value = 45.0

    class controller(fields.Base):
        update_rate = 15  # update for half the sensor's time

        def always(self):
            logger = self.module.logger
            moisture_value = self.module.moisture_sensor.sensor()[1]
            moisture_value_limit = self.module.moisture_value_limit()[1]
            if moisture_value is None:
                return
            if moisture_value > moisture_value_limit:
                self.module.fan_actuator.fan(True)
                logger.info('moisture (%s %%) over limit (%s %%), running fan',
                            moisture_value, moisture_value_limit)
            else:
                self.module.fan_actuator.fan(False)
                logger.info(
                    'moisture (%s %%) under limit (%s %%), stopping fan',
                    moisture_value, moisture_value_limit)
コード例 #2
0
ファイル: local_module.py プロジェクト: jmcomets/KHome
class BabyMonitor(module.Base):
    update_rate = 4.2
    sound_sensor = use_module('SoundSensor')
    alarm = use_module('Alarm')
    public_name = 'Babyphone'

    son = fields.proxy.readable('sound', 'SoundSensor', 'sound')

    class decibel_value(fields.io.Writable, fields.io.Readable,
            fields.syntax.BoundNumeric, fields.persistant.Database,
            fields.Base):
        public_name = 'Seuil de détection du bébé'
        update_rate = 421337
        lower_bound = 10
        upper_bound = 150
        init_value = 97.

    class alert_message(fields.io.Readable, fields.io.Writable,
            fields.syntax.String, fields.persistant.Database, fields.Base):
        public_name = 'Message d\'alerte à envoyer'
        update_rate = 421337
        init_value = 'Le bébé est en train de pleurer.'

    class controller(fields.io.Hidden, fields.Base):
        sleep_on_start = 1

        def always(self):
            try:
                decibel_value = self.module.decibel_value()[1]
                sound_now = self.module.sound_sensor.sound()[1]
            except TypeError as e:
                self.module.logger.exception(e)
            else:
                if sound_now > decibel_value:
                    self.module.alarm.message(self.module.alert_message()[1])
コード例 #3
0
class GazController(module.Base):
    public_name = 'Control du gaz'
    update_rate = 10

    co_gaz = use_module('COSensor')
    alarm = use_module('Alarm')

    butane = fields.proxy.basic('butane', 'ButaneGaz', 'butane')
    butane_actuator = fields.proxy.basic('butane_actuator', 'ButaneGaz', 'but_actuator')
    butane_lie = fields.proxy.basic('butane_lie', 'ButaneGaz', 'limit_value_but')
    butane_alarm = fields.proxy.basic('butane_alarm', 'ButaneGaz', 'message_but')

    methane = fields.proxy.basic('methane', 'MethaneGaz', 'methane')
    methane_actuator = fields.proxy.basic('methane_actuator', 'MethaneGaz', 'meth_actuator')
    methane_lie = fields.proxy.basic('methane_lie', 'MethaneGaz', 'limit_value_meth')
    methane_alarm = fields.proxy.basic('methane_alarm', 'MethaneGaz', 'message_meth')

    propane = fields.proxy.basic('propane', 'PropaneGaz', 'propane')
    propane_actuator = fields.proxy.basic('propane_actuator', 'PropaneGaz', 'prop_actuator')
    propane_lie = fields.proxy.basic('propane_lie', 'PropaneGaz', 'limit_value_prop')
    propane_alarm = fields.proxy.basic('propane_alarm', 'PropaneGaz', 'message_prop')

    co = fields.proxy.basic('co', 'COSensor', 'co')
    co_lie = fields.proxy.basic('co_lie', 'COSensor', 'limit_value_co')
    co_alarm = fields.proxy.basic('co_alarm', 'COSensor', 'message_co')

    alarm = fields.proxy.basic('alarm', 'Alarm', 'alarm')
コード例 #4
0
class COSensor(module.Base):
    update_rate = 1000
    public_name = 'Capteur CO'

    alarm = use_module('Alarm')

    class co(fields.sensor.CO, fields.syntax.Numeric, fields.io.Graphable,
             fields.persistant.Database, fields.Base):
        update_rate = 60
        public_name = 'Taux de CO (ppm)'

    class limit_value_co(fields.syntax.Numeric, fields.io.Readable,
                         fields.persistant.Database, fields.Base):
        public_name = 'Limite CO (ppm)'
        init_value = 5.00

    class message_co(fields.syntax.String, fields.io.Readable,
                     fields.io.Writable, fields.persistant.Database,
                     fields.Base):
        public_name = 'Message d\'alerte CO'
        init_value = 'Au #secours il y a la masse de #CO #YOLO #pompier'

    class security(fields.Base):
        update_rate = 60

        def always(self):
            try:
                sensor = self.module.co()[1]
                lie = self.module.limit_value_co()[1]
                message = self.module.message_co()[1]
            except TypeError:
                pass
            else:
                if sensor > lie:
                    self.module.alarm.message(message)
コード例 #5
0
ファイル: local_module.py プロジェクト: jmcomets/KHome
class Door(module.Base):
    public_name = 'Porte automatique'
    update_rate = 10

    twitter = use_module('twitter')

    class state(fields.sensor.Contact, fields.actuator.Door,
                fields.persistant.Database, fields.Base):
        public_name = 'État de la porte'

        def set_value(self, time, value):
            if value:
                self.module.twitter.tweet('La porte est correctement fermée.')
            else:
                self.module.twitter.tweet('La porte est ouverte #cambriolage')

            return super(Door.state, self).set_value(time, value)
コード例 #6
0
class MethaneGaz(module.Base):
    update_rate = 1000
    public_name = 'Méthane'

    alarm = use_module('Alarm')

    class methane(fields.sensor.Methane, fields.syntax.Numeric,
                  fields.io.Graphable, fields.persistant.Database,
                  fields.Base):
        update_rate = 60
        public_name = 'Taux de méthane (% dans l\'air)'

    class limit_value_meth(fields.syntax.Numeric, fields.io.Readable,
                           fields.persistant.Database, fields.Base):
        public_name = 'LIE Méthane'
        init_value = 5.00

    class message_meth(fields.syntax.String, fields.io.Readable,
                       fields.io.Writable, fields.persistant.Database,
                       fields.Base):
        public_name = 'Message d\'alerte methane'
        init_value = 'Au #secours il y a la masse de #methane #YOLO'

    class meth_actuator(fields.actuator.Methane, fields.syntax.Boolean,
                        fields.io.Readable, fields.persistant.Volatile,
                        fields.Base):
        public_name = 'Vanne de méthane'

    class security(fields.Base):
        update_rate = 60

        def always(self):
            try:
                sensor = self.module.methane()[1]
                lie = self.module.limit_value_meth()[1]
                message = self.module.message_meth()[1]
            except TypeError:
                pass
            else:
                if sensor > lie:
                    self.module.alarm.message(message)
                    self.module.meth_actuator(False)