framesmith-cli 0.1.0

CLI tool for controlling Samsung Frame TVs over the local network
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
use std::path::PathBuf;

use clap::{Parser, Subcommand, ValueEnum};
use clap_complete::Shell;

// ---------------------------------------------------------------------------
// Hostless CLI — for commands that don't need a TV host
// ---------------------------------------------------------------------------

#[derive(Parser)]
#[command(
    name = "framesmith",
    version,
    about = "CLI util for controlling Samsung Frame TVs"
)]
pub struct HostlessCli {
    #[command(subcommand)]
    pub command: HostlessCommand,

    /// Emit all output as JSON
    #[arg(long, global = true)]
    pub json: bool,

    /// Enable verbose/debug output
    #[arg(short, long, global = true)]
    pub verbose: bool,
}

#[derive(Subcommand)]
pub enum HostlessCommand {
    /// Find Samsung Frame TVs on the local network
    Discover,

    /// Generate shell completions
    Completions {
        /// Shell to generate completions for
        shell: Option<Shell>,
    },
}

#[derive(Subcommand)]
pub enum ServerCommand {
    /// Start a background server for a TV
    Start,

    /// Stop the background server for a TV
    Stop,

    /// Restart the server for a TV
    Restart,

    /// Show server status (does not start a server)
    Status,

    /// Tail the server log file (like tail -F)
    TailLogs,
}

// ---------------------------------------------------------------------------
// Host CLI — for commands that require a TV host as the first argument
// ---------------------------------------------------------------------------

#[derive(Parser)]
#[command(name = "framesmith", version, about = "Control Samsung Frame TVs")]
pub struct HostCli {
    /// TV IP address or hostname
    pub host: String,

    #[command(subcommand)]
    pub command: HostCommand,

    /// Path to auth token file
    #[arg(short = 't', long = "auth-token-file", global = true, default_value_os_t = default_token_path())]
    pub auth_token_file: PathBuf,

    /// Connection timeout in seconds
    #[arg(long, global = true, default_value_t = 5)]
    pub timeout: u64,

    /// Emit all output as JSON
    #[arg(long, global = true)]
    pub json: bool,

    /// Enable verbose/debug output
    #[arg(short, long, global = true)]
    pub verbose: bool,

    /// Connect directly to the TV, bypassing the background server
    #[arg(long, global = true)]
    pub direct: bool,
}

fn default_token_path() -> PathBuf {
    dirs::home_dir()
        .unwrap_or_else(|| PathBuf::from("."))
        .join(".framesmith")
        .join("token")
}

#[derive(Subcommand)]
pub enum HostCommand {
    /// Manage TV authentication
    Auth {
        #[command(subcommand)]
        sub: Option<AuthCommand>,
    },

    /// Show device information
    Info,

    /// Art images, art mode, and slideshow
    Art {
        #[command(subcommand)]
        sub: ArtCommand,
    },

    /// Display settings
    Display {
        #[command(subcommand)]
        sub: DisplayCommand,
    },

    /// Motion sensor settings
    Motion {
        #[command(subcommand)]
        sub: MotionCommand,
    },

    /// Send remote control button press
    Remote {
        /// Button to press
        button: RemoteButton,
    },

    /// Manage background server process for this TV
    Server {
        #[command(subcommand)]
        sub: ServerCommand,
    },
}

// ---------------------------------------------------------------------------
// Auth
// ---------------------------------------------------------------------------

#[derive(Clone, Subcommand)]
pub enum AuthCommand {
    /// Check if the stored token is still valid
    Verify,
    /// Delete the locally stored auth token
    Reset,
}

// ---------------------------------------------------------------------------
// Art
// ---------------------------------------------------------------------------

#[derive(Subcommand)]
pub enum ArtCommand {
    /// List uploaded art images
    List,

    /// Show content info for an art image (defaults to currently displayed)
    ShowInfo {
        /// Content ID to look up (omit for currently displayed image)
        content_id: Option<String>,
    },

    /// Select an art image for display
    Select {
        /// Content ID of the image to select
        content_id: String,
    },

    /// Upload an image to the TV
    Upload {
        /// Path to image file (JPEG or PNG)
        file: PathBuf,

        /// Select the image for display after uploading
        #[arg(long, conflicts_with = "replace_selected")]
        select: bool,

        /// Upload, select, then delete the previously selected image
        #[arg(long, conflicts_with = "select")]
        replace_selected: bool,

        /// Center image on a canvas of this color (black, white, or hex like #ff3300)
        #[arg(long)]
        canvas: Option<String>,
    },

    /// Delete uploaded art image(s)
    Delete {
        /// Content ID(s) to delete
        #[arg(required = true)]
        content_ids: Vec<String>,
    },

    /// Download thumbnail for an art image
    Thumbnail {
        /// Content ID of the image
        content_id: String,

        /// Output file path
        #[arg(short)]
        o: PathBuf,
    },

    /// Set/unset favorite on an art image
    Favorite {
        /// Content ID of the image
        content_id: String,

        /// Turn favorite on or off
        state: OnOff,
    },

    /// Matte settings
    Matte {
        #[command(subcommand)]
        sub: MatteCommand,
    },

    /// Photo filter settings
    Filter {
        #[command(subcommand)]
        sub: FilterCommand,
    },

    /// Art mode control
    Mode {
        #[command(subcommand)]
        sub: ModeCommand,
    },

    /// Slideshow control
    Slideshow {
        #[command(subcommand)]
        sub: SlideshowCommand,
    },
}

// ---------------------------------------------------------------------------
// Matte
// ---------------------------------------------------------------------------

#[derive(Subcommand)]
pub enum MatteCommand {
    /// List available mattes
    List,

    /// Set matte on an image
    Set {
        /// Content ID of the image
        content_id: String,

        /// Matte ID to apply
        matte_id: String,

        /// Portrait matte ID (optional)
        #[arg(long)]
        portrait: Option<String>,
    },
}

// ---------------------------------------------------------------------------
// Filter
// ---------------------------------------------------------------------------

#[derive(Subcommand)]
pub enum FilterCommand {
    /// List available photo filters
    List,

    /// Set filter on an image
    Set {
        /// Content ID of the image
        content_id: String,

        /// Filter ID to apply
        filter_id: String,
    },
}

// ---------------------------------------------------------------------------
// Mode
// ---------------------------------------------------------------------------

#[derive(Subcommand)]
pub enum ModeCommand {
    /// Enable art mode
    On,
    /// Disable art mode
    Off,
    /// Check if art mode is enabled
    Status,
}

// ---------------------------------------------------------------------------
// Slideshow
// ---------------------------------------------------------------------------

#[derive(Subcommand)]
pub enum SlideshowCommand {
    /// Enable slideshow
    On {
        /// Duration per image in seconds
        #[arg(long)]
        duration: Option<u64>,

        /// Shuffle images
        #[arg(long)]
        shuffle: bool,

        /// Image category
        #[arg(long)]
        category: Option<SlideshowCategoryValue>,
    },

    /// Disable slideshow
    Off,

    /// Show slideshow status and config
    Status,

    /// Update slideshow settings
    Configure {
        /// Duration per image in seconds
        #[arg(long)]
        duration: Option<u64>,

        /// Shuffle images
        #[arg(long)]
        shuffle: Option<OnOff>,

        /// Image category
        #[arg(long)]
        category: Option<SlideshowCategoryValue>,
    },
}

#[derive(Clone, ValueEnum)]
pub enum SlideshowCategoryValue {
    MyPictures,
    Favorites,
}

// ---------------------------------------------------------------------------
// Display
// ---------------------------------------------------------------------------

#[derive(Subcommand)]
pub enum DisplayCommand {
    /// Get or set brightness (0-10)
    Brightness {
        /// Brightness level (0-10). Omit to get current value.
        value: Option<u8>,
    },

    /// Get or set color temperature (-5 to 5)
    ColorTemp {
        /// Color temperature (-5 to 5). Omit to get current value.
        value: Option<i8>,
    },

    /// Get display rotation
    Rotation,

    /// Enable or disable auto-brightness
    AutoBrightness {
        /// on or off
        state: OnOff,
    },
}

// ---------------------------------------------------------------------------
// Motion
// ---------------------------------------------------------------------------

#[derive(Subcommand)]
pub enum MotionCommand {
    /// Set motion timer
    Timer {
        /// Timer value in minutes
        value: MotionTimerValue,
    },

    /// Set motion sensitivity
    Sensitivity {
        /// Sensitivity level
        value: MotionSensitivityValue,
    },
}

#[derive(Clone, ValueEnum)]
pub enum MotionTimerValue {
    Off,
    #[value(name = "5")]
    Min5,
    #[value(name = "15")]
    Min15,
    #[value(name = "30")]
    Min30,
    #[value(name = "60")]
    Min60,
    #[value(name = "120")]
    Min120,
    #[value(name = "240")]
    Min240,
}

#[derive(Clone, ValueEnum)]
pub enum MotionSensitivityValue {
    Low,
    Medium,
    High,
}

// ---------------------------------------------------------------------------
// Shared value enums
// ---------------------------------------------------------------------------

#[derive(Clone, ValueEnum)]
pub enum OnOff {
    On,
    Off,
}

// ---------------------------------------------------------------------------
// Remote button
// ---------------------------------------------------------------------------

#[derive(Clone, ValueEnum)]
pub enum RemoteButton {
    Power,
    PowerOff,
    Sleep,
    Home,
    Menu,
    Source,
    Enter,
    Back,
    Return,
    Up,
    Down,
    Left,
    Right,
    VolUp,
    VolDown,
    Mute,
    ChUp,
    ChDown,
    ChList,
    Play,
    Pause,
    Stop,
    Rewind,
    FastForward,
    Info,
    Guide,
    Tools,
    Caption,
    #[value(name = "0")]
    Num0,
    #[value(name = "1")]
    Num1,
    #[value(name = "2")]
    Num2,
    #[value(name = "3")]
    Num3,
    #[value(name = "4")]
    Num4,
    #[value(name = "5")]
    Num5,
    #[value(name = "6")]
    Num6,
    #[value(name = "7")]
    Num7,
    #[value(name = "8")]
    Num8,
    #[value(name = "9")]
    Num9,
    Red,
    Green,
    Yellow,
    Blue,
    Ambient,
    PictureSize,
    Hdmi1,
    Hdmi2,
    Hdmi3,
    Hdmi4,
}

impl RemoteButton {
    #[allow(dead_code)]
    pub fn to_library_type(&self) -> framesmith::RemoteControlButton {
        use framesmith::RemoteControlButton::*;
        match self {
            Self::Power => Power,
            Self::PowerOff => PowerOff,
            Self::Sleep => Sleep,
            Self::Home => Home,
            Self::Menu => Menu,
            Self::Source => Source,
            Self::Enter => Enter,
            Self::Back => Back,
            Self::Return => Return,
            Self::Up => Up,
            Self::Down => Down,
            Self::Left => Left,
            Self::Right => Right,
            Self::VolUp => VolumeUp,
            Self::VolDown => VolumeDown,
            Self::Mute => Mute,
            Self::ChUp => ChannelUp,
            Self::ChDown => ChannelDown,
            Self::ChList => ChannelList,
            Self::Play => Play,
            Self::Pause => Pause,
            Self::Stop => Stop,
            Self::Rewind => Rewind,
            Self::FastForward => FastForward,
            Self::Info => Info,
            Self::Guide => Guide,
            Self::Tools => Tools,
            Self::Caption => Caption,
            Self::Num0 => Number0,
            Self::Num1 => Number1,
            Self::Num2 => Number2,
            Self::Num3 => Number3,
            Self::Num4 => Number4,
            Self::Num5 => Number5,
            Self::Num6 => Number6,
            Self::Num7 => Number7,
            Self::Num8 => Number8,
            Self::Num9 => Number9,
            Self::Red => Red,
            Self::Green => Green,
            Self::Yellow => Yellow,
            Self::Blue => Blue,
            Self::Ambient => Ambient,
            Self::PictureSize => PictureSize,
            Self::Hdmi1 => Hdmi1,
            Self::Hdmi2 => Hdmi2,
            Self::Hdmi3 => Hdmi3,
            Self::Hdmi4 => Hdmi4,
        }
    }

    /// Convert to the string used in the IPC protocol.
    pub fn to_ipc_string(&self) -> &'static str {
        match self {
            Self::Power => "power",
            Self::PowerOff => "power-off",
            Self::Sleep => "sleep",
            Self::Home => "home",
            Self::Menu => "menu",
            Self::Source => "source",
            Self::Enter => "enter",
            Self::Back => "back",
            Self::Return => "return",
            Self::Up => "up",
            Self::Down => "down",
            Self::Left => "left",
            Self::Right => "right",
            Self::VolUp => "vol-up",
            Self::VolDown => "vol-down",
            Self::Mute => "mute",
            Self::ChUp => "ch-up",
            Self::ChDown => "ch-down",
            Self::ChList => "ch-list",
            Self::Play => "play",
            Self::Pause => "pause",
            Self::Stop => "stop",
            Self::Rewind => "rewind",
            Self::FastForward => "fast-forward",
            Self::Info => "info",
            Self::Guide => "guide",
            Self::Tools => "tools",
            Self::Caption => "caption",
            Self::Num0 => "0",
            Self::Num1 => "1",
            Self::Num2 => "2",
            Self::Num3 => "3",
            Self::Num4 => "4",
            Self::Num5 => "5",
            Self::Num6 => "6",
            Self::Num7 => "7",
            Self::Num8 => "8",
            Self::Num9 => "9",
            Self::Red => "red",
            Self::Green => "green",
            Self::Yellow => "yellow",
            Self::Blue => "blue",
            Self::Ambient => "ambient",
            Self::PictureSize => "picture-size",
            Self::Hdmi1 => "hdmi1",
            Self::Hdmi2 => "hdmi2",
            Self::Hdmi3 => "hdmi3",
            Self::Hdmi4 => "hdmi4",
        }
    }
}

// ---------------------------------------------------------------------------
// Completion CLI — flat command list for shell completion generation
// ---------------------------------------------------------------------------

#[derive(Parser)]
#[command(name = "framesmith")]
pub struct CompletionCli {
    #[command(subcommand)]
    pub command: CompletionCommand,
}

#[derive(Subcommand)]
pub enum CompletionCommand {
    Discover,
    Completions {
        shell: Option<Shell>,
    },
    Server {
        #[command(subcommand)]
        sub: ServerCommand,
    },
    Auth {
        #[command(subcommand)]
        sub: Option<AuthCommand>,
    },
    Info,
    Art {
        #[command(subcommand)]
        sub: ArtCommand,
    },
    Display {
        #[command(subcommand)]
        sub: DisplayCommand,
    },
    Motion {
        #[command(subcommand)]
        sub: MotionCommand,
    },
    Remote {
        button: RemoteButton,
    },
}