Skip to content

Commit

Permalink
Shutter/curtain device
Browse files Browse the repository at this point in the history
  • Loading branch information
atrovato committed Jul 31, 2022
1 parent f262ea1 commit 8dc7103
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 1 deletion.
7 changes: 6 additions & 1 deletion front/src/components/boxs/device-in-room/DeviceRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import SensorDeviceFeature from './device-features/sensor-value/SensorDeviceFeat
import LightTemperatureDeviceFeature from './device-features/LightTemperatureDeviceFeature';
import MultiLevelDeviceFeature from './device-features/MultiLevelDeviceFeature';
import NumberDeviceFeature from './device-features/NumberDeviceFeature';
import CoverDeviceFeature from './device-features/CoverDeviceFeature';

const ROW_TYPE_BY_FEATURE_TYPE = {
[DEVICE_FEATURE_TYPES.LIGHT.BINARY]: BinaryDeviceFeature,
Expand All @@ -15,7 +16,11 @@ const ROW_TYPE_BY_FEATURE_TYPE = {
[DEVICE_FEATURE_TYPES.LIGHT.BRIGHTNESS]: MultiLevelDeviceFeature,
[DEVICE_FEATURE_TYPES.LIGHT.TEMPERATURE]: LightTemperatureDeviceFeature,
[DEVICE_FEATURE_TYPES.TELEVISION.CHANNEL]: NumberDeviceFeature,
[DEVICE_FEATURE_TYPES.TELEVISION.VOLUME]: MultiLevelDeviceFeature
[DEVICE_FEATURE_TYPES.TELEVISION.VOLUME]: MultiLevelDeviceFeature,
[DEVICE_FEATURE_TYPES.SHUTTER.STATE]: CoverDeviceFeature,
[DEVICE_FEATURE_TYPES.SHUTTER.POSITION]: MultiLevelDeviceFeature,
[DEVICE_FEATURE_TYPES.CURTAIN.STATE]: CoverDeviceFeature,
[DEVICE_FEATURE_TYPES.CURTAIN.POSITION]: MultiLevelDeviceFeature
};

const DeviceRow = ({ children, ...props }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import get from 'get-value';
import { Text } from 'preact-i18n';

import { getDeviceName } from './utils';
import { DeviceFeatureCategoriesIcon } from '../../../../utils/consts';
import { COVER_STATE } from '../../../../../../server/utils/constants';

const UpDownDeviceFeature = ({ children, ...props }) => {
const { device, deviceFeature } = props;
const { category, type, last_value: lastValue } = deviceFeature;

function updateValue(value) {
props.updateValueWithDebounce(
props.x,
props.y,
device,
deviceFeature,
props.deviceIndex,
props.deviceFeatureIndex,
value,
lastValue
);
}

function open() {
updateValue(COVER_STATE.OPEN);
}

function close() {
updateValue(COVER_STATE.CLOSE);
}

function stop() {
updateValue(COVER_STATE.STOP);
}

return (
<tr>
<td>
<i class={`fe fe-${get(DeviceFeatureCategoriesIcon, `${category}.${type}`, { default: 'sliders' })}`} />
</td>
<td>{getDeviceName(device, deviceFeature)}</td>

<td class="py-0">
<div class="d-flex justify-content-end">
<div class="btn-group" role="group">
<button class="btn btn-sm btn-secondary" onClick={open}>
<Text id={`deviceFeatureAction.category.${category}.${type}`} plural={COVER_STATE.OPEN} />
</button>
<button class="btn btn-sm btn-secondary fe fe-pause" onClick={stop} />
<button class="btn btn-sm btn-secondary" onClick={close}>
<Text id={`deviceFeatureAction.category.${category}.${type}`} plural={COVER_STATE.CLOSE} />
</button>
</div>
</div>
</td>
</tr>
);
};

export default UpDownDeviceFeature;
71 changes: 71 additions & 0 deletions front/src/config/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ const data = {
},
{
type: 'user-presence'
},
{
type: 'devices-in-room',
room: 'parental-room',
device_features: ['curtain-actions', 'shutter-actions', 'shutter-position']
}
]
],
Expand Down Expand Up @@ -456,6 +461,72 @@ const data = {
}
]
},
'get /api/v1/room/parental-room?expand=devices': {
id: '1c634ff4-0476-4733-a084-b4a43d649c84',
name: 'Parental Room',
selector: 'parental-room',
devices: [
{
id: 'cb3b1a30-d1b6-4624-ac18-e581e3e3b00f',
name: 'Main curtain',
selector: 'main-curtain',
features: [
{
name: 'Curtain',
selector: 'curtain-actions',
category: 'curtain',
type: 'state',
min: -1,
max: 1,
read_only: false,
last_value: 1,
last_value_changed: '2019-02-12 07:49:07.556 +00:00'
},
{
name: 'Curtain',
selector: 'curtain-position',
category: 'curtain',
type: 'position',
min: 0,
max: 100,
read_only: true,
last_value: 30,
last_value_changed: '2019-02-12 07:49:07.556 +00:00'
}
]
},
{
id: '919be7a4-df47-4726-b1c0-7412aed99769',
name: 'Main shutter',
selector: 'main-shutter',
features: [
{
name: 'Shutter',
selector: 'shutter-actions',
category: 'shutter',
type: 'state',
min: -1,
max: 1,
read_only: false,
last_value: 1,
last_value_changed: '2019-02-12 07:49:07.556 +00:00'
},
{
name: 'Shutter position',
selector: 'shutter-position',
category: 'shutter',
type: 'position',
min: 0,
max: 100,
read_only: true,
last_value: 30,
last_value_changed: '2019-02-12 07:49:07.556 +00:00',
unit: 'percent'
}
]
}
]
},
'get /api/v1/room/kitchen?expand=devices': {
id: 'be6ba391-ebb3-472d-81af-d75d710a8430',
name: 'Kitchen',
Expand Down
28 changes: 28 additions & 0 deletions front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,24 @@
"months": "m",
"years": "y"
},
"deviceFeatureAction": {
"category": {
"shutter": {
"state": {
"zero": "Stop",
"one": "Open",
"other": "Close"
}
},
"curtain": {
"state": {
"zero": "Stop",
"one": "Open",
"other": "Close"
}
}
}
},
"deviceFeatureValue": {
"type": {
"binary": {
Expand Down Expand Up @@ -1879,6 +1897,16 @@
"decimal": "Duration (decimal)",
"integer": "Duration (integer)"
},
"shutter": {
"shortCategoryName": "Shutter",
"state": "State",
"position": "Position"
},
"curtain": {
"shortCategoryName": "Curtain",
"state": "State",
"position": "Position"
},
"unknown": {
"shortCategoryName": "Unknown",
"unknown": "Unknown"
Expand Down
28 changes: 28 additions & 0 deletions front/src/config/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,24 @@
"months": "m",
"years": "an"
},
"deviceFeatureAction": {
"category": {
"shutter": {
"state": {
"zero": "Arrêter",
"one": "Ouvrir",
"other": "Fermer"
}
},
"curtain": {
"state": {
"zero": "Arrêter",
"one": "Ouvrir",
"other": "Fermer"
}
}
}
},
"deviceFeatureValue": {
"type": {
"binary": {
Expand Down Expand Up @@ -1879,6 +1897,16 @@
"decimal": "Durée (décimale)",
"integer": "Durée (entier)"
},
"shutter": {
"shortCategoryName": "Volet",
"state": "Etat",
"position": "Position"
},
"curtain": {
"shortCategoryName": "Rideau",
"state": "Etat",
"position": "Position"
},
"unknown": {
"shortCategoryName": "Inconnu",
"unknown": "Inconnu"
Expand Down
8 changes: 8 additions & 0 deletions front/src/utils/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ export const DeviceFeatureCategoriesIcon = {
[DEVICE_FEATURE_TYPES.TELEVISION.FORWARD]: 'fast-forward',
[DEVICE_FEATURE_TYPES.TELEVISION.RECORD]: 'circle'
},
[DEVICE_FEATURE_CATEGORIES.SHUTTER]: {
[DEVICE_FEATURE_TYPES.SHUTTER.STATE]: 'sliders',
[DEVICE_FEATURE_TYPES.SHUTTER.POSITION]: 'sliders'
},
[DEVICE_FEATURE_CATEGORIES.CURTAIN]: {
[DEVICE_FEATURE_TYPES.CURTAIN.STATE]: 'sliders',
[DEVICE_FEATURE_TYPES.CURTAIN.POSITION]: 'sliders'
},
[DEVICE_FEATURE_CATEGORIES.SMOKE_SENSOR]: {
[DEVICE_FEATURE_TYPES.SENSOR.BINARY]: 'wind',
[DEVICE_FEATURE_TYPES.SENSOR.DECIMAL]: 'wind'
Expand Down
17 changes: 17 additions & 0 deletions server/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ const BUTTON_STATUS = {
LONG_CLICK: 6,
};

const COVER_STATE = {
STOP: 0,
OPEN: 1,
CLOSE: -1,
};

const USER_ROLE = {
ADMIN: 'admin',
HABITANT: 'habitant',
Expand Down Expand Up @@ -332,6 +338,8 @@ const DEVICE_FEATURE_CATEGORIES = {
PRECIPITATION_SENSOR: 'precipitation-sensor',
UV_SENSOR: 'uv-sensor',
DURATION: 'duration',
SHUTTER: 'shutter',
CURTAIN: 'curtain',
UNKNOWN: 'unknown',
};

Expand Down Expand Up @@ -451,6 +459,14 @@ const DEVICE_FEATURE_TYPES = {
DECIMAL: 'decimal',
INTEGER: 'integer',
},
SHUTTER: {
STATE: 'state',
POSITION: 'position',
},
CURTAIN: {
STATE: 'state',
POSITION: 'position',
},
UNKNOWN: {
UNKNOWN: 'unknown',
},
Expand Down Expand Up @@ -784,6 +800,7 @@ const JOB_ERROR_TYPES_LIST = createList(JOB_ERROR_TYPES);

module.exports.STATE = STATE;
module.exports.BUTTON_STATUS = BUTTON_STATUS;
module.exports.COVER_STATE = COVER_STATE;
module.exports.EVENTS = EVENTS;
module.exports.LIFE_EVENTS = LIFE_EVENTS;
module.exports.STATES = STATES;
Expand Down

0 comments on commit 8dc7103

Please sign in to comment.