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": mqtt_pass}
            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)

@@ -1327,32 +1327,33 @@
    %22topic%22: %22mpp
+-
 solar%22,%0A        
@@ -1372,32 +1372,33 @@
 %22payload%22: f%22mpp
+-
 solar,command=%7Bt
@@ -1506,24 +1506,25 @@
 topic%22: %22mpp
+-
 solar%22,%0A    
@@ -1555,16 +1555,17 @@
 %22: f%22mpp
+-
 solar,co

fix topic for influx2