]> git.basschouten.com Git - openhab-addons.git/blob
433a36f85e8941a4fb75ddeb1ced964a2979517c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.io.homekit.internal.accessories;
14
15 import java.util.List;
16 import java.util.concurrent.CompletableFuture;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.io.homekit.internal.HomekitAccessoryUpdater;
20 import org.openhab.io.homekit.internal.HomekitException;
21 import org.openhab.io.homekit.internal.HomekitSettings;
22 import org.openhab.io.homekit.internal.HomekitTaggedItem;
23
24 import io.github.hapjava.characteristics.impl.common.ActiveCharacteristic;
25 import io.github.hapjava.characteristics.impl.common.ActiveIdentifierCharacteristic;
26 import io.github.hapjava.characteristics.impl.common.ConfiguredNameCharacteristic;
27 import io.github.hapjava.characteristics.impl.television.RemoteKeyCharacteristic;
28 import io.github.hapjava.characteristics.impl.television.SleepDiscoveryModeCharacteristic;
29 import io.github.hapjava.characteristics.impl.television.SleepDiscoveryModeEnum;
30 import io.github.hapjava.services.impl.TelevisionService;
31
32 /**
33  * Implements Television
34  * 
35  * This is a little different in that we don't implement the accessory interface.
36  * This is because several of the "mandatory" characteristics we don't require,
37  * and wait until all optional attributes are added and if they don't exist
38  * it will create "default" values for them.
39  *
40  * @author Cody Cutrer - Initial contribution
41  */
42 @NonNullByDefault({})
43 public class HomekitTelevisionImpl extends AbstractHomekitAccessoryImpl {
44
45     public HomekitTelevisionImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
46             HomekitAccessoryUpdater updater, HomekitSettings settings) throws IncompleteAccessoryException {
47         super(taggedItem, mandatoryCharacteristics, updater, settings);
48     }
49
50     @Override
51     public void init() throws HomekitException {
52         super.init();
53
54         // these charactereristics are technically mandatory, but we provide defaults if they're not provided
55         var activeIdentifierCharacteristic = getCharacteristic(ActiveIdentifierCharacteristic.class)
56                 .orElseGet(() -> new ActiveIdentifierCharacteristic(() -> CompletableFuture.completedFuture(1), v -> {
57                 }, v -> {
58                 }, () -> {
59                 }));
60         var configuredNameCharacteristic = getCharacteristic(ConfiguredNameCharacteristic.class)
61                 .orElseGet(() -> new ConfiguredNameCharacteristic(() -> getName(), v -> {
62                 }, v -> {
63                 }, () -> {
64                 }));
65         var remoteKeyCharacteristic = getCharacteristic(RemoteKeyCharacteristic.class)
66                 .orElseGet(() -> new RemoteKeyCharacteristic((v) -> {
67                 }));
68         var sleepDiscoveryModeCharacteristic = getCharacteristic(SleepDiscoveryModeCharacteristic.class)
69                 .orElseGet(() -> new SleepDiscoveryModeCharacteristic(
70                         () -> CompletableFuture.completedFuture(SleepDiscoveryModeEnum.ALWAYS_DISCOVERABLE), v -> {
71                         }, () -> {
72                         }));
73
74         var service = new TelevisionService(getCharacteristic(ActiveCharacteristic.class).get(),
75                 activeIdentifierCharacteristic, configuredNameCharacteristic, remoteKeyCharacteristic,
76                 sleepDiscoveryModeCharacteristic);
77
78         addService(service);
79     }
80 }