Merge pull request #125 from ciotlosm/add_version_support

Add support for version numbers and hash
This commit is contained in:
Koen Kanters 2018-06-16 00:15:36 +02:00 committed by GitHub
commit c372618eac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 90 additions and 46 deletions

View File

@ -5,7 +5,7 @@ login() {
}
build_and_push() {
docker build -t $DOCKER_USERNAME/zigbee2mqtt:$1 -f $2 .
docker build --build-arg COMMIT=$(git rev-parse --short HEAD) -t $DOCKER_USERNAME/zigbee2mqtt:$1 -f $2 .
docker push $DOCKER_USERNAME/zigbee2mqtt:$1
}

View File

@ -7,6 +7,10 @@ RUN cp /app/docker/run.sh /app
RUN chmod +x /app/run.sh
WORKDIR /app
# Write .hash.json
ARG COMMIT
RUN echo "{\"hash\": \"$COMMIT\"}" > .hash.json
# Install dependencies
RUN apk add --update --no-cache make gcc g++ python linux-headers udev nodejs git && \
npm install --unsafe-perm && \

View File

@ -5,6 +5,10 @@ ENV QEMU_EXECVE 1
COPY docker/qemu-arm-static /usr/bin
WORKDIR /app
# Write .hash.json
ARG COMMIT
RUN echo "{\"hash\": \"$COMMIT\"}" > .hash.json
# Copy files & install dependencies
ADD . /app
RUN [ "qemu-arm-static", "/bin/sh", "-c", \

View File

@ -5,6 +5,10 @@ ENV QEMU_EXECVE 1
COPY docker/qemu-aarch64-static /usr/bin
WORKDIR /app
# Write .hash.json
ARG COMMIT
RUN echo "{\"hash\": \"$COMMIT\"}" > .hash.json
# Copy files & install dependencies
ADD . /app
RUN [ "qemu-aarch64-static", "/bin/sh", "-c", \

View File

@ -39,43 +39,45 @@ class Controller {
}
start() {
this.zigbee.start(this.handleZigbeeMessage, (error) => {
if (error) {
logger.error('Failed to start');
} else {
// Log zigbee clients on startup and configure.
const devices = this.zigbee.getAllClients();
logger.info(`Currently ${devices.length} devices are joined:`);
devices.forEach((device) => {
logger.info(this.getDeviceStartupLogMessage(device));
this.configureDevice(device);
});
this.startupLogVersion(() => {
this.zigbee.start(this.handleZigbeeMessage, (error) => {
if (error) {
logger.error('Failed to start');
} else {
// Log zigbee clients on startup and configure.
const devices = this.zigbee.getAllClients();
logger.info(`Currently ${devices.length} devices are joined:`);
devices.forEach((device) => {
logger.info(this.getDeviceStartupLogMessage(device));
this.configureDevice(device);
});
// Enable zigbee join.
if (settings.get().permit_join) {
logger.warn('`permit_join` set to `true` in configuration.yaml.');
logger.warn('Allowing new devices to join.');
logger.warn('Set `permit_join` to `false` once you joined all devices.');
this.zigbee.permitJoin(true);
// Enable zigbee join.
if (settings.get().permit_join) {
logger.warn('`permit_join` set to `true` in configuration.yaml.');
logger.warn('Allowing new devices to join.');
logger.warn('Set `permit_join` to `false` once you joined all devices.');
this.zigbee.permitJoin(true);
}
// Start timers.
this.pollTimer(true);
this.softResetTimeout(true);
// Connect to MQTT broker
const subscriptions = [
`${settings.get().mqtt.base_topic}/+/set`,
`${settings.get().mqtt.base_topic}/+/+/set`,
`${settings.get().mqtt.base_topic}/bridge/config/+`,
];
if (settings.get().homeassistant) {
subscriptions.push('hass/status');
}
this.mqtt.connect(this.handleMQTTMessage, subscriptions, () => this.handleMQTTConnected());
}
// Start timers.
this.pollTimer(true);
this.softResetTimeout(true);
// Connect to MQTT broker
const subscriptions = [
`${settings.get().mqtt.base_topic}/+/set`,
`${settings.get().mqtt.base_topic}/+/+/set`,
`${settings.get().mqtt.base_topic}/bridge/config/+`,
];
if (settings.get().homeassistant) {
subscriptions.push('hass/status');
}
this.mqtt.connect(this.handleMQTTMessage, subscriptions, () => this.handleMQTTConnected());
}
});
});
}
@ -520,6 +522,30 @@ class Controller {
this.mqtt.publish(deviceSettings.friendly_name, JSON.stringify(payload), options);
}
startupLogVersion(callback) {
const git = require('git-last-commit');
const packageJSON = require('../package.json');
const version = packageJSON.version;
git.getLastCommit((err, commit) => {
let commitHash = null;
if (err) {
try {
commitHash = require('../.hash.json').hash;
} catch (error) {
commitHash = 'unknown';
}
} else {
commitHash = commit.shortHash;
}
logger.info(`Starting zigbee2mqtt version ${version} (commit #${commitHash})`);
callback();
});
}
}
module.exports = Controller;

21
npm-shrinkwrap.json generated
View File

@ -1,13 +1,13 @@
{
"name": "zigbee2mqtt",
"version": "0.1.0",
"version": "0.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"acorn": {
"version": "5.6.2",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-5.6.2.tgz",
"integrity": "sha512-zUzo1E5dI2Ey8+82egfnttyMlMZ2y0D8xOCO3PNPPlYXpl8NZvF6Qk9L9BEtJs+43FqEmfBViDqc5d1ckRDguw==",
"version": "5.7.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.1.tgz",
"integrity": "sha512-d+nbxBUGKg7Arpsvbnlq61mc12ek3EY8EQldM3GPAhWJ1UVxC6TDGbIvUMNU6obBX3i1+ptCIzV4vq0gFPEGVQ==",
"dev": true
},
"acorn-jsx": {
@ -590,7 +590,7 @@
"integrity": "sha512-yAcIQxtmMiB/jL32dzEp2enBeidsB7xWPLNiw3IIkpVds1P+h7qF9YwJq1yUNzp2OKXgAprs4F61ih66UsoD1A==",
"dev": true,
"requires": {
"acorn": "5.6.2",
"acorn": "5.7.1",
"acorn-jsx": "3.0.1"
}
},
@ -720,6 +720,11 @@
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=",
"dev": true
},
"git-last-commit": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/git-last-commit/-/git-last-commit-0.3.0.tgz",
"integrity": "sha1-zHcBrcYpt0f9OzOuXddTp0as6d8="
},
"glob": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
@ -2782,9 +2787,9 @@
}
},
"zigbee-shepherd-converters": {
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/zigbee-shepherd-converters/-/zigbee-shepherd-converters-2.0.7.tgz",
"integrity": "sha512-yBLpHohmjw192Sp5rjX8pozLcjcnhy5AmVIob+CI0+AgGCHEpzGBjc9JvxLyH/N/XVOjMiyVK6wOb5B/Ua1xaw==",
"version": "2.0.8",
"resolved": "https://registry.npmjs.org/zigbee-shepherd-converters/-/zigbee-shepherd-converters-2.0.8.tgz",
"integrity": "sha512-UAtzGF5HZpcfvclmD1fxFkNke0EEOlXMO1VZB8z+FzkuexW6ILVG+7sbys4XIxcrmPuD6/yRGAPsWDqmLITrOg==",
"requires": {
"debounce": "1.1.0"
},

View File

@ -1,6 +1,6 @@
{
"name": "zigbee2mqtt",
"version": "0.1.0",
"version": "0.0.0",
"description": "Zigbee to MQTT bridge using zigbee-shepherd",
"main": "index.js",
"repository": {
@ -36,7 +36,8 @@
"zigbee-shepherd-converters": "*",
"json2yaml": "*",
"zcl-packet": "git+https://github.com/Koenkk/zcl-packet.git",
"js-yaml": "*"
"js-yaml": "*",
"git-last-commit": "*"
},
"devDependencies": {
"eslint": "*",