use of org.eclipse.smarthome.binding.homematic.internal.model.HmChannel in project smarthome by eclipse.
the class AbstractVirtualDatapointHandler method addDatapoint.
/**
* Creates a new datapoint with the given parameters and adds it to the channel.
*/
protected HmDatapoint addDatapoint(HmDevice device, Integer channelNumber, String datapointName, HmValueType valueType, Object value, boolean readOnly) {
HmChannel channel = device.getChannel(channelNumber);
HmDatapoint dp = new HmDatapoint(datapointName, datapointName, valueType, value, readOnly, HmParamsetType.VALUES);
return addDatapoint(channel, dp);
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmChannel in project smarthome by eclipse.
the class DisplayOptionsVirtualDatapointHandler method handleCommand.
@Override
public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value) throws IOException, HomematicClientException {
HmChannel channel = dp.getChannel();
DisplayOptionsParser rcOptionsParser = new DisplayOptionsParser(channel);
rcOptionsParser.parse(value);
if (StringUtils.isNotBlank(rcOptionsParser.getText())) {
sendDatapoint(gateway, channel, DATAPOINT_NAME_TEXT, rcOptionsParser.getText());
}
sendDatapoint(gateway, channel, DATAPOINT_NAME_BEEP, rcOptionsParser.getBeep());
sendDatapoint(gateway, channel, DATAPOINT_NAME_UNIT, rcOptionsParser.getUnit());
sendDatapoint(gateway, channel, DATAPOINT_NAME_BACKLIGHT, rcOptionsParser.getBacklight());
for (String symbol : rcOptionsParser.getSymbols()) {
sendDatapoint(gateway, channel, symbol, Boolean.TRUE);
}
sendDatapoint(gateway, channel, DATAPOINT_NAME_SUBMIT, Boolean.TRUE);
dp.setValue(value);
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmChannel in project smarthome by eclipse.
the class OnTimeAutomaticVirtualDatapointHandler method initialize.
@Override
public void initialize(HmDevice device) {
for (HmChannel channel : device.getChannels()) {
HmDatapointInfo dpInfoOnTime = HmDatapointInfo.createValuesInfo(channel, DATAPOINT_NAME_ON_TIME);
if (channel.hasDatapoint(dpInfoOnTime)) {
HmDatapointInfo dpInfoLevel = HmDatapointInfo.createValuesInfo(channel, DATAPOINT_NAME_LEVEL);
HmDatapointInfo dpInfoState = HmDatapointInfo.createValuesInfo(channel, DATAPOINT_NAME_STATE);
if (channel.hasDatapoint(dpInfoLevel) || channel.hasDatapoint(dpInfoState)) {
HmDatapoint dpOnTime = channel.getDatapoint(dpInfoOnTime);
HmDatapoint dpOnTimeAutomatic = dpOnTime.clone();
dpOnTimeAutomatic.setName(getName());
dpOnTimeAutomatic.setDescription(getName());
addDatapoint(channel, dpOnTimeAutomatic);
}
}
}
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmChannel in project smarthome by eclipse.
the class DisplayTextVirtualDatapoint method handleCommand.
@Override
public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value) throws IOException, HomematicClientException {
dp.setValue(value);
if (DATAPOINT_NAME_DISPLAY_SUBMIT.equals(dp.getName()) && MiscUtils.isTrueValue(dp.getValue())) {
HmChannel channel = dp.getChannel();
boolean isEp = isEpDisplay(channel.getDevice());
List<String> message = new ArrayList<String>();
message.add(START);
if (isEp) {
message.add(LF);
}
for (int i = 1; i <= getLineCount(channel.getDevice()); i++) {
String line = ObjectUtils.toString(channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_LINE + i).getValue());
if (StringUtils.isEmpty(line)) {
line = " ";
}
message.add(LINE);
message.add(encodeText(line));
if (!isEp) {
String color = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_COLOR + i).getOptionValue();
message.add(COLOR);
String colorCode = Color.getCode(color);
message.add(StringUtils.isBlank(colorCode) ? Color.WHITE.getCode() : colorCode);
}
String icon = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_ICON + i).getOptionValue();
String iconCode = Icon.getCode(icon);
if (StringUtils.isNotBlank(iconCode)) {
message.add(ICON);
message.add(iconCode);
}
message.add(LF);
}
if (isEp) {
String beeper = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_BEEPER).getOptionValue();
message.add(BEEPER_START);
message.add(Beeper.getCode(beeper));
message.add(BEEPER_END);
// set number of beeps
message.add(encodeBeepCount(channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_BEEPCOUNT)));
message.add(BEEPCOUNT_END);
// set interval between two beeps
message.add(encodeBeepInterval(channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_BEEPINTERVAL)));
message.add(BEEPINTERVAL_END);
// LED value must always set (same as beeps)
String led = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_LED).getOptionValue();
message.add(Led.getCode(led));
}
message.add(STOP);
gateway.sendDatapoint(channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_SUBMIT), new HmDatapointConfig(), StringUtils.join(message, ","), null);
}
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmChannel in project smarthome by eclipse.
the class HomematicThingHandler method doInitializeInBackground.
private void doInitializeInBackground() throws GatewayNotAvailableException, HomematicClientException, IOException {
HomematicGateway gateway = getHomematicGateway();
HmDevice device = gateway.getDevice(UidUtils.getHomematicAddress(getThing()));
HmChannel channelZero = device.getChannel(0);
loadHomematicChannelValues(channelZero);
updateStatus(device);
logger.debug("Initializing thing '{}' from gateway '{}'", getThing().getUID(), gateway.getId());
// update properties
Map<String, String> properties = editProperties();
setProperty(properties, channelZero, PROPERTY_BATTERY_TYPE, VIRTUAL_DATAPOINT_NAME_BATTERY_TYPE);
setProperty(properties, channelZero, Thing.PROPERTY_FIRMWARE_VERSION, VIRTUAL_DATAPOINT_NAME_FIRMWARE);
setProperty(properties, channelZero, Thing.PROPERTY_SERIAL_NUMBER, device.getAddress());
setProperty(properties, channelZero, PROPERTY_AES_KEY, DATAPOINT_NAME_AES_KEY);
updateProperties(properties);
// update data point list for reconfigurable channels
for (HmChannel channel : device.getChannels()) {
if (channel.isReconfigurable()) {
loadHomematicChannelValues(channel);
if (channel.checkForChannelFunctionChange()) {
gateway.updateChannelValueDatapoints(channel);
}
}
}
// update configurations
Configuration config = editConfiguration();
for (HmChannel channel : device.getChannels()) {
loadHomematicChannelValues(channel);
for (HmDatapoint dp : channel.getDatapoints()) {
if (dp.getParamsetType() == HmParamsetType.MASTER) {
config.put(MetadataUtils.getParameterName(dp), dp.isEnumType() ? dp.getOptionValue() : dp.getValue());
}
}
}
updateConfiguration(config);
// update thing channel list for reconfigurable channels (relies on the new value of the
// CHANNEL_FUNCTION datapoint fetched during configuration update)
List<Channel> thingChannels = new ArrayList<>(getThing().getChannels());
if (updateDynamicChannelList(device, thingChannels)) {
updateThing(editThing().withChannels(thingChannels).build());
}
}
Aggregations