use of org.eclipse.smarthome.binding.homematic.internal.model.HmDevice in project smarthome by eclipse.
the class HomegearLoadDeviceNamesParser method parse.
@Override
@SuppressWarnings("unchecked")
public Void parse(Object[] message) throws IOException {
Map<String, HmDevice> devicesById = new HashMap<String, HmDevice>();
for (HmDevice device : devices) {
devicesById.put(device.getHomegearId(), device);
}
message = (Object[]) message[0];
for (int i = 0; i < message.length; i++) {
Map<String, ?> data = (Map<String, ?>) message[i];
String id = toString(data.get("ID"));
String name = toString(data.get("NAME"));
HmDevice device = devicesById.get(getSanitizedAddress(id));
if (device != null) {
device.setName(name);
}
}
return null;
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDevice 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.HmDevice 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.HmDevice 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;
}
use of org.eclipse.smarthome.binding.homematic.internal.model.HmDevice in project smarthome by eclipse.
the class AbstractHomematicGateway method newDevices.
@Override
public void newDevices(List<String> adresses) {
if (initialized && newDeviceEventsEnabled) {
for (String address : adresses) {
try {
logger.debug("New device '{}' detected on gateway with id '{}'", address, id);
List<HmDevice> deviceDescriptions = getDeviceDescriptions();
for (HmDevice device : deviceDescriptions) {
if (device.getAddress().equals(address)) {
for (HmChannel channel : device.getChannels()) {
addChannelDatapoints(channel, HmParamsetType.MASTER);
addChannelDatapoints(channel, HmParamsetType.VALUES);
}
prepareDevice(device);
gatewayAdapter.onNewDevice(device);
}
}
} catch (Exception ex) {
logger.error("{}", ex.getMessage(), ex);
}
}
}
}
Aggregations