# Path: mppsolar/outputs/baseoutput.py
# class baseoutput:
#     def __str__(self):
#         return "the base class for the output processors, not used directly"
# 
# Path: mppsolar/helpers.py
# def get_kwargs(kwargs, key, default=None):
#     if key not in kwargs or not kwargs[key]:
#         return default
#     return kwargs[key]
# 
# Path: mppsolar/helpers.py
# def key_wanted(key, filter=None, excl_filter=None):
#     # remove any specifically excluded keys
#     if excl_filter is not None and excl_filter.search(key):
#         # log.debug(f"key_wanted: key {key} matches excl_filter {excl_filter} so key excluded")
#         return False
#     if filter is None:
#         # log.debug(
#         #    f"key_wanted: No filter and key {key} not excluded by excl_filter {excl_filter} so key wanted"
#         # )
#         return True
#     elif filter.search(key):
#         # log.debug(
#         #    f"key_wanted: key {key} matches filter {filter} and not excl_filter {excl_filter} so key wanted"
#         # )
#         return True
#     else:
#         # log.debug(f"key_wanted: key {key} does not match filter {filter} so key excluded")
#         return False


import logging
import re
import paho.mqtt.publish as publish
from .baseoutput import baseoutput
from ..helpers import get_kwargs
from ..helpers import key_wanted
                msgs.append(msg)
                if unit:
                    msg = {"topic": f"{tag}/status/{key}/unit", "payload": unit}
                    msgs.append(msg)
        log.debug(f"build_msgs: {msgs}")
        return msgs

    def output(self, *args, **kwargs):
        log.info("Using output processor: mqtt")
        log.debug(f"kwargs {kwargs}")
        data = get_kwargs(kwargs, "data")
        if data is None:
            return
        mqtt_broker = get_kwargs(kwargs, "mqtt_broker")
        if mqtt_broker is None or not mqtt_broker.name:
            return
        mqtt_port = mqtt_broker.port
        mqtt_user = mqtt_broker.username
        mqtt_pass = mqtt_broker.password

        filter = get_kwargs(kwargs, "filter")
        if filter is not None:
            filter = re.compile(filter)
        excl_filter = get_kwargs(kwargs, "excl_filter")
        if excl_filter is not None:
            excl_filter = re.compile(excl_filter)

        if mqtt_user and mqtt_pass:
            auth = {"username": mqtt_user, "password": mqtt_pass}
            log.info(f"Using mqtt authentication, username: {mqtt_user}, password: [supplied]")

# Path: mppsolar/outputs/baseoutput.py
# class baseoutput:
#     def __str__(self):
#         return "the base class for the output processors, not used directly"
# 
# Path: mppsolar/helpers.py
# def get_kwargs(kwargs, key, default=None):
#     if key not in kwargs or not kwargs[key]:
#         return default
#     return kwargs[key]
# 
# Path: mppsolar/helpers.py
# def key_wanted(key, filter=None, excl_filter=None):
#     # remove any specifically excluded keys
#     if excl_filter is not None and excl_filter.search(key):
#         # log.debug(f"key_wanted: key {key} matches excl_filter {excl_filter} so key excluded")
#         return False
#     if filter is None:
#         # log.debug(
#         #    f"key_wanted: No filter and key {key} not excluded by excl_filter {excl_filter} so key wanted"
#         # )
#         return True
#     elif filter.search(key):
#         # log.debug(
#         #    f"key_wanted: key {key} matches filter {filter} and not excl_filter {excl_filter} so key wanted"
#         # )
#         return True
#     else:
#         # log.debug(f"key_wanted: key {key} does not match filter {filter} so key excluded")
#         return False


# Path: mppsolar/outputs/mqtt.py
import logging
import re
import paho.mqtt.publish as publish
from .baseoutput import baseoutput
from ..helpers import get_kwargs
from ..helpers import key_wanted

                msgs.append(msg)
                if unit:
                    msg = {"topic": f"{tag}/status/{key}/unit", "payload": unit}
                    msgs.append(msg)
        log.debug(f"build_msgs: {msgs}")
        return msgs

    def output(self, *args, **kwargs):
        log.info("Using output processor: mqtt")
        log.debug(f"kwargs {kwargs}")
        data = get_kwargs(kwargs, "data")
        if data is None:
            return
        mqtt_broker = get_kwargs(kwargs, "mqtt_broker")
        if mqtt_broker is None or not mqtt_broker.name:
            return
        mqtt_port = mqtt_broker.port
        mqtt_user = mqtt_broker.username
        mqtt_pass = mqtt_broker.password

        filter = get_kwargs(kwargs, "filter")
        if filter is not None:
            filter = re.compile(filter)
        excl_filter = get_kwargs(kwargs, "excl_filter")
        if excl_filter is not None:
            excl_filter = re.compile(excl_filter)

        if mqtt_user and mqtt_pass:
            auth = {"username": mqtt_user, "password": mqtt_pass}
            log.info(f"Using mqtt authentication, username: {mqtt_user}, password: [supplied]")

        else: