From 59f16f76f1b93d7cb6f78c93d5e136d37ddc4b1c Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Mon, 23 Apr 2018 18:29:35 +0200 Subject: [PATCH] Refactor devices.js --- lib/devices.js | 111 +++--------------------------------------- lib/homeassistant.js | 112 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 105 deletions(-) create mode 100644 lib/homeassistant.js diff --git a/lib/devices.js b/lib/devices.js index 25c5f1726..6cbfbfcea 100644 --- a/lib/devices.js +++ b/lib/devices.js @@ -1,110 +1,7 @@ -const homeassistant = { - 'binary_sensor_occupancy': { - type: 'binary_sensor', - object_id: 'occupancy', - discovery_payload: { - payload_on: 'motion', - payload_off: 'no_motion', - value_template: '{{ value_json.occupancy }}', - device_class: 'motion', - json_attributes: ['battery'] - } - }, - 'sensor_illuminance': { - type: 'sensor', - object_id: 'illuminance', - discovery_payload: { - unit_of_measurement: 'lx', - icon: 'mdi:theme-light-dark', - value_template: '{{ value_json.illuminance }}', - json_attributes: ['battery'], - } - }, - 'binary_sensor_state': { - type: 'binary_sensor', - object_id: 'state', - discovery_payload: { - payload_on: 'open', - payload_off: 'closed', - value_template: '{{ value_json.state }}', - device_class: 'door', - json_attributes: ['battery'] - } - }, - 'binary_sensor_water_leak': { - type: 'binary_sensor', - object_id: 'water_leak', - discovery_payload: { - payload_on: true, - payload_off: false, - value_template: '{{ value_json.water_leak }}', - device_class: 'moisture', - json_attributes: ['battery'] - } - }, - 'light_brightness_colortemp_xy': { - type: 'light', - object_id: 'light', - discovery_payload: { - brightness: true, - color_temp: true, - xy: true, - platform: 'mqtt_json', - command_topic: true - } - }, - 'light_brightness_colortemp': { - type: 'light', - object_id: 'light', - discovery_payload: { - brightness: true, - color_temp: true, - platform: 'mqtt_json', - command_topic: true - } - }, - 'sensor_humidity': { - type: 'sensor', - object_id: 'humidity', - discovery_payload: { - unit_of_measurement: '%', - icon: 'mdi:water-percent', - value_template: '{{ value_json.humidity }}', - json_attributes: ['battery'], - } - }, - 'sensor_temperature': { - type: 'sensor', - object_id: 'temperature', - discovery_payload: { - unit_of_measurement: '°C', - icon: 'mdi:temperature-celsius', - value_template: '{{ value_json.temperature }}', - json_attributes: ['battery'], - } - }, - 'sensor_pressure': { - type: 'sensor', - object_id: 'pressure', - discovery_payload: { - unit_of_measurement: 'Pa', - icon: 'mdi:speedometer', - value_template: '{{ value_json.pressure }}', - json_attributes: ['battery'], - } - }, - 'sensor_button': { - type: 'sensor', - object_id: 'button', - discovery_payload: { - icon: 'mdi:toggle-switch', - value_template: '{{ value_json.click }}', - json_attributes: ['battery'], - } - } -}; +const homeassistant = require('./homeassistant'); const devices = { + // Xiaomi 'lumi.sensor_switch': { model: 'WXKG01LM', vendor: 'Xiaomi', @@ -182,6 +79,8 @@ const devices = { supports: 'water leak true/false', homeassistant: [homeassistant.binary_sensor_water_leak] }, + + // IKEA 'TRADFRI bulb E27 WS opal 980lm': { model: 'LED1545G12', vendor: 'IKEA', @@ -196,6 +95,8 @@ const devices = { supports: 'on/off, brightness, color temperature', homeassistant: [homeassistant.light_brightness_colortemp] }, + + // Philips 'LLC020': { model: '7146060PH', vendor: 'Philips', diff --git a/lib/homeassistant.js b/lib/homeassistant.js new file mode 100644 index 000000000..bbe3d41e4 --- /dev/null +++ b/lib/homeassistant.js @@ -0,0 +1,112 @@ +const homeassistant = { + // Binary sensor + 'binary_sensor_occupancy': { + type: 'binary_sensor', + object_id: 'occupancy', + discovery_payload: { + payload_on: 'motion', + payload_off: 'no_motion', + value_template: '{{ value_json.occupancy }}', + device_class: 'motion', + json_attributes: ['battery'] + } + }, + 'binary_sensor_state': { + type: 'binary_sensor', + object_id: 'state', + discovery_payload: { + payload_on: 'open', + payload_off: 'closed', + value_template: '{{ value_json.state }}', + device_class: 'door', + json_attributes: ['battery'] + } + }, + 'binary_sensor_water_leak': { + type: 'binary_sensor', + object_id: 'water_leak', + discovery_payload: { + payload_on: true, + payload_off: false, + value_template: '{{ value_json.water_leak }}', + device_class: 'moisture', + json_attributes: ['battery'] + } + }, + + // Sensor + 'sensor_illuminance': { + type: 'sensor', + object_id: 'illuminance', + discovery_payload: { + unit_of_measurement: 'lx', + icon: 'mdi:theme-light-dark', + value_template: '{{ value_json.illuminance }}', + json_attributes: ['battery'], + } + }, + 'sensor_humidity': { + type: 'sensor', + object_id: 'humidity', + discovery_payload: { + unit_of_measurement: '%', + icon: 'mdi:water-percent', + value_template: '{{ value_json.humidity }}', + json_attributes: ['battery'], + } + }, + 'sensor_temperature': { + type: 'sensor', + object_id: 'temperature', + discovery_payload: { + unit_of_measurement: '°C', + icon: 'mdi:temperature-celsius', + value_template: '{{ value_json.temperature }}', + json_attributes: ['battery'], + } + }, + 'sensor_pressure': { + type: 'sensor', + object_id: 'pressure', + discovery_payload: { + unit_of_measurement: 'Pa', + icon: 'mdi:speedometer', + value_template: '{{ value_json.pressure }}', + json_attributes: ['battery'], + } + }, + 'sensor_button': { + type: 'sensor', + object_id: 'button', + discovery_payload: { + icon: 'mdi:toggle-switch', + value_template: '{{ value_json.click }}', + json_attributes: ['battery'], + } + }, + + // Light + 'light_brightness_colortemp_xy': { + type: 'light', + object_id: 'light', + discovery_payload: { + brightness: true, + color_temp: true, + xy: true, + platform: 'mqtt_json', + command_topic: true + } + }, + 'light_brightness_colortemp': { + type: 'light', + object_id: 'light', + discovery_payload: { + brightness: true, + color_temp: true, + platform: 'mqtt_json', + command_topic: true + } + }, +}; + +module.exports = homeassistant;