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

Add support for version numbers and hash #125

Merged
merged 4 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all 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 changes: 1 addition & 1 deletion .travis/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions docker/Dockerfile.amd64
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
4 changes: 4 additions & 0 deletions docker/Dockerfile.arm32v6
Original file line number Diff line number Diff line change
Expand Up @@ -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", \
Expand Down
4 changes: 4 additions & 0 deletions docker/Dockerfile.arm64v8
Original file line number Diff line number Diff line change
Expand Up @@ -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", \
Expand Down
90 changes: 58 additions & 32 deletions lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

// 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/+`,
];

// 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');
}

if (settings.get().homeassistant) {
subscriptions.push('hass/status');
this.mqtt.connect(this.handleMQTTMessage, subscriptions, () => this.handleMQTTConnected());
}

this.mqtt.connect(this.handleMQTTMessage, subscriptions, () => this.handleMQTTConnected());
}
});
});
}

Expand Down Expand Up @@ -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 changes: 13 additions & 8 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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": "*",
Expand Down