mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-19 04:33:27 +02:00
Add valve component (#6447)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -54,6 +54,9 @@
|
||||
#ifdef USE_LOCK
|
||||
#include "esphome/components/lock/lock.h"
|
||||
#endif
|
||||
#ifdef USE_VALVE
|
||||
#include "esphome/components/valve/valve.h"
|
||||
#endif
|
||||
#ifdef USE_MEDIA_PLAYER
|
||||
#include "esphome/components/media_player/media_player.h"
|
||||
#endif
|
||||
@@ -147,6 +150,10 @@ class Application {
|
||||
void register_lock(lock::Lock *a_lock) { this->locks_.push_back(a_lock); }
|
||||
#endif
|
||||
|
||||
#ifdef USE_VALVE
|
||||
void register_valve(valve::Valve *valve) { this->valves_.push_back(valve); }
|
||||
#endif
|
||||
|
||||
#ifdef USE_MEDIA_PLAYER
|
||||
void register_media_player(media_player::MediaPlayer *media_player) { this->media_players_.push_back(media_player); }
|
||||
#endif
|
||||
@@ -348,6 +355,15 @@ class Application {
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_VALVE
|
||||
const std::vector<valve::Valve *> &get_valves() { return this->valves_; }
|
||||
valve::Valve *get_valve_by_key(uint32_t key, bool include_internal = false) {
|
||||
for (auto *obj : this->valves_)
|
||||
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
||||
return obj;
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_MEDIA_PLAYER
|
||||
const std::vector<media_player::MediaPlayer *> &get_media_players() { return this->media_players_; }
|
||||
media_player::MediaPlayer *get_media_player_by_key(uint32_t key, bool include_internal = false) {
|
||||
@@ -429,6 +445,9 @@ class Application {
|
||||
#ifdef USE_LOCK
|
||||
std::vector<lock::Lock *> locks_{};
|
||||
#endif
|
||||
#ifdef USE_VALVE
|
||||
std::vector<valve::Valve *> valves_{};
|
||||
#endif
|
||||
#ifdef USE_MEDIA_PLAYER
|
||||
std::vector<media_player::MediaPlayer *> media_players_{};
|
||||
#endif
|
||||
|
||||
@@ -277,6 +277,21 @@ void ComponentIterator::advance() {
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef USE_VALVE
|
||||
case IteratorState::VALVE:
|
||||
if (this->at_ >= App.get_valves().size()) {
|
||||
advance_platform = true;
|
||||
} else {
|
||||
auto *valve = App.get_valves()[this->at_];
|
||||
if (valve->is_internal() && !this->include_internal_) {
|
||||
success = true;
|
||||
break;
|
||||
} else {
|
||||
success = this->on_valve(valve);
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef USE_MEDIA_PLAYER
|
||||
case IteratorState::MEDIA_PLAYER:
|
||||
if (this->at_ >= App.get_media_players().size()) {
|
||||
|
||||
@@ -72,6 +72,9 @@ class ComponentIterator {
|
||||
#ifdef USE_LOCK
|
||||
virtual bool on_lock(lock::Lock *a_lock) = 0;
|
||||
#endif
|
||||
#ifdef USE_VALVE
|
||||
virtual bool on_valve(valve::Valve *valve) = 0;
|
||||
#endif
|
||||
#ifdef USE_MEDIA_PLAYER
|
||||
virtual bool on_media_player(media_player::MediaPlayer *media_player);
|
||||
#endif
|
||||
@@ -135,6 +138,9 @@ class ComponentIterator {
|
||||
#ifdef USE_LOCK
|
||||
LOCK,
|
||||
#endif
|
||||
#ifdef USE_VALVE
|
||||
VALVE,
|
||||
#endif
|
||||
#ifdef USE_MEDIA_PLAYER
|
||||
MEDIA_PLAYER,
|
||||
#endif
|
||||
|
||||
@@ -91,6 +91,12 @@ void Controller::setup_controller(bool include_internal) {
|
||||
obj->add_on_state_callback([this, obj]() { this->on_lock_update(obj); });
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_VALVE
|
||||
for (auto *obj : App.get_valves()) {
|
||||
if (include_internal || !obj->is_internal())
|
||||
obj->add_on_state_callback([this, obj]() { this->on_valve_update(obj); });
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_MEDIA_PLAYER
|
||||
for (auto *obj : App.get_media_players()) {
|
||||
if (include_internal || !obj->is_internal())
|
||||
|
||||
@@ -46,6 +46,9 @@
|
||||
#ifdef USE_LOCK
|
||||
#include "esphome/components/lock/lock.h"
|
||||
#endif
|
||||
#ifdef USE_VALVE
|
||||
#include "esphome/components/valve/valve.h"
|
||||
#endif
|
||||
#ifdef USE_MEDIA_PLAYER
|
||||
#include "esphome/components/media_player/media_player.h"
|
||||
#endif
|
||||
@@ -100,6 +103,9 @@ class Controller {
|
||||
#ifdef USE_LOCK
|
||||
virtual void on_lock_update(lock::Lock *obj){};
|
||||
#endif
|
||||
#ifdef USE_VALVE
|
||||
virtual void on_valve_update(valve::Valve *obj){};
|
||||
#endif
|
||||
#ifdef USE_MEDIA_PLAYER
|
||||
virtual void on_media_player_update(media_player::MediaPlayer *obj){};
|
||||
#endif
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
#define USE_TIME
|
||||
#define USE_TOUCHSCREEN
|
||||
#define USE_UART_DEBUGGER
|
||||
#define USE_VALVE
|
||||
#define USE_WIFI
|
||||
#define USE_WIFI_AP
|
||||
#define USE_GRAPHICAL_DISPLAY_MENU
|
||||
|
||||
Reference in New Issue
Block a user