[epsonprojector] several small improvements and formatting changes (#13207)

* several small improvements and formatting changes

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
This commit is contained in:
mlobstein 2022-08-03 09:30:42 -05:00 committed by GitHub
parent ae418a4246
commit 22f7dfe309
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 33 deletions

View File

@ -1,6 +1,6 @@
# Epson Projector Binding
This binding is compatible with Epson projectors that support the ESC/VP21 protocol over the built-in network (ethernet or Wi-Fi) port, serial port or USB to serial adapter.
This binding is compatible with Epson projectors that support the ESC/VP21 protocol over the built-in network (Ethernet or Wi-Fi) port, serial port or USB to serial adapter.
If your projector does not have built-in networking, you can connect to your projector's serial port via a TCP connection using a serial over IP device or by using`ser2net`.
## Supported Things
@ -9,7 +9,7 @@ This binding supports two thing types based on the connection used: `projector-s
## Discovery
If the projector has a built-in ethernet port connected to the same network as the openHAB server and the 'AMX Device Discovery' option is present and enabled in the projector's network menu, the thing will be discovered automatically.
If the projector has a built-in Ethernet port connected to the same network as the openHAB server and the 'AMX Device Discovery' option is present and enabled in the projector's network menu, the thing will be discovered automatically.
Serial port or serial over IP connections must be configured manually.
## Binding Configuration
@ -32,7 +32,7 @@ The `projector-tcp` thing has the following configuration parameters:
| Parameter | Name | Description | Required |
|-----------------|------------------|------------------------------------------------------------------------------------------------------------------------------------------------|----------|
| host | Host Name | Host Name or IP address for the projector or serial over IP device. | yes |
| port | Port | Port for the projector or serial over IP device; default 3629 for projectors with built-in ethernet connector or Wi-Fi. | yes |
| port | Port | Port for the projector or serial over IP device; default 3629 for projectors with built-in Ethernet connector or Wi-Fi. | yes |
| pollingInterval | Polling Interval | Polling interval in seconds to update channel states, range 5-60 seconds; default 10 seconds. | no |
| maxVolume | Max Volume Range | Set to the maximum volume level available in the projector's OSD to select the correct range for the volume control. e.g. 20 or 40; default 20 | no |
@ -51,12 +51,25 @@ Some notes:
* On Linux, you may get an error stating the serial port cannot be opened when the epsonprojector binding tries to load.
* You can get around this by adding the `openhab` user to the `dialout` group like this: `usermod -a -G dialout openhab`.
* Also on Linux you may have issues with the USB if using two serial USB devices e.g. epsonprojector and RFXcom. See the [general documentation about serial port configuration](/docs/administration/serial.html) for more on symlinking the USB ports.
* Here is an example of ser2net.conf you can use to share your serial port /dev/ttyUSB0 on IP port 4444 using [ser2net Linux tool](https://sourceforge.net/projects/ser2net/) (take care, the baud rate is specific to the Epson projector):
* Here is an example of ser2net.conf (for ser2net version < 4) you can use to share your serial port /dev/ttyUSB0 on IP port 4444 using [ser2net Linux tool](https://sourceforge.net/projects/ser2net/) (take care, the baud rate is specific to the Epson projector):
```
4444:raw:0:/dev/ttyUSB0:9600 8DATABITS NONE 1STOPBIT LOCAL
```
* Here is an example of ser2net.yaml (for ser2net version >= 4) you can use to share your serial port /dev/ttyUSB0 on IP port 4444 using [ser2net Linux tool](https://sourceforge.net/projects/ser2net/) (take care, the baud rate is specific to the Epson projector):
```
connection: &conEpson
accepter: tcp,4444
enable: on
options:
kickolduser: true
connector: serialdev,
/dev/ttyUSB0,
9600n81,local
```
## Channels
| Channel | Item Type | Purpose | Values |
@ -135,8 +148,8 @@ String epsonBackground "Background [%s]" { channel="epsonprojector
String epsonKeyCode "Key Code [%s]" { channel="epsonprojector:projector-serial:hometheater:keycode", autoupdate="false" }
String epsonPowerState "Power State [%s]" <switch> { channel="epsonprojector:projector-serial:hometheater:powerstate" }
Number epsonLampTime "Lamp Time [%d h]" <switch> { channel="epsonprojector:projector-serial:hometheater:lamptime" }
Number epsonErrCode "Error Code [%d]" <"siren-on"> { channel="epsonprojector:projector-serial:hometheater:errcode" }
String epsonErrMessage "Error Message [%s]" <"siren-off"> { channel="epsonprojector:projector-serial:hometheater:errmessage" }
Number epsonErrCode "Error Code [%d]" <error> { channel="epsonprojector:projector-serial:hometheater:errcode" }
String epsonErrMessage "Error Message [%s]" <error> { channel="epsonprojector:projector-serial:hometheater:errmessage" }
```
sitemaps/epson.sitemap

View File

@ -45,5 +45,4 @@ public class EpsonProjectorBindingConstants {
// Config properties
public static final String THING_PROPERTY_HOST = "host";
public static final String THING_PROPERTY_PORT = "port";
public static final String THING_PROPERTY_MAC = "macAddress";
}

View File

@ -15,7 +15,6 @@ package org.openhab.binding.epsonprojector.internal.discovery;
import static org.openhab.binding.epsonprojector.internal.EpsonProjectorBindingConstants.*;
import java.io.IOException;
import java.net.SocketException;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ScheduledFuture;
@ -26,9 +25,14 @@ import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.config.discovery.AbstractDiscoveryService;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
import org.openhab.core.config.discovery.DiscoveryService;
import org.openhab.core.i18n.LocaleProvider;
import org.openhab.core.i18n.TranslationProvider;
import org.openhab.core.net.NetworkAddressService;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@ -36,7 +40,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@link EpsonProjectoreDiscoveryService} class implements a service
* The {@link EpsonProjectorDiscoveryService} class implements a service
* for discovering Epson projectors using the AMX Device Discovery protocol.
*
* @author Mark Hilbush - Initial contribution
@ -53,13 +57,21 @@ public class EpsonProjectorDiscoveryService extends AbstractDiscoveryService {
public static final int BACKGROUND_DISCOVERY_DELAY_TIMEOUT_SEC = 10;
private NetworkAddressService networkAddressService;
private final TranslationProvider translationProvider;
private final LocaleProvider localeProvider;
private final @Nullable Bundle bundle;
private boolean terminate = false;
@Activate
public EpsonProjectorDiscoveryService(@Reference NetworkAddressService networkAddressService) {
public EpsonProjectorDiscoveryService(@Reference NetworkAddressService networkAddressService,
@Reference TranslationProvider translationProvider, @Reference LocaleProvider localeProvider) {
super(SUPPORTED_THING_TYPES_UIDS, 0, BACKGROUND_DISCOVERY_ENABLED);
this.networkAddressService = networkAddressService;
this.translationProvider = translationProvider;
this.localeProvider = localeProvider;
this.bundle = FrameworkUtil.getBundle(EpsonProjectorDiscoveryService.class);
epsonDiscoveryJob = null;
terminate = false;
}
@ -105,9 +117,6 @@ public class EpsonProjectorDiscoveryService extends AbstractDiscoveryService {
try {
String ip = networkAddressService.getPrimaryIpv4HostAddress();
epsonMulticastListener = new MulticastListener((ip != null ? ip : local));
} catch (SocketException se) {
logger.debug("Discovery job got Socket exception creating multicast socket: {}", se.getMessage());
return;
} catch (IOException ioe) {
logger.debug("Discovery job got IO exception creating multicast socket: {}", ioe.getMessage());
return;
@ -120,7 +129,7 @@ public class EpsonProjectorDiscoveryService extends AbstractDiscoveryService {
if (thingProperties != null) {
// The MulticastListener found a projector, add it as new thing
String uid = (String) thingProperties.get(THING_PROPERTY_MAC);
String uid = (String) thingProperties.get(Thing.PROPERTY_MAC_ADDRESS);
String ipAddress = (String) thingProperties.get(THING_PROPERTY_HOST);
if (uid != null) {
@ -128,9 +137,12 @@ public class EpsonProjectorDiscoveryService extends AbstractDiscoveryService {
ThingUID thingUid = new ThingUID(THING_TYPE_PROJECTOR_TCP, uid);
logger.trace("Creating epson projector discovery result for: {}, IP={}", uid, ipAddress);
thingDiscovered(DiscoveryResultBuilder.create(thingUid).withProperties(thingProperties)
.withLabel("Epson Projector " + uid).withRepresentationProperty(THING_PROPERTY_MAC)
.build());
thingDiscovered(
DiscoveryResultBuilder.create(thingUid).withProperties(thingProperties)
.withLabel(translationProvider.getText(bundle,
"thing-type.epsonprojector.discovery.label", "Epson Projector",
localeProvider.getLocale(), uid))
.withRepresentationProperty(Thing.PROPERTY_MAC_ADDRESS).build());
}
}
} catch (IOException ioe) {

View File

@ -14,7 +14,6 @@ package org.openhab.binding.epsonprojector.internal.discovery;
import static org.openhab.binding.epsonprojector.internal.EpsonProjectorBindingConstants.DEFAULT_PORT;
import static org.openhab.binding.epsonprojector.internal.EpsonProjectorBindingConstants.THING_PROPERTY_HOST;
import static org.openhab.binding.epsonprojector.internal.EpsonProjectorBindingConstants.THING_PROPERTY_MAC;
import static org.openhab.binding.epsonprojector.internal.EpsonProjectorBindingConstants.THING_PROPERTY_PORT;
import java.io.IOException;
@ -31,6 +30,7 @@ import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.thing.Thing;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -47,9 +47,9 @@ public class MulticastListener {
private MulticastSocket socket;
// Epson projector devices announce themselves on a multicast port
private static final String EPSON_MULTICAST_GROUP = "239.255.250.250";
private static final int EPSON_MULTICAST_PORT = 9131;
// Epson projector devices announce themselves on the AMX DDD multicast port
private static final String AMX_MULTICAST_GROUP = "239.255.250.250";
private static final int AMX_MULTICAST_PORT = 9131;
// How long to wait in milliseconds for a discovery beacon
public static final int DEFAULT_SOCKET_TIMEOUT_SEC = 3000;
@ -61,12 +61,12 @@ public class MulticastListener {
InetAddress ifAddress = InetAddress.getByName(ipv4Address);
logger.debug("Discovery job using address {} on network interface {}", ifAddress.getHostAddress(),
NetworkInterface.getByInetAddress(ifAddress).getName());
socket = new MulticastSocket(EPSON_MULTICAST_PORT);
socket = new MulticastSocket(AMX_MULTICAST_PORT);
socket.setInterface(ifAddress);
socket.setSoTimeout(DEFAULT_SOCKET_TIMEOUT_SEC);
InetAddress mcastAddress = InetAddress.getByName(EPSON_MULTICAST_GROUP);
InetAddress mcastAddress = InetAddress.getByName(AMX_MULTICAST_GROUP);
socket.joinGroup(mcastAddress);
logger.debug("Multicast listener joined multicast group {}:{}", EPSON_MULTICAST_GROUP, EPSON_MULTICAST_PORT);
logger.debug("Multicast listener joined multicast group {}:{}", AMX_MULTICAST_GROUP, AMX_MULTICAST_PORT);
}
public void shutdown() {
@ -120,7 +120,7 @@ public class MulticastListener {
if (keyValue.length == 2 && keyValue[0].contains("UUID") && !keyValue[1].isEmpty()) {
Map<String, Object> properties = new HashMap<>();
properties.put(THING_PROPERTY_MAC, keyValue[1]);
properties.put(Thing.PROPERTY_MAC_ADDRESS, keyValue[1]);
properties.put(THING_PROPERTY_HOST, packet.getAddress().getHostAddress());
properties.put(THING_PROPERTY_PORT, DEFAULT_PORT);
return properties;

View File

@ -426,13 +426,14 @@ public class EpsonProjectorHandler extends BaseThingHandler {
}
private void closeConnection() {
EpsonProjectorDevice remoteController = device.get();
if (device.isPresent()) {
try {
logger.debug("Closing connection to device '{}'", this.thing.getUID());
remoteController.disconnect();
device.get().disconnect();
updateStatus(ThingStatus.OFFLINE);
} catch (EpsonProjectorException e) {
logger.debug("Error occurred when closing connection to device '{}'", this.thing.getUID(), e);
}
}
}
}

View File

@ -5,6 +5,7 @@ binding.epsonprojector.description = This binding is compatible with Epson proje
# thing types
thing-type.epsonprojector.discovery.label = Epson Projector {0}
thing-type.epsonprojector.projector-serial.label = Epson Projector - Serial
thing-type.epsonprojector.projector-serial.description = An Epson projector which supports the ESC/VP21 protocol via a serial port connection
thing-type.epsonprojector.projector-tcp.label = Epson Projector - TCP/IP