Skip to content

Commit

Permalink
Bluetooth service: usage of shared device consts
Browse files Browse the repository at this point in the history
  • Loading branch information
atrovato committed Oct 31, 2019
1 parent ace6759 commit 58d67a9
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 80 deletions.
99 changes: 70 additions & 29 deletions front/src/config/demo.json
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,11 @@
]
}
],
"get /api/v1/service/bluetooth": {
"id": "fbedb47f-4d25-4381-8923-2633b23192a0",
"name": "bluetooth",
"enabled": true
},
"get /api/v1/service/bluetooth/device": [
{
"id": "fbedb47f-4d25-4381-8923-2633b23192a0",
Expand Down Expand Up @@ -1174,33 +1179,69 @@
"awox": ["smlw", "smlc"],
"nut": ["tracker"]
},
"get /api/v1/service/bluetooth/brand/awox/smlw": [
{
"category": "light",
"type": "binary",
"unit": "",
"min": 0,
"max": 1,
"read_only": false
}
],
"get /api/v1/service/bluetooth/brand/awox/smlc": [
{
"category": "light",
"type": "binary",
"unit": "",
"min": 0,
"max": 1,
"read_only": false
}
],
"get /api/v1/service/bluetooth/brand/nut/tracker": [
{
"category": "battery",
"unit": "%",
"min": 0,
"max": 100,
"read_only": true
}
]
"get /api/v1/service/bluetooth/brand/awox/smlw": {
"features": [
{
"category": "light",
"type": "binary",
"unit": "",
"min": 0,
"max": 1,
"read_only": false,
"has_feedback": true
},
{
"category": "light",
"type": "brightness",
"unit": "",
"min": 0,
"max": 100,
"read_only": false,
"has_feedback": true
}
]
},
"get /api/v1/service/bluetooth/brand/awox/smlc": {
"features": [
{
"category": "light",
"type": "binary",
"unit": "",
"min": 0,
"max": 1,
"read_only": false,
"has_feedback": true
},
{
"category": "light",
"type": "brightness",
"unit": "",
"min": 0,
"max": 100,
"read_only": false,
"has_feedback": true
},
{
"category": "light",
"type": "hue",
"unit": "",
"min": 0,
"max": 100,
"read_only": false,
"has_feedback": true
}
]
},
"get /api/v1/service/bluetooth/brand/nut/tracker": {
"features": [
{
"category": "battery",
"type": "integer",
"unit": "%",
"min": 0,
"max": 100,
"read_only": true
}
]
}
}
2 changes: 1 addition & 1 deletion front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@
"namePlaceholder": "Enter device name",
"roomLabel": "Room",
"featuresLabel": "Features",
"featureNamePlaceholder": "Enter feature name for \"{{type}}\" : default is \"{{name}}\"",
"featureNamePlaceholder": "Enter feature name",
"saveButton": "Save",
"deleteButton": "Delete",
"configParam": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ class BluetoothDeviceBox extends Component {
props.device.features &&
props.device.features.map(feature => (
<span class="tag">
<Text id={`deviceFeatureCategory.${feature.category}`} />
<Text id={`deviceFeatureCategory.${feature.category}.${feature.type}`} />
<div class="tag-addon">
<i class={`fe fe-${DeviceFeatureCategoriesIcon[feature.category]}`} />
<i
class={`fe fe-${get(DeviceFeatureCategoriesIcon, `${feature.category}.${feature.type}`)}`}
/>
</div>
</span>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ const createActions = store => {

device.service_id = currentIntegration.id;
device.features.forEach(feature => {
feature.name = feature.name ? feature.name : `${device.name} ${feature.type}`;
feature.external_id = `${device.external_id}:${feature.type.replace(' ', '_')}`;
feature.selector = feature.external_id;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Text, Localizer } from 'preact-i18n';
import { connect } from 'unistore/preact';
import { Link } from 'preact-router/match';
import actions from '../actions';
import get from 'get-value';
import { RequestStatus, DeviceFeatureCategoriesIcon } from '../../../../../../utils/consts';
import { WEBSOCKET_MESSAGE_TYPES } from '../../../../../../../../server/utils/constants';
import cx from 'classnames';
Expand Down Expand Up @@ -165,7 +166,7 @@ class ConfigurePeripheral extends Component {

const { device } = this.state;
const features = device.features.slice();
features[index] = e.target.value;
features[index].name = e.target.value;

this.setState({
device: {
Expand Down Expand Up @@ -410,24 +411,25 @@ class ConfigurePeripheral extends Component {
<ul class="tags">
{device.features.map((feature, index) => (
<li class="form-group">
<div class="input-group mb-2">
<div
class={cx('input-group mb-2', {
'was-validated': !feature.name || feature.name.length === 0
})}
>
<div class="input-group-prepend">
<span class="tag input-group-text">
<Text id={`deviceFeatureCategory.${feature.category}`} />
<div class="tag input-group-text">
<Text id={`deviceFeatureCategory.${feature.category}.${feature.type}`} />
<div class="tag-addon">
<i class={`fe fe-${DeviceFeatureCategoriesIcon[feature.category]}`} />
<i
class={`fe fe-${get(DeviceFeatureCategoriesIcon, `${feature.category}.${feature.type}`)}`}
/>
</div>
</span>
</div>
</div>
<Localizer>
<input
class="form-control form-control-sm"
placeholder={
<Text
id="integration.bluetooth.device.featureNamePlaceholder"
fields={{ type: feature.type, name: `${device.name} ${feature.type}` }}
/>
}
placeholder={<Text id="integration.bluetooth.device.featureNamePlaceholder" />}
value={feature.name}
disabled={disableForm}
key={`feature-${index}`}
Expand All @@ -448,7 +450,7 @@ class ConfigurePeripheral extends Component {
disableForm={disableForm}
/>

<div class="row mt-10">
<div class="row mt-5">
<div class="col">
<button
type="submit"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const { isRemote, isMesh } = require('../lib/awox.utils');
const { DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES } = require('../../../../../utils/constants');

module.exports = {
name: 'rcum',
matches: (deviceModel, deviceType) => isRemote(deviceModel) && isMesh(deviceModel),
device: {
features: [
{
category: 'light',
type: 'battery',
category: DEVICE_FEATURE_CATEGORIES.BATTERY,
type: DEVICE_FEATURE_TYPES.SENSOR.INTEGER,
unit: '%',
min: 0,
max: 100,
Expand Down
17 changes: 9 additions & 8 deletions server/services/bluetooth/devices/awox/models/awox.smlc.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
const { isRemote, isMesh, isColor } = require('../lib/awox.utils');
const { DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES } = require('../../../../../utils/constants');

module.exports = {
name: 'smlc',
matches: (deviceModel, deviceType) => !isRemote(deviceModel) && isColor(deviceType) && !isMesh(deviceModel),
device: {
features: [
{
category: 'light',
type: 'binary',
category: DEVICE_FEATURE_CATEGORIES.LIGHT,
type: DEVICE_FEATURE_TYPES.LIGHT.BINARY,
unit: '',
min: 0,
max: 1,
read_only: false,
has_feedback: true,
},
{
category: 'light',
type: 'white temperature',
category: DEVICE_FEATURE_CATEGORIES.LIGHT,
type: DEVICE_FEATURE_TYPES.LIGHT.SATURATION,
unit: '',
min: 0,
max: 100,
read_only: false,
has_feedback: true,
},
{
category: 'light',
type: 'brightness',
category: DEVICE_FEATURE_CATEGORIES.LIGHT,
type: DEVICE_FEATURE_TYPES.LIGHT.BRIGHTNESS,
unit: '',
min: 0,
max: 100,
read_only: false,
has_feedback: true,
},
{
category: 'light',
type: 'color',
category: DEVICE_FEATURE_CATEGORIES.LIGHT,
type: DEVICE_FEATURE_TYPES.LIGHT.HUE,
unit: '',
min: 0,
max: 100,
Expand Down
21 changes: 11 additions & 10 deletions server/services/bluetooth/devices/awox/models/awox.smlc.mesh.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
const { isRemote, isMesh, isColor } = require('../lib/awox.utils');
const { DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES } = require('../../../../../utils/constants');

module.exports = {
name: 'smlcm',
matches: (deviceModel, deviceType) => !isRemote(deviceModel) && isColor(deviceType) && isMesh(deviceModel),
device: {
features: [
{
category: 'light',
type: 'binary',
category: DEVICE_FEATURE_CATEGORIES.LIGHT,
type: DEVICE_FEATURE_TYPES.LIGHT.BINARY,
unit: '',
min: 0,
max: 1,
read_only: false,
has_feedback: true,
},
{
category: 'light',
type: 'white temperature',
category: DEVICE_FEATURE_CATEGORIES.LIGHT,
type: DEVICE_FEATURE_TYPES.LIGHT.SATURATION,
unit: '',
min: 0,
max: 100,
read_only: false,
has_feedback: true,
},
{
category: 'light',
type: 'brightness',
category: DEVICE_FEATURE_CATEGORIES.LIGHT,
type: DEVICE_FEATURE_TYPES.LIGHT.BRIGHTNESS,
unit: '',
min: 0,
max: 100,
read_only: false,
has_feedback: true,
},
{
category: 'light',
type: 'color',
category: DEVICE_FEATURE_CATEGORIES.LIGHT,
type: DEVICE_FEATURE_TYPES.LIGHT.HUE,
unit: '',
min: 0,
max: 100,
read_only: false,
has_feedback: true,
},
{
category: 'light',
type: 'mode',
category: DEVICE_FEATURE_CATEGORIES.UNKNOWN,
type: DEVICE_FEATURE_TYPES.UNKNOWN.UNKNOWN,
unit: '',
min: 0,
max: 3,
Expand Down
13 changes: 7 additions & 6 deletions server/services/bluetooth/devices/awox/models/awox.smlw.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
const { isRemote, isMesh, isWhite } = require('../lib/awox.utils');
const { connectAndSend } = require('../../../lib/utils/connectAndSend');
const { DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES } = require('../../../../../utils/constants');

module.exports = {
name: 'smlw',
matches: (deviceModel, deviceType) => !isRemote(deviceModel) && isWhite(deviceType) && !isMesh(deviceModel),
device: {
features: [
{
category: 'light',
type: 'binary',
category: DEVICE_FEATURE_CATEGORIES.LIGHT,
type: DEVICE_FEATURE_TYPES.LIGHT.BINARY,
unit: '',
min: 0,
max: 1,
read_only: false,
has_feedback: true,
},
{
category: 'light',
type: 'white temperature',
category: DEVICE_FEATURE_CATEGORIES.LIGHT,
type: DEVICE_FEATURE_TYPES.LIGHT.SATURATION,
unit: '',
min: 0,
max: 100,
read_only: false,
has_feedback: true,
},
{
category: 'light',
type: 'brightness',
category: DEVICE_FEATURE_CATEGORIES.LIGHT,
type: DEVICE_FEATURE_TYPES.LIGHT.BRIGHTNESS,
unit: '',
min: 0,
max: 100,
Expand Down
Loading

0 comments on commit 58d67a9

Please sign in to comment.