<commit_before>#!/usr/bin/python

import Adafruit_DHT
from sensor import Sensor


class Dht(Sensor):

    SENSOR = Adafruit_DHT.DHT22
    NAME = 'DHT'
    PIN = 21
    SLEEP = 10

    temperature = None
    humidity = None

    def sensor_read_callback(self):
        # Try to grab a sensor reading.  Use the read_retry method which will retry up
        # to 15 times to get a sensor reading (waiting 2 seconds between each retry).
        self.humidity, self.temperature = Adafruit_DHT.read_retry(self.SENSOR, self.PIN)
        self.notify(topic='%s/temperature' % self.mqtt_topic, payload=self.temperature)
        self.notify(topic='%s/humidity' % self.mqtt_topic, payload=self.humidity)
        self.logger.info('Sensor %s read data: %s *C and %s', self.NAME, self.temperature, self.humidity)

        if self.humidity is not None and self.temperature is not None:
            self.FAILED = 0
        else:
            self.FAILED += 1

    def output(self, desc=True, temp=False, hum=False):
        # Note that sometimes you won't get a reading and the results will be null
        # (because Linux can't guarantee the timing of calls to read the sensor).
        # If this happens try again!
        out = ''

        if desc and (self.temperature or self.humidity):
            out += 'Temperature = {0:0.1f}*C\n'.format(self.temperature)
            out += 'Humidity = {0:0.1f}%'.format(self.humidity)
        else:
            out = 'Failed to get reading. Try again!'

        if temp and self.temperature:
            out = str(self.temperature)

        if hum and self.humidity:
            out = str(self.humidity)

        return out
<commit_msg>Updated notify only on successful read and round the value<commit_after>#!/usr/bin/python

import Adafruit_DHT
from sensor import Sensor


class Dht(Sensor):

    SENSOR = Adafruit_DHT.DHT22
    NAME = 'DHT'
    PIN = 21
    SLEEP = 10

    temperature = None
    humidity = None

    def sensor_read_callback(self):
        # Try to grab a sensor reading.  Use the read_retry method which will retry up
        # to 15 times to get a sensor reading (waiting 2 seconds between each retry).
        self.humidity, self.temperature = Adafruit_DHT.read_retry(self.SENSOR, self.PIN)
        self.logger.info('Sensor %s read data: %s *C and %s', self.NAME, self.temperature, self.humidity)

        if self.humidity is not None and self.temperature is not None:
            self.FAILED = 0
            self.notify(topic='%s/temperature' % self.mqtt_topic, payload="{0:0.1f}".format(self.temperature))
            self.notify(topic='%s/humidity' % self.mqtt_topic, payload="{0:0.1f}".format(self.humidity))
        else:
            self.FAILED += 1

    def output(self, desc=True, temp=False, hum=False):
        # Note that sometimes you won't get a reading and the results will be null
        # (because Linux can't guarantee the timing of calls to read the sensor).
        # If this happens try again!
        out = ''

        if desc and (self.temperature or self.humidity):
            out += 'Temperature = {0:0.1f}*C\n'.format(self.temperature)
            out += 'Humidity = {0:0.1f}%'.format(self.humidity)
        else:
            out = 'Failed to get reading. Try again!'

        if temp and self.temperature:
            out = str(self.temperature)

        if hum and self.humidity:
            out = str(self.humidity)

        return out

{'fraction_non_alphanumeric': 0.10125841381328651, 'fraction_numerical': 0.011706175007316359, 'mean_word_length': 2.404382470119522, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2844446', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1021, 'n_words': 325}