Beispiel #1
0
    def test_constructor_str(self):
        """ Test for the constructor for str. """
        PluginConfigChecker([{
            'name': 'hostname',
            'type': 'str',
            'description': 'The hostname of the server.'
        }])
        PluginConfigChecker([{'name': 'hostname', 'type': 'str'}])

        try:
            PluginConfigChecker([{'type': 'str'}])
            self.fail('Excepted exception')
        except PluginException as exception:
            self.assertTrue('name' in str(exception))
Beispiel #2
0
    def test_constructor_password(self):
        """ Test for the constructor for bool. """
        PluginConfigChecker([{
            'name': 'password',
            'type': 'password',
            'description': 'A password.'
        }])
        PluginConfigChecker([{'name': 'password', 'type': 'password'}])

        try:
            PluginConfigChecker([{'type': 'password'}])
            self.fail('Excepted exception')
        except PluginException as exception:
            self.assertTrue('name' in str(exception))
Beispiel #3
0
    def test_constructor_int(self):
        """ Test for the constructor for int. """
        PluginConfigChecker([{
            'name': 'port',
            'type': 'int',
            'description': 'Port on the server.'
        }])
        PluginConfigChecker([{'name': 'port', 'type': 'int'}])

        try:
            PluginConfigChecker([{'type': 'int'}])
            self.fail('Excepted exception')
        except PluginException as exception:
            self.assertTrue('name' in str(exception))
Beispiel #4
0
    def __init__(self, webinterface, logger):
        super(Astro, self).__init__(webinterface, logger)
        self.logger('Starting Astro plugin...')

        self._config = self.read_config(Astro.default_config)
        self._config_checker = PluginConfigChecker(Astro.config_description)

        pytz_egg = '/opt/openmotics/python/plugins/Astro/pytz-2017.2-py2.7.egg'
        if pytz_egg not in sys.path:
            sys.path.insert(0, pytz_egg)

        self._latitude = None
        self._longitude = None

        self._group_actions = {}
        self._bits = {}

        self._last_request_date = None
        self._execution_plan = {}

        self._sleeper = Event()
        self._sleep_until = 0

        thread = Thread(target=self._sleep_manager)
        thread.start()

        self._read_config()

        self.logger("Started Astro plugin")
Beispiel #5
0
    def __init__(self, webinterface, logger):
        super(Astro, self).__init__(webinterface, logger)
        self.logger('Starting Astro plugin...')

        self._config = self.read_config(Astro.default_config)
        self._config_checker = PluginConfigChecker(Astro.config_description)

        pytz_egg = '/opt/openmotics/python/plugins/Astro/pytz-2017.2-py2.7.egg'
        if pytz_egg not in sys.path:
            sys.path.insert(0, pytz_egg)

        self._bright_bit = -1
        self._horizon_bit = -1
        self._civil_bit = -1
        self._nautical_bit = -1
        self._astronomical_bit = -1
        self._previous_bits = [None, None, None, None, None]
        self._sleeper = Event()
        self._sleep_until = 0

        thread = Thread(target=self._sleep_manager)
        thread.start()

        self._read_config()

        self.logger("Started Astro plugin")
Beispiel #6
0
    def __init__(self, webinterface, logger):
        super(MQTTClient, self).__init__(webinterface, logger)
        self.logger('Starting MQTTClient plugin...')

        self._config = self.read_config(MQTTClient.default_config)
        #self.logger("Default configuration '{0}'".format(self._config))
        self._config_checker = PluginConfigChecker(MQTTClient.config_description)

        paho_mqtt_wheel = '/opt/openmotics/python/plugins/MQTTClient/paho_mqtt-1.5.0-py2-none-any.whl'
        if paho_mqtt_wheel not in sys.path:
            sys.path.insert(0, paho_mqtt_wheel)

        self.client = None
        self._sensor_config = {}
        self._inputs = {}
        self._outputs = {}
        self._sensors = {}
        self._power_modules = {}

        self._read_config()
        self._try_connect()

        self._load_configuration()

        self.logger("Started MQTTClient plugin")
Beispiel #7
0
    def test_check_config_section(self):
        """ Test check_config for section. """
        checker = PluginConfigChecker([{
            'name':
            'outputs',
            'type':
            'section',
            'repeat':
            True,
            'min':
            1,
            'content': [{
                'name': 'output',
                'type': 'int'
            }]
        }])

        checker.check_config({'outputs': []})
        checker.check_config({'outputs': [{'output': 2}]})
        checker.check_config({'outputs': [{'output': 2}, {'output': 4}]})

        try:
            checker.check_config({'outputs': 'test'})
            self.fail('Excepted exception')
        except PluginException as exception:
            self.assertTrue('list' in str(exception))

        try:
            checker.check_config({'outputs': [{'test': 123}]})
            self.fail('Excepted exception')
        except PluginException as exception:
            self.assertTrue('section' in str(exception)
                            and 'output' in str(exception))
Beispiel #8
0
    def test_constructor_bool(self):
        """ Test for the constructor for bool. """
        PluginConfigChecker([{
            'name':
            'use_auth',
            'type':
            'bool',
            'description':
            'Use authentication while connecting.'
        }])
        PluginConfigChecker([{'name': 'use_auth', 'type': 'bool'}])

        try:
            PluginConfigChecker([{'type': 'bool'}])
            self.fail('Excepted exception')
        except PluginException as exception:
            self.assertTrue('name' in str(exception))
Beispiel #9
0
    def test_check_config_int(self):
        """ Test check_config for int. """
        checker = PluginConfigChecker([{'name': 'port', 'type': 'int'}])
        checker.check_config({'port': 123})

        try:
            checker.check_config({'port': "123"})
            self.fail('Excepted exception')
        except PluginException as exception:
            self.assertTrue('int' in str(exception))
Beispiel #10
0
    def test_check_config_str(self):
        """ Test check_config for str. """
        checker = PluginConfigChecker([{'name': 'hostname', 'type': 'str'}])
        checker.check_config({'hostname': 'cloud.openmotics.com'})

        try:
            checker.check_config({'hostname': 123})
            self.fail('Excepted exception')
        except PluginException as exception:
            self.assertTrue('str' in str(exception))
Beispiel #11
0
    def __init__(self, webinterface, gateway_logger):
        self.setup_logging(log_function=gateway_logger)
        super(SensorDotCommunity, self).__init__(webinterface, logger)
        logger.info('Starting %s plugin %s ...', self.name, self.version)

        self._config = self.default_config
        self._config_checker = PluginConfigChecker(
            SensorDotCommunity.config_description)

        logger.info("%s plugin started", self.name)
Beispiel #12
0
    def __init__(self, webinterface, logger):
        super(Pushetta, self).__init__(webinterface, logger)
        self.logger('Starting Pushetta plugin...')

        self._config = self.read_config(Pushetta.default_config)
        self._config_checker = PluginConfigChecker(Pushetta.config_description)

        self._read_config()

        self.logger("Started Pushetta plugin")
Beispiel #13
0
    def test_check_config_bool(self):
        """ Test check_config for bool. """
        checker = PluginConfigChecker([{'name': 'use_auth', 'type': 'bool'}])
        checker.check_config({'use_auth': True})

        try:
            checker.check_config({'use_auth': 234543})
            self.fail('Excepted exception')
        except PluginException as exception:
            self.assertTrue('bool' in str(exception))
Beispiel #14
0
    def __init__(self, webinterface, logger):
        super(OpenWeatherMap, self).__init__(webinterface, logger)
        self.logger('Starting OpenWeatherMap plugin...')

        self._config = self.read_config(OpenWeatherMap.default_config)
        self._config_checker = PluginConfigChecker(OpenWeatherMap.config_description)

        self._read_config()

        self._previous_output_state = {}

        self.logger("Started OpenWeatherMap plugin")
Beispiel #15
0
    def __init__(self, webinterface, logger):
        super(Hue, self).__init__(webinterface, logger)
        self.logger('Starting Hue plugin...')

        self._config = self.read_config(Hue.default_config)
        self._config_checker = PluginConfigChecker(Hue.config_description)

        self._read_config()

        self._previous_output_state = {}

        self.logger("Hue plugin started")
Beispiel #16
0
    def __init__(self, webinterface, logger):
        super(TasmotaHTTP, self).__init__(webinterface, logger)
        self.logger('Starting Tasmota HTTP plugin...')

        self._config = self.read_config(TasmotaHTTP.default_config)
        self._config_checker = PluginConfigChecker(
            TasmotaHTTP.config_description)

        self._read_config()

        self._previous_output_state = {}

        self.logger("Started Tasmota HTTP plugin")
Beispiel #17
0
    def __init__(self, webinterface, logger):
        super(RTI, self).__init__(webinterface, logger)
        self.logger('Starting RTI plugin...')

        self._config = self.read_config(RTI.default_config)
        self._config_checker = PluginConfigChecker(RTI.config_description)

        self._command_queue = Queue()
        self._enabled = False
        self._serial = None
        self._read_config()

        self.logger("Started RTI plugin")
Beispiel #18
0
    def __init__(self, webinterface, logger):
        super(Syncer, self).__init__(webinterface, logger)
        self.logger('Starting Syncer plugin...')

        self._config = self.read_config(Syncer.default_config)
        self._config_checker = PluginConfigChecker(Syncer.config_description)

        self._token = None
        self._enabled = False
        self._previous_outputs = set()
        self._read_config()

        self.logger("Started Syncer plugin")
Beispiel #19
0
    def test_simple(self):
        """ Test a simple valid configuration. """
        checker = PluginConfigChecker([{
            'name': 'log_inputs',
            'type': 'bool',
            'description': 'Log the input data.'
        }, {
            'name': 'log_outputs',
            'type': 'bool',
            'description': 'Log the output data.'
        }])

        checker.check_config({'log_inputs': True, 'log_outputs': False})
Beispiel #20
0
    def test_check_config_password(self):
        """ Test check_config for bool. """
        checker = PluginConfigChecker([{
            'name': 'password',
            'type': 'password'
        }])
        checker.check_config({'password': '******'})

        try:
            checker.check_config({'password': 123})
            self.fail('Excepted exception')
        except PluginException as exception:
            self.assertTrue('str' in str(exception))
Beispiel #21
0
    def __init__(self, webinterface, logger):
        super(HealthboxPlugin, self).__init__(webinterface, logger)

        self.__config = self.read_config(HealthboxPlugin.default_config)
        self.__config_checker = PluginConfigChecker(HealthboxPlugin.config_descr)
        self._enabled = True

        self.api_handler = ApiHandler(self.logger)
        self.discovered_devices = {}  # dict of all the Healthbox3 drivers mapped with register key as key
        self.serial_key_to_gateway_id = {}  # mapping of register key to gateway id (for api calls)

        self.logger("Started Healthbox 3 plugin")

        self.healtbox_manager = HealthBox3Manager()
        self.healtbox_manager.set_discovery_callback(self.discover_callback)
        self.healtbox_manager.start_discovery()

        # roomID is used as a placeholder for the room number, this is replaced through _define_sensors_with_rooms function
        self.sensorsGeneral =   [
                {
                    'sensor_id'        :'roomID - indoor temperature[roomID]_HealthBox 3[Healthbox3] - temperature',
                    'sensor_name'      :'Temperature Room roomID',
                    'physical_quantity':'temperature',
                    'unit'             :'celcius',
                },
                {
                    'sensor_id'        :'roomID - indoor relative humidity[roomID]_HealthBox 3[Healthbox3] - humidity',
                    'sensor_name'      :'Humidity Room roomID',
                    'physical_quantity':'humidity',
                    'unit'             :'percent',
                },
                {
                    'sensor_id'        :'roomID - indoor air quality[roomID]_HealthBox 3[Healthbox3] - co2',
                    'sensor_name'      :'CO2 Room roomID',
                    'physical_quantity':'co2',
                    'unit'             :'parts_per_million',
                },
                {
                    'sensor_id'        :'roomID - indoor CO2[roomID]_HealthBox 3[Healthbox3] - concentration',
                    'sensor_name'      :'CO2 Room roomID',
                    'physical_quantity':'co2',
                    'unit'             :'parts_per_million',
                },
                {
                    'sensor_id'        :'roomID - indoor volatile organic compounds[roomID]_HealthBox 3[Healthbox3] - concentration',
                    'sensor_name'      :'VOC Room roomID',
                    'physical_quantity':'voc',
                    'unit'             :'parts_per_million',
                },

            ]
Beispiel #22
0
    def __init__(self, webinterface, logger):
        """ Default constructor, called by the plugin manager. """
        OMPluginBase.__init__(self, webinterface, logger)

        self.__last_energy = None

        # The list containing whether the pump was on the last 10 minutes
        self.__window = []

        self.__config = self.read_config()

        self.__config_checker = PluginConfigChecker(Pumpy.config_descr)

        self.logger("Started Pumpy plugin")
Beispiel #23
0
    def __init__(self, webinterface, logger):
        super(Astro, self).__init__(webinterface, logger)
        self.logger('Starting Astro plugin...')

        self._config = self.read_config(Astro.default_config)
        self._config_checker = PluginConfigChecker(Astro.config_description)

        pytz_egg = '/opt/openmotics/python/plugins/Astro/pytz-2017.2-py2.7.egg'
        if pytz_egg not in sys.path:
            sys.path.insert(0, pytz_egg)

        self._read_config()

        self.logger("Started Astro plugin")
Beispiel #24
0
    def test_check_config_nested_enum(self):
        """ Test check_config for nested_enum. """
        checker = PluginConfigChecker([{
            'name':
            'network',
            'type':
            'nested_enum',
            'choices': [{
                'value': 'Facebook',
                'content': [{
                    'name': 'likes',
                    'type': 'int'
                }]
            }, {
                'value': 'Twitter',
                'content': [{
                    'name': 'followers',
                    'type': 'int'
                }]
            }]
        }])

        checker.check_config({'network': ['Twitter', {'followers': 3}]})
        checker.check_config({'network': ['Facebook', {'likes': 3}]})

        try:
            checker.check_config({'network': 'test'})
            self.fail('Excepted exception')
        except PluginException as exception:
            self.assertTrue('list' in str(exception))

        try:
            checker.check_config({'network': []})
            self.fail('Excepted exception')
        except PluginException as exception:
            self.assertTrue('list' in str(exception) and '2' in str(exception))

        try:
            checker.check_config({'network': ['something else', {}]})
            self.fail('Excepted exception')
        except PluginException as exception:
            self.assertTrue('choices' in str(exception))

        try:
            checker.check_config({'network': ['Twitter', {}]})
            self.fail('Excepted exception')
        except PluginException as exception:
            self.assertTrue('nested_enum dict' in str(exception)
                            and 'followers' in str(exception))
Beispiel #25
0
    def __init__(self, webinterface, logger):
        super(RTD10, self).__init__(webinterface, logger)
        self.logger('Starting RTD10 plugin...')

        self._config = self.read_config(RTD10.default_config)
        self._config_checker = PluginConfigChecker(RTD10.config_description)

        self._enabled = False
        self._syncing = False
        self._thermostats = {}
        self._s_values = {}

        self._read_config()

        self.logger("Started RTD10 plugin")
Beispiel #26
0
    def test_constructor_error(self):
        """ Test with an invalid data type """
        try:
            PluginConfigChecker({'test': 123})
            self.fail("Expected PluginException")
        except PluginException as exception:
            self.assertTrue('list' in str(exception))

        try:
            PluginConfigChecker([{'test': 123}])
            self.fail("Expected PluginException")
        except PluginException as exception:
            self.assertTrue('name' in str(exception))

        try:
            PluginConfigChecker([{'name': 123}])
            self.fail("Expected PluginException")
        except PluginException as exception:
            self.assertTrue('name' in str(exception)
                            and 'string' in str(exception))

        try:
            PluginConfigChecker([{'name': 'test'}])
            self.fail("Expected PluginException")
        except PluginException as exception:
            self.assertTrue('type' in str(exception))

        try:
            PluginConfigChecker([{'name': 'test', 'type': 123}])
            self.fail("Expected PluginException")
        except PluginException as exception:
            self.assertTrue('type' in str(exception)
                            and 'string' in str(exception))

        try:
            PluginConfigChecker([{'name': 'test', 'type': 'something_else'}])
            self.fail("Expected PluginException")
        except PluginException as exception:
            self.assertTrue('type' in str(exception)
                            and 'something_else' in str(exception))

        try:
            PluginConfigChecker([{
                'name': 'test',
                'type': 'str',
                'description': []
            }])
            self.fail("Expected PluginException")
        except PluginException as exception:
            self.assertTrue('description' in str(exception)
                            and 'string' in str(exception))
Beispiel #27
0
    def test_constructor_enum(self):
        """ Test for the constructor for enum. """
        PluginConfigChecker([{
            'name': 'enumtest',
            'type': 'enum',
            'description': 'Test for enum',
            'choices': ['First', 'Second']
        }])
        PluginConfigChecker([{
            'name': 'enumtest',
            'type': 'enum',
            'choices': ['First', 'Second']
        }])

        try:
            PluginConfigChecker([{
                'name': 'enumtest',
                'type': 'enum',
                'choices': 'First'
            }])
            self.fail('Excepted exception')
        except PluginException as exception:
            self.assertTrue('choices' in str(exception)
                            and 'list' in str(exception))
Beispiel #28
0
    def test_check_config_error(self):
        """ Test check_config with an invalid data type """
        checker = PluginConfigChecker([{'name': 'hostname', 'type': 'str'}])

        try:
            checker.check_config('string')
            self.fail("Expected PluginException")
        except PluginException as exception:
            self.assertTrue('dict' in str(exception))

        try:
            checker.check_config({})
            self.fail("Expected PluginException")
        except PluginException as exception:
            self.assertTrue('hostname' in str(exception))
Beispiel #29
0
    def __init__(self, webinterface, logger):
        super(Statful, self).__init__(webinterface, logger)
        self.logger('Starting Statful plugin...')

        self._config = self.read_config(Statful.default_config)
        self._config_checker = PluginConfigChecker(Statful.config_description)
        self._pending_metrics = {}
        self._send_queue = deque()

        self._send_thread = Thread(target=self._sender)
        self._send_thread.setName('Statful batch sender')
        self._send_thread.daemon = True
        self._send_thread.start()

        self._read_config()
        self.logger("Started Statful plugin")
Beispiel #30
0
    def __init__(self, webinterface, gateway_logger):
        self.setup_logging(log_function=gateway_logger)
        super(Hue, self).__init__(webinterface, logger)
        logger.info('Starting Hue plugin %s ...', self.version)

        self.discover_hue_bridges()

        self._config = self.read_config(Hue.default_config)
        self._config_checker = PluginConfigChecker(Hue.config_description)

        self._read_config()

        self._io_lock = Lock()
        self._output_event_queue = Queue(maxsize=256)

        logger.info("Hue plugin started")