Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
Improvements on Blukii support (#5295)
Browse files Browse the repository at this point in the history
- switched to UoM support
- removed "switch" channel as updates are too slow
- removed todo for magnetic values (fixes #5257)

Signed-off-by: Kai Kreuzer <kai@openhab.org>
  • Loading branch information
kaikreuzer authored and maggu2810 committed Mar 22, 2018
1 parent 771b049 commit 1169ef7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 36 deletions.
Expand Up @@ -24,8 +24,6 @@
<channel id="tiltx" typeId="blukii_tiltx" />
<channel id="tilty" typeId="blukii_tilty" />
<channel id="tiltz" typeId="blukii_tiltz" />

<channel id="switch" typeId="blukii_switch" />
</channels>

<config-description>
Expand All @@ -38,51 +36,45 @@
</thing-type>

<channel-type id="blukii_temperature">
<item-type>Number</item-type>
<item-type>Number:Temperature</item-type>
<label>Temperature</label>
<state readOnly="true" pattern="%.1f °C" />
<state readOnly="true" pattern="%.1f %unit%" />
</channel-type>

<channel-type id="blukii_humidity">
<item-type>Number</item-type>
<item-type>Number:Dimensionless</item-type>
<label>Humidity</label>
<state readOnly="true" pattern="%d %%" />
<state readOnly="true" pattern="%d %unit%" />
</channel-type>

<channel-type id="blukii_pressure">
<item-type>Number</item-type>
<item-type>Number:Pressure</item-type>
<label>Pressure</label>
<state readOnly="true" pattern="%.0f hPa" />
<state readOnly="true" pattern="%.0f %unit%" />
</channel-type>

<channel-type id="blukii_luminance">
<item-type>Number</item-type>
<item-type>Number:Illuminance</item-type>
<label>Luminance</label>
<state readOnly="true" pattern="%d lx" />
</channel-type>

<channel-type id="blukii_switch">
<item-type>Switch</item-type>
<label>Switch</label>
<state readOnly="true" />
<state readOnly="true" pattern="%d %unit%" />
</channel-type>

<channel-type id="blukii_tiltx" advanced="true">
<item-type>Number</item-type>
<item-type>Number:Angle</item-type>
<label>Tilt X</label>
<state readOnly="true" pattern="%.0f°" />
<state readOnly="true" pattern="%.0f %unit%" />
</channel-type>

<channel-type id="blukii_tilty" advanced="true">
<item-type>Number</item-type>
<item-type>Number:Angle</item-type>
<label>Tilt Y</label>
<state readOnly="true" pattern="%.0f°" />
<state readOnly="true" pattern="%.0f %unit%" />
</channel-type>

<channel-type id="blukii_tiltz" advanced="true">
<item-type>Number</item-type>
<item-type>Number:Angle</item-type>
<label>Tilt Z</label>
<state readOnly="true" pattern="%.0f°" />
<state readOnly="true" pattern="%.0f %unit%" />
</channel-type>

</thing:thing-descriptions>
Expand Up @@ -7,6 +7,8 @@ Bundle-Version: 0.10.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ClassPath: .
Import-Package:
javax.measure,
javax.measure.quantity,
org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.binding.bluetooth,
org.eclipse.smarthome.binding.bluetooth.discovery,
Expand All @@ -15,6 +17,7 @@ Import-Package:
org.eclipse.smarthome.config.discovery,
org.eclipse.smarthome.core.common.registry,
org.eclipse.smarthome.core.library.types,
org.eclipse.smarthome.core.library.unit,
org.eclipse.smarthome.core.thing,
org.eclipse.smarthome.core.thing.binding,
org.eclipse.smarthome.core.thing.binding.builder,
Expand Down
Expand Up @@ -39,7 +39,4 @@ public class BlukiiBindingConstants {
public static final String CHANNEL_ID_TILTX = "tiltx";
public static final String CHANNEL_ID_TILTY = "tilty";
public static final String CHANNEL_ID_TILTZ = "tiltz";

public static final String CHANNEL_ID_SWITCH = "switch";

}
Expand Up @@ -12,12 +12,21 @@
*/
package org.eclipse.smarthome.binding.bluetooth.blukii.handler;

import javax.measure.quantity.Angle;
import javax.measure.quantity.Dimensionless;
import javax.measure.quantity.Illuminance;
import javax.measure.quantity.Pressure;
import javax.measure.quantity.Temperature;

import org.eclipse.smarthome.binding.bluetooth.BeaconBluetoothHandler;
import org.eclipse.smarthome.binding.bluetooth.BluetoothDeviceListener;
import org.eclipse.smarthome.binding.bluetooth.blukii.BlukiiBindingConstants;
import org.eclipse.smarthome.binding.bluetooth.notification.BluetoothScanNotification;
import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.QuantityType;
import org.eclipse.smarthome.core.library.unit.MetricPrefix;
import org.eclipse.smarthome.core.library.unit.SIUnits;
import org.eclipse.smarthome.core.library.unit.SmartHomeUnits;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.util.HexUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -63,10 +72,14 @@ private void processEnvironmentData(byte[] data) {
int humidity = data[19] & 0xFF;
double temperature = (data[20] & 0xFF) + (data[21] & 0xFF) / 100000000;

updateState(BlukiiBindingConstants.CHANNEL_ID_TEMPERATURE, new DecimalType(temperature));
updateState(BlukiiBindingConstants.CHANNEL_ID_HUMIDITY, new DecimalType(humidity));
updateState(BlukiiBindingConstants.CHANNEL_ID_PRESSURE, new DecimalType(pressure));
updateState(BlukiiBindingConstants.CHANNEL_ID_LUMINANCE, new DecimalType(luminance));
updateState(BlukiiBindingConstants.CHANNEL_ID_TEMPERATURE,
new QuantityType<Temperature>(temperature, SIUnits.CELSIUS));
updateState(BlukiiBindingConstants.CHANNEL_ID_HUMIDITY,
new QuantityType<Dimensionless>(humidity, SmartHomeUnits.PERCENT));
updateState(BlukiiBindingConstants.CHANNEL_ID_PRESSURE,
new QuantityType<Pressure>(pressure, MetricPrefix.HECTO(SIUnits.PASCAL)));
updateState(BlukiiBindingConstants.CHANNEL_ID_LUMINANCE,
new QuantityType<Illuminance>(luminance, SmartHomeUnits.LUX));
}

private void processAccelerometerData(byte[] data) {
Expand All @@ -79,11 +92,12 @@ private void processAccelerometerData(byte[] data) {
double tiltY = 180 * Math.acos(y / Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2))) / Math.PI;
double tiltZ = 180 * Math.acos(z / Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2))) / Math.PI;

updateState(BlukiiBindingConstants.CHANNEL_ID_TILTX, new DecimalType(tiltX));
updateState(BlukiiBindingConstants.CHANNEL_ID_TILTY, new DecimalType(tiltY));
updateState(BlukiiBindingConstants.CHANNEL_ID_TILTZ, new DecimalType(tiltZ));

updateState(BlukiiBindingConstants.CHANNEL_ID_SWITCH, z > 0 ? OnOffType.ON : OnOffType.OFF);
updateState(BlukiiBindingConstants.CHANNEL_ID_TILTX,
new QuantityType<Angle>(tiltX, SmartHomeUnits.DEGREE_ANGLE));
updateState(BlukiiBindingConstants.CHANNEL_ID_TILTY,
new QuantityType<Angle>(tiltY, SmartHomeUnits.DEGREE_ANGLE));
updateState(BlukiiBindingConstants.CHANNEL_ID_TILTZ,
new QuantityType<Angle>(tiltZ, SmartHomeUnits.DEGREE_ANGLE));
}

@SuppressWarnings("unused")
Expand All @@ -92,7 +106,7 @@ private void processMagnetometerData(byte[] data) {
int y = (short) doubleByteToInt(data[18], data[19]);
int z = (short) doubleByteToInt(data[20], data[21]);

// future TODO: what kind of channel/feature should we offer with those values?
// It isn't easy to get a heading from these values without any calibration, so we ignore those right now.
}

private int doubleByteToInt(byte b1, byte b2) {
Expand Down

0 comments on commit 1169ef7

Please sign in to comment.