mirror of
https://github.com/esphome/esphome.git
synced 2025-04-02 08:58:17 +01:00
## Description: Move esphome-core codebase into esphome (and a bunch of other refactors). See https://github.com/esphome/feature-requests/issues/97 Yes this is a shit ton of work and no there's no way to automate it :( But it will be worth it 👍 Progress: - Core support (file copy etc): 80% - Base Abstractions (light, switch): ~50% - Integrations: ~10% - Working? Yes, (but only with ported components). Other refactors: - Moves all codegen related stuff into a single class: `esphome.codegen` (imported as `cg`) - Rework coroutine syntax - Move from `component/platform.py` to `domain/component.py` structure as with HA - Move all defaults out of C++ and into config validation. - Remove `make_...` helpers from Application class. Reason: Merge conflicts with every single new integration. - Pointer Variables are stored globally instead of locally in setup(). Reason: stack size limit. Future work: - Rework const.py - Move all `CONF_...` into a conf class (usage `conf.UPDATE_INTERVAL` vs `CONF_UPDATE_INTERVAL`). Reason: Less convoluted import block - Enable loading from `custom_components` folder. **Related issue (if applicable):** https://github.com/esphome/feature-requests/issues/97 **Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here> ## Checklist: - [ ] The code change is tested and works locally. - [ ] Tests have been added to verify that the new code works (under `tests/` folder). If user exposed functionality or configuration variables are added/changed: - [ ] Documentation added/updated in [esphomedocs](https://github.com/OttoWinter/esphomedocs).
163 lines
4.5 KiB
C++
163 lines
4.5 KiB
C++
#pragma once
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/core/defines.h"
|
|
#include "api_message.h"
|
|
|
|
namespace esphome {
|
|
namespace api {
|
|
|
|
#ifdef USE_COVER
|
|
enum LegacyCoverCommand {
|
|
LEGACY_COVER_COMMAND_OPEN = 0,
|
|
LEGACY_COVER_COMMAND_CLOSE = 1,
|
|
LEGACY_COVER_COMMAND_STOP = 2,
|
|
};
|
|
|
|
class CoverCommandRequest : public APIMessage {
|
|
public:
|
|
bool decode_varint(uint32_t field_id, uint32_t value) override;
|
|
bool decode_32bit(uint32_t field_id, uint32_t value) override;
|
|
APIMessageType message_type() const override;
|
|
uint32_t get_key() const;
|
|
optional<LegacyCoverCommand> get_legacy_command() const;
|
|
optional<float> get_position() const;
|
|
optional<float> get_tilt() const;
|
|
bool get_stop() const { return this->stop_; }
|
|
|
|
protected:
|
|
uint32_t key_{0};
|
|
bool has_legacy_command_{false};
|
|
LegacyCoverCommand legacy_command_{LEGACY_COVER_COMMAND_OPEN};
|
|
bool has_position_{false};
|
|
float position_{0.0f};
|
|
bool has_tilt_{false};
|
|
float tilt_{0.0f};
|
|
bool stop_{false};
|
|
};
|
|
#endif
|
|
|
|
#ifdef USE_FAN
|
|
class FanCommandRequest : public APIMessage {
|
|
public:
|
|
bool decode_varint(uint32_t field_id, uint32_t value) override;
|
|
bool decode_32bit(uint32_t field_id, uint32_t value) override;
|
|
APIMessageType message_type() const override;
|
|
uint32_t get_key() const;
|
|
optional<bool> get_state() const;
|
|
optional<fan::FanSpeed> get_speed() const;
|
|
optional<bool> get_oscillating() const;
|
|
|
|
protected:
|
|
uint32_t key_{0};
|
|
bool has_state_{false};
|
|
bool state_{false};
|
|
bool has_speed_{false};
|
|
fan::FanSpeed speed_{fan::FAN_SPEED_LOW};
|
|
bool has_oscillating_{false};
|
|
bool oscillating_{false};
|
|
};
|
|
#endif
|
|
|
|
#ifdef USE_LIGHT
|
|
class LightCommandRequest : public APIMessage {
|
|
public:
|
|
bool decode_varint(uint32_t field_id, uint32_t value) override;
|
|
bool decode_length_delimited(uint32_t field_id, const uint8_t *value, size_t len) override;
|
|
bool decode_32bit(uint32_t field_id, uint32_t value) override;
|
|
APIMessageType message_type() const override;
|
|
uint32_t get_key() const;
|
|
optional<bool> get_state() const;
|
|
optional<float> get_brightness() const;
|
|
optional<float> get_red() const;
|
|
optional<float> get_green() const;
|
|
optional<float> get_blue() const;
|
|
optional<float> get_white() const;
|
|
optional<float> get_color_temperature() const;
|
|
optional<uint32_t> get_transition_length() const;
|
|
optional<uint32_t> get_flash_length() const;
|
|
optional<std::string> get_effect() const;
|
|
|
|
protected:
|
|
uint32_t key_{0};
|
|
bool has_state_{false};
|
|
bool state_{false};
|
|
bool has_brightness_{false};
|
|
float brightness_{0.0f};
|
|
bool has_rgb_{false};
|
|
float red_{0.0f};
|
|
float green_{0.0f};
|
|
float blue_{0.0f};
|
|
bool has_white_{false};
|
|
float white_{0.0f};
|
|
bool has_color_temperature_{false};
|
|
float color_temperature_{0.0f};
|
|
bool has_transition_length_{false};
|
|
uint32_t transition_length_{0};
|
|
bool has_flash_length_{false};
|
|
uint32_t flash_length_{0};
|
|
bool has_effect_{false};
|
|
std::string effect_{};
|
|
};
|
|
#endif
|
|
|
|
#ifdef USE_SWITCH
|
|
class SwitchCommandRequest : public APIMessage {
|
|
public:
|
|
bool decode_varint(uint32_t field_id, uint32_t value) override;
|
|
bool decode_32bit(uint32_t field_id, uint32_t value) override;
|
|
APIMessageType message_type() const override;
|
|
uint32_t get_key() const;
|
|
bool get_state() const;
|
|
|
|
protected:
|
|
uint32_t key_{0};
|
|
bool state_{false};
|
|
};
|
|
#endif
|
|
|
|
#ifdef USE_ESP32_CAMERA
|
|
class CameraImageRequest : public APIMessage {
|
|
public:
|
|
bool decode_varint(uint32_t field_id, uint32_t value) override;
|
|
bool get_single() const;
|
|
bool get_stream() const;
|
|
APIMessageType message_type() const override;
|
|
|
|
protected:
|
|
bool single_{false};
|
|
bool stream_{false};
|
|
};
|
|
#endif
|
|
|
|
#ifdef USE_CLIMATE
|
|
class ClimateCommandRequest : public APIMessage {
|
|
public:
|
|
bool decode_varint(uint32_t field_id, uint32_t value) override;
|
|
bool decode_32bit(uint32_t field_id, uint32_t value) override;
|
|
APIMessageType message_type() const override;
|
|
uint32_t get_key() const;
|
|
optional<climate::ClimateMode> get_mode() const;
|
|
optional<float> get_target_temperature() const;
|
|
optional<float> get_target_temperature_low() const;
|
|
optional<float> get_target_temperature_high() const;
|
|
optional<bool> get_away() const;
|
|
|
|
protected:
|
|
uint32_t key_{0};
|
|
bool has_mode_{false};
|
|
climate::ClimateMode mode_{climate::CLIMATE_MODE_OFF};
|
|
bool has_target_temperature_{false};
|
|
float target_temperature_{0.0f};
|
|
bool has_target_temperature_low_{false};
|
|
float target_temperature_low_{0.0f};
|
|
bool has_target_temperature_high_{false};
|
|
float target_temperature_high_{0.0f};
|
|
bool has_away_{false};
|
|
bool away_{false};
|
|
};
|
|
#endif
|
|
|
|
} // namespace api
|
|
} // namespace esphome
|