-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: J. Nick Koston <nick@koston.org>
- Loading branch information
1 parent
f8ee5e8
commit 8df1cbe
Showing
44 changed files
with
1,229 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import esphome.codegen as cg | ||
import esphome.config_validation as cv | ||
from esphome.components import rtttl | ||
from esphome.const import CONF_ID | ||
|
||
CONF_RTTTL = "rtttl" | ||
CONF_SONG = "song" | ||
|
||
|
||
from .. import RATGDO_CLIENT_SCHMEA, ratgdo_ns, register_ratgdo_child | ||
|
||
DEPENDENCIES = ["esp32", "ratgdo", "rtttl"] | ||
|
||
RATGDOOutput = ratgdo_ns.class_("RATGDOOutput", cg.Component) | ||
OutputType = ratgdo_ns.enum("OutputType") | ||
|
||
CONF_TYPE = "type" | ||
TYPES = {"beeper": OutputType.RATGDO_BEEPER} | ||
|
||
CONFIG_SCHEMA = cv.Schema( | ||
{ | ||
cv.Required(CONF_ID): cv.declare_id(RATGDOOutput), | ||
cv.Required(CONF_TYPE): cv.enum(TYPES, lower=True), | ||
cv.Required(CONF_RTTTL): cv.use_id(rtttl), | ||
cv.Required(CONF_SONG): cv.string, | ||
} | ||
).extend(RATGDO_CLIENT_SCHMEA) | ||
|
||
|
||
async def to_code(config): | ||
var = cg.new_Pvariable(config[CONF_ID]) | ||
await cg.register_component(var, config) | ||
rtttl = await cg.get_variable(config[CONF_RTTTL]) | ||
cg.add(var.set_rtttl(rtttl)) | ||
cg.add(var.set_song(config[CONF_SONG])) | ||
await register_ratgdo_child(var, config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "ratgdo_output.h" | ||
#include "../ratgdo_state.h" | ||
#include "esphome/core/log.h" | ||
|
||
namespace esphome { | ||
namespace ratgdo { | ||
|
||
static const char* TAG = "ratgdo.output"; | ||
|
||
void RATGDOOutput::setup() | ||
{ | ||
ESP_LOGD(TAG, "Output was setup"); | ||
|
||
if (this->output_type_ == OutputType::RATGDO_BEEPER) { | ||
this->beeper_->add_on_finished_playback_callback([=] { this->finished_playback(); }); | ||
|
||
this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) { | ||
if (state == VehicleArrivingState::YES) { | ||
this->play(); | ||
} | ||
}); | ||
|
||
this->parent_->subscribe_door_action_delayed([=](DoorActionDelayed state) { | ||
if (state == DoorActionDelayed::YES) { | ||
this->play(); | ||
this->repeat_ = true; | ||
} else if (state == DoorActionDelayed::NO) { | ||
this->repeat_ = false; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
void RATGDOOutput::play() | ||
{ | ||
this->beeper_->play(this->rtttlSong_); | ||
} | ||
|
||
void RATGDOOutput::finished_playback() | ||
{ | ||
if (this->repeat_) | ||
this->play(); | ||
} | ||
|
||
void RATGDOOutput::dump_config() | ||
{ | ||
if (this->output_type_ == OutputType::RATGDO_BEEPER) { | ||
ESP_LOGCONFIG(TAG, " Type: Beeper"); | ||
} | ||
} | ||
|
||
void RATGDOOutput::set_output_type(OutputType output_type_) | ||
{ | ||
this->output_type_ = output_type_; | ||
} | ||
|
||
} // namespace ratgdo | ||
} // namespace esphome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include "../ratgdo.h" | ||
#include "esphome/components/rtttl/rtttl.h" | ||
#include "esphome/core/component.h" | ||
|
||
namespace esphome { | ||
namespace ratgdo { | ||
|
||
enum OutputType { | ||
RATGDO_BEEPER | ||
}; | ||
|
||
class RATGDOOutput : public RATGDOClient, public Component { | ||
public: | ||
void setup() override; | ||
void play(); | ||
void finished_playback(); | ||
void dump_config() override; | ||
void set_output_type(OutputType output_type); | ||
void set_song(std::string rtttlSong) { this->rtttlSong_ = rtttlSong; } | ||
void set_rtttl(rtttl::Rtttl* output) { this->beeper_ = output; } | ||
|
||
protected: | ||
OutputType output_type_; | ||
rtttl::Rtttl* beeper_; | ||
std::string rtttlSong_; | ||
bool repeat_; | ||
}; | ||
|
||
} // namespace ratgdo | ||
} // namespace esphome |
Oops, something went wrong.