Skip to content

Commit

Permalink
Regex fixes, and better labels for things
Browse files Browse the repository at this point in the history
  • Loading branch information
EricMeeks committed Dec 12, 2018
1 parent 8592ff4 commit 3a42c6a
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<binding:binding id="hdmicec"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:binding="http://eclipse.org/smarthome/schemas/binding/v1.0.0"
xsi:schemaLocation="http://eclipse.org/smarthome/schemas/binding/v1.0.0 http://eclipse.org/smarthome/schemas/binding-1.0.0.xsd">
<binding:binding id="hdmicec" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:binding="http://eclipse.org/smarthome/schemas/binding/v1.0.0"
xsi:schemaLocation="http://eclipse.org/smarthome/schemas/binding/v1.0.0 http://eclipse.org/smarthome/schemas/binding-1.0.0.xsd">

<name>HdmiCec Binding</name>
<description>Binding for cec-client.</description>
<author>David Masshardt</author>
<name>HdmiCec Binding</name>
<description>Binding for cec-client.</description>
<author>David Masshardt</author>

</binding:binding>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<thing:thing-descriptions bindingId="hdmicec"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:thing="http://eclipse.org/smarthome/schemas/thing-description/v1.0.0"
xsi:schemaLocation="http://eclipse.org/smarthome/schemas/thing-description/v1.0.0 http://eclipse.org/smarthome/schemas/thing-description-1.0.0.xsd">

<!-- HDMI CEC Bridge -->
<bridge-type id="bridge" listed="true">
<label>HDMI-CEC Bridge</label>
<description>The HDMI-CEC Bridge.</description>

<config-description>
<parameter name="cecClientPath" type="text" required="true">
<label>cec-client executable path</label>
<description>e.g. /usr/local/bin/cec-client</description>
</parameter>
<parameter name="comPort" type="text" required="true">
<label>Device com port</label>
<description>e.g. /dev/ttyACM0</description>
</parameter>
</config-description>
</bridge-type>

<thing-type id="equipment" listed="true">
<supported-bridge-type-refs>
<bridge-type-ref id="bridge" />
</supported-bridge-type-refs>
<label>HDMI-CEC Equipment</label>
<description>Represents your TV, Home Theater, Blu-Ray, etc. that speaks HDMI CEC</description>

<channels>
<channel id="power" typeId="power" />
<channel id="activeSource" typeId="activeSource" />
<channel id="event" typeId="event" />
<channel id="send" typeId="send" />
</channels>

<config-description>
<parameter name="device" type="text" required="true">
<label>device</label>
<description>CEC Device, a single HEX value such as 0, 1, 2, E (0 is TV)</description>
</parameter>
<parameter name="address" type="text" required="true">
<label>address</label>
<description>CEC Address, of the form 0.0.0.0</description>
</parameter>
</config-description>
</thing-type>

<channel-type id="power">
<item-type>Switch</item-type>
<label>Power</label>
<description>Power on/off your device</description>
</channel-type>

<channel-type id="activeSource">
<item-type>Switch</item-type>
<label>Active Source</label>
<description>Make source active/inactive</description>
</channel-type>

<!-- Event Channel Type -->
<channel-type id="event">
<kind>trigger</kind>
<label>Traffic Event</label>
<description>Triggers when something happens</description>
</channel-type>

<!-- Transmit Channel Type -->
<channel-type id="send">
<item-type>String</item-type>
<label>Send Command</label>
<description>Used to send CEC commands</description>
</channel-type>

</thing:thing-descriptions>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
/**
* Copyright (c) 2014,2018 Contributors to the Eclipse Foundation
* Copyright (c) 2010-2018 by the respective copyright holders.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
* 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.hdmicec.handler;

Expand Down Expand Up @@ -55,11 +51,11 @@ public class HdmiCecBridgeHandler extends BaseBridgeHandler {
private String comPort;

// we're betting on the fact that the first value in () is the device ID. Seems valid from what I've seen!
private Pattern deviceStatement = Pattern.compile("DEBUG.* \\((.)\\) .*");
private Pattern deviceStatement = Pattern.compile("DEBUG.* \\((.)\\).*");
private Pattern powerOn = Pattern.compile(".*: power status changed from '(.*)' to 'on'");
private Pattern powerOff = Pattern.compile(".*: power status changed from '(.*)' to 'standby'");
private Pattern activeSourceOn = Pattern.compile(".* making .* the active source");
private Pattern activeSourceOff = Pattern.compile(".* marking .* \\((.)\\) as inactive source");
private Pattern activeSourceOn = Pattern.compile(".*making .* \\((.)\\) the active source");
private Pattern activeSourceOff = Pattern.compile(".*marking .* \\((.)\\) as inactive source");
private Pattern eventPattern = Pattern.compile("^(?!.*(<<|>>)).*: (.*)$"); // the 2nd group is the event

private boolean isRunning;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public String getAddressAsFrame() {
@Override
public void initialize() {
try {
getThing().setLabel(getThing().getLabel().replace("Equipment", getThing().getUID().getId()));
device = (String) this.getConfig().get(DEVICE);
address = (String) this.getConfig().get(ADDRESS);

Expand Down Expand Up @@ -118,22 +119,22 @@ public void cecClientStatus(boolean online, String status) {
void cecMatchLine(String line) {
Matcher matcher = bridgeHandler.getPowerOn().matcher(line);
if (matcher.matches()) {
this.updateState(HdmiCecBindingConstants.CHANNEL_POWER, OnOffType.ON);
updateState(HdmiCecBindingConstants.CHANNEL_POWER, OnOffType.ON);
return;
}
matcher = bridgeHandler.getPowerOff().matcher(line);
if (matcher.matches()) {
this.updateState(HdmiCecBindingConstants.CHANNEL_POWER, OnOffType.OFF);
updateState(HdmiCecBindingConstants.CHANNEL_POWER, OnOffType.OFF);
return;
}
matcher = bridgeHandler.getActiveSourceOn().matcher(line);
if (matcher.matches()) {
this.updateState(HdmiCecBindingConstants.CHANNEL_ACTIVE_SOURCE, OnOffType.ON);
updateState(HdmiCecBindingConstants.CHANNEL_ACTIVE_SOURCE, OnOffType.ON);
return;
}
matcher = bridgeHandler.getActiveSourceOff().matcher(line);
if (matcher.matches()) {
this.updateState(HdmiCecBindingConstants.CHANNEL_ACTIVE_SOURCE, OnOffType.OFF);
updateState(HdmiCecBindingConstants.CHANNEL_ACTIVE_SOURCE, OnOffType.OFF);
return;
}
matcher = bridgeHandler.getEventPattern().matcher(line);
Expand Down

0 comments on commit 3a42c6a

Please sign in to comment.