10static const char *
const TAG =
"tormatic.cover";
16 if (restore.has_value()) {
27 traits.set_supports_stop(
true);
28 traits.set_supports_position(
true);
29 traits.set_is_assumed_state(
false);
34 LOG_COVER(
"",
"Tormatic Cover",
this);
37 ESP_LOGCONFIG(TAG,
" Open Duration: %.1fs", this->
open_duration_ / 1e3f);
38 ESP_LOGCONFIG(TAG,
" Close Duration: %.1fs", this->
close_duration_ / 1e3f);
41 if (restore.has_value()) {
42 ESP_LOGCONFIG(TAG,
" Saved position %d%%", (
int) (restore->position * 100.f));
51 auto status = o_status.value();
62 if (
call.get_stop()) {
68 auto pos =
call.get_position().value();
100 ESP_LOGD(TAG,
"Gate paused, clearing direction start time");
108 ESP_LOGD(TAG,
"Gate started moving from fully open or closed state");
120 ESP_LOGI(TAG,
"Recalibrated the gate's open duration to %dms", this->
open_duration_);
124 ESP_LOGI(TAG,
"Recalibrated the gate's close duration to %dms", this->
close_duration_);
173 const uint32_t now =
millis();
187 this->last_recompute_time_ = now;
199 ESP_LOGI(TAG,
"Fully opening gate");
204 ESP_LOGI(TAG,
"Fully closing gate");
214 ESP_LOGI(TAG,
"Opening gate towards %.1f", target);
220 ESP_LOGI(TAG,
"Closing gate towards %.1f", target);
258 ESP_LOGE(TAG,
"Timeout reading message header");
261 auto hdr = o_hdr.value();
266 ESP_LOGE(TAG,
"Header specifies payload size %d but size of StatusReply is %d", hdr.payload_size(),
275 auto status = o_status.value();
291 ESP_LOGE(TAG,
"Reading remaining %d payload bytes of unknown type 0x%x", hdr.payload_size(), hdr.type);
303 ESP_LOGV(TAG,
"Requesting gate status");
320 out.insert(out.end(), reqv.begin(), reqv.end());
327 uint32_t start =
millis();
329 auto ok = this->
read_array((uint8_t *) &obj,
sizeof(obj));
336 ESP_LOGV(TAG,
"Read %s in %d ms", obj.print().c_str(),
millis() - start);
348 if (n > 0 && count >= n) {
send_message_t send_message_
const optional< float > & get_position() const
CoverOperation current_operation
The current operation of the cover (idle, opening, closing).
optional< CoverRestoreState > restore_state_()
void publish_state(bool save=true)
Publish the current state of the cover.
float position
The position of the cover from 0.0 (fully closed) to 1.0 (fully open).
value_type const & value() const
optional< GateStatus > read_gate_status_()
void dump_config() override
void send_message_(MessageType t, T r)
GateStatus current_status_
void recalibrate_duration_(GateStatus s)
uint32_t direction_start_time_
void drain_rx_(uint16_t n=0)
void request_gate_status_()
optional< float > target_position_
void recompute_position_()
void send_gate_command_(GateStatus s)
void control(const cover::CoverCall &call) override
optional< T > read_data_()
void control_position_(float target)
void handle_gate_status_(GateStatus s)
uint32_t last_publish_time_
uint32_t last_recompute_time_
cover::CoverTraits get_traits() override
void publish_state(bool save=true, uint32_t ratelimit=0)
optional< std::array< uint8_t, N > > read_array()
void check_uart_settings(uint32_t baud_rate, uint8_t stop_bits=1, UARTParityOptions parity=UART_CONFIG_PARITY_NONE, uint8_t data_bits=8)
Check that the configuration of the UART bus matches the provided values and otherwise print a warnin...
bool read_byte(uint8_t *data)
void write_array(const uint8_t *data, size_t len)
@ COVER_OPERATION_OPENING
The cover is currently opening.
@ COVER_OPERATION_CLOSING
The cover is currently closing.
@ COVER_OPERATION_IDLE
The cover is currently idle (not moving)
CoverOperation gate_status_to_cover_operation(GateStatus s)
std::vector< uint8_t > serialize(T obj)
const char * gate_status_to_str(GateStatus s)
@ UART_CONFIG_PARITY_NONE
Providing packet encoding functions for exchanging data with a remote host.
uint32_t IRAM_ATTR HOT millis()
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)