Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zigbee2mqtt device parser #1302

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,175 changes: 2,175 additions & 0 deletions front/src/config/demo.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,6 @@
"device": "({{nbDevices}}) Devices",
"permitJoin": "Permit joining",
"noDeviceDiscovered": "No new device discovered, please click on scan button.",
"scanButton": "Scan",
"serverNoResponse": "Gladys server is not available.",
"serverNoResponseWebSocker": "Gladys server is not available. Pleash refresh the page.",
"deviceNotHandled": "Device not handled yet, please contact us to help us connect it in Gladys!",
Expand Down Expand Up @@ -1525,6 +1524,7 @@
"kilowatt": "Kilowatt (kW)",
"kilowatt-hour": "Kilowatt hour (kWh)",
"ampere": "Ampere (A)",
"millivolt": "Millivolt (mV)",
"volt": "Volt (V)",
"ppm": "Parts per million (ppm)",
"cm": "Centimeter (cm)",
Expand All @@ -1541,6 +1541,7 @@
"kilowatt": "kW",
"kilowatt-hour": "kWh",
"ampere": "A",
"millivolt": "mV",
"volt": "V",
"ppm": "ppm",
"cm": "cm",
Expand Down
3 changes: 2 additions & 1 deletion front/src/config/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,6 @@
"device": "({{nbDevices}}) Appareils",
"permitJoin": "Autoriser l'association",
"noDeviceDiscovered": "Aucun nouvel appareil trouvé. Veuillez autoriser l'association des appareils et les appairer.\nATTENTION : Pour la sécurité de votre installation, n'oubliez pas d'interdire l'association après appairage.",
"scanButton": "Scanner",
"serverNoResponse": "Gladys n'est pas accessible.",
"serverNoResponseWebSocker": "Gladys n'est pas accessible. Veuillez actualiser la page.",
"deviceNotHandled": "L'appareil n'est pas encore géré, veuillez nous contacter pour nous aider à le connecter dans Gladys !",
Expand Down Expand Up @@ -1525,6 +1524,7 @@
"kilowatt": "Kilowatt",
"kilowatt-hour": "Kilowatt heure (kWh)",
"ampere": "Ampère (A)",
"millivolt": "Millivolt (mV)",
"volt": "Volt (V)",
"ppm": "Partie par million (ppm)",
"cm": "Centimètre (cm)",
Expand All @@ -1541,6 +1541,7 @@
"kilowatt": "kW",
"kilowatt-hour": "kWh",
"ampere": "A",
"millivolt": "mV",
"volt": "V",
"ppm": "ppm",
"cm": "cm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ const DiscoverTab = ({ children, ...props }) => (
</span>
</label>
</div>
<div class="page-options d-flex">
<button
class="btn btn-outline-primary"
onClick={props.discover}
disabled={props.discoverZigbee2mqtt || !props.z2mEnabled || !props.usbConfigured}
>
<Text id="integration.zigbee2mqtt.discover.scanButton" /> <i class="fe fe-radio" />
</button>
</div>
</div>
<div class="card-body">
<CheckStatus />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,28 @@ import update from 'immutability-helper';
import createActionsIntegration from '../../../../../actions/integration';
import createActionsHouse from '../../../../../actions/house';

let scanTimer;

function createActions(store) {
const integrationActions = createActionsIntegration(store);
const houseActions = createActionsHouse(store);
const actions = {
async discover(state) {
async getDiscoveredDevices(state) {
store.setState({
discoverZigbee2mqtt: true,
discoverZigbee2mqttError: null
});
if (state.session.websocketConnected) {
try {
await state.httpClient.post('/api/v1/service/zigbee2mqtt/discover');
scanTimer = setTimeout(store.setState, 5000, {
discoverZigbee2mqtt: false,
discoverZigbee2mqttError: null
});
} catch (e) {
clearTimeout(scanTimer);
store.setState({
zigbee2mqttDevices: [],
discoverZigbee2mqtt: false,
discoverZigbee2mqttError: 'integration.zigbee2mqtt.discover.serverNoResponse'
});
}
} else {

try {
const zigbee2mqttDevices = await state.httpClient.get('/api/v1/service/zigbee2mqtt/discovered');
store.setState({ zigbee2mqttDevices, discoverZigbee2mqtt: false });
} catch (e) {
store.setState({
zigbee2mqttDevices: [],
discoverZigbee2mqtt: false,
discoverZigbee2mqttError: 'integration.zigbee2mqtt.discover.serverNoResponseWebSocker'
discoverZigbee2mqttError: 'integration.zigbee2mqtt.discover.serverNoResponse'
});
}
},
setDiscoveredDevices(state, zigbee2mqttDevices) {
clearTimeout(scanTimer);
store.setState({
zigbee2mqttDevices,
discoverZigbee2mqtt: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Zigbee2mqttIntegration extends Component {
this.props.setDiscoveredDevices(undefined);
this.props.getHouses();
this.props.getIntegrationByName('zigbee2mqtt');
this.props.getDiscoveredDevices();
}

componentWillUnmount() {
Expand Down
16 changes: 8 additions & 8 deletions server/services/zigbee2mqtt/api/zigbee2mqtt.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const logger = require('../../../utils/logger');

module.exports = function Zigbee2mqttController(gladys, zigbee2mqttManager) {
/**
* @api {post} /api/v1/service/zigbee2mqtt/discover Launch Zigbee2mqtt devices discovery
* @apiName discover
* @api {get} /api/v1/service/zigbee2mqtt/discovered Get discovered Zigbee2mqtt devices
* @apiName getDiscoveredDevices
* @apiGroup Zigbee2mqtt
*/
async function discover(req, res) {
logger.log('Launching devices discovery');
await zigbee2mqttManager.discoverDevices();
res.json({ status: 'discovering' });
async function getDiscoveredDevices(req, res) {
logger.log('Get discovered devices');
const devices = zigbee2mqttManager.getDiscoveredDevices();
res.json(devices);
}

/**
Expand Down Expand Up @@ -101,9 +101,9 @@ module.exports = function Zigbee2mqttController(gladys, zigbee2mqttManager) {
}

return {
'post /api/v1/service/zigbee2mqtt/discover': {
'get /api/v1/service/zigbee2mqtt/discovered': {
authenticated: true,
controller: asyncMiddleware(discover),
controller: asyncMiddleware(getDiscoveredDevices),
},
'get /api/v1/service/zigbee2mqtt/status': {
authenticated: true,
Expand Down
71 changes: 71 additions & 0 deletions server/services/zigbee2mqtt/exposes/binaryType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const { DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES } = require('../../../utils/constants');

module.exports = {
type: 'binary',
feature: {
category: DEVICE_FEATURE_CATEGORIES.SWITCH,
type: DEVICE_FEATURE_TYPES.SWITCH.BINARY,
min: 0,
max: 1,
},
names: {
contact: {
feature: {
category: DEVICE_FEATURE_CATEGORIES.OPENING_SENSOR,
type: DEVICE_FEATURE_TYPES.SENSOR.BINARY,
},
},
eco_mode: {
feature: {
category: DEVICE_FEATURE_CATEGORIES.SWITCH,
type: DEVICE_FEATURE_TYPES.SENSOR.BINARY,
},
},
occupancy: {
feature: {
category: DEVICE_FEATURE_CATEGORIES.MOTION_SENSOR,
type: DEVICE_FEATURE_TYPES.SENSOR.BINARY,
},
},
interlock: {
feature: {
category: DEVICE_FEATURE_CATEGORIES.SWITCH,
type: DEVICE_FEATURE_TYPES.SENSOR.BINARY,
},
},
presence: {
feature: {
category: DEVICE_FEATURE_CATEGORIES.MOTION_SENSOR,
type: DEVICE_FEATURE_TYPES.SENSOR.BINARY,
},
},
smoke: {
feature: {
category: DEVICE_FEATURE_CATEGORIES.SMOKE_SENSOR,
type: DEVICE_FEATURE_TYPES.SENSOR.BINARY,
},
},
state: {
types: {
light: {
category: DEVICE_FEATURE_CATEGORIES.LIGHT,
type: DEVICE_FEATURE_TYPES.LIGHT.BINARY,
},
lock: {
category: DEVICE_FEATURE_CATEGORIES.ACCESS_CONTROL,
type: DEVICE_FEATURE_TYPES.ACCESS_CONTROL.MODE,
},
switch: {
category: DEVICE_FEATURE_CATEGORIES.SWITCH,
type: DEVICE_FEATURE_TYPES.SWITCH.BINARY,
},
},
},
water_leak: {
feature: {
category: DEVICE_FEATURE_CATEGORIES.LEAK_SENSOR,
type: DEVICE_FEATURE_TYPES.SENSOR.BINARY,
},
},
},
};
17 changes: 17 additions & 0 deletions server/services/zigbee2mqtt/exposes/compositeType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES } = require('../../../utils/constants');

module.exports = {
type: 'composite',
names: {
color_xy: {
feature: {
category: DEVICE_FEATURE_CATEGORIES.LIGHT,
type: DEVICE_FEATURE_TYPES.LIGHT.COLOR,
has_feedback: true,
read_only: false,
min: 0,
max: 16777215,
},
},
},
};
17 changes: 17 additions & 0 deletions server/services/zigbee2mqtt/exposes/enumType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES } = require('../../../utils/constants');

module.exports = {
type: 'enum',
feature: {
min: 0,
max: 1,
},
names: {
action: {
feature: {
category: DEVICE_FEATURE_CATEGORIES.BUTTON,
type: DEVICE_FEATURE_TYPES.BUTTON.CLICK,
},
},
},
};
11 changes: 11 additions & 0 deletions server/services/zigbee2mqtt/exposes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const binaryType = require('./binaryType');
const numericType = require('./numericType');
const enumType = require('./enumType');
const compositeType = require('./compositeType');

module.exports = {
[binaryType.type]: binaryType,
[numericType.type]: numericType,
[enumType.type]: enumType,
[compositeType.type]: compositeType,
};
Loading