Skip to content

Commit

Permalink
Add Air Conditioning device category (#1718)
Browse files Browse the repository at this point in the history
  • Loading branch information
euguuu authored Mar 31, 2023
1 parent 27eba3d commit 772a96d
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 6 deletions.
5 changes: 4 additions & 1 deletion front/src/components/boxs/device-in-room/DeviceRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import MultiLevelDeviceFeature from './device-features/MultiLevelDeviceFeature';
import NumberDeviceFeature from './device-features/NumberDeviceFeature';
import CoverDeviceFeature from './device-features/CoverDeviceFeature';
import ThermostatDeviceFeature from './device-features/ThermostatDeviceFeature';
import AirConditioningModeDeviceFeature from './device-features/AirConditioningModeDeviceFeature';

const ROW_TYPE_BY_FEATURE_TYPE = {
[DEVICE_FEATURE_TYPES.LIGHT.BINARY]: BinaryDeviceFeature,
Expand All @@ -22,7 +23,9 @@ const ROW_TYPE_BY_FEATURE_TYPE = {
[DEVICE_FEATURE_TYPES.SHUTTER.POSITION]: MultiLevelDeviceFeature,
[DEVICE_FEATURE_TYPES.CURTAIN.STATE]: CoverDeviceFeature,
[DEVICE_FEATURE_TYPES.CURTAIN.POSITION]: MultiLevelDeviceFeature,
[DEVICE_FEATURE_TYPES.THERMOSTAT.TARGET_TEMPERATURE]: ThermostatDeviceFeature
[DEVICE_FEATURE_TYPES.THERMOSTAT.TARGET_TEMPERATURE]: ThermostatDeviceFeature,
[DEVICE_FEATURE_TYPES.AIR_CONDITIONING.MODE]: AirConditioningModeDeviceFeature,
[DEVICE_FEATURE_TYPES.AIR_CONDITIONING.TARGET_TEMPERATURE]: ThermostatDeviceFeature
};

const DeviceRow = ({ children, ...props }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const SUPPORTED_FEATURE_TYPES = [
DEVICE_FEATURE_TYPES.TELEVISION.VOLUME,
DEVICE_FEATURE_TYPES.SHUTTER.POSITION,
DEVICE_FEATURE_TYPES.SHUTTER.STATE,
DEVICE_FEATURE_TYPES.THERMOSTAT.TARGET_TEMPERATURE
DEVICE_FEATURE_TYPES.THERMOSTAT.TARGET_TEMPERATURE,
DEVICE_FEATURE_TYPES.AIR_CONDITIONING.MODE,
DEVICE_FEATURE_TYPES.AIR_CONDITIONING.TARGET_TEMPERATURE
];

@connect('httpClient', {})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import get from 'get-value';
import { Text } from 'preact-i18n';
import cx from 'classnames';

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

const AirConditioningModeDeviceFeature = ({ 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 auto() {
updateValue(AC_MODE.AUTO);
}

function cooling() {
updateValue(AC_MODE.COOLING);
}

function heating() {
updateValue(AC_MODE.HEATING);
}

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={cx('btn btn-sm btn-secondary', {
active: lastValue === AC_MODE.AUTO
})}
onClick={auto}
>
<Text id={`deviceFeatureAction.category.${category}.${type}.auto`} plural={AC_MODE.HEATING} />
</button>
<button
class={cx('btn btn-sm btn-secondary', {
active: lastValue === AC_MODE.COOLING
})}
onClick={cooling}
>
<Text id={`deviceFeatureAction.category.${category}.${type}.cooling`} plural={AC_MODE.HEATING} />
</button>
<button
class={cx('btn btn-sm', 'btn-secondary', {
active: lastValue === AC_MODE.HEATING
})}
onClick={heating}
>
<Text id={`deviceFeatureAction.category.${category}.${type}.heating`} plural={AC_MODE.HEATING} />
</button>
</div>
</div>
</td>
</tr>
);
};

export default AirConditioningModeDeviceFeature;
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import cx from 'classnames';

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

import style from './style.css';

const isNullOrUndefined = val => val === null || val === undefined;
const DEFAULT_TEMPERATURE_IN_CASE_EMPTY = 18;

const ThermostatDeviceFeature = ({ children, ...props }) => {
const TEMPERATURE_STEP = props.deviceFeature.category == DEVICE_FEATURE_CATEGORIES.AIR_CONDITIONING ? 1 : 0.5;

function updateValue(value) {
props.updateValueWithDebounce(
props.x,
Expand All @@ -32,14 +35,14 @@ const ThermostatDeviceFeature = ({ children, ...props }) => {
const prevValue = isNullOrUndefined(props.deviceFeature.last_value)
? DEFAULT_TEMPERATURE_IN_CASE_EMPTY
: props.deviceFeature.last_value;
updateValue(prevValue + 0.5);
updateValue(prevValue + TEMPERATURE_STEP);
}

function substract() {
const prevValue = isNullOrUndefined(props.deviceFeature.last_value)
? DEFAULT_TEMPERATURE_IN_CASE_EMPTY
: props.deviceFeature.last_value;
updateValue(prevValue - 0.5);
updateValue(prevValue - TEMPERATURE_STEP);
}

return (
Expand Down Expand Up @@ -69,7 +72,7 @@ const ThermostatDeviceFeature = ({ children, ...props }) => {
value={props.deviceFeature.last_value}
class={cx('form-control text-center', style.removeNumberArrow)}
onChange={updateValueEvent}
step={0.5}
step={TEMPERATURE_STEP}
min={props.deviceFeature.min}
max={props.deviceFeature.max}
/>
Expand All @@ -92,7 +95,7 @@ const ThermostatDeviceFeature = ({ children, ...props }) => {
value={props.deviceFeature.last_value}
class={cx('form-control text-center input-sm', style.removeNumberArrow)}
onChange={updateValueEvent}
step={0.5}
step={TEMPERATURE_STEP}
min={props.deviceFeature.min}
max={props.deviceFeature.max}
/>
Expand Down
42 changes: 42 additions & 0 deletions front/src/config/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const data = {
'main-tv-channel',
'main-presence-sensor',
'main-signal-sensor',
'air-conditioning',
'button-click'
]
}
Expand Down Expand Up @@ -486,6 +487,47 @@ const data = {
last_value_changed: '2019-02-12 07:49:07.556 +00:00'
}
]
},
{
id: 'db3e81b6-00d4-4f9b-8aa6-0e50e719a729',
name: 'AC Conditioning',
selector: 'air-conditioning',
features: [
{
name: 'AC Conditioning',
selector: 'air-conditioning',
category: 'air-conditioning',
type: 'binary',
min: 0,
max: 1,
read_only: false,
last_value: 1,
last_value_changed: '2022-10-10 07:49:07.556 +00:00'
},
{
name: 'AC Conditioning',
selector: 'air-conditioning',
category: 'air-conditioning',
type: 'mode',
min: 0,
max: 2,
read_only: false,
last_value: 1,
last_value_changed: '2022-10-10 07:49:07.556 +00:00'
},
{
name: 'AC Conditioning',
selector: 'air-conditioning',
category: 'air-conditioning',
type: 'target-temperature',
min: 0,
max: 30,
read_only: false,
last_value: 24,
last_value_changed: '2022-10-10 07:49:07.556 +00:00',
unit: 'celsius'
}
]
}
]
},
Expand Down
13 changes: 13 additions & 0 deletions front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,13 @@
"one": "Open",
"other": "Close"
}
},
"air-conditioning": {
"mode": {
"auto": "Auto",
"cooling": "Cool",
"heating": "Heat"
}
}
}
},
Expand Down Expand Up @@ -2057,6 +2064,12 @@
"shortCategoryName": "Signal",
"integer": "Signal strength"
},
"air-conditioning": {
"shortCategoryName": "Air Conditioning",
"binary": "Switch (On/Off)",
"mode": "Mode",
"target-temperature": "Temperature"
},
"television": {
"shortCategoryName": "Television",
"binary": "Power",
Expand Down
13 changes: 13 additions & 0 deletions front/src/config/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,13 @@
"one": "Ouvrir",
"other": "Fermer"
}
},
"air-conditioning": {
"mode": {
"auto": "Auto",
"cooling": "Clim.",
"heating": "Chauffage"
}
}
}
},
Expand Down Expand Up @@ -2057,6 +2064,12 @@
"shortCategoryName": "Signal",
"integer": "Intensité du signal"
},
"air-conditioning": {
"shortCategoryName": "Climatisation",
"binary": "Commutateur",
"mode": "Mode",
"target-temperature": "Température"
},
"television": {
"shortCategoryName": "Télévision",
"binary": "Power",
Expand Down
5 changes: 5 additions & 0 deletions front/src/utils/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ export const DeviceFeatureCategoriesIcon = {
[DEVICE_FEATURE_TYPES.SWITCH.VOLTAGE]: 'zap',
[DEVICE_FEATURE_TYPES.SWITCH.DIMMER]: 'bar-chart-2'
},
[DEVICE_FEATURE_CATEGORIES.AIR_CONDITIONING]: {
[DEVICE_FEATURE_TYPES.AIR_CONDITIONING.BINARY]: 'power',
[DEVICE_FEATURE_TYPES.AIR_CONDITIONING.MODE]: 'settings',
[DEVICE_FEATURE_TYPES.AIR_CONDITIONING.TARGET_TEMPERATURE]: 'thermometer'
},
[DEVICE_FEATURE_CATEGORIES.TELEVISION]: {
[DEVICE_FEATURE_TYPES.TELEVISION.BINARY]: 'power',
[DEVICE_FEATURE_TYPES.TELEVISION.SOURCE]: 'airplay',
Expand Down
13 changes: 13 additions & 0 deletions server/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ const COVER_STATE = {
CLOSE: -1,
};

const AC_MODE = {
AUTO: 0,
COOLING: 1,
HEATING: 2,
};

const USER_ROLE = {
ADMIN: 'admin',
HABITANT: 'habitant',
Expand Down Expand Up @@ -317,6 +323,7 @@ const INTENTS = {
const DEVICE_FEATURE_CATEGORIES = {
ACCESS_CONTROL: 'access-control',
AIRQUALITY_SENSOR: 'airquality-sensor',
AIR_CONDITIONING: 'air-conditioning',
BATTERY: 'battery',
BUTTON: 'button',
CAMERA: 'camera',
Expand Down Expand Up @@ -418,6 +425,11 @@ const DEVICE_FEATURE_TYPES = {
SIGNAL: {
QUALITY: 'integer',
},
AIR_CONDITIONING: {
BINARY: 'binary',
MODE: 'mode',
TARGET_TEMPERATURE: 'target-temperature',
},
TELEVISION: {
BINARY: 'binary',
SOURCE: 'source',
Expand Down Expand Up @@ -886,6 +898,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.AC_MODE = AC_MODE;
module.exports.EVENTS = EVENTS;
module.exports.LIFE_EVENTS = LIFE_EVENTS;
module.exports.STATES = STATES;
Expand Down

0 comments on commit 772a96d

Please sign in to comment.