#include "temphum.h"

namespace homekit::mqtt {

static const char TOPIC_TEMPHUM_DATA[] = "temphum/data";

void MqttTemphumModule::init(Mqtt &mqtt) {}

void MqttTemphumModule::tick(homekit::mqtt::Mqtt& mqtt) {
    if (!tickElapsed())
        return;

    temphum::SensorData sd = sensor->read();
    MqttTemphumPayload payload {
        .temp = sd.temp,
        .rh = sd.rh,
        .error = sd.error
    };

    mqtt.publish(TOPIC_TEMPHUM_DATA, reinterpret_cast<uint8_t*>(&payload), sizeof(payload));
}

}
