mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 09:17:46 +01:00
commit
ccc13cc9e1
11 changed files with 75 additions and 16 deletions
|
@ -113,6 +113,7 @@ void BLEClient::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t es
|
||||||
}
|
}
|
||||||
case ESP_GATTC_OPEN_EVT: {
|
case ESP_GATTC_OPEN_EVT: {
|
||||||
ESP_LOGV(TAG, "[%s] ESP_GATTC_OPEN_EVT", this->address_str().c_str());
|
ESP_LOGV(TAG, "[%s] ESP_GATTC_OPEN_EVT", this->address_str().c_str());
|
||||||
|
this->conn_id = param->open.conn_id;
|
||||||
if (param->open.status != ESP_GATT_OK) {
|
if (param->open.status != ESP_GATT_OK) {
|
||||||
ESP_LOGW(TAG, "connect to %s failed, status=%d", this->address_str().c_str(), param->open.status);
|
ESP_LOGW(TAG, "connect to %s failed, status=%d", this->address_str().c_str(), param->open.status);
|
||||||
this->set_states_(espbt::ClientState::IDLE);
|
this->set_states_(espbt::ClientState::IDLE);
|
||||||
|
@ -122,7 +123,10 @@ void BLEClient::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t es
|
||||||
}
|
}
|
||||||
case ESP_GATTC_CONNECT_EVT: {
|
case ESP_GATTC_CONNECT_EVT: {
|
||||||
ESP_LOGV(TAG, "[%s] ESP_GATTC_CONNECT_EVT", this->address_str().c_str());
|
ESP_LOGV(TAG, "[%s] ESP_GATTC_CONNECT_EVT", this->address_str().c_str());
|
||||||
this->conn_id = param->connect.conn_id;
|
if (this->conn_id != param->connect.conn_id) {
|
||||||
|
ESP_LOGD(TAG, "[%s] Unexpected conn_id in CONNECT_EVT: param conn=%d, open conn=%d",
|
||||||
|
this->address_str().c_str(), param->connect.conn_id, this->conn_id);
|
||||||
|
}
|
||||||
auto ret = esp_ble_gattc_send_mtu_req(this->gattc_if, param->connect.conn_id);
|
auto ret = esp_ble_gattc_send_mtu_req(this->gattc_if, param->connect.conn_id);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ESP_LOGW(TAG, "esp_ble_gattc_send_mtu_req failed, status=%x", ret);
|
ESP_LOGW(TAG, "esp_ble_gattc_send_mtu_req failed, status=%x", ret);
|
||||||
|
@ -183,9 +187,10 @@ void BLEClient::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t es
|
||||||
descr->uuid.to_string().c_str());
|
descr->uuid.to_string().c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
uint8_t notify_en = 1;
|
uint16_t notify_en = 1;
|
||||||
auto status = esp_ble_gattc_write_char_descr(this->gattc_if, this->conn_id, descr->handle, sizeof(notify_en),
|
auto status =
|
||||||
¬ify_en, ESP_GATT_WRITE_TYPE_RSP, ESP_GATT_AUTH_REQ_NONE);
|
esp_ble_gattc_write_char_descr(this->gattc_if, this->conn_id, descr->handle, sizeof(notify_en),
|
||||||
|
(uint8_t *) ¬ify_en, ESP_GATT_WRITE_TYPE_RSP, ESP_GATT_AUTH_REQ_NONE);
|
||||||
if (status) {
|
if (status) {
|
||||||
ESP_LOGW(TAG, "esp_ble_gattc_write_char_descr error, status=%d", status);
|
ESP_LOGW(TAG, "esp_ble_gattc_write_char_descr error, status=%d", status);
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ async def to_code(config):
|
||||||
cg.add(var.set_request_interval(config[CONF_REQUEST_INTERVAL].total_milliseconds))
|
cg.add(var.set_request_interval(config[CONF_REQUEST_INTERVAL].total_milliseconds))
|
||||||
cg.add(var.set_receive_timeout(config[CONF_RECEIVE_TIMEOUT].total_milliseconds))
|
cg.add(var.set_receive_timeout(config[CONF_RECEIVE_TIMEOUT].total_milliseconds))
|
||||||
|
|
||||||
cg.add_define("DSMR_GAS_MBUS_ID", config[CONF_GAS_MBUS_ID])
|
cg.add_build_flag("-DDSMR_GAS_MBUS_ID=" + str(config[CONF_GAS_MBUS_ID]))
|
||||||
|
|
||||||
# DSMR Parser
|
# DSMR Parser
|
||||||
cg.add_library("glmnet/Dsmr", "0.5")
|
cg.add_library("glmnet/Dsmr", "0.5")
|
||||||
|
|
|
@ -20,6 +20,9 @@ MediaPlayer = media_player_ns.class_("MediaPlayer")
|
||||||
PlayAction = media_player_ns.class_(
|
PlayAction = media_player_ns.class_(
|
||||||
"PlayAction", automation.Action, cg.Parented.template(MediaPlayer)
|
"PlayAction", automation.Action, cg.Parented.template(MediaPlayer)
|
||||||
)
|
)
|
||||||
|
PlayMediaAction = media_player_ns.class_(
|
||||||
|
"PlayMediaAction", automation.Action, cg.Parented.template(MediaPlayer)
|
||||||
|
)
|
||||||
ToggleAction = media_player_ns.class_(
|
ToggleAction = media_player_ns.class_(
|
||||||
"ToggleAction", automation.Action, cg.Parented.template(MediaPlayer)
|
"ToggleAction", automation.Action, cg.Parented.template(MediaPlayer)
|
||||||
)
|
)
|
||||||
|
@ -44,11 +47,14 @@ CONF_VOLUME = "volume"
|
||||||
CONF_ON_IDLE = "on_idle"
|
CONF_ON_IDLE = "on_idle"
|
||||||
CONF_ON_PLAY = "on_play"
|
CONF_ON_PLAY = "on_play"
|
||||||
CONF_ON_PAUSE = "on_pause"
|
CONF_ON_PAUSE = "on_pause"
|
||||||
|
CONF_MEDIA_URL = "media_url"
|
||||||
|
|
||||||
StateTrigger = media_player_ns.class_("StateTrigger", automation.Trigger.template())
|
StateTrigger = media_player_ns.class_("StateTrigger", automation.Trigger.template())
|
||||||
IdleTrigger = media_player_ns.class_("IdleTrigger", automation.Trigger.template())
|
IdleTrigger = media_player_ns.class_("IdleTrigger", automation.Trigger.template())
|
||||||
PlayTrigger = media_player_ns.class_("PlayTrigger", automation.Trigger.template())
|
PlayTrigger = media_player_ns.class_("PlayTrigger", automation.Trigger.template())
|
||||||
PauseTrigger = media_player_ns.class_("PauseTrigger", automation.Trigger.template())
|
PauseTrigger = media_player_ns.class_("PauseTrigger", automation.Trigger.template())
|
||||||
|
IsIdleCondition = media_player_ns.class_("IsIdleCondition", automation.Condition)
|
||||||
|
IsPlayingCondition = media_player_ns.class_("IsPlayingCondition", automation.Condition)
|
||||||
|
|
||||||
|
|
||||||
async def setup_media_player_core_(var, config):
|
async def setup_media_player_core_(var, config):
|
||||||
|
@ -103,6 +109,25 @@ MEDIA_PLAYER_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(
|
||||||
MEDIA_PLAYER_ACTION_SCHEMA = maybe_simple_id({cv.GenerateID(): cv.use_id(MediaPlayer)})
|
MEDIA_PLAYER_ACTION_SCHEMA = maybe_simple_id({cv.GenerateID(): cv.use_id(MediaPlayer)})
|
||||||
|
|
||||||
|
|
||||||
|
@automation.register_action(
|
||||||
|
"media_player.play_media",
|
||||||
|
PlayMediaAction,
|
||||||
|
cv.maybe_simple_value(
|
||||||
|
{
|
||||||
|
cv.GenerateID(): cv.use_id(MediaPlayer),
|
||||||
|
cv.Required(CONF_MEDIA_URL): cv.templatable(cv.url),
|
||||||
|
},
|
||||||
|
key=CONF_MEDIA_URL,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
async def media_player_play_media_action(config, action_id, template_arg, args):
|
||||||
|
var = cg.new_Pvariable(action_id, template_arg)
|
||||||
|
await cg.register_parented(var, config[CONF_ID])
|
||||||
|
media_url = await cg.templatable(config[CONF_MEDIA_URL], args, cg.std_string)
|
||||||
|
cg.add(var.set_media_url(media_url))
|
||||||
|
return var
|
||||||
|
|
||||||
|
|
||||||
@automation.register_action("media_player.play", PlayAction, MEDIA_PLAYER_ACTION_SCHEMA)
|
@automation.register_action("media_player.play", PlayAction, MEDIA_PLAYER_ACTION_SCHEMA)
|
||||||
@automation.register_action(
|
@automation.register_action(
|
||||||
"media_player.toggle", ToggleAction, MEDIA_PLAYER_ACTION_SCHEMA
|
"media_player.toggle", ToggleAction, MEDIA_PLAYER_ACTION_SCHEMA
|
||||||
|
@ -117,6 +142,12 @@ MEDIA_PLAYER_ACTION_SCHEMA = maybe_simple_id({cv.GenerateID(): cv.use_id(MediaPl
|
||||||
@automation.register_action(
|
@automation.register_action(
|
||||||
"media_player.volume_down", VolumeDownAction, MEDIA_PLAYER_ACTION_SCHEMA
|
"media_player.volume_down", VolumeDownAction, MEDIA_PLAYER_ACTION_SCHEMA
|
||||||
)
|
)
|
||||||
|
@automation.register_condition(
|
||||||
|
"media_player.is_idle", IsIdleCondition, MEDIA_PLAYER_ACTION_SCHEMA
|
||||||
|
)
|
||||||
|
@automation.register_condition(
|
||||||
|
"media_player.is_playing", IsPlayingCondition, MEDIA_PLAYER_ACTION_SCHEMA
|
||||||
|
)
|
||||||
async def media_player_action(config, action_id, template_arg, args):
|
async def media_player_action(config, action_id, template_arg, args):
|
||||||
var = cg.new_Pvariable(action_id, template_arg)
|
var = cg.new_Pvariable(action_id, template_arg)
|
||||||
await cg.register_parented(var, config[CONF_ID])
|
await cg.register_parented(var, config[CONF_ID])
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace media_player {
|
||||||
#define MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(TRIGGER_CLASS, TRIGGER_STATE) \
|
#define MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(TRIGGER_CLASS, TRIGGER_STATE) \
|
||||||
class TRIGGER_CLASS : public Trigger<> { \
|
class TRIGGER_CLASS : public Trigger<> { \
|
||||||
public: \
|
public: \
|
||||||
TRIGGER_CLASS(MediaPlayer *player) { \
|
explicit TRIGGER_CLASS(MediaPlayer *player) { \
|
||||||
player->add_on_state_callback([this, player]() { \
|
player->add_on_state_callback([this, player]() { \
|
||||||
if (player->state == MediaPlayerState::MEDIA_PLAYER_STATE_##TRIGGER_STATE) \
|
if (player->state == MediaPlayerState::MEDIA_PLAYER_STATE_##TRIGGER_STATE) \
|
||||||
this->trigger(); \
|
this->trigger(); \
|
||||||
|
@ -32,6 +32,11 @@ MEDIA_PLAYER_SIMPLE_COMMAND_ACTION(ToggleAction, TOGGLE)
|
||||||
MEDIA_PLAYER_SIMPLE_COMMAND_ACTION(VolumeUpAction, VOLUME_UP)
|
MEDIA_PLAYER_SIMPLE_COMMAND_ACTION(VolumeUpAction, VOLUME_UP)
|
||||||
MEDIA_PLAYER_SIMPLE_COMMAND_ACTION(VolumeDownAction, VOLUME_DOWN)
|
MEDIA_PLAYER_SIMPLE_COMMAND_ACTION(VolumeDownAction, VOLUME_DOWN)
|
||||||
|
|
||||||
|
template<typename... Ts> class PlayMediaAction : public Action<Ts...>, public Parented<MediaPlayer> {
|
||||||
|
TEMPLATABLE_VALUE(std::string, media_url)
|
||||||
|
void play(Ts... x) override { this->parent_->make_call().set_media_url(this->media_url_.value(x...)).perform(); }
|
||||||
|
};
|
||||||
|
|
||||||
template<typename... Ts> class VolumeSetAction : public Action<Ts...>, public Parented<MediaPlayer> {
|
template<typename... Ts> class VolumeSetAction : public Action<Ts...>, public Parented<MediaPlayer> {
|
||||||
TEMPLATABLE_VALUE(float, volume)
|
TEMPLATABLE_VALUE(float, volume)
|
||||||
void play(Ts... x) override { this->parent_->make_call().set_volume(this->volume_.value(x...)).perform(); }
|
void play(Ts... x) override { this->parent_->make_call().set_volume(this->volume_.value(x...)).perform(); }
|
||||||
|
@ -39,7 +44,7 @@ template<typename... Ts> class VolumeSetAction : public Action<Ts...>, public Pa
|
||||||
|
|
||||||
class StateTrigger : public Trigger<> {
|
class StateTrigger : public Trigger<> {
|
||||||
public:
|
public:
|
||||||
StateTrigger(MediaPlayer *player) {
|
explicit StateTrigger(MediaPlayer *player) {
|
||||||
player->add_on_state_callback([this]() { this->trigger(); });
|
player->add_on_state_callback([this]() { this->trigger(); });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -48,5 +53,15 @@ MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(IdleTrigger, IDLE)
|
||||||
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(PlayTrigger, PLAYING)
|
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(PlayTrigger, PLAYING)
|
||||||
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(PauseTrigger, PAUSED)
|
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(PauseTrigger, PAUSED)
|
||||||
|
|
||||||
|
template<typename... Ts> class IsIdleCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
|
||||||
|
public:
|
||||||
|
bool check(Ts... x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_IDLE; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename... Ts> class IsPlayingCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
|
||||||
|
public:
|
||||||
|
bool check(Ts... x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_PLAYING; }
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace media_player
|
} // namespace media_player
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
|
@ -187,7 +187,7 @@ void MQTTClientComponent::start_connect_() {
|
||||||
|
|
||||||
this->mqtt_backend_.set_credentials(username, password);
|
this->mqtt_backend_.set_credentials(username, password);
|
||||||
|
|
||||||
this->mqtt_backend_.set_server((uint32_t) this->ip_, this->credentials_.port);
|
this->mqtt_backend_.set_server(this->credentials_.address.c_str(), this->credentials_.port);
|
||||||
if (!this->last_will_.topic.empty()) {
|
if (!this->last_will_.topic.empty()) {
|
||||||
this->mqtt_backend_.set_will(this->last_will_.topic.c_str(), this->last_will_.qos, this->last_will_.retain,
|
this->mqtt_backend_.set_will(this->last_will_.topic.c_str(), this->last_will_.qos, this->last_will_.retain,
|
||||||
this->last_will_.payload.c_str());
|
this->last_will_.payload.c_str());
|
||||||
|
|
|
@ -140,5 +140,7 @@ async def to_code(config):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
cg.add_library(
|
cg.add_library(
|
||||||
None, None, "https://github.com/Sensirion/arduino-gas-index-algorithm.git"
|
None,
|
||||||
|
None,
|
||||||
|
"https://github.com/Sensirion/arduino-gas-index-algorithm.git#3.2.1",
|
||||||
)
|
)
|
||||||
|
|
|
@ -170,8 +170,8 @@ bool SGP4xComponent::measure_gas_indices_(int32_t &voc, int32_t &nox) {
|
||||||
// much
|
// much
|
||||||
if (this->store_baseline_ && this->seconds_since_last_store_ > SHORTEST_BASELINE_STORE_INTERVAL) {
|
if (this->store_baseline_ && this->seconds_since_last_store_ > SHORTEST_BASELINE_STORE_INTERVAL) {
|
||||||
voc_algorithm_.get_states(this->voc_state0_, this->voc_state1_);
|
voc_algorithm_.get_states(this->voc_state0_, this->voc_state1_);
|
||||||
if ((uint32_t) abs(this->voc_baselines_storage_.state0 - this->voc_state0_) > MAXIMUM_STORAGE_DIFF ||
|
if (std::abs(this->voc_baselines_storage_.state0 - this->voc_state0_) > MAXIMUM_STORAGE_DIFF ||
|
||||||
(uint32_t) abs(this->voc_baselines_storage_.state1 - this->voc_state1_) > MAXIMUM_STORAGE_DIFF) {
|
std::abs(this->voc_baselines_storage_.state1 - this->voc_state1_) > MAXIMUM_STORAGE_DIFF) {
|
||||||
this->seconds_since_last_store_ = 0;
|
this->seconds_since_last_store_ = 0;
|
||||||
this->voc_baselines_storage_.state0 = this->voc_state0_;
|
this->voc_baselines_storage_.state0 = this->voc_state0_;
|
||||||
this->voc_baselines_storage_.state1 = this->voc_state1_;
|
this->voc_baselines_storage_.state1 = this->voc_state1_;
|
||||||
|
|
|
@ -49,7 +49,7 @@ static const uint16_t SPG41_SELFTEST_TIME = 320; // 320 ms for self test
|
||||||
static const uint16_t SGP40_MEASURE_TIME = 30;
|
static const uint16_t SGP40_MEASURE_TIME = 30;
|
||||||
static const uint16_t SGP41_MEASURE_TIME = 55;
|
static const uint16_t SGP41_MEASURE_TIME = 55;
|
||||||
// Store anyway if the baseline difference exceeds the max storage diff value
|
// Store anyway if the baseline difference exceeds the max storage diff value
|
||||||
const uint32_t MAXIMUM_STORAGE_DIFF = 50;
|
const float MAXIMUM_STORAGE_DIFF = 50.0f;
|
||||||
|
|
||||||
class SGP4xComponent;
|
class SGP4xComponent;
|
||||||
|
|
||||||
|
@ -120,8 +120,8 @@ class SGP4xComponent : public PollingComponent, public sensor::Sensor, public se
|
||||||
sensor::Sensor *voc_sensor_{nullptr};
|
sensor::Sensor *voc_sensor_{nullptr};
|
||||||
VOCGasIndexAlgorithm voc_algorithm_;
|
VOCGasIndexAlgorithm voc_algorithm_;
|
||||||
optional<GasTuning> voc_tuning_params_;
|
optional<GasTuning> voc_tuning_params_;
|
||||||
int32_t voc_state0_;
|
float voc_state0_;
|
||||||
int32_t voc_state1_;
|
float voc_state1_;
|
||||||
int32_t voc_index_ = 0;
|
int32_t voc_index_ = 0;
|
||||||
|
|
||||||
sensor::Sensor *nox_sensor_{nullptr};
|
sensor::Sensor *nox_sensor_{nullptr};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""Constants used by esphome."""
|
"""Constants used by esphome."""
|
||||||
|
|
||||||
__version__ = "2022.6.1"
|
__version__ = "2022.6.2"
|
||||||
|
|
||||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ lib_deps =
|
||||||
wjtje/qr-code-generator-library@1.7.0 ; qr_code
|
wjtje/qr-code-generator-library@1.7.0 ; qr_code
|
||||||
functionpointer/arduino-MLX90393@1.0.0 ; mlx90393
|
functionpointer/arduino-MLX90393@1.0.0 ; mlx90393
|
||||||
; This is using the repository until a new release is published to PlatformIO
|
; This is using the repository until a new release is published to PlatformIO
|
||||||
https://github.com/Sensirion/arduino-gas-index-algorithm.git ; Sensirion Gas Index Algorithm Arduino Library
|
https://github.com/Sensirion/arduino-gas-index-algorithm.git#3.2.1 ; Sensirion Gas Index Algorithm Arduino Library
|
||||||
build_flags =
|
build_flags =
|
||||||
-DESPHOME_LOG_LEVEL=ESPHOME_LOG_LEVEL_VERY_VERBOSE
|
-DESPHOME_LOG_LEVEL=ESPHOME_LOG_LEVEL_VERY_VERBOSE
|
||||||
src_filter =
|
src_filter =
|
||||||
|
|
|
@ -615,12 +615,18 @@ media_player:
|
||||||
mute_pin: GPIO14
|
mute_pin: GPIO14
|
||||||
on_state:
|
on_state:
|
||||||
- media_player.play:
|
- media_player.play:
|
||||||
|
- media_player.play_media: http://localhost/media.mp3
|
||||||
|
- media_player.play_media: !lambda 'return "http://localhost/media.mp3";'
|
||||||
on_idle:
|
on_idle:
|
||||||
- media_player.pause:
|
- media_player.pause:
|
||||||
on_play:
|
on_play:
|
||||||
- media_player.stop:
|
- media_player.stop:
|
||||||
on_pause:
|
on_pause:
|
||||||
- media_player.toggle:
|
- media_player.toggle:
|
||||||
|
- wait_until:
|
||||||
|
media_player.is_idle:
|
||||||
|
- wait_until:
|
||||||
|
media_player.is_playing:
|
||||||
- media_player.volume_up:
|
- media_player.volume_up:
|
||||||
- media_player.volume_down:
|
- media_player.volume_down:
|
||||||
- media_player.volume_set: 50%
|
- media_player.volume_set: 50%
|
||||||
|
|
Loading…
Reference in a new issue