Remove precision rounding from HA MQTT autodiscovery template (#3636)

* Remove precision rounding from HA MQTT autodiscovery template

Precision rounding should be handled in converters and made available to
all MQTT consumers (not just HA)

* Update homeassistant.test.js

Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
This commit is contained in:
Crowbar Z
2020-05-29 22:13:09 +01:00
committed by GitHub
parent 7d1a97841c
commit 51a6b9226d
2 changed files with 3 additions and 12 deletions
-9
View File
@@ -1908,15 +1908,6 @@ class HomeAssistant extends Extension {
payload.availability_topic = `${settings.get().mqtt.base_topic}/bridge/state`;
}
// Add precision to value_template
if (deviceSettings.hasOwnProperty(`${config.object_id}_precision`)) {
const precision = deviceSettings[`${config.object_id}_precision`];
let template = payload.value_template;
template = template.replace('{{ ', '').replace(' }}', '');
template = `{{ (${template} | float) | round(${precision}) }}`;
payload.value_template = template;
}
if (payload.command_topic) {
payload.command_topic = `${settings.get().mqtt.base_topic}/${friendlyName}/`;
+3 -3
View File
@@ -204,7 +204,7 @@ describe('HomeAssistant extension', () => {
payload = {
'unit_of_measurement': '°C',
'device_class': 'temperature',
'value_template': "{{ (value_json.temperature | float) | round(1) }}",
'value_template': "{{ value_json.temperature }}",
'state_topic': 'zigbee2mqtt/weather_sensor',
'json_attributes_topic': 'zigbee2mqtt/weather_sensor',
'name': 'weather_sensor_temperature',
@@ -229,7 +229,7 @@ describe('HomeAssistant extension', () => {
payload = {
'unit_of_measurement': '%',
'device_class': 'humidity',
'value_template': '{{ (value_json.humidity | float) | round(0) }}',
'value_template': '{{ value_json.humidity }}',
'state_topic': 'zigbee2mqtt/weather_sensor',
'json_attributes_topic': 'zigbee2mqtt/weather_sensor',
'name': 'weather_sensor_humidity',
@@ -254,7 +254,7 @@ describe('HomeAssistant extension', () => {
payload = {
'unit_of_measurement': 'hPa',
'device_class': 'pressure',
'value_template': '{{ (value_json.pressure | float) | round(2) }}',
'value_template': '{{ value_json.pressure }}',
'state_topic': 'zigbee2mqtt/weather_sensor',
'json_attributes_topic': 'zigbee2mqtt/weather_sensor',
'name': 'weather_sensor_pressure',