#pragma once #ifdef USE_LIGHT class NbsLightManager; #include "esphome.h" #include "hciemulator.h" #include "hoermann.h" //#include "cover.h" #define RS485 Serial2 #define TX_ON 25 //#define configMAX_PRIORITIES 25 namespace esphome { namespace hoermann_door { // Custom binary output, for exposing binary states class NbsLightManager: public binary::BinaryLightOutput, public light::LightState { protected: public: void setup() override { //single = HoermannSingleton::getInstance(); //single->initializeGetInstance } bool lastState = false; bool firstState = false; void loop() override { //if(!DoorManager.getEmulator().getState().valid) false; //if(!firstState || DoorManager.getEmulator().getState().lampOn != lastState){ //ESP_LOGD("Test", "I have no idea"); // lastState = DoorManager.getEmulator().getState().lampOn; // this->write_state(lastState); // firstState = true; //} } }; // Custom binary output, for exposing binary states class NbsLightOutput: public output::BinaryOutput, public Component{ light::LightState *callback; bool lastState = false; bool firstState = true; HoermannMainComponent *mainComponent; public: virtual void write_state(bool state){ if(lastState != state){ mainComponent->getEmulator()->toggleLamp(); //lastState = state; } } void set_state_callback(light::LightState *callback){ if(callback == nullptr) ESP_LOGW(COMP_TAG, "Got Nullable callback"); this->callback = callback; } void set_emulator_component(HoermannMainComponent* component){ this->mainComponent = component; } void loop() override { if(!mainComponent->getEmulator()->getState().valid) false; if(firstState || mainComponent->getEmulator()->getState().lampOn != lastState){ //ESP_LOGD("Test", "I have no idea"); lastState = mainComponent->getEmulator()->getState().lampOn; if(lastState == true){ ESP_LOGD(COMP_TAG, "Light State ON"); auto call = callback->make_call(); call.set_state(true); call.perform(); } else { ESP_LOGD(COMP_TAG, "Light State OFF"); auto call = callback->make_call(); call.set_state(false); call.perform(); } firstState = false; } } void setup() override { } void turn_on() override { this->write_state(true); } void turn_off() override { this->write_state(false); } }; } // namespace hoermann } // namespace esphome #endif