functions/public/Get-KlippyAnnouncement.ps1

function Get-KlippyAnnouncement {
    <#
    .SYNOPSIS
        Gets announcements from a Klipper printer.

    .DESCRIPTION
        Retrieves announcements from configured RSS feeds on the Moonraker server.
        Announcements include updates from Klipper, Moonraker, and other configured sources.

    .PARAMETER Id
        The unique identifier of the printer.

    .PARAMETER PrinterName
        The friendly name of the printer.

    .PARAMETER InputObject
        A printer object from pipeline input.

    .PARAMETER IncludeDismissed
        Include previously dismissed announcements.

    .EXAMPLE
        Get-KlippyAnnouncement
        Gets active announcements from the default printer.

    .EXAMPLE
        Get-KlippyAnnouncement -IncludeDismissed
        Gets all announcements including dismissed ones.

    .EXAMPLE
        Get-KlippyPrinter | Get-KlippyAnnouncement
        Gets announcements from all registered printers.

    .OUTPUTS
        KlippyCLI.Announcement objects.
    #>

    [CmdletBinding(DefaultParameterSetName = 'Default')]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(ParameterSetName = 'ById')]
        [ValidateNotNullOrEmpty()]
        [string]$Id,

        [Parameter(ParameterSetName = 'ByName', Position = 0)]
        [ValidateNotNullOrEmpty()]
        [string]$PrinterName,

        [Parameter(ParameterSetName = 'ByObject', ValueFromPipeline = $true)]
        [PSCustomObject]$InputObject,

        [Parameter()]
        [switch]$IncludeDismissed
    )

    process {
        # Resolve printer
        $resolveParams = @{}
        switch ($PSCmdlet.ParameterSetName) {
            'ById' { $resolveParams['Id'] = $Id }
            'ByName' { $resolveParams['PrinterName'] = $PrinterName }
            'ByObject' { $resolveParams['InputObject'] = $InputObject }
        }

        $printer = Resolve-KlippyPrinterTarget @resolveParams

        try {
            $endpoint = "server/announcements/list"
            if ($IncludeDismissed) {
                $endpoint += "?include_dismissed=true"
            }

            $response = Invoke-KlippyJsonRpc -Printer $printer -Method $endpoint -NoNormalize

            if (-not $response -or -not $response.entries) {
                Write-Verbose "No announcements found on '$($printer.PrinterName)'."
                return
            }

            foreach ($entry in $response.entries) {
                $datePosted = if ($entry.date) {
                    [DateTimeOffset]::FromUnixTimeSeconds([long]$entry.date).LocalDateTime
                } else { $null }

                $dismissedTime = if ($entry.dismissed -and $entry.dismiss_time) {
                    [DateTimeOffset]::FromUnixTimeSeconds([long]$entry.dismiss_time).LocalDateTime
                } else { $null }

                [PSCustomObject]@{
                    PSTypeName    = 'KlippyCLI.Announcement'
                    PrinterId     = $printer.Id
                    PrinterName   = $printer.PrinterName
                    EntryId       = $entry.entry_id
                    Title         = $entry.title
                    Description   = $entry.description
                    Url           = $entry.url
                    Category      = $entry.category
                    Priority      = $entry.priority
                    DatePosted    = $datePosted
                    Dismissed     = $entry.dismissed
                    DismissedTime = $dismissedTime
                    DismissWake   = $entry.dismiss_wake
                    Source        = $entry.source
                    Feed          = $entry.feed
                }
            }
        }
        catch {
            Write-Error "Failed to get announcements from '$($printer.PrinterName)': $_"
        }
    }
}