This repository has been archived by the owner on May 17, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[satel] Support for troubles added #5162
Merged
+811
−440
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 63 additions & 63 deletions
126
...nding.satel/src/main/java/org/openhab/binding/satel/config/SatelBindingConfigFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,63 @@ | ||
/** | ||
* Copyright (c) 2010-2016 by the respective copyright holders. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.openhab.binding.satel.config; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import org.openhab.binding.satel.SatelBindingConfig; | ||
import org.openhab.model.item.binding.BindingConfigParseException; | ||
|
||
/** | ||
* Creates proper binding configuration class for given configuration string. | ||
* | ||
* @author Krzysztof Goworek | ||
* @since 1.8.0 | ||
*/ | ||
public class SatelBindingConfigFactory { | ||
|
||
private final List<Class<? extends SatelBindingConfig>> bindingConfigurationClasses = new LinkedList<Class<? extends SatelBindingConfig>>(); | ||
|
||
/** | ||
* Constructs factory object. Adds all known types of configuration classes | ||
* to internal registry. | ||
*/ | ||
public SatelBindingConfigFactory() { | ||
bindingConfigurationClasses.add(IntegraStateBindingConfig.class); | ||
bindingConfigurationClasses.add(IntegraStatusBindingConfig.class); | ||
bindingConfigurationClasses.add(ConnectionStatusBindingConfig.class); | ||
} | ||
|
||
/** | ||
* Creates binding configuration class basing on given configuration string. | ||
* | ||
* @param bindingConfig | ||
* configuration string | ||
* @return an instance of {@link SatelBindingConfig} | ||
* @throws BindingConfigParseException | ||
* on any parsing error | ||
*/ | ||
public SatelBindingConfig createBindingConfig(String bindingConfig) throws BindingConfigParseException { | ||
try { | ||
for (Class<? extends SatelBindingConfig> c : bindingConfigurationClasses) { | ||
Method parseConfigMethod = c.getMethod("parseConfig", String.class); | ||
SatelBindingConfig bc = (SatelBindingConfig) parseConfigMethod.invoke(null, bindingConfig); | ||
if (bc != null) { | ||
return bc; | ||
} | ||
} | ||
// no more options, throw parse exception | ||
} catch (Exception e) { | ||
// throw parse exception in case of any error | ||
} | ||
|
||
throw new BindingConfigParseException(String.format("Invalid binding configuration: %s", bindingConfig)); | ||
} | ||
} | ||
/** | ||
* Copyright (c) 2010-2016 by the respective copyright holders. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.openhab.binding.satel.config; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import org.openhab.binding.satel.SatelBindingConfig; | ||
import org.openhab.model.item.binding.BindingConfigParseException; | ||
|
||
/** | ||
* Creates proper binding configuration class for given configuration string. | ||
* | ||
* @author Krzysztof Goworek | ||
* @since 1.8.0 | ||
*/ | ||
public class SatelBindingConfigFactory { | ||
|
||
private final List<Class<? extends SatelBindingConfig>> bindingConfigurationClasses = new LinkedList<Class<? extends SatelBindingConfig>>(); | ||
|
||
/** | ||
* Constructs factory object. Adds all known types of configuration classes | ||
* to internal registry. | ||
*/ | ||
public SatelBindingConfigFactory() { | ||
bindingConfigurationClasses.add(IntegraStateBindingConfig.class); | ||
bindingConfigurationClasses.add(IntegraStatusBindingConfig.class); | ||
bindingConfigurationClasses.add(ConnectionStatusBindingConfig.class); | ||
} | ||
|
||
/** | ||
* Creates binding configuration class basing on given configuration string. | ||
* | ||
* @param bindingConfig | ||
* configuration string | ||
* @return an instance of {@link SatelBindingConfig} | ||
* @throws BindingConfigParseException | ||
* on any parsing error | ||
*/ | ||
public SatelBindingConfig createBindingConfig(String bindingConfig) throws BindingConfigParseException { | ||
try { | ||
for (Class<? extends SatelBindingConfig> c : bindingConfigurationClasses) { | ||
Method parseConfigMethod = c.getMethod("parseConfig", String.class); | ||
SatelBindingConfig bc = (SatelBindingConfig) parseConfigMethod.invoke(null, bindingConfig); | ||
if (bc != null) { | ||
return bc; | ||
} | ||
} | ||
// no more options, throw parse exception | ||
} catch (Exception e) { | ||
// throw parse exception in case of any error | ||
} | ||
|
||
throw new BindingConfigParseException(String.format("Invalid binding configuration: %s", bindingConfig)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a warn instead of an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The level hasn't changed in this PR, it was always an error. But I can change it, if you wish.