<commit_before>import eventlet

eventlet.monkey_patch(
    os=True,
    select=True,
    socket=True,
    thread=True,
    time=True)

from st2reactor.sensor.base import Sensor
import paho.mqtt.client as mqtt


class MQTTSensor(Sensor):
    def __init__(self, sensor_service, config=None):
        super(MQTTSensor, self).__init__(sensor_service=sensor_service,
                                         config=config)

        self._trigger = 'mqtt.message'
        self._logger = self._sensor_service.get_logger(__name__)

        self._client = None
        self._hostname = self._config.get('hostname', None)
        self._port = self._config.get('port', 1883)
        self._client_id = self._config.get('client_id', None)
        self._userdata = self._config.get('userdata', None)
        self._username = self._config.get('username', None)
        self._password = self._config.get('password', None)
        self._subscribe = self._config.get('subscribe', None)
        self._ssl = self._config.get('ssl', False)
        self._ssl_cacert = self._config.get('ssl_cacert', None)
        self._ssl_cert = self._config.get('ssl_cert', None)
        self._ssl_key = self._config.get('ssl_key', None)

    def setup(self):
        self._client = mqtt.Client(self._client_id, clean_session=True,
                             userdata=self._userdata, protocol=MQTTv311)

        if self._username:
            self.client.username_pw_set(self._username, password=self._password)

        if self._ssl:
            if not self._ssl_cacert:
                raise ValueError('[mqtt_sensor]: Missing "ssl_cacert" \<commit_msg>set protocol as a config option<commit_after>import eventlet

eventlet.monkey_patch(
    os=True,
    select=True,
    socket=True,
    thread=True,
    time=True)

from st2reactor.sensor.base import Sensor
import paho.mqtt.client as mqtt


class MQTTSensor(Sensor):
    def __init__(self, sensor_service, config=None):
        super(MQTTSensor, self).__init__(sensor_service=sensor_service,
                                         config=config)

        self._trigger = 'mqtt.message'
        self._logger = self._sensor_service.get_logger(__name__)

        self._client = None
        self._hostname = self._config.get('hostname', None)
        self._port = self._config.get('port', 1883)
        self._protocol = self._config.get('protocol', 'MQTTv311')
        self._client_id = self._config.get('client_id', None)
        self._userdata = self._config.get('userdata', None)
        self._username = self._config.get('username', None)
        self._password = self._config.get('password', None)
        self._subscribe = self._config.get('subscribe', None)
        self._ssl = self._config.get('ssl', False)
        self._ssl_cacert = self._config.get('ssl_cacert', None)
        self._ssl_cert = self._config.get('ssl_cert', None)
        self._ssl_key = self._config.get('ssl_key', None)

    def setup(self):
        self._client = mqtt.Client(self._client_id, clean_session=True,
                             userdata=self._userdata, protocol=self._protocol)

        if self._username:
            self.client.username_pw_set(self._username, password=self._password)

        if self._ssl:
            if not self._ssl_cacert:
                raise ValueError('[mqtt_sensor]: Missing "ssl_cacert" \
{'fraction_non_alphanumeric': 0.11591591591591592, 'fraction_numerical': 0.004804804804804805, 'mean_word_length': 2.63646288209607, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7228265', 'n_tokens_mistral': 1025, 'n_tokens_neox': 1001, 'n_words': 176}