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.nio.charset.StandardCharsets;
18 import java.util.Collections;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.binding.onewire.internal.OwDynamicStateDescriptionProvider;
24 import org.openhab.binding.onewire.internal.OwException;
25 import org.openhab.binding.onewire.internal.OwPageBuffer;
26 import org.openhab.binding.onewire.internal.device.EDS006x;
27 import org.openhab.binding.onewire.internal.device.OwSensorType;
28 import org.openhab.core.thing.Thing;
29 import org.openhab.core.thing.ThingTypeUID;
32 * The {@link EDSSensorThingHandler} is responsible for handling EDS multisensors
34 * @author Jan N. Klug - Initial contribution
37 public class EDSSensorThingHandler extends OwBaseThingHandler {
38 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_EDS_ENV);
39 public static final Set<OwSensorType> SUPPORTED_SENSOR_TYPES = Set.of(OwSensorType.EDS0064, OwSensorType.EDS0065,
40 OwSensorType.EDS0066, OwSensorType.EDS0067, OwSensorType.EDS0068);
41 private static final Set<String> REQUIRED_PROPERTIES = Collections.singleton(PROPERTY_HW_REVISION);
43 public EDSSensorThingHandler(Thing thing, OwDynamicStateDescriptionProvider dynamicStateDescriptionProvider) {
44 super(thing, dynamicStateDescriptionProvider, SUPPORTED_SENSOR_TYPES, REQUIRED_PROPERTIES);
48 public void initialize() {
49 if (!super.configureThingHandler()) {
54 sensors.add(new EDS006x(sensorId, sensorType, this));
56 scheduler.execute(this::configureThingChannels);
60 public void updateSensorProperties(OwserverBridgeHandler bridgeHandler) throws OwException {
61 Map<String, String> properties = editProperties();
63 OwPageBuffer pages = bridgeHandler.readPages(sensorId);
65 OwSensorType sensorType = OwSensorType.UNKNOWN;
67 sensorType = OwSensorType.valueOf(new String(pages.getPage(0), 0, 7, StandardCharsets.US_ASCII));
68 } catch (IllegalArgumentException ignored) {
71 if (!SUPPORTED_SENSOR_TYPES.contains(sensorType)) {
72 throw new OwException("sensorType not supported for EDSSensorThing");
75 int fwRevisionLow = pages.getByte(3, 3);
76 int fwRevisionHigh = pages.getByte(3, 4);
77 String fwRevision = String.format("%d.%d", fwRevisionHigh, fwRevisionLow);
79 properties.put(PROPERTY_MODELID, sensorType.name());
80 properties.put(PROPERTY_VENDOR, "Embedded Data Systems");
81 properties.put(PROPERTY_HW_REVISION, String.valueOf(fwRevision));
83 updateProperties(properties);