Fixed exceptions and color selection

This commit is contained in:
Ziver Koc 2023-10-04 23:32:24 +02:00
parent 54a9fcedf8
commit 8a5267b0f8
6 changed files with 1974 additions and 11 deletions

View file

@ -24,9 +24,7 @@ package se.hal.struct.devicedata;
import se.hal.intf.HalEventData;
import zutil.ColorUtil;
import zutil.converter.Converter;
import java.awt.*;
import java.awt.color.ColorSpace;
/**
@ -96,10 +94,6 @@ public class ColorEventData extends HalEventData {
return ColorUtil.getLightness(red, green, blue);
}
public float[] getCieXYZ() {
return cieXYZ.fromRGB(new float[]{red, green, blue});
}
public String getHex() {
return ColorUtil.getHexString(red, green, blue);
}

View file

@ -6,9 +6,11 @@ import com.zsmartsystems.zigbee.zcl.ZclCluster;
import com.zsmartsystems.zigbee.zcl.ZclCommand;
import com.zsmartsystems.zigbee.zcl.clusters.ZclColorControlCluster;
import com.zsmartsystems.zigbee.zcl.clusters.colorcontrol.MoveToColorCommand;
import com.zsmartsystems.zigbee.zcl.clusters.colorcontrol.MoveToHueAndSaturationCommand;
import se.hal.intf.HalDeviceData;
import se.hal.intf.HalEventConfig;
import se.hal.intf.HalEventData;
import se.hal.plugin.zigbee.util.Cie;
import se.hal.struct.devicedata.ColorEventData;
import zutil.log.LogUtil;
@ -32,9 +34,11 @@ public class ZigbeeColorConfig extends ZigbeeHalEventDeviceConfig implements Hal
try {
ZclAttribute attribute = cluster.getAttribute(ZclColorControlCluster.ATTR_CURRENTHUE);
//attribute.setReporting(1, 900).get();
attribute.readValue(60);
attribute = cluster.getAttribute(ZclColorControlCluster.ATTR_CURRENTSATURATION);
//attribute.setReporting(1, 900).get();
attribute.readValue(60);
} catch (Exception e) {
logger.log(Level.WARNING, "Was unable to initialize cluster reporting rate.", e);
@ -67,8 +71,23 @@ public class ZigbeeColorConfig extends ZigbeeHalEventDeviceConfig implements Hal
if (! (data instanceof ColorEventData))
return null;
float[] cieXYZ = ((ColorEventData) data).getCieXYZ();
return new MoveToColorCommand((int) (cieXYZ[0] * 65536), (int) (cieXYZ[2] * 65536), 1);
//float[] cie = ((ColorEventData) data).getCieXYZ();
//int x = (int) (cie[0] * 65536);
//int y = (int) (cie[1] * 65536);
Cie cie = Cie.rgb2cie(((ColorEventData) data).getRed(), ((ColorEventData) data).getGreen(), ((ColorEventData) data).getBlue());
int x = (int) (cie.x * 65536);
int y = (int) (cie.y * 65536);
if (x > 65279)
x = 65279;
if (y > 65279)
y = 65279;
return new MoveToColorCommand(x, y, 10);
//double hue = ((ColorEventData) data).getHue() * 254.0f / 360.0f + 0.5f;
//double saturation = ((ColorEventData) data).getSaturation() * 256;
//return new MoveToHueAndSaturationCommand((int) hue, (int) saturation, 1);
}
// --------------------------

View file

@ -32,7 +32,7 @@ public class ZigbeeLevelConfig extends ZigbeeHalEventDeviceConfig implements Hal
try {
ZclAttribute attribute = cluster.getAttribute(ZclLevelControlCluster.ATTR_CURRENTLEVEL);
attribute.setReporting(1, 900).get();
//attribute.setReporting(1, 900).get();
attribute.readValue(60);
} catch (Exception e) {
logger.log(Level.WARNING, "Was unable to initialize cluster reporting rate.", e);

View file

@ -30,7 +30,7 @@ public class ZigbeeOccupancyConfig extends ZigbeeHalEventDeviceConfig implements
try {
ZclAttribute attribute = cluster.getAttribute(ZclOccupancySensingCluster.ATTR_OCCUPANCY);
attribute.setReporting(1, 900).get();
//attribute.setReporting(1, 900).get();
attribute.readValue(60);
} catch (Exception e) {
logger.log(Level.WARNING, "Was unable to initialize cluster reporting rate.", e);

View file

@ -33,7 +33,7 @@ public class ZigbeeOnOffConfig extends ZigbeeHalEventDeviceConfig implements Hal
try {
ZclAttribute attribute = cluster.getAttribute(ZclOnOffCluster.ATTR_ONOFF);
attribute.setReporting(1, 900).get();
//attribute.setReporting(1, 900).get();
attribute.readValue(60);
} catch (Exception e) {
logger.log(Level.WARNING, "Was unable to initialize cluster reporting rate.", e);

File diff suppressed because it is too large Load diff