def test_log_all_values(self, connector_mock):
        config = '{ "database_logger": { "enabled": true, "host": "testserver.local", "user_name": "database_user", "password": "******" } }'
        cursor_mock = mock.MagicMock()
        insert_cursor_mock = mock.MagicMock()
        connector_mock.connect.return_value = cursor_mock
        cursor_mock.cursor.return_value = insert_cursor_mock

        sut = DatabaseLogger(json.loads(config))
        sut.log_data(Frame(frame_data=TestLogToDatabase.raw_test_data))
        insert_cursor_mock.execute.assert_called_with((
            'INSERT INTO boiler_data ('
            'flow_temp, return_temp, dhw_in_temp, outside_temp, calorifier_temp, boiler_control_temp, room_temp, '
            'cv_setpoint, dhw_setpoint, room_setpoint, airflow_setpoint, airflow_actual, ionisation_current, '
            'intern_setpoint, output, pump_speed, setpoint_power, actual_power, dwh_heat_demand, anti_legionella, '
            'dhw_blocking, dhw_eco_boiler_not_kept_warm, frost_protection, heat_demand, modulating_controller_demand, '
            'modulating_controller, dhw_enabled, ch_enabled, min_gas_pressure, flow_switch_for_detecting_dhw, '
            'ionisation, release_input, shutdown_input, ext_gas_valve, ext_three_way_valve, three_way_valve, ignition, '
            'gas_valve, opentherm_smart_power, status_report, ext_ch_pump, calorifier_pump, pump, status, locking, '
            'blocking, substatus, fan_speed, su_state, su_locking, su_blocking, hydr_pressure, dhw_timer_enable, '
            'ch_timer_enable, hru_active, control_temp, dhw_flow, solar_temp, hmi_active, ch_setpoint_hmi, '
            'dhw_setpoint_hmi, service_mode, serial_mode, whole_frame) VALUES '
            '(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
            '%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '
            '%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'
        ), (47.7, 25.6, -32.0, 4.5, 48.6, 37.4, 17.45, 47.5, 50.0, 22.0, 2408,
            2410, 5.800000000000001, 47.5, 71, 69, 100, 71, 0, 0, 0, 0, 0, 0,
            1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 3, 255,
            255, 30, 3888, 4, -1, -1, 0.0, 1, 1, 0, 46.86, 0.0, -3276.8,
            839, 64, 53, 0, 0,
            b'\xa2\x12\x00\n\x80\xf3\xc2\x01\xfc\x12\x00\x80\x9c\x0e\xd1\x06\x8e\x12\x88\x13\x98\x08h\tj\t:\x8e\x12GE\x00dG\x00\x00\x13\xc6@\x05\x03\xff\xff\x1e0\x0f\x04\xff\xff\x00\xc0N\x12\x00\x00\x00\x00\x80G\x03@5\x00\x00'
            ))
    def test_when_database_usage_disabled_then_do_not_use_database(
            self, connector_mock):
        config = '{ "database_logger": { "enabled": false, "host": "testserver.local", "user_name": "database_user", "password": "******" } }'

        sut = DatabaseLogger(json.loads(config))
        sut.log_data(Frame(frame_data=TestLogToDatabase.raw_test_data))
        assert not connector_mock.connect.called
Exemple #3
0
    def test_default_config(self):
        """
        test the default config causes the right values to be logged
        """
        with open(
                path.join(path.dirname(path.realpath(__file__)), "..",
                          "config", "remeha.conf")) as json_file:
            with mock.patch('mqtt_logger.mqttClient') as mqtt_mock:
                mqtt_mock.Client.return_value = mqtt_mock
                sut = LogToMQtt(json.load(json_file), 5)

                TestLogToMQtt.raw_test_data[13] = 10
                TestLogToMQtt.raw_test_data[14] = 0
                # update checksum
                TestLogToMQtt.raw_test_data[71] = 0x61
                TestLogToMQtt.raw_test_data[72] = 0xed
                sut.log(Frame(frame_data=TestLogToMQtt.raw_test_data), 0)

                calls = [
                    call('boiler/outside_temp', '0.1', retain=True),
                    call('boiler/flow_temp', '47.7', retain=True),
                    call('boiler/return_temp', '25.6', retain=True),
                    call('boiler/calorifier_temp', '48.6', retain=True),
                    call('boiler/airflow_actual', '83.1', retain=True),
                    call('boiler/status', 'Burning CH (0s)', retain=True),
                    call('boiler/substatus',
                         'Normal internal setpoint (0s)',
                         retain=True),
                    call('boiler/locking', 'No locking (0s)', retain=True),
                    call('boiler/blocking', 'No Blocking (0s)', retain=True)
                ]
                mqtt_mock.publish.assert_has_calls(calls)
Exemple #4
0
    def test_log_single_value__scale_from_config(self):
        """
        test case where the value to post with mqtt is increases the "not changed since"
        """
        with mock.patch('mqtt_logger.mqttClient') as mqtt_mock:
            mqtt_mock.Client.return_value = mqtt_mock
            sut = LogToMQtt(
                json.loads(
                    """{ "mqtt_logger": { "enabled": true, "host": "localhost", "port": 1883,
                "topic": "boiler",
                "log_values": ["outside_temp"],
                "scale_to_percent": [
                    {
                        "value_name": "outside_temp",
                        "lower_limit": 0,
                        "upper_limit": 1
                    }
                ]
              }}
            """), 5)

            TestLogToMQtt.raw_test_data[13] = 10
            TestLogToMQtt.raw_test_data[14] = 0
            # update checksum
            TestLogToMQtt.raw_test_data[71] = 0x61
            TestLogToMQtt.raw_test_data[72] = 0xed
            sut.log(Frame(frame_data=TestLogToMQtt.raw_test_data), 0)

            mqtt_mock.publish.assert_called_once_with('boiler/outside_temp',
                                                      '10.0',
                                                      retain=True)
Exemple #5
0
    def test_log(self):
        """
        test case where the value to post with mqtt is a string
        """
        with mock.patch('mqtt_logger.mqttClient') as mqtt_mock:
            mqtt_mock.Client.return_value = mqtt_mock
            sut = LogToMQtt(self.default_config, 5)

            sut.log(Frame(frame_data=TestLogToMQtt.raw_test_data), 0)
            mqtt_mock.publish.assert_called()
Exemple #6
0
    def test_log_single_value_when_no_config(self):
        """
        test case where the value to post with mqtt is increases the "not changed since"
        """
        with mock.patch('mqtt_logger.mqttClient') as mqtt_mock:
            mqtt_mock.Client.return_value = mqtt_mock
            sut = LogToMQtt(json.loads("""{}"""), 5)
            sut.log(Frame(frame_data=TestLogToMQtt.raw_test_data), 0)

            mqtt_mock.publish.assert_not_called()
    def test_fail_on_missing_database_config(self, connector_mock):
        config = '{ "database_logger": { "enabled": true, "host": "testserver.local" } }'

        sut = DatabaseLogger(json.loads(config))
        sut.log_data(Frame(frame_data=TestLogToDatabase.raw_test_data))
        assert not connector_mock.execute.called