GitHub PullRequestReviewCommentEvent at 2014-04-17 19:50:56
Repository: openhab
Actor: kgoderis
Payload: {"comment":{"url":"https://api.github.com/repos/openhab/openhab/pulls/comments/11750657","id":11750657,"diff_hunk":"@@ -0,0 +1,533 @@\n+/**\n+ * Copyright (c) 2010-2014, openHAB.org and others.\n+ *\n+ * All rights reserved. This program and the accompanying materials\n+ * are made available under the terms of the Eclipse Public License v1.0\n+ * which accompanies this distribution, and is available at\n+ * http://www.eclipse.org/legal/epl-v10.html\n+ */\n+package org.openhab.binding.oceanic.internal;\n+\n+import static org.quartz.JobBuilder.newJob;\n+import static org.quartz.SimpleScheduleBuilder.simpleSchedule;\n+import static org.quartz.TriggerBuilder.newTrigger;\n+import static org.quartz.impl.matchers.GroupMatcher.jobGroupEquals;\n+import gnu.io.CommPortIdentifier;\n+import gnu.io.PortInUseException;\n+import gnu.io.SerialPort;\n+import gnu.io.SerialPortEvent;\n+import gnu.io.SerialPortEventListener;\n+import gnu.io.UnsupportedCommOperationException;\n+import java.io.BufferedReader;\n+import java.io.IOException;\n+import java.io.InputStream;\n+import java.io.InputStreamReader;\n+import java.io.OutputStream;\n+import java.util.ArrayList;\n+import java.util.Dictionary;\n+import java.util.Enumeration;\n+import java.util.HashMap;\n+import java.util.HashSet;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.Set;\n+import java.util.TooManyListenersException;\n+import org.apache.commons.io.IOUtils;\n+import org.apache.commons.lang.StringUtils;\n+import org.openhab.binding.oceanic.OceanicBindingProvider;\n+import org.openhab.binding.oceanic.OceanicValueSelector;\n+import org.openhab.binding.oceanic.OceanicValueSelector.ValueSelectorType;\n+import org.openhab.core.binding.AbstractActiveBinding;\n+import org.openhab.core.events.EventPublisher;\n+import org.openhab.core.types.Command;\n+import org.openhab.core.types.State;\n+import org.openhab.core.types.Type;\n+import org.openhab.core.types.TypeParser;\n+import org.openhab.model.item.binding.BindingConfigParseException;\n+import org.osgi.service.cm.ConfigurationException;\n+import org.osgi.service.cm.ManagedService;\n+import org.quartz.Job;\n+import org.quartz.JobDataMap;\n+import org.quartz.JobDetail;\n+import org.quartz.JobExecutionContext;\n+import org.quartz.JobExecutionException;\n+import org.quartz.JobKey;\n+import org.quartz.Scheduler;\n+import org.quartz.SchedulerException;\n+import org.quartz.Trigger;\n+import org.quartz.impl.StdSchedulerFactory;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+/**\n+ * \n+ * Binding to support the Oceanic Watersoftener. \n+ * \n+ * @author Karel Goderis\n+ * @since 1.5.0\n+ * \n+ */\n+public class OceanicBinding extends AbstractActiveBinding<OceanicBindingProvider>\n+implements ManagedService {\n+\n+\tprivate static final Logger logger = LoggerFactory.getLogger(OceanicBinding.class);\n+\n+\t/** stores information about serial devices / pump gateways in use  */ \n+\tprivate Map<String, SerialDevice> serialDevices = new HashMap<String, SerialDevice>();\n+\n+\t/** stores information about the context of items. The map has this content structure: context -> Set of itemNames */ \n+\tprivate Map<String, Set<String>> contextMap = new HashMap<String, Set<String>>();\n+\n+\t/** the refresh interval which is used to check for changes in the binding configurations */\n+\tprivate static long refreshInterval = 5000;\n+\n+\tpublic void setEventPublisher(EventPublisher eventPublisher) {\n+\t\tthis.eventPublisher = eventPublisher;\n+\n+\t\tfor(SerialDevice serialDevice : serialDevices.values()) {\n+\t\t\tserialDevice.setEventPublisher(eventPublisher);\n+\t\t}\n+\t}\n+\n+\tpublic void unsetEventPublisher(EventPublisher eventPublisher) {\n+\t\tthis.eventPublisher = null;\n+\n+\t\tfor(SerialDevice serialDevice : serialDevices.values()) {\n+\t\t\tserialDevice.setEventPublisher(null);\n+\t\t}\n+\t}\n+\n+\tpublic void activate() {\n+\t\t// Nothing to do here. \n+\t}\n+\n+\t@Override\n+\tprotected void internalReceiveCommand(String itemName, Command command) {\n+\n+\t\tOceanicBindingProvider provider = findFirstMatchingBindingProvider(itemName);\n+\t\tString serialPort = ((OceanicBindingProvider)provider).getSerialPort(itemName);\n+\t\tOceanicValueSelector valueSelector = OceanicValueSelector.getValueSelector(((OceanicBindingProvider)provider).getValueSelector(itemName),ValueSelectorType.SET);\n+\t\tSerialDevice serialDevice = serialDevices.get(serialPort);\n+\n+\t\tif(valueSelector.name().contains(\"set\")) {\n+\t\t\tString commandAsString = command.toString();\n+\t\t\tswitch(valueSelector) {\n+\t\t\tcase setSV1:\n+\t\t\t\tcommandAsString = valueSelector.name()+commandAsString;\n+\t\t\tdefault:\n+\t\t\t\tcommandAsString = valueSelector.name();\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tString response = serialDevice.requestResponse(commandAsString);\n+\t\t\tif(response.equals(\"ERR\")) {\n+\t\t\t\tlogger.error(\"An error occurred while setting '{}' to {}\",valueSelector.toString(),command.toString());\n+\t\t\t}\n+\t\t} else {\n+\t\t\t// can not set the value of a read-only \"get\" variable\n+\t\t\tlogger.warn(\"An error occurred while trying to set the read-only variable '{}' to {}\",valueSelector.toString(),command.toString());\n+\t\t}\t\n+\t}\n+\n+\n+\n+\t@SuppressWarnings(\"rawtypes\")\n+\tpublic void updated(Dictionary config) throws ConfigurationException {\n+\t\tsetProperlyConfigured(true);\n+\t}\n+\n+\t@Override\n+\tprotected void execute() {\n+\t\tif(isProperlyConfigured()) {\n+\n+\t\t\tScheduler sched = null;\n+\t\t\ttry {\n+\t\t\t\tsched =  StdSchedulerFactory.getDefaultScheduler();\n+\t\t\t} catch (SchedulerException e) {\n+\t\t\t\tlogger.error(\"An exception occurred while getting a reference to the Quartz Scheduler\");\n+\t\t\t}\n+\n+\t\t\t//reset the contextMap before rebuilding it\n+\t\t\tfor(String serialPort : serialDevices.keySet()) {\n+\t\t\t\tSet<String> itemNames = contextMap.get(serialPort);\n+\t\t\t\tif(itemNames != null ) {\n+\t\t\t\t\tcontextMap.clear();\t\t\t\t\t\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tfor(OceanicBindingProvider provider : providers) {","path":"bundles/binding/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/OceanicBinding.java","position":157,"original_position":157,"commit_id":"25b7f2c688e2698e82abe3d8c68e4b5437700d2c","original_commit_id":"d70212bb7f99fa98df8847182ce8300b513786e8","user":{"login":"kgoderis","id":5459062,"avatar_url":"https://avatars.githubusercontent.com/u/5459062?","gravatar_id":"b524726d30e253e6f3d1b3e83a6713b9","url":"https://api.github.com/users/kgoderis","html_url":"https://github.com/kgoderis","followers_url":"https://api.github.com/users/kgoderis/followers","following_url":"https://api.github.com/users/kgoderis/following{/other_user}","gists_url":"https://api.github.com/users/kgoderis/gists{/gist_id}","starred_url":"https://api.github.com/users/kgoderis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kgoderis/subscriptions","organizations_url":"https://api.github.com/users/kgoderis/orgs","repos_url":"https://api.github.com/users/kgoderis/repos","events_url":"https://api.github.com/users/kgoderis/events{/privacy}","received_events_url":"https://api.github.com/users/kgoderis/received_events","type":"User","site_admin":false},"body":"I was referring to the \"base\" binding approach in OH 2.0, e.g. the equivalent AbstractActiveBinding etc...","created_at":"2014-04-17T19:50:56Z","updated_at":"2014-04-17T19:50:56Z","html_url":"https://github.com/openhab/openhab/pull/946#discussion_r11750657","pull_request_url":"https://api.github.com/repos/openhab/openhab/pulls/946","_links":{"self":{"href":"https://api.github.com/repos/openhab/openhab/pulls/comments/11750657"},"html":{"href":"https://github.com/openhab/openhab/pull/946#discussion_r11750657"},"pull_request":{"href":"https://api.github.com/repos/openhab/openhab/pulls/946"}}}}