]> git.basschouten.com Git - openhab-addons.git/blob
0ffd28c3a63c4e9a0dc96ad6d1c2ec79f3dbdf16
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.bosesoundtouch.internal;
14
15 import static org.openhab.binding.bosesoundtouch.internal.BoseSoundTouchBindingConstants.SUPPORTED_THING_TYPES_UIDS;
16
17 import org.openhab.binding.bosesoundtouch.internal.handler.BoseSoundTouchHandler;
18 import org.openhab.core.storage.Storage;
19 import org.openhab.core.storage.StorageService;
20 import org.openhab.core.thing.Thing;
21 import org.openhab.core.thing.ThingTypeUID;
22 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
23 import org.openhab.core.thing.binding.ThingHandler;
24 import org.openhab.core.thing.binding.ThingHandlerFactory;
25 import org.osgi.service.component.annotations.Component;
26 import org.osgi.service.component.annotations.Reference;
27
28 /**
29  * The {@link BoseSoundTouchHandlerFactory} is responsible for creating things and thing
30  * handlers.
31  *
32  * @author Christian Niessner - Initial contribution
33  */
34 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.bosesoundtouch")
35 public class BoseSoundTouchHandlerFactory extends BaseThingHandlerFactory {
36
37     private StorageService storageService;
38     private BoseStateDescriptionOptionProvider stateOptionProvider;
39
40     @Override
41     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
42         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
43     }
44
45     @Override
46     protected ThingHandler createHandler(Thing thing) {
47         Storage<ContentItem> storage = storageService.getStorage(thing.getUID().toString(),
48                 ContentItem.class.getClassLoader());
49         BoseSoundTouchHandler handler = new BoseSoundTouchHandler(thing, new PresetContainer(storage),
50                 stateOptionProvider);
51         return handler;
52     }
53
54     @Reference
55     protected void setStorageService(StorageService storageService) {
56         this.storageService = storageService;
57     }
58
59     protected void unsetStorageService(StorageService storageService) {
60         this.storageService = null;
61     }
62
63     @Reference
64     protected void setPresetChannelTypeProvider(BoseStateDescriptionOptionProvider stateOptionProvider) {
65         this.stateOptionProvider = stateOptionProvider;
66     }
67
68     protected void unsetPresetChannelTypeProvider(BoseStateDescriptionOptionProvider stateOptionProvider) {
69         this.stateOptionProvider = null;
70     }
71 }