import time
import math
import random
from twisted.internet import reactor
from twisted.internet.protocol import ClientCreator
from twisted.internet.protocol import ClientFactory
from twisted.internet.protocol import Protocol

def Dummy(dummy_funct):
    """
    Return a class generating dummy data describe by the *dummy_funct* function.
    *dummy_funct* receive the time as parameter and return one value
    """

    class _Dummy(object):
        def acquire_value(self):
            return dummy_funct(time.time())
    return _Dummy

# TemperatureSensor = Dummy(lambda t:
#         math.sin(t) * 15 + 20 + 0.5 * (random.random() - 0.5))
AirSensor = Dummy(lambda t:
        math.sin(t) * 15 + 20 + 0.5 * (random.random() - 0.5))

ButaneSensor = Dummy(lambda t:
        math.sin(t) * 15 + 20 + 0.5 * (random.random() - 0.5))

COSensor = Dummy(lambda t:
        math.sin(t) * 15 + 20 + 0.5 * (random.random() - 0.5))

CameraSensor = Dummy(lambda t:
        math.sin(t) * 15 + 20 + 0.5 * (random.random() - 0.5))

DoorSensor = Dummy(lambda t:
        math.sin(t) * 15 + 20 + 0.5 * (random.random() - 0.5))

ElectricCurrentSensor = Dummy(lambda t:
        math.sin(t) * 15 + 20 + 0.5 * (random.random() - 0.5))

Sensor = Dummy(lambda t:
        math.sin(t) * 15 + 20 + 0.5 * (random.random() - 0.5))

Sensor = Dummy(lambda t:
        math.sin(t) * 15 + 20 + 0.5 * (random.random() - 0.5))

Sensor = Dummy(lambda t:
        math.sin(t) * 15 + 20 + 0.5 * (random.random() - 0.5))

Sensor = Dummy(lambda t:
        math.sin(t) * 15 + 20 + 0.5 * (random.random() - 0.5))

Sensor = Dummy(lambda t:
        math.sin(t) * 15 + 20 + 0.5 * (random.random() - 0.5))

class SensorConnection(Protocol):
    def __init__(self, sensor, filter_id):
        self.sensor = sensor
        self.filter_id = filter_id

    def dataReceived(self, data):
        print "Server said:", data

# Analyse
        org = data[6:8]
        value = data[8:16]
        sensor_id = data[16:24]
        status = data[24:26]

        if sensor_id == self.filter_id:
            self.sensor.emit_value(value)

class SensorConnectionFactory(ClientFactory):
    def __init__(self, sensor, filter_id):
        self.sensor = sensor
        self.filter_id = filter_id

    def clientConnectionFailed(self, connector, reason):
        print "Connection failed - goodbye!"
# Do something ?

    def clientConnectionLost(self, connector, reason):
        print "Connection lost - goodbye!"
# Do something ?

    def buildProtocol(self, addr):
        return SensorConnection(self.sensor, self.filter_id)

class Sensor(object):
    sensor_host = '134.214.106.23'
    sensor_port = 5000
    sensor_id = 0

    def __init__(self):
        super(Sensor, self).__init__()
        reactor.connectTCP(type(self).sensor_host,
                type(self).sensor_port,
                SensorConnectionFactory(self,
                    type(self).sensor_id))

    def start(self):
        super(Sensor, self).start()

    def close(self):
        super(Sensor, self).close()

if __name__ == '__main__':
    reactor.run()

@@ -636,16 +636,90 @@
 - 0.5))%0A
+%0A#DoorSensor = Dummy(%0A#        True if random.random() %3E 0.5 else False)%0A%0A
 AirSenso
@@ -1083,18 +1083,192 @@
  0.5))%0A%0A
-Do
+ElectricCurrentSensor = Dummy(%0A        True if random.random() %3E 0.5 else False)%0A%0ALightButtonSensor = Dummy(%0A        True if random.random() %3E 0.5 else False)%0A%0ALuminosityExteri
 orSensor
@@ -1346,39 +1346,31 @@
 () - 0.5))%0A%0A
-ElectricCurrent
+Methane
 Sensor = Dum
@@ -1438,32 +1438,40 @@
 ndom() - 0.5))%0A%0A
+Moisture
 Sensor = Dummy(l
@@ -1471,32 +1471,32 @@
 Dummy(lambda t:%0A
-
         math.sin
@@ -1535,32 +1535,49 @@
 ndom() - 0.5))%0A%0A
+OutsideBrightness
 Sensor = Dummy(l
@@ -1577,32 +1577,32 @@
 Dummy(lambda t:%0A
-
         math.sin
@@ -1641,32 +1641,39 @@
 ndom() - 0.5))%0A%0A
+Propane
 Sensor = Dummy(l
@@ -1673,32 +1673,32 @@
 Dummy(lambda t:%0A
-
         math.sin
@@ -1737,38 +1737,44 @@
 ndom() - 0.5))%0A%0A
-Sensor
+RainForecast
  = Dummy(lambda 
@@ -1840,16 +1840,23 @@
  0.5))%0A%0A
+Shutter
 Sensor =
@@ -1936,16 +1936,417 @@
  0.5))%0A%0A
+SmokeSensor = Dummy(lambda t:%0A        math.sin(t) * 15 + 20 + 0.5 * (random.random() - 0.5))%0A%0ASoundSensor = Dummy(lambda t:%0A        math.sin(t) * 15 + 20 + 0.5 * (random.random() - 0.5))%0A%0ATemperatureForecast = Dummy(lambda t:%0A        math.sin(t) * 15 + 20 + 0.5 * (random.random() - 0.5))%0A%0ATemperatureExteriorSensor = Dummy(lambda t:%0A        math.sin(t) * 15 + 20 + 0.5 * (random.random() - 0.5))%0A%0A%0A%0A%0A
 class Se

add all sensor type