# Path: Devices/Device.py
# class Device(threading.Thread):
# 
#     def __init__(self, sinterval):
#         """ Initializes device with the sampling interval. """
#         threading.Thread.__init__(self)
#         self.queues = []
#         self.sinterval = float(sinterval)
# 
#     def deviceFactory(device_type, name, ip, port,
#                       channels, sinterval, username = None, password = None):
#         """ Device factory that instantiates the following types of devices: 
#             1. Eaton
#             2. Veris
#             3. Zwave (SmartSwitch, TemperatureSensor, LightSensor),
#             4. Raritan
#             Note: Only Raritan requires that the username and password be specified
#             """
#         import LabSenseModbus.Eaton.EatonDevice as EatonDevice
#         import LabSenseModbus.Veris.VerisDevice as VerisDevice
#         import LabSenseZwave.ZwaveDevice as ZwaveDevice
#         import LabSenseRaritan.RaritanDevice as RaritanDevice
# 
#         if device_type == "Eaton":
#             return EatonDevice.EatonDevice(name, 
#                                            ip,
#                                            port,
#                                            channels,
#                                            sinterval)
#         elif device_type == "Veris":
#             return VerisDevice.VerisDevice(name,
#                                            ip,
#                                            port,
#                                            channels,
#                                            sinterval)
#         elif device_type == "Raritan":
#             return RaritanDevice.RaritanDevice(name,
#                                            ip,
#                                            port,
#                                            channels,
#                                            sinterval,
#                                            username,
#                                            password)
#         elif device_type in ["SmartSwitch",
#                              "LightSensor",
#                              "TemperatureSensor"]:
#             return ZwaveDevice.ZwaveDevice(device_type,
#                                            name,
#                                            ip,
#                                            port,
#                                            channels,
#                                            sinterval)
#         else:
#             raise KeyError("Unrecognized Device Name " +
#                            device_type)
#     # Make deviceFactory static so Device does not have to be instantiated
#     # to run
#     deviceFactory = staticmethod(deviceFactory)
# 
#     def attach(self, queue):
#         if not queue in self.queues:
#             self.queues.append(queue)
# 
#     def detach(self, queue):
#         try:
#             self.queues.remove(queue)
#         except ValueError:
#             pass
# 
#     def notify(self, data):
#         if data:
#             for queue in self.queues:
#                 queue.put(data)
# 
#     def getData(self):
#         data = self.client.getData()
#         if data:
#             self.notify(data)
#             return data
# 
#     def run(self):
#         print "Starting Device"
#         while True:
#             self.getData()
#             time.sleep(self.sinterval)


import argparse                             # For parsing command line arguments
import sys                                  # For importing from common directory
import os                                   # For importing from common directory
import Queue                                # For communicating between datasinks and devices
    import LabSenseHandler.configReader as configReader
from RaritanClient import RaritanClient 
from Devices.Device import Device 
    from DataSinks.DataSink import DataSink

device_path = os.path.join(os.path.dirname(sys.argv[0]), "../..")
sys.path.insert(1, device_path)

class RaritanDevice(Device):

    def __init__(self, name, IP, PORT, channels, sinterval, username, password):
        super(RaritanDevice, self).__init__(sinterval)
        self.client = RaritanClient(name, IP, PORT, channels, username, password)

if __name__ == "__main__":

    # Import sinks and configReader

    # Parse command line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("config", help="Configuration path.")
    parser.add_argument("name", help="Name of device (name field in config.json file)")
    args = parser.parse_args()

    # Read configuration
    config = configReader.readConfiguration(args.config)

    # Create communication threads
    threads = []

    # Get the device config

# Path: Devices/Device.py
# class Device(threading.Thread):
# 
#     def __init__(self, sinterval):
#         """ Initializes device with the sampling interval. """
#         threading.Thread.__init__(self)
#         self.queues = []
#         self.sinterval = float(sinterval)
# 
#     def deviceFactory(device_type, name, ip, port,
#                       channels, sinterval, username = None, password = None):
#         """ Device factory that instantiates the following types of devices: 
#             1. Eaton
#             2. Veris
#             3. Zwave (SmartSwitch, TemperatureSensor, LightSensor),
#             4. Raritan
#             Note: Only Raritan requires that the username and password be specified
#             """
#         import LabSenseModbus.Eaton.EatonDevice as EatonDevice
#         import LabSenseModbus.Veris.VerisDevice as VerisDevice
#         import LabSenseZwave.ZwaveDevice as ZwaveDevice
#         import LabSenseRaritan.RaritanDevice as RaritanDevice
# 
#         if device_type == "Eaton":
#             return EatonDevice.EatonDevice(name, 
#                                            ip,
#                                            port,
#                                            channels,
#                                            sinterval)
#         elif device_type == "Veris":
#             return VerisDevice.VerisDevice(name,
#                                            ip,
#                                            port,
#                                            channels,
#                                            sinterval)
#         elif device_type == "Raritan":
#             return RaritanDevice.RaritanDevice(name,
#                                            ip,
#                                            port,
#                                            channels,
#                                            sinterval,
#                                            username,
#                                            password)
#         elif device_type in ["SmartSwitch",
#                              "LightSensor",
#                              "TemperatureSensor"]:
#             return ZwaveDevice.ZwaveDevice(device_type,
#                                            name,
#                                            ip,
#                                            port,
#                                            channels,
#                                            sinterval)
#         else:
#             raise KeyError("Unrecognized Device Name " +
#                            device_type)
#     # Make deviceFactory static so Device does not have to be instantiated
#     # to run
#     deviceFactory = staticmethod(deviceFactory)
# 
#     def attach(self, queue):
#         if not queue in self.queues:
#             self.queues.append(queue)
# 
#     def detach(self, queue):
#         try:
#             self.queues.remove(queue)
#         except ValueError:
#             pass
# 
#     def notify(self, data):
#         if data:
#             for queue in self.queues:
#                 queue.put(data)
# 
#     def getData(self):
#         data = self.client.getData()
#         if data:
#             self.notify(data)
#             return data
# 
#     def run(self):
#         print "Starting Device"
#         while True:
#             self.getData()
#             time.sleep(self.sinterval)


# Path: Devices/LabSenseRaritan/RaritanDevice.py
import argparse                             # For parsing command line arguments
import sys                                  # For importing from common directory
import os                                   # For importing from common directory
import Queue                                # For communicating between datasinks and devices
    import LabSenseHandler.configReader as configReader
from RaritanClient import RaritanClient 
from Devices.Device import Device 
    from DataSinks.DataSink import DataSink


device_path = os.path.join(os.path.dirname(sys.argv[0]), "../..")
sys.path.insert(1, device_path)

class RaritanDevice(Device):

    def __init__(self, name, IP, PORT, channels, sinterval, username, password):
        super(RaritanDevice, self).__init__(sinterval)
        self.client = RaritanClient(name, IP, PORT, channels, username, password)

if __name__ == "__main__":

    # Import sinks and configReader

    # Parse command line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("config", help="Configuration path.")
    parser.add_argument("name", help="Name of device (name field in config.json file)")
    args = parser.parse_args()

    # Read configuration
    config = configReader.readConfiguration(args.config)

    # Create communication threads
    threads = []

    # Get the device config

    device_name = "Raritan"