use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.
the class GetAllScriptsParser method parse.
@Override
public Void parse(Object[] message) throws IOException {
message = (Object[]) message[0];
for (int i = 0; i < message.length; i++) {
String scriptName = ObjectUtils.toString(message[i]);
HmDatapoint dpScript = new HmDatapoint(scriptName, scriptName, HmValueType.BOOL, Boolean.FALSE, false, HmParamsetType.VALUES);
dpScript.setInfo(scriptName);
channel.addDatapoint(dpScript);
}
return null;
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint 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());
}
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.
the class HomematicThingHandler method updateDynamicChannelList.
/**
* Update the given thing channel list to reflect the device's current datapoint set
*
* @return true if the list was modified, false if it was not modified
*/
private boolean updateDynamicChannelList(HmDevice device, List<Channel> thingChannels) {
boolean changed = false;
for (HmChannel channel : device.getChannels()) {
if (!channel.isReconfigurable()) {
continue;
}
final String expectedFunction = channel.getDatapoint(HmParamsetType.MASTER, HomematicConstants.DATAPOINT_NAME_CHANNEL_FUNCTION).getOptionValue();
final String propertyName = String.format(PROPERTY_DYNAMIC_FUNCTION_FORMAT, channel.getNumber());
// remove thing channels that were configured for a different function
Iterator<Channel> channelIter = thingChannels.iterator();
while (channelIter.hasNext()) {
Map<String, String> properties = channelIter.next().getProperties();
String function = properties.get(propertyName);
if (function != null && !function.equals(expectedFunction)) {
channelIter.remove();
changed = true;
}
}
for (HmDatapoint dp : channel.getDatapoints()) {
if (HomematicTypeGeneratorImpl.isIgnoredDatapoint(dp) || dp.getParamsetType() != HmParamsetType.VALUES) {
continue;
}
ChannelUID channelUID = UidUtils.generateChannelUID(dp, getThing().getUID());
if (containsChannel(thingChannels, channelUID)) {
// Channel is already present -> channel configuration likely hasn't changed
continue;
}
Map<String, String> channelProps = new HashMap<>();
channelProps.put(propertyName, expectedFunction);
Channel thingChannel = ChannelBuilder.create(channelUID, MetadataUtils.getItemType(dp)).withProperties(channelProps).withLabel(MetadataUtils.getLabel(dp)).withDescription(MetadataUtils.getDatapointDescription(dp)).withType(UidUtils.generateChannelTypeUID(dp)).build();
thingChannels.add(thingChannel);
changed = true;
}
}
return changed;
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.
the class HomematicThingHandler method handleConfigurationUpdate.
@Override
public void handleConfigurationUpdate(Map<String, Object> configurationParameters) throws ConfigValidationException {
super.handleConfigurationUpdate(configurationParameters);
try {
HomematicGateway gateway = getHomematicGateway();
HmDevice device = gateway.getDevice(UidUtils.getHomematicAddress(getThing()));
for (Entry<String, Object> configurationParameter : configurationParameters.entrySet()) {
String key = configurationParameter.getKey();
Object newValue = configurationParameter.getValue();
if (key.startsWith("HMP_")) {
key = StringUtils.removeStart(key, "HMP_");
Integer channelNumber = NumberUtils.toInt(StringUtils.substringBefore(key, "_"));
String dpName = StringUtils.substringAfter(key, "_");
HmDatapointInfo dpInfo = new HmDatapointInfo(device.getAddress(), HmParamsetType.MASTER, channelNumber, dpName);
HmDatapoint dp = device.getChannel(channelNumber).getDatapoint(dpInfo);
if (dp != null) {
try {
if (newValue != null) {
if (newValue instanceof BigDecimal) {
final BigDecimal decimal = (BigDecimal) newValue;
if (dp.isIntegerType()) {
newValue = decimal.intValue();
} else if (dp.isFloatType()) {
newValue = decimal.doubleValue();
}
}
if (ObjectUtils.notEqual(dp.isEnumType() ? dp.getOptionValue() : dp.getValue(), newValue)) {
sendDatapoint(dp, new HmDatapointConfig(), newValue);
}
}
} catch (IOException ex) {
logger.error("Error setting thing property {}: {}", dpInfo, ex.getMessage());
}
} else {
logger.error("Can't find datapoint for thing property {}", dpInfo);
}
}
}
gateway.triggerDeviceValuesReload(device);
} catch (HomematicClientException | GatewayNotAvailableException ex) {
logger.error("Error setting thing properties: {}", ex.getMessage(), ex);
}
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.
the class AbstractHomematicGateway method getDatapoint.
@Override
public HmDatapoint getDatapoint(HmDatapointInfo dpInfo) throws HomematicClientException {
HmDevice device = getDevice(dpInfo.getAddress());
HmChannel channel = device.getChannel(dpInfo.getChannel());
if (channel == null) {
throw new HomematicClientException(String.format("Channel %s in device '%s' not found on gateway '%s'", dpInfo.getChannel(), dpInfo.getAddress(), id));
}
HmDatapoint dp = channel.getDatapoint(dpInfo);
if (dp == null) {
throw new HomematicClientException(String.format("Datapoint '%s' not found on gateway '%s'", dpInfo, id));
}
return dp;
}
Aggregations