ESPHome 2026.10.0-dev
Loading...
Searching...
No Matches
preferences.h
Go to the documentation of this file.
1#pragma once
2
4
5// Include the concrete preferences manager for the active platform.
6// Each header defines its manager class and provides the Preferences,
7// ESPPreferences, and global_preferences declarations.
8#ifdef USE_ESP32
10#elif defined(USE_ESP8266)
12#elif defined(USE_RP2)
14#elif defined(USE_LIBRETINY)
16#elif defined(USE_HOST)
18#elif defined(USE_ZEPHYR) && defined(CONFIG_SETTINGS)
20#else
21namespace esphome {
22struct Preferences : public PreferencesMixin<Preferences> {
24 ESPPreferenceObject make_preference(size_t, uint32_t, bool) { return {}; }
26 bool load_from_key(uint32_t, uint8_t *, size_t) { return false; }
27
33 bool sync() { return false; }
34
41 bool reset() { return false; }
42};
44extern ESPPreferences *global_preferences; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
45} // namespace esphome
46#endif
47
48namespace esphome {
49static_assert(PreferencesContract<ESPPreferences>,
50 "The platform's preferences manager is missing part of the ESPPreferences surface "
51 "(esphome/core/preference_backend.h)");
52} // namespace esphome
53
54#ifdef USE_PREFERENCE_KEY_LOOKUP
55namespace esphome {
56static_assert(PreferencesKeyLookupContract<ESPPreferences>,
57 "This platform emits USE_PREFERENCE_KEY_LOOKUP but its preferences manager does not provide "
58 "load_from_key() (esphome/core/preference_backend.h)");
59} // namespace esphome
60#endif // USE_PREFERENCE_KEY_LOOKUP
CRTP mixin providing type-safe template make_preference<T>() helpers.
ESPPreferences * global_preferences
static void uint32_t
bool reset()
Forget all unsaved changes and re-initialize the permanent preferences storage.
Definition preferences.h:41
ESPPreferenceObject make_preference(size_t, uint32_t, bool)
Definition preferences.h:24
bool load_from_key(uint32_t, uint8_t *, size_t)
Definition preferences.h:26
ESPPreferenceObject make_preference(size_t, uint32_t)
Definition preferences.h:25
bool sync()
Commit pending writes to flash.
Definition preferences.h:33