only define attr topic if provided a template
This commit is contained in:
parent
c79621c850
commit
58388d857b
19
src/mqtt.js
19
src/mqtt.js
@ -150,7 +150,7 @@ class MQTT {
|
||||
payload_not_available: 'false',
|
||||
state_topic: this.getStateTopic(diag),
|
||||
value_template: `{{ value_json.${MQTT.convertName(diagEl.name)} }}`,
|
||||
json_attributes_topic: this.getStateTopic(diag),
|
||||
json_attributes_topic: _.isUndefined(attr) ? undefined : this.getStateTopic(diag),
|
||||
json_attributes_template: attr
|
||||
};
|
||||
}
|
||||
@ -160,23 +160,6 @@ class MQTT {
|
||||
return _.extend(
|
||||
this.mapBaseConfigPayload(diag, diagEl, device_class, name, attr),
|
||||
{unit_of_measurement: diagEl.unit});
|
||||
return {
|
||||
device_class,
|
||||
name,
|
||||
device: {
|
||||
identifiers: [this.vehicle.vin],
|
||||
manufacturer: this.vehicle.make,
|
||||
model: this.vehicle.year,
|
||||
name: this.vehicle.toString()
|
||||
},
|
||||
availability_topic: this.getAvailabilityTopic(),
|
||||
payload_available: 'true',
|
||||
payload_not_available: 'false',
|
||||
state_topic: this.getStateTopic(diag),
|
||||
unit_of_measurement: diagEl.unit,
|
||||
value_template: `{{ value_json.${MQTT.convertName(diagEl.name)} }}`,
|
||||
json_attributes_template: attr
|
||||
};
|
||||
}
|
||||
|
||||
mapBinarySensorConfigPayload(diag, diagEl, device_class, name, attr) {
|
||||
|
@ -73,7 +73,7 @@ describe('MQTT', () => {
|
||||
payload_available: 'true',
|
||||
payload_not_available: 'false',
|
||||
state_topic: 'homeassistant/sensor/XXX/ambient_air_temperature/state',
|
||||
json_attributes_topic: 'homeassistant/sensor/XXX/ambient_air_temperature/state',
|
||||
json_attributes_topic: undefined,
|
||||
unit_of_measurement: '°C',
|
||||
value_template: '{{ value_json.ambient_air_temperature }}'
|
||||
});
|
||||
@ -106,7 +106,7 @@ describe('MQTT', () => {
|
||||
payload_off: false,
|
||||
payload_on: true,
|
||||
state_topic: 'homeassistant/binary_sensor/XXX/ev_charge_state/state',
|
||||
json_attributes_topic: 'homeassistant/binary_sensor/XXX/ev_charge_state/state',
|
||||
json_attributes_topic: undefined,
|
||||
value_template: '{{ value_json.priority_charge_indicator }}'
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user