]> git.basschouten.com Git - openhab-addons.git/blob
1c0b09618af09ad473e1a379f48e7007fc6ff8a6
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.sonyaudio.internal;
14
15 import org.eclipse.jetty.websocket.client.WebSocketClient;
16 import org.openhab.binding.sonyaudio.internal.handler.HtCt800Handler;
17 import org.openhab.binding.sonyaudio.internal.handler.HtMt500Handler;
18 import org.openhab.binding.sonyaudio.internal.handler.HtSt5000Handler;
19 import org.openhab.binding.sonyaudio.internal.handler.HtZ9fHandler;
20 import org.openhab.binding.sonyaudio.internal.handler.HtZf9Handler;
21 import org.openhab.binding.sonyaudio.internal.handler.SrsZr5Handler;
22 import org.openhab.binding.sonyaudio.internal.handler.StrDn1080Handler;
23 import org.openhab.core.io.net.http.WebSocketFactory;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.thing.ThingTypeUID;
26 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
27 import org.openhab.core.thing.binding.ThingHandler;
28 import org.openhab.core.thing.binding.ThingHandlerFactory;
29 import org.osgi.service.component.annotations.Component;
30 import org.osgi.service.component.annotations.Reference;
31
32 /**
33  * The {@link SonyAudioHandlerFactory} is responsible for creating things and thing
34  * handlers.
35  *
36  * @author David - Initial contribution
37  */
38 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.sonyaudio")
39 public class SonyAudioHandlerFactory extends BaseThingHandlerFactory {
40
41     private WebSocketClient webSocketClient;
42
43     @Override
44     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
45         return SonyAudioBindingConstants.SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
46     }
47
48     @Override
49     protected ThingHandler createHandler(Thing thing) {
50         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
51
52         switch (thingTypeUID.getId()) {
53             case SonyAudioBindingConstants.SONY_TYPE_STRDN1080:
54                 return new StrDn1080Handler(thing, webSocketClient);
55             case SonyAudioBindingConstants.SONY_TYPE_HTCT800:
56                 return new HtCt800Handler(thing, webSocketClient);
57             case SonyAudioBindingConstants.SONY_TYPE_HTST5000:
58                 return new HtSt5000Handler(thing, webSocketClient);
59             case SonyAudioBindingConstants.SONY_TYPE_HTZ9F:
60                 return new HtZ9fHandler(thing, webSocketClient);
61             case SonyAudioBindingConstants.SONY_TYPE_HTZF9:
62                 return new HtZf9Handler(thing, webSocketClient);
63             case SonyAudioBindingConstants.SONY_TYPE_HTMT500:
64                 return new HtMt500Handler(thing, webSocketClient);
65             case SonyAudioBindingConstants.SONY_TYPE_SRSZR5:
66                 return new SrsZr5Handler(thing, webSocketClient);
67             default:
68                 return null;
69         }
70     }
71
72     @Reference
73     protected void setWebSocketFactory(WebSocketFactory webSocketFactory) {
74         this.webSocketClient = webSocketFactory.getCommonWebSocketClient();
75     }
76
77     protected void unsetWebSocketFactory(WebSocketFactory webSocketFactory) {
78         this.webSocketClient = null;
79     }
80 }