14#ifdef USE_MDNS_SUPPORTS_ENABLE_DISABLE
18#include <sendspin/client.h>
19#include <sendspin/config.h>
20#include <sendspin/types.h>
22#ifdef USE_SENDSPIN_ARTWORK
23#include <sendspin/artwork_role.h>
25#ifdef USE_SENDSPIN_CONTROLLER
26#include <sendspin/controller_role.h>
28#ifdef USE_SENDSPIN_METADATA
29#include <sendspin/metadata_role.h>
31#ifdef USE_SENDSPIN_PLAYER
32#include <sendspin/player_role.h>
52namespace sendspin_priority {
86#ifdef USE_SENDSPIN_ARTWORK
87 public sendspin::ArtworkRoleListener,
89#ifdef USE_SENDSPIN_CONTROLLER
90 public sendspin::ControllerRoleListener,
92#ifdef USE_SENDSPIN_METADATA
93 public sendspin::MetadataRoleListener,
95 public sendspin::SendspinClientListener,
96 public sendspin::SendspinNetworkProvider,
97 public sendspin::SendspinPersistenceProvider {
102 void setup()
override;
103 void loop()
override;
216#ifdef USE_MDNS_SUPPORTS_ENABLE_DISABLE
229#ifdef USE_SENDSPIN_ARTWORK
250#ifdef USE_SENDSPIN_CONTROLLER
251 void send_client_command(sendspin::SendspinControllerCommand command, std::optional<uint8_t> volume = std::nullopt,
252 std::optional<bool> mute = std::nullopt);
267#ifdef USE_SENDSPIN_METADATA
280#ifdef USE_SENDSPIN_PLAYER
294 std::pair<ESPPreferenceObject *, size_t>
pref_for_key_(
const std::string &key);
305#ifdef USE_MDNS_SUPPORTS_ENABLE_DISABLE
311 void on_group_update(
const sendspin::GroupUpdateObject &group)
override;
327 void on_pairing_failed(
const std::string &server_id, sendspin::SendspinPairAbortReason reason)
override;
334 std::optional<std::vector<uint8_t>>
load_blob(
const std::string &key)
override;
335 bool save_blob(
const std::string &key,
const uint8_t *data,
size_t len)
override;
340#ifdef USE_SENDSPIN_ARTWORK
351 CallbackManager<void(uint8_t,
const uint8_t *,
size_t, sendspin::SendspinImageFormat)>
357#ifdef USE_SENDSPIN_CONTROLLER
370#ifdef USE_SENDSPIN_METADATA
373 void on_metadata(
const sendspin::ServerMetadataStateObject &metadata)
override;
381#ifdef USE_SENDSPIN_PLAYER
396 std::unique_ptr<sendspin::SendspinClient>
client_;
412#ifdef USE_MDNS_SUPPORTS_ENABLE_DISABLE
426#ifdef USE_MDNS_SUPPORTS_ENABLE_DISABLE
Helper class to easily give an object a parent of type T.
This class simplifies creating components that periodically check a state.
StringRef is a reference to a string owned by something else.
Base class for all sendspin subcomponents.
float get_setup_priority() const override
Thin adapter over sendspin::SendspinClient.
const char * manufacturer_
ESPPreferenceObject output_delay_pref_
uint32_t get_feature_flags() const
Returns the SendspinFeature flags reported to API clients.
CallbackManager< void(uint8_t, const uint8_t *, size_t, sendspin::SendspinImageFormat)> artwork_image_decode_callbacks_
void add_image_clear_callback(F &&callback)
CallbackManager< void(uint8_t, uint32_t)> artwork_image_display_callbacks_
sendspin::PlayerRoleListener * player_listener_
const char * firmware_version_
void set_firmware_version(const char *firmware_version)
bool pairing_code_display_supported_
void add_on_clear_pairing_code_callback(F &&callback)
const char * get_product_name_() const
Returns the product name reported to the server: the configured model, or the device name.
void set_static_pairing_code(const char *code)
The static pairing code, used on every boot.
std::optional< bool > unpaired_access_
void on_controller_state_clear() override
std::optional< std::vector< uint8_t > > load_blob(const std::string &key) override
void set_artwork_config(const sendspin::ArtworkRoleConfig &config)
void confirm_pairing_window()
Confirms a pairing attempt on the device.
CallbackManager< void(const sendspin::ServerMetadataStateObject &)> metadata_update_callbacks_
ESPPreferenceObject record_order_pref_
std::optional< std::string > get_pairing_token() const
Returns the pairing token a Sendspin server uses to pair with this device.
LazyCallbackManager< void(const std::string &, StringRef)> pairing_failed_callbacks_
void add_image_decode_callback(F &&callback)
void set_unpaired_access_enabled(bool enabled)
Turns unpaired (Sentinel) access on or off.
LazyCallbackManager< void(const sendspin::ServerStateControllerObject &)> controller_state_callbacks_
void add_group_update_callback(F &&callback)
void on_release_high_performance() override
void set_manufacturer(const char *manufacturer)
Sets the device information reported to the server in the client/hello message.
bool save_blob(const std::string &key, const uint8_t *data, size_t len) override
LazyCallbackManager< void()> clear_pairing_code_callbacks_
bool is_network_ready() override
sendspin::MetadataRole * metadata_role_
void on_display_pairing_code(const std::string &code, sendspin::SendspinPairingCodeFormat format) override
void on_open_pairing_window() override
bool is_client_running() const
Returns whether the Sendspin client is running.
void add_on_open_pairing_window_callback(F &&callback)
const char * pairing_code_method_() const
CallbackManager< void(const sendspin::GroupUpdateObject &)> group_update_callbacks_
LazyCallbackManager< void(const std::string &)> display_pairing_code_callbacks_
void switch_client()
Sends the SWITCH controller command; exposed as the sendspin.switch action.
void leave_group()
Leaves the current group so another source can use the speaker.
sendspin::PlayerRoleConfig player_config_
void set_pairing_code_display_supported(bool supported)
Set when on_display_pairing_code or a pairing_code text sensor is configured, so the device offers th...
void on_metadata(const sendspin::ServerMetadataStateObject &metadata) override
void cancel_pairing_window()
Closes an open pairing window, so a waiting pairing attempt is not confirmed.
void add_on_pairing_succeeded_callback(F &&callback)
ESPPreferenceObject last_played_pref_
void add_on_close_pairing_window_callback(F &&callback)
void set_player_config(const sendspin::PlayerRoleConfig &config)
void dump_config() override
LazyCallbackManager< void(const std::string &)> pairing_succeeded_callbacks_
const char * static_pairing_code_
void on_shutdown() override
static const char * get_mac_address_into_buffer(std::span< char, MAC_ADDRESS_PRETTY_BUFFER_SIZE > buf)
Writes the active network interface's MAC, in lowercase, into buf and returns its data pointer.
sendspin::PlayerRole * get_player_role()
Child components call this to get the PlayerRole instance after setup, so they can push updates to it...
void set_listener(sendspin::PlayerRoleListener *listener)
void on_image_clear(uint8_t slot) override
void on_pairing_failed(const std::string &server_id, sendspin::SendspinPairAbortReason reason) override
void on_clear_pairing_code() override
void add_controller_state_clear_callback(F &&callback)
Registers a callback that fires when the connection is lost and the cached controller state is droppe...
bool is_disabled() const
Returns whether the client has been turned off with set_enabled().
void disconnect_from_server(sendspin::SendspinGoodbyeReason reason)
Disconnects the underlying client from the current server.
std::unique_ptr< sendspin::SendspinClient > client_
sendspin::ArtworkRoleConfig artwork_config_
void update_mdns_service_()
Keeps the _sendspin mDNS service advertised while the client is running.
void add_on_pairing_failed_callback(F &&callback)
sendspin::SendspinClientConfig build_client_config_()
Builds the SendspinClientConfig from ESPHome configuration and platform info.
mdns::MDNSComponent * mdns_
sendspin::ControllerRole * controller_role_
void on_pairing_succeeded(const std::string &server_id) override
void add_on_display_pairing_code_callback(F &&callback)
bool task_stack_in_psram_
uint32_t get_track_progress_ms() const
Returns the interpolated track progress in milliseconds, or 0 if the hub is not yet ready.
void add_controller_state_callback(F &&callback)
std::optional< bool > enabled_
StringRef get_client_id() const
Returns the Sendspin client_id: base64url of the client's static public key.
void set_mdns(mdns::MDNSComponent *mdns)
void send_client_command(sendspin::SendspinControllerCommand command, std::optional< uint8_t > volume=std::nullopt, std::optional< bool > mute=std::nullopt)
void set_model(const char *model)
LazyCallbackManager< void()> controller_state_clear_callbacks_
void on_metadata_clear() override
CallbackManager< void(uint8_t)> artwork_image_clear_callbacks_
ESPPreferenceObject keypair_pref_
void on_close_pairing_window() override
LazyCallbackManager< void()> open_pairing_window_callbacks_
void set_task_stack_in_psram(bool task_stack_in_psram)
sendspin::ArtworkRole * artwork_role_
void on_request_high_performance() override
float get_setup_priority() const override
std::pair< ESPPreferenceObject *, size_t > pref_for_key_(const std::string &key)
The preference a library key is stored in and its blob size, or {nullptr, 0} for a key with no storag...
void set_enabled(bool enabled)
Requests the Sendspin client, including the server, the roles and the mDNS advertisement,...
std::array< ESPPreferenceObject, SENDSPIN_RECORD_SLOTS > record_slot_prefs_
void on_image_display(uint8_t slot, uint32_t lateness_ms) override
void on_image_decode(uint8_t slot, const uint8_t *data, size_t length, sendspin::SendspinImageFormat format) override
ESPPreferenceObject pairing_psk_pref_
void on_controller_state(const sendspin::ServerStateControllerObject &state) override
LazyCallbackManager< void()> close_pairing_window_callbacks_
void connect_to_server(const std::string &url)
Connects the underlying client to the given Sendspin server.
void add_image_display_callback(F &&callback)
void on_group_update(const sendspin::GroupUpdateObject &group) override
void add_metadata_update_callback(F &&callback)
Registers a callback that fires when the server sends metadata.
void artwork_frame_done(uint8_t slot)
Acknowledges the most recent artwork delivery (display or clear) for a slot.
Base class for sendspin subcomponents that need polling behavior.
float get_setup_priority() const override
constexpr size_t SENDSPIN_RECORD_SLOTS
Pairing-record slots, handed to the client as max_pairing_records.
SendspinFeature
Feature flags reported to API clients in DeviceCapabilitiesResponse.
@ SENDSPIN_FEATURE_PAIRING_TOKEN
SendspinHub * global_sendspin_hub
constexpr float AFTER_WIFI
For components that should be initialized after WiFi is connected.