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.io.imperihome.internal.model.device;
15 import org.openhab.core.items.Item;
16 import org.openhab.io.imperihome.internal.model.param.NumericValueParam;
17 import org.openhab.io.imperihome.internal.model.param.ParamType;
18 import org.openhab.io.imperihome.internal.processor.ItemProcessor;
21 * Abstraction of devices that allow a link to a current energy consumption item.
23 * @author Pepijn de Geus - Initial contribution
25 public abstract class AbstractEnergyLinkDevice extends AbstractDevice {
27 public AbstractEnergyLinkDevice(DeviceType type, Item item) {
32 public void updateParams() {
35 if (getLinks().containsKey("energy")) {
36 String deviceName = getLinks().get("energy");
37 String deviceId = ItemProcessor.getDeviceId(deviceName);
38 AbstractDevice energyDevice = getDeviceRegistry().getDevice(deviceId);
39 if (energyDevice == null) {
40 logger.error("Couldn't resolve linked energy device '{}', make sure the Item has iss tags", deviceName);
42 NumericValueParam valueParam = (NumericValueParam) energyDevice.getParams().get(ParamType.WATTS);
43 if (valueParam == null) {
44 logger.warn("Linked energy device has no Watts value parameter: {}", energyDevice);
46 NumericValueParam energyParam = new NumericValueParam(ParamType.ENERGY, valueParam.getUnit(), null);
47 energyParam.setValue(valueParam.getValue());
48 addParam(energyParam);