|
31 | 31 | import org.openhab.binding.haywardomnilogiclocal.internal.config.MspConfig; |
32 | 32 | import org.openhab.binding.haywardomnilogiclocal.internal.config.PumpConfig; |
33 | 33 | import org.openhab.binding.haywardomnilogiclocal.internal.config.RelayConfig; |
34 | | -import org.openhab.binding.haywardomnilogiclocal.internal.config.SystemConfig; |
35 | 34 | import org.openhab.binding.haywardomnilogiclocal.internal.config.VirtualHeaterConfig; |
36 | 35 | import org.openhab.binding.haywardomnilogiclocal.internal.handler.HaywardBridgeHandler; |
37 | 36 | import org.openhab.core.config.discovery.AbstractThingHandlerDiscoveryService; |
@@ -73,136 +72,133 @@ protected void startScan() { |
73 | 72 | public synchronized void mspConfigDiscovery(String xmlResponse) { |
74 | 73 | MspConfig config = ConfigParser.parse(xmlResponse); |
75 | 74 |
|
76 | | - for (SystemConfig system : config.getSystems()) { |
77 | | - String systemId = system.getSystemId(); |
| 75 | + for (BackyardConfig backyard : config.getBackyards()) { |
| 76 | + Map<String, Object> backyardProps = new HashMap<>(); |
| 77 | + backyardProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.BACKYARD); |
| 78 | + String systemId = backyard.getSystemId(); |
| 79 | + if (systemId != null) { |
| 80 | + backyardProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, systemId); |
| 81 | + } |
| 82 | + onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_BACKYARD, "Backyard", backyardProps); |
| 83 | + |
| 84 | + for (BodyOfWaterConfig bow : backyard.getBodiesOfWater()) { |
| 85 | + Map<String, Object> bowProps = new HashMap<>(); |
| 86 | + bowProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.BOW); |
| 87 | + String bowId = bow.getSystemId(); |
| 88 | + if (bowId != null) { |
| 89 | + bowProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, bowId); |
| 90 | + } |
| 91 | + onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_BOW, bowId != null ? bowId : "BodyOfWater", |
| 92 | + bowProps); |
| 93 | + } |
78 | 94 |
|
79 | | - for (BackyardConfig backyard : system.getBackyards()) { |
80 | | - Map<String, Object> backyardProps = new HashMap<>(); |
81 | | - backyardProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.BACKYARD); |
82 | | - if (systemId != null) { |
83 | | - backyardProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, systemId); |
| 95 | + for (PumpConfig pump : backyard.getPumps()) { |
| 96 | + Map<String, Object> pumpProps = new HashMap<>(); |
| 97 | + pumpProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.PUMP); |
| 98 | + String pumpId = pump.getSystemId(); |
| 99 | + if (pumpId != null) { |
| 100 | + pumpProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, pumpId); |
84 | 101 | } |
85 | | - onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_BACKYARD, "Backyard", backyardProps); |
86 | | - |
87 | | - for (BodyOfWaterConfig bow : backyard.getBodiesOfWater()) { |
88 | | - Map<String, Object> bowProps = new HashMap<>(); |
89 | | - bowProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.BOW); |
90 | | - String bowId = bow.getSystemId(); |
91 | | - if (bowId != null) { |
92 | | - bowProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, bowId); |
93 | | - } |
94 | | - onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_BOW, bowId != null ? bowId : "BodyOfWater", |
95 | | - bowProps); |
| 102 | + String name = pump.getName() != null ? pump.getName() : pumpId; |
| 103 | + if (name == null) { |
| 104 | + name = "Pump"; |
96 | 105 | } |
| 106 | + onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_PUMP, name, pumpProps); |
| 107 | + } |
97 | 108 |
|
98 | | - for (PumpConfig pump : backyard.getPumps()) { |
99 | | - Map<String, Object> pumpProps = new HashMap<>(); |
100 | | - pumpProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.PUMP); |
101 | | - String pumpId = pump.getSystemId(); |
102 | | - if (pumpId != null) { |
103 | | - pumpProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, pumpId); |
104 | | - } |
105 | | - String name = pump.getName() != null ? pump.getName() : pumpId; |
106 | | - if (name == null) { |
107 | | - name = "Pump"; |
108 | | - } |
109 | | - onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_PUMP, name, pumpProps); |
| 109 | + for (FilterConfig filter : backyard.getFilters()) { |
| 110 | + Map<String, Object> filterProps = new HashMap<>(); |
| 111 | + filterProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.FILTER); |
| 112 | + String filterId = filter.getSystemId(); |
| 113 | + if (filterId != null) { |
| 114 | + filterProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, filterId); |
110 | 115 | } |
| 116 | + onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_FILTER, |
| 117 | + filterId != null ? filterId : "Filter", filterProps); |
| 118 | + } |
111 | 119 |
|
112 | | - for (FilterConfig filter : backyard.getFilters()) { |
113 | | - Map<String, Object> filterProps = new HashMap<>(); |
114 | | - filterProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.FILTER); |
115 | | - String filterId = filter.getSystemId(); |
116 | | - if (filterId != null) { |
117 | | - filterProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, filterId); |
118 | | - } |
119 | | - onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_FILTER, |
120 | | - filterId != null ? filterId : "Filter", filterProps); |
| 120 | + for (HeaterConfig heater : backyard.getHeaters()) { |
| 121 | + Map<String, Object> heaterProps = new HashMap<>(); |
| 122 | + heaterProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.HEATER); |
| 123 | + String heaterId = heater.getSystemId(); |
| 124 | + if (heaterId != null) { |
| 125 | + heaterProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, heaterId); |
| 126 | + } |
| 127 | + String type = heater.getType(); |
| 128 | + if (type != null) { |
| 129 | + heaterProps.put(HaywardBindingConstants.PROPERTY_HEATER_TYPE, type); |
121 | 130 | } |
| 131 | + onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_HEATER, |
| 132 | + heaterId != null ? heaterId : "Heater", heaterProps); |
| 133 | + } |
122 | 134 |
|
123 | | - for (HeaterConfig heater : backyard.getHeaters()) { |
124 | | - Map<String, Object> heaterProps = new HashMap<>(); |
125 | | - heaterProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.HEATER); |
126 | | - String heaterId = heater.getSystemId(); |
127 | | - if (heaterId != null) { |
128 | | - heaterProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, heaterId); |
129 | | - } |
130 | | - String type = heater.getType(); |
131 | | - if (type != null) { |
132 | | - heaterProps.put(HaywardBindingConstants.PROPERTY_HEATER_TYPE, type); |
133 | | - } |
134 | | - onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_HEATER, |
135 | | - heaterId != null ? heaterId : "Heater", heaterProps); |
| 135 | + for (ChlorinatorConfig chlorinator : backyard.getChlorinators()) { |
| 136 | + Map<String, Object> chlorProps = new HashMap<>(); |
| 137 | + chlorProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.CHLORINATOR); |
| 138 | + String id = chlorinator.getSystemId(); |
| 139 | + if (id != null) { |
| 140 | + chlorProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id); |
136 | 141 | } |
| 142 | + onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_CHLORINATOR, id != null ? id : "Chlorinator", |
| 143 | + chlorProps); |
| 144 | + } |
137 | 145 |
|
138 | | - for (ChlorinatorConfig chlorinator : backyard.getChlorinators()) { |
139 | | - Map<String, Object> chlorProps = new HashMap<>(); |
140 | | - chlorProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.CHLORINATOR); |
141 | | - String id = chlorinator.getSystemId(); |
142 | | - if (id != null) { |
143 | | - chlorProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id); |
144 | | - } |
145 | | - onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_CHLORINATOR, id != null ? id : "Chlorinator", |
146 | | - chlorProps); |
| 146 | + for (ColorLogicLightConfig light : backyard.getColorLogicLights()) { |
| 147 | + Map<String, Object> lightProps = new HashMap<>(); |
| 148 | + lightProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.COLORLOGIC); |
| 149 | + String id = light.getSystemId(); |
| 150 | + if (id != null) { |
| 151 | + lightProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id); |
147 | 152 | } |
| 153 | + onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_COLORLOGIC, id != null ? id : "ColorLogic", |
| 154 | + lightProps); |
| 155 | + } |
148 | 156 |
|
149 | | - for (ColorLogicLightConfig light : backyard.getColorLogicLights()) { |
150 | | - Map<String, Object> lightProps = new HashMap<>(); |
151 | | - lightProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.COLORLOGIC); |
152 | | - String id = light.getSystemId(); |
| 157 | + for (RelayConfig relay : backyard.getRelays()) { |
| 158 | + String id = relay.getSystemId(); |
| 159 | + String relayType = relay.getType(); |
| 160 | + if ("RLY_VALVE_ACTUATOR".equals(relayType)) { |
| 161 | + Map<String, Object> valveProps = new HashMap<>(); |
| 162 | + valveProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.VALVEACTUATOR); |
153 | 163 | if (id != null) { |
154 | | - lightProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id); |
| 164 | + valveProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id); |
155 | 165 | } |
156 | | - onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_COLORLOGIC, id != null ? id : "ColorLogic", |
157 | | - lightProps); |
158 | | - } |
159 | | - |
160 | | - for (RelayConfig relay : backyard.getRelays()) { |
161 | | - String id = relay.getSystemId(); |
162 | | - String relayType = relay.getType(); |
163 | | - if ("RLY_VALVE_ACTUATOR".equals(relayType)) { |
164 | | - Map<String, Object> valveProps = new HashMap<>(); |
165 | | - valveProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.VALVEACTUATOR); |
166 | | - if (id != null) { |
167 | | - valveProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id); |
168 | | - } |
169 | | - if (relayType != null) { |
170 | | - valveProps.put(HaywardBindingConstants.PROPERTY_RELAY_TYPE, relayType); |
171 | | - } |
172 | | - String function = relay.getFunction(); |
173 | | - if (function != null) { |
174 | | - valveProps.put(HaywardBindingConstants.PROPERTY_RELAY_FUNCTION, function); |
175 | | - } |
176 | | - String name = relay.getName(); |
177 | | - if (name == null) { |
178 | | - name = id != null ? id : "ValveActuator"; |
179 | | - } |
180 | | - onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_VALVEACTUATOR, name, valveProps); |
181 | | - continue; |
| 166 | + if (relayType != null) { |
| 167 | + valveProps.put(HaywardBindingConstants.PROPERTY_RELAY_TYPE, relayType); |
182 | 168 | } |
183 | | - |
184 | | - Map<String, Object> relayProps = new HashMap<>(); |
185 | | - relayProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.RELAY); |
186 | | - if (id != null) { |
187 | | - relayProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id); |
| 169 | + String function = relay.getFunction(); |
| 170 | + if (function != null) { |
| 171 | + valveProps.put(HaywardBindingConstants.PROPERTY_RELAY_FUNCTION, function); |
188 | 172 | } |
189 | 173 | String name = relay.getName(); |
190 | 174 | if (name == null) { |
191 | | - name = id != null ? id : "Relay"; |
| 175 | + name = id != null ? id : "ValveActuator"; |
192 | 176 | } |
193 | | - onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_RELAY, name, relayProps); |
| 177 | + onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_VALVEACTUATOR, name, valveProps); |
| 178 | + continue; |
194 | 179 | } |
195 | 180 |
|
196 | | - for (VirtualHeaterConfig vh : backyard.getVirtualHeaters()) { |
197 | | - Map<String, Object> vhProps = new HashMap<>(); |
198 | | - vhProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.VIRTUALHEATER); |
199 | | - String id = vh.getSystemId(); |
200 | | - if (id != null) { |
201 | | - vhProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id); |
202 | | - } |
203 | | - onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_VIRTUALHEATER, |
204 | | - id != null ? id : "VirtualHeater", vhProps); |
| 181 | + Map<String, Object> relayProps = new HashMap<>(); |
| 182 | + relayProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.RELAY); |
| 183 | + if (id != null) { |
| 184 | + relayProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id); |
| 185 | + } |
| 186 | + String name = relay.getName(); |
| 187 | + if (name == null) { |
| 188 | + name = id != null ? id : "Relay"; |
| 189 | + } |
| 190 | + onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_RELAY, name, relayProps); |
| 191 | + } |
| 192 | + |
| 193 | + for (VirtualHeaterConfig vh : backyard.getVirtualHeaters()) { |
| 194 | + Map<String, Object> vhProps = new HashMap<>(); |
| 195 | + vhProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.VIRTUALHEATER); |
| 196 | + String id = vh.getSystemId(); |
| 197 | + if (id != null) { |
| 198 | + vhProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id); |
205 | 199 | } |
| 200 | + onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_VIRTUALHEATER, |
| 201 | + id != null ? id : "VirtualHeater", vhProps); |
206 | 202 | } |
207 | 203 | } |
208 | 204 | } |
|
0 commit comments