use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.
the class HomematicTypeGeneratorImpl method generate.
@Override
public void generate(HmDevice device) {
if (thingTypeProvider != null) {
ThingTypeUID thingTypeUID = UidUtils.generateThingTypeUID(device);
ThingType tt = thingTypeProvider.getInternalThingType(thingTypeUID);
if (tt == null || device.isGatewayExtras()) {
logger.debug("Generating ThingType for device '{}' with {} datapoints", device.getType(), device.getDatapointCount());
List<ChannelGroupType> groupTypes = new ArrayList<ChannelGroupType>();
for (HmChannel channel : device.getChannels()) {
List<ChannelDefinition> channelDefinitions = new ArrayList<ChannelDefinition>();
// those will be populated dynamically during thing initialization
if (!channel.isReconfigurable()) {
// generate channel
for (HmDatapoint dp : channel.getDatapoints()) {
if (!isIgnoredDatapoint(dp) && dp.getParamsetType() == HmParamsetType.VALUES) {
ChannelTypeUID channelTypeUID = UidUtils.generateChannelTypeUID(dp);
ChannelType channelType = channelTypeProvider.getInternalChannelType(channelTypeUID);
if (channelType == null) {
channelType = createChannelType(dp, channelTypeUID);
channelTypeProvider.addChannelType(channelType);
}
ChannelDefinition channelDef = new ChannelDefinitionBuilder(dp.getName(), channelType.getUID()).build();
channelDefinitions.add(channelDef);
}
}
}
// generate group
ChannelGroupTypeUID groupTypeUID = UidUtils.generateChannelGroupTypeUID(channel);
ChannelGroupType groupType = channelGroupTypeProvider.getInternalChannelGroupType(groupTypeUID);
if (groupType == null || device.isGatewayExtras()) {
String groupLabel = String.format("%s", WordUtils.capitalizeFully(StringUtils.replace(channel.getType(), "_", " ")));
groupType = ChannelGroupTypeBuilder.instance(groupTypeUID, groupLabel).withChannelDefinitions(channelDefinitions).build();
channelGroupTypeProvider.addChannelGroupType(groupType);
groupTypes.add(groupType);
}
}
tt = createThingType(device, groupTypes);
thingTypeProvider.addThingType(tt);
}
addFirmware(device);
}
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.
the class StateContactVirtualDatapointHandler method initialize.
@Override
public void initialize(HmDevice device) {
if (isApplicable(device)) {
HmChannel channelOne = device.getChannel(1);
if (channelOne != null) {
HmDatapointInfo dpStateInfo = HmDatapointInfo.createValuesInfo(channelOne, DATAPOINT_NAME_STATE);
HmDatapoint dpState = channelOne.getDatapoint(dpStateInfo);
if (dpState != null) {
addDatapoint(device, 1, getName(), HmValueType.BOOL, convertState(dpState.getValue()), true);
}
}
}
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.
the class DeleteDeviceVirtualDatapointHandler method handleCommand.
@Override
public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value) throws IOException, HomematicClientException {
dp.setValue(value);
if (MiscUtils.isTrueValue(dp.getValue())) {
try {
HmDatapoint deleteMode = dp.getChannel().getDatapoint(HmDatapointInfo.createValuesInfo(dp.getChannel(), VIRTUAL_DATAPOINT_NAME_DELETE_DEVICE_MODE));
HmDevice device = dp.getChannel().getDevice();
int flag = -1;
switch(deleteMode.getOptionValue()) {
case MODE_RESET:
flag = 1;
break;
case MODE_FORCE:
flag = 2;
break;
case MODE_DEFER:
flag = 4;
}
if (flag == -1) {
logger.info("Can't delete device '{}' from gateway '{}', DELETE_MODE is LOCKED", device.getAddress(), gateway.getId());
} else {
gateway.getRpcClient(device.getHmInterface()).deleteDevice(device, flag);
}
} finally {
gateway.disableDatapoint(dp, AbstractHomematicGateway.DEFAULT_DISABLE_DELAY);
}
}
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.
the class DisplayTextVirtualDatapoint method addEnumDisplayDatapoint.
/**
* Adds a Datapoint to the device with the values of the given enum.
*/
private void addEnumDisplayDatapoint(HmDevice device, int channelNumber, String datapointName, Class<? extends Enum<?>> e) {
HmDatapoint dpEnum = addDatapoint(device, channelNumber, datapointName, HmValueType.ENUM, null, false);
dpEnum.setOptions(getEnumNames(e));
dpEnum.setMinValue(0);
dpEnum.setMaxValue(e.getEnumConstants().length);
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.
the class DisplayTextVirtualDatapoint method initialize.
@Override
public void initialize(HmDevice device) {
if (isDisplay(device)) {
for (HmChannel channel : device.getChannels()) {
if (channel.hasDatapoint(new HmDatapointInfo(HmParamsetType.VALUES, channel, DATAPOINT_NAME_SUBMIT))) {
for (int i = 1; i <= getLineCount(device); i++) {
addDatapoint(device, channel.getNumber(), DATAPOINT_NAME_DISPLAY_LINE + i, HmValueType.STRING, null, false);
addEnumDisplayDatapoint(device, channel.getNumber(), DATAPOINT_NAME_DISPLAY_ICON + i, Icon.class);
if (!isEpDisplay(device)) {
addEnumDisplayDatapoint(device, channel.getNumber(), DATAPOINT_NAME_DISPLAY_COLOR + i, Color.class);
}
}
if (isEpDisplay(device)) {
addEnumDisplayDatapoint(device, channel.getNumber(), DATAPOINT_NAME_DISPLAY_BEEPER, Beeper.class);
HmDatapoint bc = addDatapoint(device, channel.getNumber(), DATAPOINT_NAME_DISPLAY_BEEPCOUNT, HmValueType.INTEGER, 1, false);
bc.setMinValue(0);
bc.setMaxValue(15);
HmDatapoint bd = addDatapoint(device, channel.getNumber(), DATAPOINT_NAME_DISPLAY_BEEPINTERVAL, HmValueType.INTEGER, 1, false);
bd.setMinValue(10);
bd.setMaxValue(160);
bd.setStep(10);
addEnumDisplayDatapoint(device, channel.getNumber(), DATAPOINT_NAME_DISPLAY_LED, Led.class);
}
addDatapoint(device, channel.getNumber(), DATAPOINT_NAME_DISPLAY_SUBMIT, HmValueType.BOOL, false, false);
}
}
}
}
Aggregations