Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5fe96315d0 | |||
| 1118c308ee | |||
| 0f60f9a4c5 | |||
| 9b94c01dfe |
@@ -2,7 +2,7 @@ const log4js = require('log4js');
|
|||||||
const logger = log4js.getLogger("autodiscover");
|
const logger = log4js.getLogger("autodiscover");
|
||||||
const configldr = require('./config')
|
const configldr = require('./config')
|
||||||
|
|
||||||
logger.level = 'debug';
|
logger.level = 'info';
|
||||||
let discover_mqtt = undefined
|
let discover_mqtt = undefined
|
||||||
|
|
||||||
module.exports.setup = async (mqtt) => {
|
module.exports.setup = async (mqtt) => {
|
||||||
@@ -15,20 +15,27 @@ module.exports.setup = async (mqtt) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.publishDevice = async (deviceid,device_name,config) => {
|
module.exports.publishDevice = async (device,config) => {
|
||||||
// deviceid: unique device id, ideally based on the tuya device id
|
// deviceid: unique device id, ideally based on the tuya device id
|
||||||
// device_name: firendlyname displayed in the gui
|
// device_name: firendlyname displayed in the gui
|
||||||
// config: device config
|
// config: device config
|
||||||
|
|
||||||
let unique_identifier = `luminea2mqtt_${deviceid}`
|
let unique_identifier = `luminea2mqtt_${device.deviceid}`
|
||||||
Object.keys(config).forEach(component =>{
|
Object.keys(config).forEach(component =>{
|
||||||
|
|
||||||
let items = config[component]
|
let items = config[component]
|
||||||
Object.keys(items).forEach(item =>{
|
Object.keys(items).forEach((item,ix) =>{
|
||||||
let mqtt_topic = `${configldr.config.autodiscover.topic}/${component}/${deviceid}/${item}/config`
|
let mqtt_topic = `${configldr.config.autodiscover.topic}/${component}/${device.deviceid}/${item}/config`
|
||||||
let temp_data = JSON.parse(JSON.stringify(config[component][item]))
|
let temp_data = JSON.parse(JSON.stringify(config[component][item]))
|
||||||
temp_data.unique_id = `${deviceid}_${item}_luminea2mqtt`
|
temp_data.unique_id = `${device.deviceid}_${item}_luminea2mqtt`
|
||||||
temp_data.object_id = `${device_name}_${item}`
|
temp_data.object_id = `${device.friendlyname}_${item}`
|
||||||
|
if (component == "switch"){
|
||||||
|
if (items.length > 1){
|
||||||
|
temp_data.name = `${device.friendlyname}_${ix}`
|
||||||
|
}else{
|
||||||
|
temp_data.name = `${device.friendlyname}`
|
||||||
|
}
|
||||||
|
}
|
||||||
temp_data.origin = {
|
temp_data.origin = {
|
||||||
name : "luminea2mqtt",
|
name : "luminea2mqtt",
|
||||||
support_url: "https://github.com/dennis9819/luminea2mqtt"
|
support_url: "https://github.com/dennis9819/luminea2mqtt"
|
||||||
@@ -37,9 +44,9 @@ module.exports.publishDevice = async (deviceid,device_name,config) => {
|
|||||||
identifiers : [
|
identifiers : [
|
||||||
unique_identifier
|
unique_identifier
|
||||||
],
|
],
|
||||||
name: device_name,
|
name: device.friendlyname,
|
||||||
manufacturer: "dennisgunia",
|
manufacturer: device.manufacturer ? device.manufacturer : "Unkown",
|
||||||
model: "Unknown",
|
model: device.model ? device.model : "Unkown",
|
||||||
|
|
||||||
//via_device: `luminea2mqtt_bridge_${configldr.config.mqtt.devenv1}`
|
//via_device: `luminea2mqtt_bridge_${configldr.config.mqtt.devenv1}`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class DeviceBase {
|
|||||||
|
|
||||||
pushAutodiscover(config){
|
pushAutodiscover(config){
|
||||||
if (configldr.config.autodiscover.enabled){
|
if (configldr.config.autodiscover.enabled){
|
||||||
autodiscover.publishDevice(this.deviceid,this.friendlyname,config)
|
autodiscover.publishDevice(this,config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +104,6 @@ class DeviceBase {
|
|||||||
this.device.find().then(el => {
|
this.device.find().then(el => {
|
||||||
if (el) {
|
if (el) {
|
||||||
this.device.connect().catch(el => {
|
this.device.connect().catch(el => {
|
||||||
console.log(this.device)
|
|
||||||
this.logger.debug("Reconnect failed: device offline")
|
this.logger.debug("Reconnect failed: device offline")
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ const DeviceBase = require('../devicebase')
|
|||||||
class Lineplug extends DeviceBase {
|
class Lineplug extends DeviceBase {
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
this.manufacturer = "Luminea"
|
||||||
|
this.model = "NX-4458"
|
||||||
this.lastdata = {
|
this.lastdata = {
|
||||||
voltage: 0,
|
voltage: 0,
|
||||||
current: 0,
|
current: 0,
|
||||||
@@ -129,7 +131,7 @@ class Lineplug extends DeviceBase {
|
|||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
if (updatedValues.includes('17')) {
|
if (updatedValues.includes('17')) {
|
||||||
this.lastdata.power = dps['17'] / 100
|
this.lastdata.work = dps['17'] / 100
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
if (updatedValues.includes('9')) {
|
if (updatedValues.includes('9')) {
|
||||||
|
|||||||
128
src/schemas/b6232c5534f12aa0.json
Normal file
128
src/schemas/b6232c5534f12aa0.json
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
{
|
||||||
|
"1": {
|
||||||
|
"code": "switch_1",
|
||||||
|
"id": "1",
|
||||||
|
"mode": "rw",
|
||||||
|
"name": "开关1",
|
||||||
|
"property": "{\"type\":\"bool\"}",
|
||||||
|
"schemaType": "bool",
|
||||||
|
"type": "obj"
|
||||||
|
},
|
||||||
|
"17": {
|
||||||
|
"code": "add_ele",
|
||||||
|
"id": "17",
|
||||||
|
"mode": "rw",
|
||||||
|
"name": "增加电量",
|
||||||
|
"property": "{\"max\":50000,\"min\":0,\"scale\":3,\"step\":100,\"type\":\"value\",\"unit\":\"kwh\"}",
|
||||||
|
"schemaType": "value",
|
||||||
|
"type": "obj"
|
||||||
|
},
|
||||||
|
"18": {
|
||||||
|
"code": "cur_current",
|
||||||
|
"id": "18",
|
||||||
|
"mode": "ro",
|
||||||
|
"name": "当前电流",
|
||||||
|
"property": "{\"max\":30000,\"min\":0,\"scale\":0,\"step\":1,\"type\":\"value\",\"unit\":\"mA\"}",
|
||||||
|
"schemaType": "value",
|
||||||
|
"type": "obj"
|
||||||
|
},
|
||||||
|
"19": {
|
||||||
|
"code": "cur_power",
|
||||||
|
"id": "19",
|
||||||
|
"mode": "ro",
|
||||||
|
"name": "当前功率",
|
||||||
|
"property": "{\"max\":50000,\"min\":0,\"scale\":1,\"step\":1,\"type\":\"value\",\"unit\":\"W\"}",
|
||||||
|
"schemaType": "value",
|
||||||
|
"type": "obj"
|
||||||
|
},
|
||||||
|
"20": {
|
||||||
|
"code": "cur_voltage",
|
||||||
|
"id": "20",
|
||||||
|
"mode": "ro",
|
||||||
|
"name": "当前电压",
|
||||||
|
"property": "{\"max\":5000,\"min\":0,\"scale\":1,\"step\":1,\"type\":\"value\",\"unit\":\"V\"}",
|
||||||
|
"schemaType": "value",
|
||||||
|
"type": "obj"
|
||||||
|
},
|
||||||
|
"21": {
|
||||||
|
"code": "test_bit",
|
||||||
|
"id": "21",
|
||||||
|
"mode": "ro",
|
||||||
|
"name": "产测结果位",
|
||||||
|
"property": "{\"max\":5,\"min\":0,\"scale\":0,\"step\":1,\"type\":\"value\"}",
|
||||||
|
"schemaType": "value",
|
||||||
|
"type": "obj"
|
||||||
|
},
|
||||||
|
"22": {
|
||||||
|
"code": "voltage_coe",
|
||||||
|
"id": "22",
|
||||||
|
"mode": "ro",
|
||||||
|
"name": "电压校准系数",
|
||||||
|
"property": "{\"max\":1000000,\"min\":0,\"scale\":0,\"step\":1,\"type\":\"value\"}",
|
||||||
|
"schemaType": "value",
|
||||||
|
"type": "obj"
|
||||||
|
},
|
||||||
|
"23": {
|
||||||
|
"code": "electric_coe",
|
||||||
|
"id": "23",
|
||||||
|
"mode": "ro",
|
||||||
|
"name": "电流校准系数",
|
||||||
|
"property": "{\"max\":1000000,\"min\":0,\"scale\":0,\"step\":1,\"type\":\"value\"}",
|
||||||
|
"schemaType": "value",
|
||||||
|
"type": "obj"
|
||||||
|
},
|
||||||
|
"24": {
|
||||||
|
"code": "power_coe",
|
||||||
|
"id": "24",
|
||||||
|
"mode": "ro",
|
||||||
|
"name": "功率校准系数",
|
||||||
|
"property": "{\"max\":1000000,\"min\":0,\"scale\":0,\"step\":1,\"type\":\"value\"}",
|
||||||
|
"schemaType": "value",
|
||||||
|
"type": "obj"
|
||||||
|
},
|
||||||
|
"25": {
|
||||||
|
"code": "electricity_coe",
|
||||||
|
"id": "25",
|
||||||
|
"mode": "ro",
|
||||||
|
"name": "电量校准系数",
|
||||||
|
"property": "{\"max\":1000000,\"min\":0,\"scale\":0,\"step\":1,\"type\":\"value\"}",
|
||||||
|
"schemaType": "value",
|
||||||
|
"type": "obj"
|
||||||
|
},
|
||||||
|
"26": {
|
||||||
|
"code": "fault",
|
||||||
|
"id": "26",
|
||||||
|
"mode": "ro",
|
||||||
|
"name": "故障告警",
|
||||||
|
"property": "{\"label\":[\"ov_cr\",\"ov_vol\",\"ov_pwr\",\"ls_cr\",\"ls_vol\",\"ls_pow\"],\"maxlen\":6,\"type\":\"bitmap\"}",
|
||||||
|
"schemaType": "bitmap",
|
||||||
|
"type": "obj"
|
||||||
|
},
|
||||||
|
"41": {
|
||||||
|
"code": "cycle_time",
|
||||||
|
"id": "41",
|
||||||
|
"mode": "rw",
|
||||||
|
"name": "循环定时",
|
||||||
|
"property": "{\"maxlen\":255,\"type\":\"string\"}",
|
||||||
|
"schemaType": "string",
|
||||||
|
"type": "obj"
|
||||||
|
},
|
||||||
|
"42": {
|
||||||
|
"code": "random_time",
|
||||||
|
"id": "42",
|
||||||
|
"mode": "rw",
|
||||||
|
"name": "随机定时",
|
||||||
|
"property": "{\"maxlen\":255,\"type\":\"string\"}",
|
||||||
|
"schemaType": "string",
|
||||||
|
"type": "obj"
|
||||||
|
},
|
||||||
|
"9": {
|
||||||
|
"code": "countdown_1",
|
||||||
|
"id": "9",
|
||||||
|
"mode": "rw",
|
||||||
|
"name": "开关1倒计时",
|
||||||
|
"property": "{\"max\":86400,\"min\":0,\"scale\":0,\"step\":1,\"type\":\"value\",\"unit\":\"s\"}",
|
||||||
|
"schemaType": "value",
|
||||||
|
"type": "obj"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user