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.*;
17 import java.util.Collections;
20 import java.util.stream.Collectors;
21 import java.util.stream.Stream;
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.openhab.binding.onewire.internal.DS2438Configuration;
25 import org.openhab.binding.onewire.internal.OwDynamicStateDescriptionProvider;
26 import org.openhab.binding.onewire.internal.OwException;
27 import org.openhab.binding.onewire.internal.config.MstxHandlerConfiguration;
28 import org.openhab.binding.onewire.internal.device.DS1923;
29 import org.openhab.binding.onewire.internal.device.DS2438;
30 import org.openhab.binding.onewire.internal.device.DS2438.CurrentSensorType;
31 import org.openhab.binding.onewire.internal.device.DS2438.LightSensorType;
32 import org.openhab.binding.onewire.internal.device.OwSensorType;
33 import org.openhab.core.thing.Thing;
34 import org.openhab.core.thing.ThingTypeUID;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
39 * The {@link BasicMultisensorThingHandler} is responsible for handling DS2438/DS1923 based multisensors (single
42 * @author Jan N. Klug - Initial contribution
45 public class BasicMultisensorThingHandler extends OwBaseThingHandler {
46 public Logger logger = LoggerFactory.getLogger(BasicMultisensorThingHandler.class);
47 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_MS_TX);
48 public static final Set<OwSensorType> SUPPORTED_SENSOR_TYPES = Collections
49 .unmodifiableSet(Stream.of(OwSensorType.MS_TH, OwSensorType.MS_TC, OwSensorType.MS_TL, OwSensorType.MS_TV,
50 OwSensorType.DS1923, OwSensorType.DS2438).collect(Collectors.toSet()));
52 public BasicMultisensorThingHandler(Thing thing,
53 OwDynamicStateDescriptionProvider dynamicStateDescriptionProvider) {
54 super(thing, dynamicStateDescriptionProvider, SUPPORTED_SENSOR_TYPES);
58 public void initialize() {
59 if (!super.configureThingHandler()) {
63 MstxHandlerConfiguration configuration = getConfig().as(MstxHandlerConfiguration.class);
64 if (configuration.manualsensor != null && sensorType != configuration.manualsensor) {
65 logger.debug("sensorType override for thing {}: old={}, new={}", thing.getUID(), sensorType,
66 configuration.manualsensor);
67 sensorType = configuration.manualsensor;
71 if (sensorType == OwSensorType.DS1923) {
72 sensors.add(new DS1923(sensorId, this));
74 sensors.add(new DS2438(sensorId, this));
77 scheduler.execute(() -> {
78 configureThingChannels();
83 protected void configureThingChannels() {
86 ((DS2438) sensors.get(0)).setCurrentSensorType(CurrentSensorType.INTERNAL);
89 ((DS2438) sensors.get(0)).setCurrentSensorType(CurrentSensorType.IBUTTONLINK);
92 ((DS2438) sensors.get(0)).setLightSensorType(LightSensorType.IBUTTONLINK);
97 super.configureThingChannels();
101 public void updateSensorProperties(OwserverBridgeHandler bridgeHandler) throws OwException {
102 Map<String, String> properties = editProperties();
103 sensorType = bridgeHandler.getType(sensorId);
105 if (sensorType == OwSensorType.DS1923) {
106 properties.put(PROPERTY_MODELID, sensorType.toString());
107 properties.put(PROPERTY_VENDOR, "Dallas/Maxim");
109 DS2438Configuration ds2438configuration = new DS2438Configuration(bridgeHandler, sensorId);
111 sensorType = ds2438configuration.getSensorSubType();
112 properties.put(PROPERTY_MODELID, sensorType.toString());
114 String vendor = ds2438configuration.getVendor();
115 properties.put(PROPERTY_VENDOR, vendor);
118 updateProperties(properties);