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.onewire.internal.handler;
15 import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.onewire.internal.DS2438Configuration;
22 import org.openhab.binding.onewire.internal.OwDynamicStateDescriptionProvider;
23 import org.openhab.binding.onewire.internal.OwException;
24 import org.openhab.binding.onewire.internal.config.MstxHandlerConfiguration;
25 import org.openhab.binding.onewire.internal.device.DS1923;
26 import org.openhab.binding.onewire.internal.device.DS2438;
27 import org.openhab.binding.onewire.internal.device.DS2438.CurrentSensorType;
28 import org.openhab.binding.onewire.internal.device.DS2438.LightSensorType;
29 import org.openhab.binding.onewire.internal.device.OwSensorType;
30 import org.openhab.core.thing.Thing;
31 import org.openhab.core.thing.ThingTypeUID;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * The {@link BasicMultisensorThingHandler} is responsible for handling DS2438/DS1923 based multisensors (single
39 * @author Jan N. Klug - Initial contribution
42 public class BasicMultisensorThingHandler extends OwBaseThingHandler {
43 public Logger logger = LoggerFactory.getLogger(BasicMultisensorThingHandler.class);
44 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_MS_TX);
45 public static final Set<OwSensorType> SUPPORTED_SENSOR_TYPES = Set.of(OwSensorType.MS_TH, OwSensorType.MS_TC,
46 OwSensorType.MS_TL, OwSensorType.MS_TV, OwSensorType.DS1923, OwSensorType.DS2438);
48 public BasicMultisensorThingHandler(Thing thing,
49 OwDynamicStateDescriptionProvider dynamicStateDescriptionProvider) {
50 super(thing, dynamicStateDescriptionProvider, SUPPORTED_SENSOR_TYPES);
54 public void initialize() {
55 if (!super.configureThingHandler()) {
59 MstxHandlerConfiguration configuration = getConfig().as(MstxHandlerConfiguration.class);
60 if (configuration.manualsensor != null && sensorType != configuration.manualsensor) {
61 logger.debug("sensorType override for thing {}: old={}, new={}", thing.getUID(), sensorType,
62 configuration.manualsensor);
63 sensorType = configuration.manualsensor;
67 if (sensorType == OwSensorType.DS1923) {
68 sensors.add(new DS1923(sensorId, this));
70 sensors.add(new DS2438(sensorId, this));
73 scheduler.execute(this::configureThingChannels);
77 protected void configureThingChannels() {
79 case DS2438 -> ((DS2438) sensors.get(0)).setCurrentSensorType(CurrentSensorType.INTERNAL);
80 case MS_TC -> ((DS2438) sensors.get(0)).setCurrentSensorType(CurrentSensorType.IBUTTONLINK);
81 case MS_TL -> ((DS2438) sensors.get(0)).setLightSensorType(LightSensorType.IBUTTONLINK);
86 super.configureThingChannels();
90 public void updateSensorProperties(OwserverBridgeHandler bridgeHandler) throws OwException {
91 Map<String, String> properties = editProperties();
92 sensorType = bridgeHandler.getType(sensorId);
94 if (sensorType == OwSensorType.DS1923) {
95 properties.put(PROPERTY_MODELID, sensorType.toString());
96 properties.put(PROPERTY_VENDOR, "Dallas/Maxim");
98 DS2438Configuration ds2438configuration = new DS2438Configuration(bridgeHandler, sensorId);
100 sensorType = ds2438configuration.getSensorSubType();
101 properties.put(PROPERTY_MODELID, sensorType.toString());
103 String vendor = ds2438configuration.getVendor();
104 properties.put(PROPERTY_VENDOR, vendor);
107 updateProperties(properties);