2 * Copyright (c) 2010-2020 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.io.imperihome.internal.model.device;
15 import org.apache.commons.lang.StringUtils;
16 import org.openhab.core.items.Item;
17 import org.openhab.core.library.types.DecimalType;
18 import org.openhab.core.types.State;
19 import org.openhab.io.imperihome.internal.model.param.NumericValueParam;
20 import org.openhab.io.imperihome.internal.model.param.ParamType;
21 import org.openhab.io.imperihome.internal.processor.ItemProcessor;
26 * @author Pepijn de Geus - Initial contribution
28 public class WindDevice extends AbstractNumericValueDevice {
30 private static final String LINK_DIRECTION = "direction";
32 public WindDevice(Item item) {
33 super(DeviceType.WIND, item, "km/h");
37 public void updateParams() {
40 if (getLinks().containsKey(LINK_DIRECTION)) {
41 String deviceName = getLinks().get(LINK_DIRECTION);
42 String deviceId = ItemProcessor.getDeviceId(deviceName);
43 AbstractDevice dirDevice = getDeviceRegistry().getDevice(deviceId);
44 if (dirDevice == null) {
45 logger.error("Couldn't resolve linked wind direction device '{}', make sure the Item has iss tags",
50 NumericValueParam valueParam = (NumericValueParam) dirDevice.getParams().get(ParamType.GENERIC_VALUE);
51 if (valueParam == null) {
52 logger.warn("Linked Wind direction device has no Value parameter: {}", dirDevice);
56 NumericValueParam dirParam = new NumericValueParam(ParamType.DIRECTION, valueParam.getUnit(), null);
57 if (StringUtils.isEmpty(dirParam.getUnit())) {
58 dirParam.setUnit("Degrees");
61 dirParam.setValue(valueParam.getValue());
67 public void stateUpdated(Item item, State newState) {
68 super.stateUpdated(item, newState);
70 DecimalType value = (DecimalType) item.getStateAs(DecimalType.class);
71 addParam(new NumericValueParam(ParamType.SPEED, getUnit(), value));