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.SmartHeater;
40 import org.openhab.binding.solarwatt.internal.domain.model.SunSpecInverter;
43 * Factory to produce concrete instances which match the device structure returned by the energy manager.
45 * @author Sven Carstens - Initial contribution
48 public class EnergyManagerDevicesFactory {
50 * Generate a concrete collection of devices which where discovered by the energy manager.
52 * @param energyManagerDTO raw transfer object generated from json
53 * @return collection of all devices
55 public static EnergyManagerCollection getEnergyManagerCollection(EnergyManagerDTO energyManagerDTO) {
56 return new EnergyManagerCollection(energyManagerDTO);
60 * Generate one concrete device instance from one raw device.
62 * Specific implementation to use is determined by looking at the
63 * deviceModels supported by the device and prioritising them according from the bottom up.
65 * @param deviceDTO raw transfer object for one device
66 * @return device fille from the {@link DeviceDTO}
68 public static @Nullable Device getEnergyManagerDevice(DeviceDTO deviceDTO) {
70 if (deviceDTO.getDeviceModelStrings().contains(MyReserve.SOLAR_WATT_CLASSNAME)) {
71 return new MyReserve(deviceDTO);
74 if (deviceDTO.getDeviceModelStrings().contains(S0Counter.SOLAR_WATT_CLASSNAME)) {
75 return new S0Counter(deviceDTO);
77 if (deviceDTO.getDeviceModelStrings().contains(KebaEv.SOLAR_WATT_CLASSNAME)) {
78 return new KebaEv(deviceDTO);
80 if (deviceDTO.getDeviceModelStrings().contains(MyReservePowerMeter.SOLAR_WATT_CLASSNAME)) {
81 return new MyReservePowerMeter(deviceDTO);
83 if (deviceDTO.getDeviceModelStrings().contains(SunSpecInverter.SOLAR_WATT_CLASSNAME)) {
84 return new SunSpecInverter(deviceDTO);
86 if (deviceDTO.getDeviceModelStrings().contains(MyReserveInverter.SOLAR_WATT_CLASSNAME)) {
87 return new MyReserveInverter(deviceDTO);
89 if (deviceDTO.getDeviceModelStrings().contains(BatteryConverter.SOLAR_WATT_CLASSNAME)) {
90 return new BatteryConverter(deviceDTO);
93 if (deviceDTO.getDeviceModelStrings().contains(ScheduleApp.SOLAR_WATT_CLASSNAME)) {
94 return new ScheduleApp(deviceDTO);
96 if (deviceDTO.getDeviceModelStrings().contains(SmartEnergyManagement.SOLAR_WATT_CLASSNAME)) {
97 return new SmartEnergyManagement(deviceDTO);
99 if (deviceDTO.getDeviceModelStrings().contains(EnergyManager.SOLAR_WATT_CLASSNAME)) {
100 return new EnergyManager(deviceDTO);
102 if (deviceDTO.getDeviceModelStrings().contains(Forecast.SOLAR_WATT_CLASSNAME)) {
103 return new Forecast(deviceDTO);
105 if (deviceDTO.getDeviceModelStrings().contains(Location.SOLAR_WATT_CLASSNAME)) {
106 return new Location(deviceDTO);
108 if (deviceDTO.getDeviceModelStrings().contains(EVStation.SOLAR_WATT_CLASSNAME)) {
109 return new EVStation(deviceDTO);
111 if (deviceDTO.getDeviceModelStrings().contains(PowerMeter.SOLAR_WATT_CLASSNAME)) {
112 return new PowerMeter(deviceDTO);
114 if (deviceDTO.getDeviceModelStrings().contains(SimpleSwitcher.SOLAR_WATT_CLASSNAME)) {
115 return new SimpleSwitcher(deviceDTO);
117 if (deviceDTO.getDeviceModelStrings().contains(GridFlow.SOLAR_WATT_CLASSNAME)) {
118 return new GridFlow(deviceDTO);
120 if (deviceDTO.getDeviceModelStrings().contains(PVPlant.SOLAR_WATT_CLASSNAME)) {
121 return new PVPlant(deviceDTO);
123 if (deviceDTO.getDeviceModelStrings().contains(Inverter.SOLAR_WATT_CLASSNAME)) {
124 return new Inverter(deviceDTO);
126 if (deviceDTO.getDeviceModelStrings().contains(ProfileApp.SOLAR_WATT_CLASSNAME)) {
127 return new ProfileApp(deviceDTO);
129 if (deviceDTO.getDeviceModelStrings().contains(SmartHeater.SOLAR_WATT_CLASSNAME)) {
130 return new SmartHeater(deviceDTO);
133 // Objects on level 0
134 if (deviceDTO.getDeviceModelStrings().contains(Device.SOLAR_WATT_CLASSNAME)) {
135 return new Device(deviceDTO);