1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-03 10:32:21 +01:00

🏗 Merge C++ into python codebase (#504)

## 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).
This commit is contained in:
Otto Winter
2019-04-17 12:06:00 +02:00
committed by GitHub
parent 049807e3ab
commit 6682c43dfa
817 changed files with 54156 additions and 10830 deletions

View File

@@ -0,0 +1,94 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/core/preferences.h"
#include <WiFiServer.h>
#include <WiFiClient.h>
namespace esphome {
namespace ota {
enum OTAResponseTypes {
OTA_RESPONSE_OK = 0,
OTA_RESPONSE_REQUEST_AUTH = 1,
OTA_RESPONSE_HEADER_OK = 64,
OTA_RESPONSE_AUTH_OK = 65,
OTA_RESPONSE_UPDATE_PREPARE_OK = 66,
OTA_RESPONSE_BIN_MD5_OK = 67,
OTA_RESPONSE_RECEIVE_OK = 68,
OTA_RESPONSE_UPDATE_END_OK = 69,
OTA_RESPONSE_ERROR_MAGIC = 128,
OTA_RESPONSE_ERROR_UPDATE_PREPARE = 129,
OTA_RESPONSE_ERROR_AUTH_INVALID = 130,
OTA_RESPONSE_ERROR_WRITING_FLASH = 131,
OTA_RESPONSE_ERROR_UPDATE_END = 132,
OTA_RESPONSE_ERROR_INVALID_BOOTSTRAPPING = 133,
OTA_RESPONSE_ERROR_WRONG_CURRENT_FLASH_CONFIG = 134,
OTA_RESPONSE_ERROR_WRONG_NEW_FLASH_CONFIG = 135,
OTA_RESPONSE_ERROR_ESP8266_NOT_ENOUGH_SPACE = 136,
OTA_RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE = 137,
OTA_RESPONSE_ERROR_UNKNOWN = 255,
};
/// OTAComponent provides a simple way to integrate Over-the-Air updates into your app using ArduinoOTA.
class OTAComponent : public Component {
public:
/** Construct an OTAComponent. Defaults to no authentication.
*
* @param port The port ArduinoOTA will listen on.
*/
explicit OTAComponent(uint16_t port);
/** Set a plaintext password that OTA will use for authentication.
*
* Warning: This password will be stored in plaintext in the ROM and can be read
* by intruders.
*
* @param password The plaintext password.
*/
void set_auth_password(const std::string &password);
/// Manually set the port OTA should listen on.
void set_port(uint16_t port);
void start_safe_mode(uint8_t num_attempts = 10, uint32_t enable_time = 120000);
// ========== INTERNAL METHODS ==========
// (In most use cases you won't need these)
void setup() override;
void dump_config() override;
float get_setup_priority() const override;
void loop() override;
uint16_t get_port() const;
void clean_rtc();
void on_safe_shutdown() override;
protected:
void write_rtc_(uint32_t val);
uint32_t read_rtc_();
void handle_();
size_t wait_receive_(uint8_t *buf, size_t bytes, bool check_disconnected = true);
std::string password_;
uint16_t port_;
WiFiServer *server_{nullptr};
WiFiClient client_{};
bool has_safe_mode_{false}; ///< stores whether safe mode can be enabled.
uint32_t safe_mode_start_time_; ///< stores when safe mode was enabled.
uint32_t safe_mode_enable_time_{60000}; ///< The time safe mode should be on for.
uint32_t safe_mode_rtc_value_;
uint8_t safe_mode_num_attempts_;
ESPPreferenceObject rtc_;
};
} // namespace ota
} // namespace esphome