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;
}
}
Aggregations