]> git.basschouten.com Git - openhab-addons.git/blob
72068c9d0c660dbd39c3e0f16514ce7cf94480a5
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.miio.internal.handler;
14
15 import static org.openhab.binding.miio.internal.MiIoBindingConstants.CHANNEL_COMMAND;
16
17 import java.awt.Color;
18 import java.io.IOException;
19 import java.net.URL;
20 import java.util.ArrayList;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.concurrent.TimeUnit;
25
26 import org.eclipse.jdt.annotation.NonNullByDefault;
27 import org.eclipse.jdt.annotation.Nullable;
28 import org.openhab.binding.miio.internal.MiIoBindingConfiguration;
29 import org.openhab.binding.miio.internal.MiIoCommand;
30 import org.openhab.binding.miio.internal.MiIoCryptoException;
31 import org.openhab.binding.miio.internal.MiIoSendCommand;
32 import org.openhab.binding.miio.internal.Utils;
33 import org.openhab.binding.miio.internal.basic.ActionConditions;
34 import org.openhab.binding.miio.internal.basic.CommandParameterType;
35 import org.openhab.binding.miio.internal.basic.Conversions;
36 import org.openhab.binding.miio.internal.basic.MiIoBasicChannel;
37 import org.openhab.binding.miio.internal.basic.MiIoBasicDevice;
38 import org.openhab.binding.miio.internal.basic.MiIoDatabaseWatchService;
39 import org.openhab.binding.miio.internal.basic.MiIoDeviceAction;
40 import org.openhab.binding.miio.internal.basic.MiIoDeviceActionCondition;
41 import org.openhab.binding.miio.internal.transport.MiIoAsyncCommunication;
42 import org.openhab.core.cache.ExpiringCache;
43 import org.openhab.core.library.types.DecimalType;
44 import org.openhab.core.library.types.HSBType;
45 import org.openhab.core.library.types.OnOffType;
46 import org.openhab.core.library.types.PercentType;
47 import org.openhab.core.library.types.StringType;
48 import org.openhab.core.thing.Channel;
49 import org.openhab.core.thing.ChannelUID;
50 import org.openhab.core.thing.Thing;
51 import org.openhab.core.thing.binding.builder.ChannelBuilder;
52 import org.openhab.core.thing.binding.builder.ThingBuilder;
53 import org.openhab.core.thing.type.ChannelTypeRegistry;
54 import org.openhab.core.thing.type.ChannelTypeUID;
55 import org.openhab.core.types.Command;
56 import org.openhab.core.types.RefreshType;
57 import org.slf4j.Logger;
58 import org.slf4j.LoggerFactory;
59
60 import com.google.gson.Gson;
61 import com.google.gson.GsonBuilder;
62 import com.google.gson.JsonArray;
63 import com.google.gson.JsonElement;
64 import com.google.gson.JsonIOException;
65 import com.google.gson.JsonObject;
66 import com.google.gson.JsonPrimitive;
67 import com.google.gson.JsonSyntaxException;
68
69 /**
70  * The {@link MiIoBasicHandler} is responsible for handling commands, which are
71  * sent to one of the channels.
72  *
73  * @author Marcel Verpaalen - Initial contribution
74  */
75 @NonNullByDefault
76 public class MiIoBasicHandler extends MiIoAbstractHandler {
77     private final Logger logger = LoggerFactory.getLogger(MiIoBasicHandler.class);
78     private boolean hasChannelStructure;
79
80     private final ExpiringCache<Boolean> updateDataCache = new ExpiringCache<>(CACHE_EXPIRY, () -> {
81         scheduler.schedule(this::updateData, 0, TimeUnit.SECONDS);
82         return true;
83     });
84
85     List<MiIoBasicChannel> refreshList = new ArrayList<>();
86     private Map<String, MiIoBasicChannel> refreshListCustomCommands = new HashMap<>();
87
88     private @Nullable MiIoBasicDevice miioDevice;
89     private Map<ChannelUID, MiIoBasicChannel> actions = new HashMap<>();
90     private ChannelTypeRegistry channelTypeRegistry;
91
92     public MiIoBasicHandler(Thing thing, MiIoDatabaseWatchService miIoDatabaseWatchService,
93             ChannelTypeRegistry channelTypeRegistry) {
94         super(thing, miIoDatabaseWatchService);
95         this.channelTypeRegistry = channelTypeRegistry;
96     }
97
98     @Override
99     public void initialize() {
100         super.initialize();
101         hasChannelStructure = false;
102         isIdentified = false;
103         refreshList = new ArrayList<>();
104         refreshListCustomCommands = new HashMap<>();
105     }
106
107     @Override
108     public void handleCommand(ChannelUID channelUID, Command command) {
109         if (command == RefreshType.REFRESH) {
110             if (updateDataCache.isExpired()) {
111                 logger.debug("Refreshing {}", channelUID);
112                 updateDataCache.getValue();
113             } else {
114                 logger.debug("Refresh {} skipped. Already refreshing", channelUID);
115             }
116             return;
117         }
118         if (channelUID.getId().equals(CHANNEL_COMMAND)) {
119             cmds.put(sendCommand(command.toString()), command.toString());
120             return;
121         }
122         logger.debug("Locating action for channel '{}': '{}'", channelUID.getId(), command);
123         if (!actions.isEmpty()) {
124             if (actions.containsKey(channelUID)) {
125                 int valuePos = 0;
126                 MiIoBasicChannel miIoBasicChannel = actions.get(channelUID);
127                 for (MiIoDeviceAction action : miIoBasicChannel.getActions()) {
128                     @Nullable
129                     JsonElement value = null;
130                     JsonArray parameters = action.getParameters().deepCopy();
131                     for (int i = 0; i < action.getParameters().size(); i++) {
132                         JsonElement p = action.getParameters().get(i);
133                         if (p.isJsonPrimitive() && p.getAsString().toLowerCase().contains("$value$")) {
134                             valuePos = i;
135                             break;
136                         }
137                     }
138                     String cmd = action.getCommand();
139                     CommandParameterType paramType = action.getparameterType();
140                     if (paramType == CommandParameterType.COLOR) {
141                         if (command instanceof HSBType) {
142                             HSBType hsb = (HSBType) command;
143                             Color color = Color.getHSBColor(hsb.getHue().floatValue() / 360,
144                                     hsb.getSaturation().floatValue() / 100, hsb.getBrightness().floatValue() / 100);
145                             value = new JsonPrimitive(
146                                     (color.getRed() << 16) + (color.getGreen() << 8) + color.getBlue());
147                         } else if (command instanceof DecimalType) {
148                             // actually brightness is being set instead of a color
149                             value = new JsonPrimitive(((DecimalType) command).toBigDecimal());
150                         } else if (command instanceof OnOffType) {
151                             value = new JsonPrimitive(command == OnOffType.ON ? 100 : 0);
152                         } else {
153                             logger.debug("Unsupported command for COLOR: {}", command);
154                         }
155                     } else if (command instanceof OnOffType) {
156                         if (paramType == CommandParameterType.ONOFF) {
157                             value = new JsonPrimitive(command == OnOffType.ON ? "on" : "off");
158                         } else if (paramType == CommandParameterType.ONOFFPARA) {
159                             cmd = cmd.replace("*", command == OnOffType.ON ? "on" : "off");
160                             value = new JsonArray();
161                         } else if (paramType == CommandParameterType.ONOFFBOOL) {
162                             boolean boolCommand = command == OnOffType.ON;
163                             value = new JsonPrimitive(boolCommand);
164                         } else if (paramType == CommandParameterType.ONOFFBOOLSTRING) {
165                             value = new JsonPrimitive(command == OnOffType.ON ? "true" : "false");
166                         }
167                     } else if (command instanceof DecimalType) {
168                         value = new JsonPrimitive(((DecimalType) command).toBigDecimal());
169                     } else if (command instanceof StringType) {
170                         if (paramType == CommandParameterType.STRING) {
171                             value = new JsonPrimitive(command.toString().toLowerCase());
172                         } else if (paramType == CommandParameterType.CUSTOMSTRING) {
173                             value = new JsonPrimitive(parameters.get(valuePos).getAsString().replace("$value",
174                                     command.toString().toLowerCase()));
175                         }
176                     } else {
177                         value = new JsonPrimitive(command.toString().toLowerCase());
178                     }
179                     if (paramType == CommandParameterType.EMPTY) {
180                         value = new JsonArray();
181                     }
182                     final MiIoDeviceActionCondition miIoDeviceActionCondition = action.getCondition();
183                     if (miIoDeviceActionCondition != null) {
184                         value = ActionConditions.executeAction(miIoDeviceActionCondition, deviceVariables, value,
185                                 command);
186                     }
187                     // Check for miot channel
188                     if (value != null) {
189                         if (action.isMiOtAction()) {
190                             value = miotActionTransform(action, miIoBasicChannel, value);
191                         } else if (miIoBasicChannel.isMiOt()) {
192                             value = miotTransform(miIoBasicChannel, value);
193                         }
194                     }
195                     if (paramType != CommandParameterType.NONE && paramType != CommandParameterType.ONOFFPARA
196                             && value != null) {
197                         if (parameters.size() > 0) {
198                             parameters.set(valuePos, value);
199                         } else {
200                             parameters.add(value);
201                         }
202                     }
203                     cmd = cmd + parameters.toString();
204                     if (value != null) {
205                         logger.debug("Sending command {}", cmd);
206                         sendCommand(cmd);
207                     } else {
208                         if (miIoDeviceActionCondition != null) {
209                             logger.debug("Conditional command {} not send, condition '{}' not met", cmd,
210                                     miIoDeviceActionCondition.getName());
211                         } else {
212                             logger.debug("Command not send. Value null");
213                         }
214                     }
215                 }
216             } else {
217                 logger.debug("Channel Id {} not in mapping.", channelUID.getId());
218                 if (logger.isTraceEnabled()) {
219                     for (ChannelUID a : actions.keySet()) {
220                         logger.trace("Available entries: {} : {}", a, actions.get(a).getFriendlyName());
221                     }
222                 }
223             }
224             updateDataCache.invalidateValue();
225             updateData();
226         } else {
227             logger.debug("Actions not loaded yet");
228         }
229     }
230
231     private @Nullable JsonElement miotTransform(MiIoBasicChannel miIoBasicChannel, @Nullable JsonElement value) {
232         JsonObject json = new JsonObject();
233         json.addProperty("did", miIoBasicChannel.getChannel());
234         json.addProperty("siid", miIoBasicChannel.getSiid());
235         json.addProperty("piid", miIoBasicChannel.getPiid());
236         json.add("value", value);
237         return json;
238     }
239
240     private @Nullable JsonElement miotActionTransform(MiIoDeviceAction action, MiIoBasicChannel miIoBasicChannel,
241             @Nullable JsonElement value) {
242         JsonObject json = new JsonObject();
243         json.addProperty("did", miIoBasicChannel.getChannel());
244         json.addProperty("siid", action.getSiid());
245         json.addProperty("aiid", action.getAiid());
246         if (value != null) {
247             json.add("in", value);
248         }
249         return json;
250     }
251
252     @Override
253     protected synchronized void updateData() {
254         logger.debug("Periodic update for '{}' ({})", getThing().getUID().toString(), getThing().getThingTypeUID());
255         final MiIoAsyncCommunication miioCom = getConnection();
256         try {
257             if (!hasConnection() || skipUpdate() || miioCom == null) {
258                 return;
259             }
260             checkChannelStructure();
261             if (!isIdentified) {
262                 miioCom.queueCommand(MiIoCommand.MIIO_INFO);
263             }
264             final MiIoBasicDevice midevice = miioDevice;
265             if (midevice != null) {
266                 refreshProperties(midevice);
267                 refreshCustomProperties(midevice);
268                 refreshNetwork();
269             }
270         } catch (Exception e) {
271             logger.debug("Error while updating '{}': ", getThing().getUID().toString(), e);
272         }
273     }
274
275     private void refreshCustomProperties(MiIoBasicDevice midevice) {
276         for (MiIoBasicChannel miChannel : refreshListCustomCommands.values()) {
277             sendCommand(miChannel.getChannelCustomRefreshCommand());
278         }
279     }
280
281     private boolean refreshProperties(MiIoBasicDevice device) {
282         MiIoCommand command = MiIoCommand.getCommand(device.getDevice().getPropertyMethod());
283         int maxProperties = device.getDevice().getMaxProperties();
284         JsonArray getPropString = new JsonArray();
285         for (MiIoBasicChannel miChannel : refreshList) {
286             JsonElement property;
287             if (miChannel.isMiOt()) {
288                 JsonObject json = new JsonObject();
289                 json.addProperty("did", miChannel.getProperty());
290                 json.addProperty("siid", miChannel.getSiid());
291                 json.addProperty("piid", miChannel.getPiid());
292                 property = json;
293             } else {
294                 property = new JsonPrimitive(miChannel.getProperty());
295             }
296             getPropString.add(property);
297             if (getPropString.size() >= maxProperties) {
298                 sendRefreshProperties(command, getPropString);
299                 getPropString = new JsonArray();
300             }
301         }
302         if (getPropString.size() > 0) {
303             sendRefreshProperties(command, getPropString);
304         }
305         return true;
306     }
307
308     private void sendRefreshProperties(MiIoCommand command, JsonArray getPropString) {
309         try {
310             final MiIoAsyncCommunication miioCom = this.miioCom;
311             if (miioCom != null) {
312                 miioCom.queueCommand(command, getPropString.toString());
313             }
314         } catch (MiIoCryptoException | IOException e) {
315             logger.debug("Send refresh failed {}", e.getMessage(), e);
316         }
317     }
318
319     /**
320      * Checks if the channel structure has been build already based on the model data. If not build it.
321      */
322     private void checkChannelStructure() {
323         final MiIoBindingConfiguration configuration = this.configuration;
324         if (configuration == null) {
325             return;
326         }
327         if (!hasChannelStructure) {
328             if (configuration.model == null || configuration.model.isEmpty()) {
329                 logger.debug("Model needs to be determined");
330                 isIdentified = false;
331             } else {
332                 hasChannelStructure = buildChannelStructure(configuration.model);
333             }
334         }
335         if (hasChannelStructure) {
336             refreshList = new ArrayList<>();
337             final MiIoBasicDevice miioDevice = this.miioDevice;
338             if (miioDevice != null) {
339                 for (MiIoBasicChannel miChannel : miioDevice.getDevice().getChannels()) {
340                     if (miChannel.getRefresh()) {
341                         if (miChannel.getChannelCustomRefreshCommand().isBlank()) {
342                             refreshList.add(miChannel);
343                         } else {
344                             String i = miChannel.getChannelCustomRefreshCommand().split("\\[")[0];
345                             refreshListCustomCommands.put(i.trim(), miChannel);
346                         }
347                     }
348                 }
349             }
350
351         }
352     }
353
354     private boolean buildChannelStructure(String deviceName) {
355         logger.debug("Building Channel Structure for {} - Model: {}", getThing().getUID().toString(), deviceName);
356         URL fn = miIoDatabaseWatchService.getDatabaseUrl(deviceName);
357         if (fn == null) {
358             logger.warn("Database entry for model '{}' cannot be found.", deviceName);
359             return false;
360         }
361         try {
362             JsonObject deviceMapping = Utils.convertFileToJSON(fn);
363             logger.debug("Using device database: {} for device {}", fn.getFile(), deviceName);
364             Gson gson = new GsonBuilder().serializeNulls().create();
365             miioDevice = gson.fromJson(deviceMapping, MiIoBasicDevice.class);
366             for (Channel ch : getThing().getChannels()) {
367                 logger.debug("Current thing channels {}, type: {}", ch.getUID(), ch.getChannelTypeUID());
368             }
369             ThingBuilder thingBuilder = editThing();
370             int channelsAdded = 0;
371
372             // make a map of the actions
373             actions = new HashMap<>();
374             final MiIoBasicDevice device = this.miioDevice;
375             if (device != null) {
376                 for (MiIoBasicChannel miChannel : device.getDevice().getChannels()) {
377                     logger.debug("properties {}", miChannel);
378                     if (!miChannel.getType().isEmpty()) {
379                         ChannelUID channelUID = addChannel(thingBuilder, miChannel.getChannel(),
380                                 miChannel.getChannelType(), miChannel.getType(), miChannel.getFriendlyName());
381                         if (channelUID != null) {
382                             actions.put(channelUID, miChannel);
383                             channelsAdded++;
384                         } else {
385                             logger.debug("Channel for {} ({}) not loaded", miChannel.getChannel(),
386                                     miChannel.getFriendlyName());
387                         }
388                     } else {
389                         logger.debug("Channel {} ({}), not loaded, missing type", miChannel.getChannel(),
390                                 miChannel.getFriendlyName());
391                     }
392                 }
393             }
394             // only update if channels were added/removed
395             if (channelsAdded > 0) {
396                 logger.debug("Current thing channels added: {}", channelsAdded);
397                 updateThing(thingBuilder.build());
398             }
399             return true;
400         } catch (JsonIOException | JsonSyntaxException e) {
401             logger.warn("Error parsing database Json", e);
402         } catch (IOException e) {
403             logger.warn("Error reading database file", e);
404         } catch (Exception e) {
405             logger.warn("Error creating channel structure", e);
406         }
407         return false;
408     }
409
410     private @Nullable ChannelUID addChannel(ThingBuilder thingBuilder, @Nullable String channel, String channelType,
411             @Nullable String datatype, String friendlyName) {
412         if (channel == null || channel.isEmpty() || datatype == null || datatype.isEmpty()) {
413             logger.info("Channel '{}', UID '{}' cannot be added incorrectly configured database. ", channel,
414                     getThing().getUID());
415             return null;
416         }
417         ChannelUID channelUID = new ChannelUID(getThing().getUID(), channel);
418
419         // TODO: Need to understand if this harms anything. If yes, channel only to be added when not there already.
420         // current way allows to have no issues when channels are changing.
421         if (getThing().getChannel(channel) != null) {
422             logger.info("Channel '{}' for thing {} already exist... removing", channel, getThing().getUID());
423             thingBuilder.withoutChannel(new ChannelUID(getThing().getUID(), channel));
424         }
425         ChannelBuilder newChannel = ChannelBuilder.create(channelUID, datatype).withLabel(friendlyName);
426         if (!channelType.isBlank()) {
427             ChannelTypeUID channelTypeUID = new ChannelTypeUID(channelType);
428             if (channelTypeRegistry.getChannelType(channelTypeUID) != null) {
429                 newChannel = newChannel.withType(channelTypeUID);
430             } else {
431                 logger.debug("ChannelType '{}' is not available. Check the Json file for {}", channelTypeUID,
432                         getThing().getUID());
433             }
434         }
435         thingBuilder.withChannel(newChannel.build());
436         return channelUID;
437     }
438
439     private @Nullable MiIoBasicChannel getChannel(String parameter) {
440         for (MiIoBasicChannel refreshEntry : refreshList) {
441             if (refreshEntry.getProperty().equals(parameter)) {
442                 return refreshEntry;
443             }
444         }
445         logger.trace("Did not find channel for {} in {}", parameter, refreshList);
446         return null;
447     }
448
449     private void updatePropsFromJsonArray(MiIoSendCommand response) {
450         JsonArray res = response.getResult().getAsJsonArray();
451         JsonArray para = parser.parse(response.getCommandString()).getAsJsonObject().get("params").getAsJsonArray();
452         if (res.size() != para.size()) {
453             logger.debug("Unexpected size different. Request size {},  response size {}. (Req: {}, Resp:{})",
454                     para.size(), res.size(), para, res);
455             return;
456         }
457         for (int i = 0; i < para.size(); i++) {
458             // This is a miot parameter
459             String param;
460             final JsonElement paraElement = para.get(i);
461             if (paraElement.isJsonObject()) { // miot channel
462                 param = paraElement.getAsJsonObject().get("did").getAsString();
463             } else {
464                 param = paraElement.getAsString();
465             }
466             JsonElement val = res.get(i);
467             if (val.isJsonNull()) {
468                 logger.debug("Property '{}' returned null (is it supported?).", param);
469                 continue;
470             } else if (val.isJsonObject()) { // miot channel
471                 val = val.getAsJsonObject().get("value");
472             }
473             MiIoBasicChannel basicChannel = getChannel(param);
474             updateChannel(basicChannel, param, val);
475         }
476     }
477
478     private void updatePropsFromJsonObject(MiIoSendCommand response) {
479         JsonObject res = response.getResult().getAsJsonObject();
480         for (Object k : res.keySet()) {
481             String param = (String) k;
482             JsonElement val = res.get(param);
483             if (val.isJsonNull()) {
484                 logger.debug("Property '{}' returned null (is it supported?).", param);
485                 continue;
486             }
487             MiIoBasicChannel basicChannel = getChannel(param);
488             updateChannel(basicChannel, param, val);
489         }
490     }
491
492     private void updateChannel(@Nullable MiIoBasicChannel basicChannel, String param, JsonElement value) {
493         JsonElement val = value;
494         if (basicChannel == null) {
495             logger.debug("Channel not found for {}", param);
496             return;
497         }
498         final String transformation = basicChannel.getTransfortmation();
499         if (transformation != null) {
500             JsonElement transformed = Conversions.execute(transformation, val);
501             logger.debug("Transformed with '{}': {} {} -> {} ", transformation, basicChannel.getFriendlyName(), val,
502                     transformed);
503             val = transformed;
504         }
505         try {
506             switch (basicChannel.getType().toLowerCase()) {
507                 case "number":
508                     updateState(basicChannel.getChannel(), new DecimalType(val.getAsBigDecimal()));
509                     break;
510                 case "dimmer":
511                     updateState(basicChannel.getChannel(), new PercentType(val.getAsBigDecimal()));
512                     break;
513                 case "string":
514                     updateState(basicChannel.getChannel(), new StringType(val.getAsString()));
515                     break;
516                 case "switch":
517                     updateState(basicChannel.getChannel(), val.getAsString().toLowerCase().equals("on")
518                             || val.getAsString().toLowerCase().equals("true") ? OnOffType.ON : OnOffType.OFF);
519                     break;
520                 case "color":
521                     Color rgb = new Color(val.getAsInt());
522                     HSBType hsb = HSBType.fromRGB(rgb.getRed(), rgb.getGreen(), rgb.getBlue());
523                     updateState(basicChannel.getChannel(), hsb);
524                     break;
525                 default:
526                     logger.debug("No update logic for channeltype '{}' ", basicChannel.getType());
527             }
528         } catch (Exception e) {
529             logger.debug("Error updating {} property {} with '{}' : {}: {}", getThing().getUID(),
530                     basicChannel.getChannel(), val, e.getClass().getCanonicalName(), e.getMessage());
531             logger.trace("Property update error detail:", e);
532         }
533     }
534
535     @Override
536     public void onMessageReceived(MiIoSendCommand response) {
537         super.onMessageReceived(response);
538         if (response.isError()) {
539             return;
540         }
541         try {
542             switch (response.getCommand()) {
543                 case MIIO_INFO:
544                     break;
545                 case GET_VALUE:
546                 case GET_PROPERTIES:
547                 case GET_PROPERTY:
548                     if (response.getResult().isJsonArray()) {
549                         updatePropsFromJsonArray(response);
550                     } else if (response.getResult().isJsonObject()) {
551                         updatePropsFromJsonObject(response);
552                     }
553                     break;
554                 default:
555                     if (refreshListCustomCommands.containsKey(response.getMethod())) {
556                         logger.debug("Processing custom refresh command response for !{}", response.getMethod());
557                         MiIoBasicChannel ch = refreshListCustomCommands.get(response.getMethod());
558                         if (response.getResult().isJsonArray()) {
559                             JsonArray cmdResponse = response.getResult().getAsJsonArray();
560                             final String transformation = ch.getTransfortmation();
561                             if (transformation == null || transformation.isBlank()) {
562                                 updateChannel(ch, ch.getChannel(),
563                                         cmdResponse.get(0).isJsonPrimitive() ? cmdResponse.get(0)
564                                                 : new JsonPrimitive(cmdResponse.get(0).toString()));
565                             } else {
566                                 updateChannel(ch, ch.getChannel(), cmdResponse);
567                             }
568                         } else {
569                             updateChannel(ch, ch.getChannel(), new JsonPrimitive(response.getResult().toString()));
570                         }
571                     }
572                     break;
573             }
574         } catch (Exception e) {
575             logger.debug("Error while handing message {}", response.getResponse(), e);
576         }
577     }
578 }