device = new Device(); device.setSource("noolite"); device.setInternalName("noolite/channel/" + channel); device.setStatus("listening"); device.setType("Noolite Device"); device.setManufName("Nootechnika"); device.setNode((short) (1000 + channel)); device.setUuid(UUID.randomUUID().toString()); device.setInternalType("switch"); device.addValue(new DeviceValue("channel", String.valueOf(channel), "", "", device.getUuid(), true)); device.addValue(new DeviceValue("type", "switch", "", "", device.getUuid(), false)); } else { device.setInternalType("sensor"); device.addValue(new DeviceValue("channel", String.valueOf(channel), "", "", device.getUuid(), true)); device.addValue(new DeviceValue("type", "sensor", "", "", device.getUuid(), false)); device.addValue(new DeviceValue("sensorname", sensor.name(), "", "", device.getUuid(), false)); LOGGER.info("Channel " + channel + ": Got OFF command"); updateValue(device, "Level", "0"); DBLogger.info("Device is OFF", device.getUuid()); SensorData.log(device.getUuid(), "Switch", "OFF"); if (device.getProductName().equals("unknown")) { device.setProductName("Generic Switch"); messaging.broadcast("event.devices.noolite.value.changed", new GenericAdvertisement("DeviceOff", device.getUuid())); break;
private void deviceSetLevel(GenericAdvertisement advertisement, Integer level) { String label = "Level"; String uuid; if (level == null) { level = (Integer) advertisement.getValue("data"); label = (String) advertisement.getValue("label"); uuid = (String) advertisement.getValue(); } else { uuid = (String) advertisement.getValue(); } Device ZWaveDevice = Device.getDeviceByUUID(uuid); if (ZWaveDevice != null && !ZWaveDevice.getSource().equals("zwave")) { // not zwave return; } if (ZWaveDevice == null) { LOGGER.info("Cant find device with UUID " + uuid); return; } int node = ZWaveDevice.getNode(); if (!ZWaveDevice.getStatus().equals("Dead")) { LOGGER.info("Setting value: " + level + " to label \"" + label + "\" on node " + node + " (UUID: " + uuid + ")"); setValue(uuid, label, level); } else { LOGGER.info("Node: " + node + " Cant set empty value or node dead"); } }
private void updateValue(Device device, String label, String value) { DeviceValue deviceValue = device.getValue(label); if (deviceValue == null) { deviceValue = new DeviceValue(); deviceValue.setLabel(label); deviceValue.setValue(value); deviceValue.setReadonly(false); deviceValue.setValueId("{ }"); device.addValue(deviceValue); } else { device.setValue(label, value); } }
private void setValue(String uuid, String label, Integer value) { Device device = Device.getDeviceByUUID(uuid); DeviceValue zv = device.getValue(label); if (zv != null) { if (!Manager.get().isValueReadOnly(gson.fromJson(zv.getValueId(), ValueId.class))) { setTypedValue(gson.fromJson(zv.getValueId(), ValueId.class), String.valueOf(value)); } else { LOGGER.info("Value \"%s\" is read-only! Skip.", label); } } }
ZWaveDevice = new Device(); ZWaveDevice.setInternalType(type); ZWaveDevice.setSource("zwave"); ZWaveDevice.setInternalName("zwave/" + type + "/" + notification.getNodeId()); ZWaveDevice.setType(Manager.get().getNodeType(notification.getHomeId(), notification.getNodeId())); ZWaveDevice.setNode(notification.getNodeId()); ZWaveDevice.setUuid(uuid); ZWaveDevice.setManufName(manufName); ZWaveDevice.setProductName(productName); ZWaveDevice.setStatus(state); ZWaveDevice.addValue(new DeviceValue( label, uuid, beaming.setValue(String.valueOf(Manager.get().isNodeBeamingDevice(homeId, ZWaveDevice.getNode()))); beaming.setReadonly(true); ZWaveDevice.addValue(beaming); ZWaveDevice.setManufName(manufName); ZWaveDevice.setProductName(productName); ZWaveDevice.setStatus(state); LOGGER.info("Node " + ZWaveDevice.getNode() + ": Add \"" + label + "\" value \"" + Utils.getValue(notification.getValueId()) + "\""); DeviceValue udv = ZWaveDevice.getValue(label);
data.put("uuid", device.getUuid()); data.put("label", Manager.get().getValueLabel(notification.getValueId())); data.put("data", String.valueOf(Utils.getValue(notification.getValueId()))); device = Device.getDeviceByNode(node); device.removeValue(manager.getValueLabel(notification.getValueId())); data.put("uuid", device.getUuid()); data.put("label", Manager.get().getValueLabel(notification.getValueId())); data.put("data", String.valueOf(Utils.getValue(notification.getValueId()))); LOGGER.info("Node " + device.getNode() + ": Value " + manager.getValueLabel(notification.getValueId()) + " removed"); device = Device.getDeviceByNode(node); if (manager.isNodeAwake(homeId, device.getNode()) && device.getStatus().equals("Sleeping")) { LOGGER.info("Setting node " + device.getNode() + " to LISTEN state"); device.setStatus("Listening"); device.getNode() + ": " + "Value for label \"" + manager.getValueLabel(notification.getValueId()) + "\" changed --> " + "\"" + Utils.getValue(notification.getValueId()) + "\""); DeviceValue udvChg = device.getValue(manager.getValueLabel(notification.getValueId())); device.removeValue(udvChg); else udvChg = new DeviceValue();
if (device != null && !device.getSource().equals("noolite")) { LOGGER.info("Device with UUID " + uuid + " is not Noolite!"); return; channel = Byte.valueOf(device.getValue("channel").getValue()); } else { channel = Double.valueOf(advertisement.getValue().toString()).byteValue(); LOGGER.info("Turn on device on channel " + channel); updateValue(device, "Level", "255"); DBLogger.info("Device is ON", device.getUuid()); pc.turnOn(channel); break; LOGGER.info("Turn off device on channel " + channel); updateValue(device, "Level", "0"); DBLogger.info("Device is OFF", device.getUuid()); pc.turnOff(channel); break; if (device.getValue("type") != null && device.getValue("type").getValue().contains("dimmer")) { if (level > 99 || level == 99) { DBLogger.info("Device is ON", device.getUuid()); DBLogger.info("Device is OFF", device.getUuid()); DBLogger.info("Device level set: " + level, device.getUuid());
if (Manager.get().isNodeFailed(homeId, ZWaveDevice.getNode())) { LOGGER.info("Setting node " + ZWaveDevice.getNode() + " to DEAD state"); ZWaveDevice.setStatus("dead"); ZWaveDevice.save(); if (!Manager.get().isNodeAwake(homeId, ZWaveDevice.getNode())) { LOGGER.info("Setting node " + ZWaveDevice.getNode() + " to SLEEP state"); ZWaveDevice.setStatus("sleeping"); Manager.get().refreshNodeInfo(homeId, ZWaveDevice.getNode()); ZWaveDevice.save();
private void updateValue(Device device, String label, String value) { DeviceValue deviceValue = device.getValue(label); if (deviceValue == null) { deviceValue = new DeviceValue(); deviceValue.setLabel(label); deviceValue.setValue(value); deviceValue.setReadonly(false); deviceValue.setValueId("{ }"); } else { device.setValue(label, value); } }
public static void set(String name, int value) { Device device = Ebean.find(Device.class).where().eq("friendlyname", name).findUnique(); if (device == null) { LOGGER.error("Device not found: " + name); return; } if (value == 255) messaging.broadcast("event.devices.setvalue", new GenericAdvertisement("DeviceOn", device.getUuid())); else messaging.broadcast("event.devices.setvalue", new GenericAdvertisement("DeviceOff", device.getUuid())); } }