]> git.basschouten.com Git - openhab-addons.git/blob
b3b6e756ffdda9bbf8beb883eeeb13664e81c0ec
[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 static org.openhab.io.homekit.internal.HomekitCharacteristicType.*;
16
17 import java.util.List;
18
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 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 import io.github.hapjava.characteristics.Characteristic;
27 import io.github.hapjava.characteristics.impl.thermostat.CurrentHeatingCoolingStateCharacteristic;
28 import io.github.hapjava.characteristics.impl.thermostat.CurrentTemperatureCharacteristic;
29 import io.github.hapjava.characteristics.impl.thermostat.TargetHeatingCoolingStateCharacteristic;
30 import io.github.hapjava.characteristics.impl.thermostat.TargetTemperatureCharacteristic;
31 import io.github.hapjava.characteristics.impl.thermostat.TemperatureDisplayUnitCharacteristic;
32 import io.github.hapjava.services.impl.ThermostatService;
33
34 /**
35  * Implements Thermostat as a GroupedAccessory made up of multiple items:
36  * <ul>
37  * <li>Current Temperature: Number type</li>
38  * <li>Target Temperature: Number type</li>
39  * <li>Current Heating/Cooling Mode: String type (see HomekitSettings.thermostat*Mode)</li>
40  * <li>Target Heating/Cooling Mode: String type (see HomekitSettings.thermostat*Mode)</li>
41  * </ul>
42  *
43  * @author Andy Lintner - Initial contribution
44  */
45 class HomekitThermostatImpl extends AbstractHomekitAccessoryImpl {
46     private final Logger logger = LoggerFactory.getLogger(HomekitThermostatImpl.class);
47
48     public HomekitThermostatImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
49             List<Characteristic> mandatoryRawCharacteristics, HomekitAccessoryUpdater updater,
50             HomekitSettings settings) {
51         super(taggedItem, mandatoryCharacteristics, mandatoryRawCharacteristics, updater, settings);
52     }
53
54     @Override
55     public void init() throws HomekitException {
56         super.init();
57
58         // This characteristic is technically mandatory, but we provide a default if it's not provided
59         var displayUnitCharacteristic = getCharacteristic(TemperatureDisplayUnitCharacteristic.class)
60                 .orElseGet(() -> HomekitCharacteristicFactory.createSystemTemperatureDisplayUnitCharacteristic());
61
62         addService(new ThermostatService(getCharacteristic(CurrentHeatingCoolingStateCharacteristic.class).get(),
63                 getCharacteristic(TargetHeatingCoolingStateCharacteristic.class).get(),
64                 getCharacteristic(CurrentTemperatureCharacteristic.class).get(),
65                 getCharacteristic(TargetTemperatureCharacteristic.class).get(), displayUnitCharacteristic));
66     }
67 }