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.solarwatt.internal.factory;
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;
42 * Factory to produce concrete instances which match the device structure returned by the energy manager.
44 * @author Sven Carstens - Initial contribution
47 public class EnergyManagerDevicesFactory {
49 * Generate a concrete collection of devices which where discovered by the energy manager.
51 * @param energyManagerDTO raw transfer object generated from json
52 * @return collection of all devices
54 public static EnergyManagerCollection getEnergyManagerCollection(EnergyManagerDTO energyManagerDTO) {
55 return new EnergyManagerCollection(energyManagerDTO);
59 * Generate one concrete device instance from one raw device.
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.
64 * @param deviceDTO raw transfer object for one device
65 * @return device fille from the {@link DeviceDTO}
67 public static @Nullable Device getEnergyManagerDevice(DeviceDTO deviceDTO) {
69 if (deviceDTO.getDeviceModelStrings().contains(MyReserve.SOLAR_WATT_CLASSNAME)) {
70 return new MyReserve(deviceDTO);
73 if (deviceDTO.getDeviceModelStrings().contains(S0Counter.SOLAR_WATT_CLASSNAME)) {
74 return new S0Counter(deviceDTO);
76 if (deviceDTO.getDeviceModelStrings().contains(KebaEv.SOLAR_WATT_CLASSNAME)) {
77 return new KebaEv(deviceDTO);
79 if (deviceDTO.getDeviceModelStrings().contains(MyReservePowerMeter.SOLAR_WATT_CLASSNAME)) {
80 return new MyReservePowerMeter(deviceDTO);
82 if (deviceDTO.getDeviceModelStrings().contains(SunSpecInverter.SOLAR_WATT_CLASSNAME)) {
83 return new SunSpecInverter(deviceDTO);
85 if (deviceDTO.getDeviceModelStrings().contains(MyReserveInverter.SOLAR_WATT_CLASSNAME)) {
86 return new MyReserveInverter(deviceDTO);
88 if (deviceDTO.getDeviceModelStrings().contains(BatteryConverter.SOLAR_WATT_CLASSNAME)) {
89 return new BatteryConverter(deviceDTO);
92 if (deviceDTO.getDeviceModelStrings().contains(ScheduleApp.SOLAR_WATT_CLASSNAME)) {
93 return new ScheduleApp(deviceDTO);
95 if (deviceDTO.getDeviceModelStrings().contains(SmartEnergyManagement.SOLAR_WATT_CLASSNAME)) {
96 return new SmartEnergyManagement(deviceDTO);
98 if (deviceDTO.getDeviceModelStrings().contains(EnergyManager.SOLAR_WATT_CLASSNAME)) {
99 return new EnergyManager(deviceDTO);
101 if (deviceDTO.getDeviceModelStrings().contains(Forecast.SOLAR_WATT_CLASSNAME)) {
102 return new Forecast(deviceDTO);
104 if (deviceDTO.getDeviceModelStrings().contains(Location.SOLAR_WATT_CLASSNAME)) {
105 return new Location(deviceDTO);
107 if (deviceDTO.getDeviceModelStrings().contains(EVStation.SOLAR_WATT_CLASSNAME)) {
108 return new EVStation(deviceDTO);
110 if (deviceDTO.getDeviceModelStrings().contains(PowerMeter.SOLAR_WATT_CLASSNAME)) {
111 return new PowerMeter(deviceDTO);
113 if (deviceDTO.getDeviceModelStrings().contains(SimpleSwitcher.SOLAR_WATT_CLASSNAME)) {
114 return new SimpleSwitcher(deviceDTO);
116 if (deviceDTO.getDeviceModelStrings().contains(GridFlow.SOLAR_WATT_CLASSNAME)) {
117 return new GridFlow(deviceDTO);
119 if (deviceDTO.getDeviceModelStrings().contains(PVPlant.SOLAR_WATT_CLASSNAME)) {
120 return new PVPlant(deviceDTO);
122 if (deviceDTO.getDeviceModelStrings().contains(Inverter.SOLAR_WATT_CLASSNAME)) {
123 return new Inverter(deviceDTO);
125 if (deviceDTO.getDeviceModelStrings().contains(ProfileApp.SOLAR_WATT_CLASSNAME)) {
126 return new ProfileApp(deviceDTO);
129 // Objects on level 0
130 if (deviceDTO.getDeviceModelStrings().contains(Device.SOLAR_WATT_CLASSNAME)) {
131 return new Device(deviceDTO);