
#include "DomoEspManager.h"
DomoEspManager::DomoEspManager()
{
  vars.config(&avar, &topics);
  sens.Config(&vars);
}

void DomoEspManager::inicia(PubSubClient *mqttClient, WiFiClient* espClient, DomoConfig* conf)
{
  wifi.inicia(espClient, conf->ssidWifi, conf->keyWifi);
  mqtt.inicia(mqttClient,conf->ideEsp, conf->hostMQTT, conf->portMQTT, this);

  //pasar funcion de configuracion de añadir sensores
 conf->ConfigSens(&sens);
  
  vars.inicia(mqttClient);
  sens.inicia();

  
}

void DomoEspManager::loop()
{
  if(!wifi.loop())
    return;
  if(!mqtt.loop())
    return;
  sens.loop();
  vars.loop();
}

void DomoEspManager::OnMqtt(char* topic, char* payload)
{
  vars.OnMqtt(topic, payload);
}

void DomoEspManager::SubscribeMqtt(PubSubClient *client_mqtt)
{
  
}
