Skip to content

Commit

Permalink
feat(z2m): Add pilot wire mode
Browse files Browse the repository at this point in the history
  • Loading branch information
cicoub13 committed Aug 7, 2024
1 parent 41755fd commit 5e2ca5d
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 2 deletions.
2 changes: 2 additions & 0 deletions front/src/components/boxs/device-in-room/DeviceRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import NumberDeviceFeature from './device-features/NumberDeviceFeature';
import CoverDeviceFeature from './device-features/CoverDeviceFeature';
import ThermostatDeviceFeature from './device-features/ThermostatDeviceFeature';
import AirConditioningModeDeviceFeature from './device-features/AirConditioningModeDeviceFeature';
import PilotWireModeDeviceFeature from './device-features/PilotWireModeDeviceFeature';
import LMHVolumeDeviceFeature from './device-features/LMHVolumeDeviceFeature';

const ROW_TYPE_BY_FEATURE_TYPE = {
Expand All @@ -29,6 +30,7 @@ const ROW_TYPE_BY_FEATURE_TYPE = {
[DEVICE_FEATURE_TYPES.THERMOSTAT.TARGET_TEMPERATURE]: ThermostatDeviceFeature,
[DEVICE_FEATURE_TYPES.AIR_CONDITIONING.MODE]: AirConditioningModeDeviceFeature,
[DEVICE_FEATURE_TYPES.AIR_CONDITIONING.TARGET_TEMPERATURE]: ThermostatDeviceFeature,
[DEVICE_FEATURE_TYPES.HEATER.PILOT_WIRE_MODE]: PilotWireModeDeviceFeature,
[DEVICE_FEATURE_TYPES.SIREN.LMH_VOLUME]: LMHVolumeDeviceFeature,
[DEVICE_FEATURE_TYPES.SIREN.MELODY]: NumberDeviceFeature,
[DEVICE_FEATURE_TYPES.DURATION.DECIMAL]: MultiLevelDeviceFeature
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import get from 'get-value';
import { Text } from 'preact-i18n';
import cx from 'classnames';

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

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

function updateValue(value) {
props.updateValueWithDebounce(deviceFeature, value);
}

function comfort() {
updateValue(PILOT_WIRE_MODE.COMFORT);
}

function eco() {
updateValue(PILOT_WIRE_MODE.ECO);
}

function frost_protection() {
updateValue(PILOT_WIRE_MODE.FROST_PROTECTION);
}

function off() {
updateValue(PILOT_WIRE_MODE.OFF);
}

return (
<tr>
<td>
<i class={`fe fe-${get(DeviceFeatureCategoriesIcon, `${category}.${type}`, { default: 'sliders' })}`} />
</td>
<td>{props.rowName}</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 === PILOT_WIRE_MODE.COMFORT
})}
onClick={comfort}
>
<Text id={`deviceFeatureAction.category.${category}.${type}.comfort`} plural={PILOT_WIRE_MODE.COMFORT} />
</button>
<button
class={cx('btn btn-sm btn-secondary', {
active: lastValue === PILOT_WIRE_MODE.ECO
})}
onClick={eco}
>
<Text id={`deviceFeatureAction.category.${category}.${type}.eco`} plural={PILOT_WIRE_MODE.ECO} />
</button>
<button
class={cx('btn btn-sm btn-secondary', {
active: lastValue === PILOT_WIRE_MODE.FROST_PROTECTION
})}
onClick={frost_protection}
>
<Text
id={`deviceFeatureAction.category.${category}.${type}.frost_protection`}
plural={PILOT_WIRE_MODE.FROST_PROTECTION}
/>
</button>
<button
class={cx('btn btn-sm', 'btn-secondary', {
active: lastValue === PILOT_WIRE_MODE.OFF
})}
onClick={off}
>
<Text id={`deviceFeatureAction.category.${category}.${type}.off`} plural={PILOT_WIRE_MODE.OFF} />
</button>
</div>
</div>
</td>
</tr>
);
};

export default PilotWireModeDeviceFeature;
21 changes: 19 additions & 2 deletions front/src/config/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ const data = {
'main-presence-sensor',
'main-signal-sensor',
'air-conditioning',
'button-click'
'button-click',
'pilot-wire-mode'
]
}
],
Expand Down Expand Up @@ -2642,7 +2643,7 @@ const data = {
]
}
],
'get /api/v1/device?device_feature_selectors=main-tv-binary,main-tv-volume,main-tv-channel,main-presence-sensor,main-signal-sensor,air-conditioning,button-click': [
'get /api/v1/device?device_feature_selectors=main-tv-binary,main-tv-volume,main-tv-channel,main-presence-sensor,main-signal-sensor,air-conditioning,button-click,pilot-wire-mode': [
{
id: '20deebe6-57df-4940-afd1-11c189a407c2',
name: 'TV',
Expand Down Expand Up @@ -2885,6 +2886,22 @@ const data = {
unit: 'celsius'
}
]
},
{
id: 'db3e81b6-00d4-4f9b-8aa6-0e50e719a729',
name: 'Heater',
selector: 'pilot-wire-mode',
features: [
{
name: 'Pilot Wire mode',
selector: 'pilot-wire-mode',
category: 'heater',
type: 'pilot-wire-mode',
read_only: false,
last_value: 'off',
last_value_changed: '2022-10-10 07:49:07.556 +00:00'
}
]
}
],
'get /api/v1/device?device_feature_selectors=curtain-actions,shutter-actions,shutter-position,thermostat,water-leak,smoke-sensor,light-sensor': [
Expand Down
12 changes: 12 additions & 0 deletions front/src/config/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2732,6 +2732,14 @@
"heating": "Heizen"
}
},
"heater": {
"pilot-wire-mode": {
"comfort": "Komf.",
"eco": "Öko",
"off": "Aus",
"frost_protection": "Frostschutzmittel"
}
},
"siren": {
"lmh_volume": {
"low": "Niedrig",
Expand Down Expand Up @@ -3006,6 +3014,10 @@
"mode": "Modus",
"target-temperature": "Temperatur"
},
"heater": {
"shortCategoryName": "Heizung",
"pilot-wire-mode": "Mode"
},
"tamper": {
"shortCategoryName": "Manipulation",
"binary": "Manipulation (ja/nein)"
Expand Down
12 changes: 12 additions & 0 deletions front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2732,6 +2732,14 @@
"heating": "Heat"
}
},
"heater": {
"pilot-wire-mode": {
"comfort": "Comf.",
"eco": "Eco",
"off": "Off",
"frost_protection": "Anti-Frost"
}
},
"siren": {
"lmh_volume": {
"low": "Low",
Expand Down Expand Up @@ -3006,6 +3014,10 @@
"mode": "Mode",
"target-temperature": "Temperature"
},
"heater": {
"shortCategoryName": "Heater",
"pilot-wire-mode": "Mode"
},
"tamper": {
"shortCategoryName": "Tamper",
"binary": "Tamper (yes/no)"
Expand Down
12 changes: 12 additions & 0 deletions front/src/config/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2732,6 +2732,14 @@
"heating": "Chauffage"
}
},
"heater": {
"pilot-wire-mode": {
"comfort": "Conf.",
"eco": "Eco",
"off": "Off",
"frost_protection": "Anti Gel"
}
},
"siren": {
"lmh_volume": {
"low": "Faible",
Expand Down Expand Up @@ -3006,6 +3014,10 @@
"mode": "Mode",
"target-temperature": "Température"
},
"heater": {
"shortCategoryName": "Chauffage",
"pilot-wire-mode": "Mode"
},
"tamper": {
"shortCategoryName": "Détecteur de sabotage",
"binary": "Détection sabotage (Oui/Non)"
Expand Down
3 changes: 3 additions & 0 deletions front/src/utils/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ export const DeviceFeatureCategoriesIcon = {
[DEVICE_FEATURE_TYPES.AIR_CONDITIONING.MODE]: 'settings',
[DEVICE_FEATURE_TYPES.AIR_CONDITIONING.TARGET_TEMPERATURE]: 'thermometer'
},
[DEVICE_FEATURE_CATEGORIES.HEATER]: {
[DEVICE_FEATURE_TYPES.HEATER.PILOT_WIRE_MODE]: 'thermometer'
},
[DEVICE_FEATURE_CATEGORIES.TELEVISION]: {
[DEVICE_FEATURE_TYPES.TELEVISION.BINARY]: 'power',
[DEVICE_FEATURE_TYPES.TELEVISION.SOURCE]: 'airplay',
Expand Down
12 changes: 12 additions & 0 deletions server/services/zigbee2mqtt/exposes/enumType.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
BUTTON_STATUS,
COVER_STATE,
SIREN_LMH_VOLUME,
PILOT_WIRE_MODE,
} = require('../../../utils/constants');

const WRITE_VALUE_MAPPING = {};
Expand Down Expand Up @@ -85,6 +86,11 @@ addMapping('volume', SIREN_LMH_VOLUME.LOW, 'low');
addMapping('volume', SIREN_LMH_VOLUME.MEDIUM, 'medium');
addMapping('volume', SIREN_LMH_VOLUME.HIGH, 'high');

addMapping('pilot_wire_mode', PILOT_WIRE_MODE.ECO, 'eco');
addMapping('pilot_wire_mode', PILOT_WIRE_MODE.COMFORT, 'comfort');
addMapping('pilot_wire_mode', PILOT_WIRE_MODE.OFF, 'off');
addMapping('pilot_wire_mode', PILOT_WIRE_MODE.FROST_PROTECTION, 'frost_protection');

module.exports = {
type: 'enum',
writeValue: (expose, value) => {
Expand Down Expand Up @@ -143,6 +149,12 @@ module.exports = {
type: DEVICE_FEATURE_TYPES.SIREN.MELODY,
},
},
pilot_wire_mode: {
feature: {
category: DEVICE_FEATURE_CATEGORIES.HEATER,
type: DEVICE_FEATURE_TYPES.HEATER.PILOT_WIRE_MODE,
},
},
},
getFeatureIndexes: (values = []) => {
const indexes = values
Expand Down
12 changes: 12 additions & 0 deletions server/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ const AC_MODE = {
FAN: 4,
};

const PILOT_WIRE_MODE = {
COMFORT: 'comfort',
ECO: 'eco',
FROST_PROTECTION: 'frost-protection',
OFF: 'off',
};

const MUSIC_PLAYBACK_STATE = {
PLAYING: 1,
PAUSED: 0,
Expand Down Expand Up @@ -439,6 +446,7 @@ const DEVICE_FEATURE_CATEGORIES = {
DISTANCE_SENSOR: 'distance-sensor',
DURATION: 'duration',
ENERGY_SENSOR: 'energy-sensor',
HEATER: 'heater',
HUMIDITY_SENSOR: 'humidity-sensor',
LEAK_SENSOR: 'leak-sensor',
LIGHT: 'light',
Expand Down Expand Up @@ -547,6 +555,9 @@ const DEVICE_FEATURE_TYPES = {
MODE: 'mode',
TARGET_TEMPERATURE: 'target-temperature',
},
HEATER: {
PILOT_WIRE_MODE: 'pilot-wire-mode',
},
SURFACE: {
DECIMAL: 'decimal',
},
Expand Down Expand Up @@ -1136,6 +1147,7 @@ module.exports.BUTTON_STATUS = BUTTON_STATUS;
module.exports.COVER_STATE = COVER_STATE;
module.exports.SIREN_LMH_VOLUME = SIREN_LMH_VOLUME;
module.exports.AC_MODE = AC_MODE;
module.exports.PILOT_WIRE_MODE = PILOT_WIRE_MODE;
module.exports.EVENTS = EVENTS;
module.exports.LIFE_EVENTS = LIFE_EVENTS;
module.exports.STATES = STATES;
Expand Down

0 comments on commit 5e2ca5d

Please sign in to comment.