Text of api-docs.esphome.io › sendspin__hub_8h_source as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

ESPHome: esphome/components/sendspin/sendspin_hub.h Source File

ESPHome 2026.11.0 Loading... Searching... No Matches esphome components sendspin sendspin_hub.h Go to the documentation of this file. 1 #pragma once 2 3 #include " esphome/core/defines.h " 4 5 #ifdef USE_ESP_IDF 6 7 #include " esphome/core/automation.h " 8 #include " esphome/core/component.h " 9 #include " esphome/core/helpers.h " 10 #include " esphome/core/preferences.h " 11 #include " esphome/core/string_ref.h " 12 #include " esphome/core/version.h " 13 14 #ifdef USE_MDNS_SUPPORTS_ENABLE_DISABLE 15 #include " esphome/components/mdns/mdns_component.h " 16 #endif 17 #ifdef USE_SENDSPIN_ENABLED_SWITCH 18 #include " esphome/components/switch/switch.h " 19 #endif 20 21 #include <sendspin/client.h> 22 #include <sendspin/config.h> 23 #include <sendspin/types.h> 24 25 #ifdef USE_SENDSPIN_ARTWORK 26 #include <sendspin/artwork_role.h> 27 #endif 28 #ifdef USE_SENDSPIN_CONTROLLER 29 #include <sendspin/controller_role.h> 30 #endif 31 #ifdef USE_SENDSPIN_METADATA 32 #include <sendspin/metadata_role.h> 33 #endif 34 #ifdef USE_SENDSPIN_PLAYER 35 #include <sendspin/player_role.h> 36 #endif 37 #ifdef USE_SENDSPIN_SOURCE 38 #include " esphome/components/microphone/microphone_source.h " 39 40 #include <sendspin/source_role.h> 41 #endif 42 43 #include <array> 44 #include <cstddef> 45 #include <cstdint> 46 #include <functional> 47 #include <memory> 48 #include <optional> 49 #include <string> 50 #include <utility> 51 #include <vector> 52 53 namespace esphome::sendspin_ { 54 60 namespace sendspin_priority { 61 // AFTER_WIFI so the hub runs after the wifi/ethernet drivers are up and we can read the active 62 // interface's MAC address for the device info.

63 inline constexpr float HUB = esphome::setup_priority::AFTER_WIFI ; 64 inline constexpr float CHILD = HUB - 1.0f; 65 } // namespace sendspin_priority 66 67 // PREFERENCE KEYS: each library persistence key has its own preference, hashed from "sendspin_" + name. Renaming 68 // one erases it. 69 71 inline constexpr size_t SENDSPIN_RECORD_SLOTS = sendspin::SendspinClientConfig::DEFAULT_MAX_PAIRING_RECORDS; 72 74 enum SendspinFeature : uint32_t { 75 SENDSPIN_FEATURE_PAIRING_TOKEN = 1 << 0, 76 }; 77 94 class SendspinHub final : public Component , 95 #ifdef USE_SENDSPIN_ARTWORK 96 public sendspin::ArtworkRoleListener, 97 #endif 98 #ifdef USE_SENDSPIN_CONTROLLER 99 public sendspin::ControllerRoleListener, 100 #endif 101 #ifdef USE_SENDSPIN_METADATA 102 public sendspin::MetadataRoleListener, 103 #endif 104 #ifdef USE_SENDSPIN_SOURCE 105 public sendspin::SourceRoleListener, 106 #endif 107 public sendspin::SendspinClientListener, 108 public sendspin::SendspinNetworkProvider, 109 public sendspin::SendspinPersistenceProvider { 110 public : 111 SendspinHub (); 112 113 float get_setup_priority () const override { return sendspin_priority::HUB ; } 114 void setup () override ; 115 void loop () override ; 116 void on_shutdown () override ; 117 void dump_config () override ; 118 124 void connect_to_server ( const std::string &url); 125 135 void disconnect_from_server (sendspin::SendspinGoodbyeReason reason); 136 141 void leave_group (); 142 147 void confirm_pairing_window (); 148 152 void cancel_pairing_window (); 153 154 // --- Configuration setters (called from codegen) --- 155 156 template < typename F> void add_group_update_callback (F &&callback) { 157 this-> group_update_callbacks_ .add(std::forward<F>(callback)); 158 } 159 160 template < typename F> void add_on_open_pairing_window_callback (F &&callback) { 161 this-> open_pairing_window_callbacks_ .add(std::forward<F>(callback)); 162 } 163 164 template < typename F> void add_on_close_pairing_window_callback (F &&callback) { 165 this-> close_pairing_window_callbacks_ .add(std::forward<F>(callback)); 166 } 167 168 template < typename F> void add_on_display_pairing_code_callback (F &&callback) { 169 this-> display_pairing_code_callbacks_ .add(std::forward<F>(callback)); 170 } 171 172 template < typename F> void add_on_clear_pairing_code_callback (F &&callback) { 173 this-> clear_pairing_code_callbacks_ .add(std::forward<F>(callback)); 174 } 175 176 template < typename F> void add_on_pairing_succeeded_callback (F &&callback) { 177 this-> pairing_succeeded_callbacks_ .add(std::forward<F>(callback)); 178 } 179 180 template < typename F> void add_on_pairing_failed_callback (F &&callback) { 181 this-> pairing_failed_callbacks_ .add(std::forward<F>(callback)); 182 } 183 184 void set_task_stack_in_psram ( bool task_stack_in_psram) { this-> task_stack_in_psram_ = task_stack_in_psram; } 185 192 void set_enabled ( bool enabled); 193 #ifdef USE_SENDSPIN_ENABLED_SWITCH 194 SUB_SWITCH (enabled) 195 #endif 196 199 void set_unpaired_access_enabled( bool enabled); 200 202 bool is_client_running () const { return this-> client_ != nullptr && this-> client_ ->is_started(); } 203 205 bool is_disabled () const { return this-> enabled_ .has_value() && !this-> enabled_ .value(); } 206 208 uint32_t get_feature_flags () const { return SENDSPIN_FEATURE_PAIRING_TOKEN ; } 209 214 std::optional<std::string> get_pairing_token () const ; 215 220 StringRef get_client_id () const ; 221 227 void set_manufacturer ( const char *manufacturer) { this-> manufacturer_ = manufacturer; } 228 void set_model ( const char *model) { this-> model_ = model; } 229 void set_firmware_version ( const char *firmware_version) { this-> firmware_version_ = firmware_version; } 230 231 #ifdef USE_MDNS_SUPPORTS_ENABLE_DISABLE 232 void set_mdns ( mdns::MDNSComponent *mdns) { this-> mdns_ = mdns; } 233 #endif 234 236 void set_static_pairing_code ( const char *code) { this-> static_pairing_code_ = code; } 237 240 void set_pairing_code_display_supported ( bool supported) { this-> pairing_code_display_supported_ = supported; } 241 242 // --- Sendspin role specific methods --- 243 244 #ifdef USE_SENDSPIN_ARTWORK 245 void set_artwork_config ( const sendspin::ArtworkRoleConfig &config) { this-> artwork_config_ = config; } 246 252 void artwork_frame_done (uint8_t slot); 253 254 template < typename F> void add_image_decode_callback (F &&callback) { 255 this-> artwork_image_decode_callbacks_ .add(std::forward<F>(callback)); 256 } 257 template < typename F> void add_image_display_callback (F &&callback) { 258 this-> artwork_image_display_callbacks_ .add(std::forward<F>(callback)); 259 } 260 template < typename F> void add_image_clear_callback (F &&callback) { 261 this-> artwork_image_clear_callbacks_ .add(std::forward<F>(callback)); 262 } 263 #endif 264 265 #ifdef USE_SENDSPIN_CONTROLLER 266 void send_client_command (sendspin::SendspinControllerCommand command, std::optional<uint8_t> volume = std::nullopt, 267 std::optional<bool> mute = std::nullopt); 268 270 void switch_client (); 271 272 template < typename F> void add_controller_state_callback (F &&callback) { 273 this-> controller_state_callbacks_ .add(std::forward<F>(callback)); 274 } 275 277 template < typename F> void add_controller_state_clear_callback (F &&callback) { 278 this-> controller_state_clear_callbacks_ .add(std::forward<F>(callback)); 279 } 280 #endif 281 282 #ifdef USE_SENDSPIN_METADATA 287 template < typename F> void add_metadata_update_callback (F &&callback) { 288 this-> metadata_update_callbacks_ .add(std::forward<F>(callback)); 289 } 290 292 uint32_t get_track_progress_ms () const ; 293 #endif 294 295 #ifdef USE_SENDSPIN_PLAYER 296 void set_listener (sendspin::PlayerRoleListener *listener) { this-> player_listener_ = listener; } 297 void set_player_config ( const sendspin::PlayerRoleConfig &config) { this-> player_config_ = config; } 298 300 sendspin::PlayerRole * get_player_role (); 301 #endif 302 303 #ifdef USE_SENDSPIN_SOURCE 304 void set_source_config ( const sendspin::SourceRoleConfig &config) { this-> source_config_ = config; } 305 void set_microphone_source ( microphone::MicrophoneSource *microphone_source) { 306 this-> microphone_source_ = microphone_source; 307 } 308 312 void set_source_signal ( bool present); 313 315 bool is_source_streaming () const { return this->

The rest of this page is on the live site.