Skip to content

Refactor: Clean up app initialization and connection handling - #36

Merged
balloob merged 1 commit into
mainfrom
random-cleanups
Jan 4, 2026
Merged

balloob merged 1 commit into
mainfrom
random-cleanups

Conversation

@balloob

@balloob balloob commented Jan 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Move client ID/name resolution from app classes to CLI layer
  • Create app dependencies in __init__ instead of run() for better testability
  • Consolidate connection loop as a method on SendspinApp and SendspinDaemon
  • Use DiscoveredServer objects throughout instead of raw URLs

Changes

CLI Layer (cli.py)

  • Add _resolve_client_info() to centralize client ID/name resolution with proper error handling
  • Make _run_daemon_mode and _run_client_mode async, with single asyncio.run() at entry point

App Initialization

  • SendspinApp and SendspinDaemon now create SendspinClient, AudioStreamHandler, ServiceDiscovery, and ConnectionManager in __init__
  • AppConfig and DaemonConfig now require client_id and client_name (no longer optional)
  • SendspinUI now takes delay_ms in constructor

Connection Handling

  • Move connection_loop from standalone function to _connection_loop method on SendspinApp
  • Convert standalone handler functions (_handle_metadata_update, _handle_group_update, etc.) to methods
  • Simplify ConnectionManager by using DiscoveredServer objects instead of URL strings

Discovery (discovery.py)

  • Add DiscoveredServer.from_url() factory method for creating server objects from CLI URLs
  • Replace current_url() and wait_for_first_server() with unified wait_for_server() that returns DiscoveredServer
  • Remove unused _current_url tracking

Other

  • Simplify sleep_interruptible using asyncio.wait with timeout instead of polling loop
  • Remove redundant assertions on fields that are always set in __init__

Result

~125 lines removed while improving code organization and testability.

@balloob balloob added the refactor Changes code without changing behavior label Jan 4, 2026
@balloob
balloob merged commit 8380cbb into main Jan 4, 2026
1 check passed
@balloob
balloob deleted the random-cleanups branch January 4, 2026 14:33
trisweb pushed a commit to trisweb/sendspin-cli that referenced this pull request Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Changes code without changing behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant