Fixed bug from upstream update preventing publishing of location to MQTT
This commit is contained in:
parent
6fb09602d7
commit
f1c167668a
16
src/index.js
16
src/index.js
@ -83,22 +83,22 @@ const configureMQTT = async (commands, client, mqttHA) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const commandFn = cmd.bind(commands);
|
const commandFn = cmd.bind(commands);
|
||||||
logger.info('Command sent', {command});
|
logger.info('Command sent', { command });
|
||||||
commandFn(options || {})
|
commandFn(options || {})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
// TODO refactor the response handling for commands
|
// TODO refactor the response handling for commands
|
||||||
logger.info('Command completed', {command});
|
logger.info('Command completed', { command });
|
||||||
data = _.get(data, 'response.data');
|
const responseData = _.get(data, 'response.data');
|
||||||
if (data) {
|
if (responseData) {
|
||||||
logger.info('Command response data', {data});
|
logger.info('Command response data', { responseData });
|
||||||
const location = _.get(data, 'response.data.commandResponse.body.location');
|
const location = _.get(data, 'response.data.commandResponse.body.location');
|
||||||
if (location) {
|
if (location) {
|
||||||
const topic = mqttHA.getStateTopic({name: command});
|
const topic = mqttHA.getStateTopic({ name: command });
|
||||||
// TODO create device_tracker entity. MQTT device tracker doesn't support lat/lon and mqtt_json
|
// TODO create device_tracker entity. MQTT device tracker doesn't support lat/lon and mqtt_json
|
||||||
// doesn't have discovery
|
// doesn't have discovery
|
||||||
client.publish(topic,
|
client.publish(topic,
|
||||||
JSON.stringify({latitude: location.lat, longitude: location.long}), {retain: true})
|
JSON.stringify({ latitude: location.lat, longitude: location.long }), { retain: true })
|
||||||
.then(() => logger.info('Published location to topic.', {topic}));
|
.then(() => logger.info('Published location to topic.', { topic }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user