2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.freeboxos.internal.api.rest;
17 import javax.ws.rs.core.UriBuilder;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.freeboxos.internal.api.FreeboxException;
22 import org.openhab.binding.freeboxos.internal.api.Response;
23 import org.openhab.binding.freeboxos.internal.api.rest.MediaReceiverManager.Receiver;
26 * The {@link MediaReceiverManager} is the Java class used to handle api requests related to air media receivers
28 * @author Gaƫl L'hopital - Initial contribution
31 public class MediaReceiverManager extends ListableRest<Receiver, MediaReceiverManager.ReceiverResponse> {
32 private static final String SUB_PATH = "receivers";
34 public static record Receiver(boolean passwordProtected, //
35 Map<MediaType, Boolean> capabilities, //
36 String name // This name is the UPnP name of the host
40 protected static class ReceiverResponse extends Response<Receiver> {
49 public enum MediaType {
57 private static record Request(String password, String action, String mediaType, @Nullable String media,
59 Request(String password, Action action, MediaType mediaType, @Nullable String media, int position) {
60 this(password, action.name().toLowerCase(), mediaType.name().toLowerCase(), media, position);
64 public MediaReceiverManager(FreeboxOsSession session, UriBuilder uriBuilder) throws FreeboxException {
65 super(session, LoginManager.Permission.NONE, ReceiverResponse.class, uriBuilder.path(SUB_PATH));
68 public @Nullable Receiver getReceiver(String receiverName) throws FreeboxException {
69 return getDevices().stream().filter(rcv -> receiverName.equals(rcv.name())).findFirst().orElse(null);
72 public void sendToReceiver(String receiver, String password, Action action, MediaType type)
73 throws FreeboxException {
74 sendToReceiver(receiver, new Request(password, action, type, null, 0));
77 public void sendToReceiver(String receiver, String password, Action action, MediaType type, String url)
78 throws FreeboxException {
79 sendToReceiver(receiver, new Request(password, action, type, url, 0));
82 private void sendToReceiver(String receiver, Request payload) throws FreeboxException {
83 post(payload, receiver);