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.draytonwiser.internal.model;
15 import java.util.Collections;
16 import java.util.List;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
22 * Helper class to get specific data from the domain object.
24 * @author Andrew Schofield - Initial contribution
25 * @author Hilbrand Bouwkamp - Moved domain object helper code to it's own class
28 public class DraytonWiserDTO {
30 private final DomainDTO domain;
32 public DraytonWiserDTO(final DomainDTO domain) {
36 public List<RoomStatDTO> getRoomStats() {
37 return domain.getRoomStat() == null ? Collections.emptyList() : domain.getRoomStat();
40 public List<SmartValveDTO> getSmartValves() {
41 return domain.getSmartValve() == null ? Collections.emptyList() : domain.getSmartValve();
44 public List<SmartPlugDTO> getSmartPlugs() {
45 return domain.getSmartPlug() == null ? Collections.emptyList() : domain.getSmartPlug();
48 public List<RoomDTO> getRooms() {
49 return domain.getRoom() == null ? Collections.emptyList() : domain.getRoom();
52 public @Nullable RoomDTO getRoomByName(final String name) {
53 for (final RoomDTO room : domain.getRoom()) {
54 if (room.getName().equalsIgnoreCase(name)) {
61 public @Nullable RoomStatDTO getRoomStat(final String serialNumber) {
62 final Integer id = getIdFromSerialNumber(serialNumber);
64 return id == null ? null : getRoomStat(id);
67 public @Nullable RoomStatDTO getRoomStat(final int id) {
68 for (final RoomStatDTO roomStat : domain.getRoomStat()) {
69 if (roomStat.getId().equals(id)) {
76 public @Nullable SmartPlugDTO getSmartPlug(final String serialNumber) {
77 final Integer id = getIdFromSerialNumber(serialNumber);
82 for (final SmartPlugDTO smartPlug : domain.getSmartPlug()) {
83 if (smartPlug.getId().equals(id)) {
90 public @Nullable DeviceDTO getExtendedDeviceProperties(final int id) {
91 for (final DeviceDTO device : domain.getDevice()) {
92 if (device.getId().equals(id)) {
100 public @Nullable SystemDTO getSystem() {
101 return domain.getSystem();
104 public List<HeatingChannelDTO> getHeatingChannels() {
105 return domain.getHeatingChannel() == null ? Collections.emptyList() : domain.getHeatingChannel();
108 public List<HotWaterDTO> getHotWater() {
109 return domain.getHotWater() == null ? Collections.emptyList() : domain.getHotWater();
113 public RoomDTO getRoomForDeviceId(final Integer id) {
114 for (final RoomDTO room : domain.getRoom()) {
116 if (room.getRoomStatId() != null && room.getRoomStatId().equals(id)) {
120 final List<Integer> trvs = room.getSmartValveIds();
122 for (final Integer itrv : trvs) {
123 if (itrv.equals(id)) {
133 public @Nullable SmartValveDTO getSmartValve(final String serialNumber) {
134 final Integer id = getIdFromSerialNumber(serialNumber);
140 for (final SmartValveDTO smartValve : domain.getSmartValve()) {
141 if (smartValve.getId().equals(id)) {
148 private @Nullable Integer getIdFromSerialNumber(final String serialNumber) {
149 for (final DeviceDTO device : domain.getDevice()) {
150 if (device.getSerialNumber() != null
151 && device.getSerialNumber().toLowerCase().equals(serialNumber.toLowerCase())) {
152 return device.getId();