<commit_before>import logging
import paho.mqtt.publish as publish

log = logging.getLogger("MPP-Solar")


class influx2_mqtt:
    def __init__(self, *args, **kwargs) -> None:
        log.debug(f"processor.influx2_mqtt __init__ kwargs {kwargs}")

    def output(self, data=None, tag=None, mqtt_broker="localhost", mqtt_user=None, mqtt_pass=None):
        log.info("Using output processor: influx2_mqtt")

        if data is None:
            return

        if tag is None:
            tag = "mpp-solar"

        if mqtt_user is not None and mqtt_pass is not None:
            auth = {"username": mqtt_user, "password": <PASSWORD>}
            log.info(f"Using mqtt authentication, username: {mqtt_user}, password: [supplied]")
        else:
            log.debug("No mqtt authentication used")
            auth = None

        # Build array of Influx Line Protocol II messages
        msgs = []
        # Remove command and _command_description
        data.pop("_command", None)
        data.pop("_command_description", None)
        # Loop through responses
        for key in data:
            value = data[key][0]
            # unit = _data[key][1]
            # Message format is: mpp-solar,command=QPGS0 max_charger_range=120.0
            msg = {
                "topic": "mppsolar",
                "payload": f"mppsolar,command={tag} {key}={value}",
            }
            msgs.append(msg)
        publish.multiple(msgs, hostname=mqtt_broker, auth=auth)<commit_msg>tweak infux2 for value types<commit_after>import logging
import paho.mqtt.publish as publish

log = logging.getLogger("MPP-Solar")


class influx2_mqtt:
    def __init__(self, *args, **kwargs) -> None:
        log.debug(f"processor.influx2_mqtt __init__ kwargs {kwargs}")

    def output(self, data=None, tag=None, mqtt_broker="localhost", mqtt_user=None, mqtt_pass=None):
        log.info("Using output processor: influx2_mqtt")

        if data is None:
            return

        if tag is None:
            tag = "mpp-solar"

        if mqtt_user is not None and mqtt_pass is not None:
            auth = {"username": mqtt_user, "password": <PASSWORD>}
            log.info(f"Using mqtt authentication, username: {mqtt_user}, password: [supplied]")
        else:
            log.debug("No mqtt authentication used")
            auth = None

        # Build array of Influx Line Protocol II messages
        msgs = []
        # Remove command and _command_description
        data.pop("_command", None)
        data.pop("_command_description", None)
        # Loop through responses
        for key in data:
            value = data[key][0]
            # unit = _data[key][1]
            # Message format is: mpp-solar,command=QPGS0 max_charger_range=120.0
            if isinstance(value, int) or isinstance(value, float):
                msg = {
                    "topic": "mppsolar",
                    "payload": f"mppsolar,command={tag} {key}={value}",
                }
            else:
                msg = {
                    "topic": "mppsolar",
                    "payload": f"mppsolar,command={tag} {key}='{value}'",
                }
            msgs.append(msg)
        publish.multiple(msgs, hostname=mqtt_broker, auth=auth)
{'fraction_non_alphanumeric': 0.1109389525875426, 'fraction_numerical': 0.006507592190889371, 'mean_word_length': 2.1248789932236205, 'pattern_counts': {'":': 10, '<': 5, '<?xml version=': 0, '>': 7, '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': '3375900', 'n_tokens_mistral': 1005, 'n_tokens_neox': 965, 'n_words': 242}