/* eslint unicorn/filename-case: "off", func-names: "off", camelcase: "off", no-unused-vars: "off" */

module.exports = function (charName, obj, iface) {
    const {acc, settings, subtype} = obj;
    const {mqttStatus, mqttPub, mqttSub, Characteristic, log} = iface;

    if (!Characteristic[charName]) {
        throw new Error('Unknown Characteristic ' + charName);
    }

    const setTopic = 'set' + charName;
    const statusTopic = 'status' + charName.replace(/^Status/, '');

    const service = acc.getService(subtype);
    const characteristic = service.getCharacteristic(Characteristic[charName]);

    if (settings.props && settings.props[charName]) {
        characteristic.setProps(settings.props[charName]);
    }

    const {props, eventOnlyCharacteristic} = characteristic;

    /* istanbul ignore else */
    if (props.perms.includes(Characteristic.Perms.PAIRED_READ) && settings.topic[statusTopic]) {
        mqttSub(settings.topic[statusTopic], val => {
            log.debug('> hap update', settings.name, charName, val);
            service.updateCharacteristic(Characteristic[charName], val);
        });

        /* istanbul ignore else */
        if (!eventOnlyCharacteristic) {
            characteristic.on('get', callback => {
                log.debug('< hap get', settings.name, charName);
                log.debug('> hap re_get', settings.name, charName, mqttStatus[settings.topic[statusTopic]]);
                callback(null, mqttStatus[settings.topic[statusTopic]]);
            });
        }
    }

    /* istanbul ignore else */
    if (props.perms.includes(Characteristic.Perms.PAIRED_WRITE) && settings.topic[setTopic]) {
        characteristic.on('set', (value, callback) => {
            log.debug('< hap set', settings.name, charName, value);
            mqttPub(settings.topic[setTopic], value);
            callback();
        });
    }
};

@@ -368,28 +368,26 @@
 %0A    %7D%0A%0A    
-cons
+le
 t setTopic =
@@ -409,20 +409,18 @@
 me;%0A    
-cons
+le
 t status
@@ -437,16 +437,49 @@
 tatus' +
+ charName;%0A    const topicShort =
  charNam
@@ -490,16 +490,21 @@
 place(/%5E
+Set%7C%5E
 Status/,
@@ -508,16 +508,353 @@
 s/, '');
+%0A    const setTopicShort = 'set' + topicShort;%0A    const statusTopicShort = 'status' + topicShort;%0A%0A    if (setTopic !== setTopicShort && settings.topic%5BsetTopicShort%5D) %7B%0A        setTopic = setTopicShort;%0A    %7D%0A%0A    if (statusTopic !== statusTopicShort && settings.topic%5BstatusTopicShort%5D) %7B%0A        statusTopic = statusTopicShort;%0A    %7D
 %0A%0A    co
@@ -2195,24 +2195,53 @@
 opic%5D, value
+, settings.mqttPublishOptions
 );%0A         

fix short topic names, add mqttPublishOptions