Search in sources :

Example 1 with DeviceType

use of org.openhab.binding.satel.command.ReadDeviceInfoCommand.DeviceType in project openhab1-addons by openhab.

the class Satel method satelReadDeviceName.

/**
     * Reads name of alarm system's device.
     * Device types:
     * <ul>
     * <li>PARTITION</li>
     * <li>ZONE</li>
     * <li>USER</li>
     * <li>EXPANDER</li>
     * <li>LCD</li>
     * <li>OUTPUT</li>
     * <li>TIMER</li>
     * <li>TELEPHONE</li>
     * <li>OBJECT</li>
     * </ul>
     *
     * @param deviceType type of the device
     * @param deviceNumber number of the device
     * @return string representing device's name or <code>null</code> if device is not present or an error occurred
     */
@ActionDoc(text = "Returns name of a device.")
public static String satelReadDeviceName(@ParamDoc(name = "deviceType", text = "type of the device, one of: PARTITION, ZONE, USER, EXPANDER, LCD, OUTPUT, TIMER, TELEPHONE, OBJECT") String deviceType, @ParamDoc(name = "deviceNumber", text = "number of the device to read") int deviceNumber) {
    if (!satelIsConnected()) {
        logger.warn("Not connected to communication module or Satel binding not available.");
        return null;
    }
    DeviceType devType;
    try {
        devType = DeviceType.valueOf(deviceType.toUpperCase());
    } catch (Exception e) {
        logger.warn("Invalid device type given: {}", deviceType);
        return null;
    }
    ReadDeviceInfoCommand cmd = new ReadDeviceInfoCommand(devType, deviceNumber);
    if (!SatelActionService.satelCommModule.sendCommand(cmd)) {
        logger.warn("Unable to read device info: {}, {}", deviceType, deviceNumber);
        return null;
    }
    try {
        return cmd.getName(SatelActionService.satelCommModule.getTextEncoding());
    } catch (UnsupportedEncodingException e) {
        logger.error("Unsupported encoding: {}", SatelActionService.satelCommModule.getTextEncoding());
        return null;
    }
}
Also used : DeviceType(org.openhab.binding.satel.command.ReadDeviceInfoCommand.DeviceType) ReadDeviceInfoCommand(org.openhab.binding.satel.command.ReadDeviceInfoCommand) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ActionDoc(org.openhab.core.scriptengine.action.ActionDoc)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ReadDeviceInfoCommand (org.openhab.binding.satel.command.ReadDeviceInfoCommand)1 DeviceType (org.openhab.binding.satel.command.ReadDeviceInfoCommand.DeviceType)1 ActionDoc (org.openhab.core.scriptengine.action.ActionDoc)1