2 * Copyright (c) 2010-2023 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.yamahareceiver.internal.protocol.xml;
15 import java.util.function.Supplier;
17 import org.openhab.binding.yamahareceiver.internal.YamahaReceiverBindingConstants;
18 import org.openhab.binding.yamahareceiver.internal.config.YamahaBridgeConfig;
19 import org.openhab.binding.yamahareceiver.internal.config.YamahaZoneConfig;
20 import org.openhab.binding.yamahareceiver.internal.protocol.AbstractConnection;
21 import org.openhab.binding.yamahareceiver.internal.protocol.ConnectionStateListener;
22 import org.openhab.binding.yamahareceiver.internal.protocol.DeviceInformation;
23 import org.openhab.binding.yamahareceiver.internal.protocol.InputConverter;
24 import org.openhab.binding.yamahareceiver.internal.protocol.InputWithNavigationControl;
25 import org.openhab.binding.yamahareceiver.internal.protocol.InputWithPlayControl;
26 import org.openhab.binding.yamahareceiver.internal.protocol.InputWithPresetControl;
27 import org.openhab.binding.yamahareceiver.internal.protocol.InputWithTunerBandControl;
28 import org.openhab.binding.yamahareceiver.internal.protocol.ProtocolFactory;
29 import org.openhab.binding.yamahareceiver.internal.protocol.SystemControl;
30 import org.openhab.binding.yamahareceiver.internal.protocol.ZoneAvailableInputs;
31 import org.openhab.binding.yamahareceiver.internal.protocol.ZoneControl;
32 import org.openhab.binding.yamahareceiver.internal.state.AvailableInputStateListener;
33 import org.openhab.binding.yamahareceiver.internal.state.DabBandStateListener;
34 import org.openhab.binding.yamahareceiver.internal.state.DeviceInformationState;
35 import org.openhab.binding.yamahareceiver.internal.state.NavigationControlState;
36 import org.openhab.binding.yamahareceiver.internal.state.NavigationControlStateListener;
37 import org.openhab.binding.yamahareceiver.internal.state.PlayInfoStateListener;
38 import org.openhab.binding.yamahareceiver.internal.state.PresetInfoStateListener;
39 import org.openhab.binding.yamahareceiver.internal.state.SystemControlStateListener;
40 import org.openhab.binding.yamahareceiver.internal.state.ZoneControlStateListener;
43 * Implementation of {@link ProtocolFactory} for XML protocol.
45 * @author Tomasz Maruszak - Initial contribution.
47 public class XMLProtocolFactory implements ProtocolFactory {
49 public void createConnection(String host, ConnectionStateListener connectionStateListener) {
50 connectionStateListener.onConnectionCreated(new XMLConnection(host));
54 public SystemControl SystemControl(AbstractConnection connection, SystemControlStateListener listener,
55 DeviceInformationState deviceInformationState) {
56 return new SystemControlXML(connection, listener, deviceInformationState);
60 public InputWithPlayControl InputWithPlayControl(AbstractConnection connection, String currentInputID,
61 PlayInfoStateListener listener, YamahaBridgeConfig bridgeConfig,
62 DeviceInformationState deviceInformationState) {
63 return new InputWithPlayControlXML(currentInputID, connection, listener, bridgeConfig, deviceInformationState);
67 public InputWithPresetControl InputWithPresetControl(AbstractConnection connection, String currentInputID,
68 PresetInfoStateListener listener, DeviceInformationState deviceInformationState) {
69 return new InputWithPresetControlXML(currentInputID, connection, listener, deviceInformationState);
73 public InputWithTunerBandControl InputWithDabBandControl(String currentInputID, AbstractConnection connection,
74 DabBandStateListener observerForBand, PresetInfoStateListener observerForPreset,
75 PlayInfoStateListener observerForPlayInfo, DeviceInformationState deviceInformationState) {
76 return new InputWithTunerDABControlXML(currentInputID, connection, observerForBand, observerForPreset,
77 observerForPlayInfo, deviceInformationState);
81 public InputWithNavigationControl InputWithNavigationControl(AbstractConnection connection,
82 NavigationControlState state, String inputID, NavigationControlStateListener observer,
83 DeviceInformationState deviceInformationState) {
84 return new InputWithNavigationControlXML(state, inputID, connection, observer, deviceInformationState);
88 public ZoneControl ZoneControl(AbstractConnection connection, YamahaZoneConfig zoneSettings,
89 ZoneControlStateListener listener, Supplier<InputConverter> inputConverterSupplier,
90 DeviceInformationState deviceInformationState) {
91 if (isZoneB(zoneSettings.getZone(), deviceInformationState)) {
92 return new ZoneBControlXML(connection, zoneSettings, listener, deviceInformationState,
93 inputConverterSupplier);
95 return new ZoneControlXML(connection, zoneSettings.getZone(), zoneSettings, listener, deviceInformationState,
96 inputConverterSupplier);
100 public ZoneAvailableInputs ZoneAvailableInputs(AbstractConnection connection, YamahaZoneConfig zoneSettings,
101 AvailableInputStateListener listener, Supplier<InputConverter> inputConverterSupplier,
102 DeviceInformationState deviceInformationState) {
103 if (isZoneB(zoneSettings.getZone(), deviceInformationState)) {
104 return new ZoneBAvailableInputsXML(connection, listener, inputConverterSupplier);
106 return new ZoneAvailableInputsXML(connection, zoneSettings.getZone(), listener, inputConverterSupplier);
110 * Checks if the specified Zone_2 should be emulated using Zone_B feature.
113 * @param deviceInformationState
116 private boolean isZoneB(YamahaReceiverBindingConstants.Zone zone, DeviceInformationState deviceInformationState) {
117 return YamahaReceiverBindingConstants.Zone.Zone_2.equals(zone)
118 && deviceInformationState.features.contains(YamahaReceiverBindingConstants.Feature.ZONE_B);
122 public DeviceInformation DeviceInformation(AbstractConnection connection, DeviceInformationState state) {
123 return new DeviceInformationXML(connection, state);
127 public InputConverter InputConverter(AbstractConnection connection, String setting) {
128 return new InputConverterXML(connection, setting);