// Adafruit temp/humidity sensor
// We are using the SHT10
// Humid accuracy +/- 5%
// Steady accuracy between 10-80
// example at 10/90 +/- 6%, 0/100 +/- 7.5%

#include "esphome.h"
#include <SHT1x.h>

//sht1xDataPin  A5 / 4
//sht1xClockPin A1 / 25
SHT1x sht1x(4, 25);

class SHT1xSensor : public PollingComponent, public sensor::Sensor {
 public:
  sensor::Sensor *temp_c_sensor = new sensor::Sensor();
  sensor::Sensor *temp_f_sensor = new sensor::Sensor();
  sensor::Sensor *humidity_sensor = new sensor::Sensor();

  SHT1xSensor() : PollingComponent(60*60*1000) { }

  void setup() override {
  }

  void update() override {
    float temp_c = sht1x.readTemperatureC();
    float temp_f = sht1x.readTemperatureF();
    float humidity = sht1x.readHumidity();

    temp_c_sensor->publish_state(temp_c);
    temp_f_sensor->publish_state(temp_f);
    humidity_sensor->publish_state(humidity);
  }
};
