]> git.basschouten.com Git - openhab-addons.git/blob
ea52b7b729b8b0798395072f3cca1822c2678eab
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.solarwatt.internal.factory;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.solarwatt.internal.domain.EnergyManagerCollection;
18 import org.openhab.binding.solarwatt.internal.domain.dto.DeviceDTO;
19 import org.openhab.binding.solarwatt.internal.domain.dto.EnergyManagerDTO;
20 import org.openhab.binding.solarwatt.internal.domain.model.BatteryConverter;
21 import org.openhab.binding.solarwatt.internal.domain.model.Device;
22 import org.openhab.binding.solarwatt.internal.domain.model.EVStation;
23 import org.openhab.binding.solarwatt.internal.domain.model.EnergyManager;
24 import org.openhab.binding.solarwatt.internal.domain.model.Forecast;
25 import org.openhab.binding.solarwatt.internal.domain.model.GridFlow;
26 import org.openhab.binding.solarwatt.internal.domain.model.Inverter;
27 import org.openhab.binding.solarwatt.internal.domain.model.KebaEv;
28 import org.openhab.binding.solarwatt.internal.domain.model.Location;
29 import org.openhab.binding.solarwatt.internal.domain.model.MyReserve;
30 import org.openhab.binding.solarwatt.internal.domain.model.MyReserveInverter;
31 import org.openhab.binding.solarwatt.internal.domain.model.MyReservePowerMeter;
32 import org.openhab.binding.solarwatt.internal.domain.model.PVPlant;
33 import org.openhab.binding.solarwatt.internal.domain.model.PowerMeter;
34 import org.openhab.binding.solarwatt.internal.domain.model.ProfileApp;
35 import org.openhab.binding.solarwatt.internal.domain.model.S0Counter;
36 import org.openhab.binding.solarwatt.internal.domain.model.ScheduleApp;
37 import org.openhab.binding.solarwatt.internal.domain.model.SimpleSwitcher;
38 import org.openhab.binding.solarwatt.internal.domain.model.SmartEnergyManagement;
39 import org.openhab.binding.solarwatt.internal.domain.model.SunSpecInverter;
40
41 /**
42  * Factory to produce concrete instances which match the device structure returned by the energy manager.
43  *
44  * @author Sven Carstens - Initial contribution
45  */
46 @NonNullByDefault
47 public class EnergyManagerDevicesFactory {
48     /**
49      * Generate a concrete collection of devices which where discovered by the energy manager.
50      *
51      * @param energyManagerDTO raw transfer object generated from json
52      * @return collection of all devices
53      */
54     public static EnergyManagerCollection getEnergyManagerCollection(EnergyManagerDTO energyManagerDTO) {
55         return new EnergyManagerCollection(energyManagerDTO);
56     }
57
58     /**
59      * Generate one concrete device instance from one raw device.
60      *
61      * Specific implementation to use is determined by looking at the
62      * deviceModels supported by the device and prioritising them according from the bottom up.
63      *
64      * @param deviceDTO raw transfer object for one device
65      * @return device fille from the {@link DeviceDTO}
66      */
67     public static @Nullable Device getEnergyManagerDevice(DeviceDTO deviceDTO) {
68         // objects on level 3
69         if (deviceDTO.getDeviceModelStrings().contains(MyReserve.SOLAR_WATT_CLASSNAME)) {
70             return new MyReserve(deviceDTO);
71         }
72         // objects on level 2
73         if (deviceDTO.getDeviceModelStrings().contains(S0Counter.SOLAR_WATT_CLASSNAME)) {
74             return new S0Counter(deviceDTO);
75         }
76         if (deviceDTO.getDeviceModelStrings().contains(KebaEv.SOLAR_WATT_CLASSNAME)) {
77             return new KebaEv(deviceDTO);
78         }
79         if (deviceDTO.getDeviceModelStrings().contains(MyReservePowerMeter.SOLAR_WATT_CLASSNAME)) {
80             return new MyReservePowerMeter(deviceDTO);
81         }
82         if (deviceDTO.getDeviceModelStrings().contains(SunSpecInverter.SOLAR_WATT_CLASSNAME)) {
83             return new SunSpecInverter(deviceDTO);
84         }
85         if (deviceDTO.getDeviceModelStrings().contains(MyReserveInverter.SOLAR_WATT_CLASSNAME)) {
86             return new MyReserveInverter(deviceDTO);
87         }
88         if (deviceDTO.getDeviceModelStrings().contains(BatteryConverter.SOLAR_WATT_CLASSNAME)) {
89             return new BatteryConverter(deviceDTO);
90         }
91         // objects on level 1
92         if (deviceDTO.getDeviceModelStrings().contains(ScheduleApp.SOLAR_WATT_CLASSNAME)) {
93             return new ScheduleApp(deviceDTO);
94         }
95         if (deviceDTO.getDeviceModelStrings().contains(SmartEnergyManagement.SOLAR_WATT_CLASSNAME)) {
96             return new SmartEnergyManagement(deviceDTO);
97         }
98         if (deviceDTO.getDeviceModelStrings().contains(EnergyManager.SOLAR_WATT_CLASSNAME)) {
99             return new EnergyManager(deviceDTO);
100         }
101         if (deviceDTO.getDeviceModelStrings().contains(Forecast.SOLAR_WATT_CLASSNAME)) {
102             return new Forecast(deviceDTO);
103         }
104         if (deviceDTO.getDeviceModelStrings().contains(Location.SOLAR_WATT_CLASSNAME)) {
105             return new Location(deviceDTO);
106         }
107         if (deviceDTO.getDeviceModelStrings().contains(EVStation.SOLAR_WATT_CLASSNAME)) {
108             return new EVStation(deviceDTO);
109         }
110         if (deviceDTO.getDeviceModelStrings().contains(PowerMeter.SOLAR_WATT_CLASSNAME)) {
111             return new PowerMeter(deviceDTO);
112         }
113         if (deviceDTO.getDeviceModelStrings().contains(SimpleSwitcher.SOLAR_WATT_CLASSNAME)) {
114             return new SimpleSwitcher(deviceDTO);
115         }
116         if (deviceDTO.getDeviceModelStrings().contains(GridFlow.SOLAR_WATT_CLASSNAME)) {
117             return new GridFlow(deviceDTO);
118         }
119         if (deviceDTO.getDeviceModelStrings().contains(PVPlant.SOLAR_WATT_CLASSNAME)) {
120             return new PVPlant(deviceDTO);
121         }
122         if (deviceDTO.getDeviceModelStrings().contains(Inverter.SOLAR_WATT_CLASSNAME)) {
123             return new Inverter(deviceDTO);
124         }
125         if (deviceDTO.getDeviceModelStrings().contains(ProfileApp.SOLAR_WATT_CLASSNAME)) {
126             return new ProfileApp(deviceDTO);
127         }
128
129         // Objects on level 0
130         if (deviceDTO.getDeviceModelStrings().contains(Device.SOLAR_WATT_CLASSNAME)) {
131             return new Device(deviceDTO);
132         }
133
134         return null;
135     }
136 }