4 Commits

Author SHA1 Message Date
5fe96315d0 add device name 2024-08-18 11:22:08 +02:00
1118c308ee added model and manufacturer 2024-08-17 13:45:26 +02:00
0f60f9a4c5 added schema file 2024-08-17 13:44:51 +02:00
9b94c01dfe changed loglevel 2024-08-17 11:18:23 +02:00
4 changed files with 149 additions and 13 deletions

View File

@@ -2,7 +2,7 @@ const log4js = require('log4js');
const logger = log4js.getLogger("autodiscover");
const configldr = require('./config')
logger.level = 'debug';
logger.level = 'info';
let discover_mqtt = undefined
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
// device_name: firendlyname displayed in the gui
// config: device config
let unique_identifier = `luminea2mqtt_${deviceid}`
let unique_identifier = `luminea2mqtt_${device.deviceid}`
Object.keys(config).forEach(component =>{
let items = config[component]
Object.keys(items).forEach(item =>{
let mqtt_topic = `${configldr.config.autodiscover.topic}/${component}/${deviceid}/${item}/config`
Object.keys(items).forEach((item,ix) =>{
let mqtt_topic = `${configldr.config.autodiscover.topic}/${component}/${device.deviceid}/${item}/config`
let temp_data = JSON.parse(JSON.stringify(config[component][item]))
temp_data.unique_id = `${deviceid}_${item}_luminea2mqtt`
temp_data.object_id = `${device_name}_${item}`
temp_data.unique_id = `${device.deviceid}_${item}_luminea2mqtt`
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 = {
name : "luminea2mqtt",
support_url: "https://github.com/dennis9819/luminea2mqtt"
@@ -37,9 +44,9 @@ module.exports.publishDevice = async (deviceid,device_name,config) => {
identifiers : [
unique_identifier
],
name: device_name,
manufacturer: "dennisgunia",
model: "Unknown",
name: device.friendlyname,
manufacturer: device.manufacturer ? device.manufacturer : "Unkown",
model: device.model ? device.model : "Unkown",
//via_device: `luminea2mqtt_bridge_${configldr.config.mqtt.devenv1}`
}

View File

@@ -96,7 +96,7 @@ class DeviceBase {
pushAutodiscover(config){
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 => {
if (el) {
this.device.connect().catch(el => {
console.log(this.device)
this.logger.debug("Reconnect failed: device offline")
})
} else {

View File

@@ -9,6 +9,8 @@ const DeviceBase = require('../devicebase')
class Lineplug extends DeviceBase {
init() {
this.manufacturer = "Luminea"
this.model = "NX-4458"
this.lastdata = {
voltage: 0,
current: 0,
@@ -129,7 +131,7 @@ class Lineplug extends DeviceBase {
changed = true
}
if (updatedValues.includes('17')) {
this.lastdata.power = dps['17'] / 100
this.lastdata.work = dps['17'] / 100
changed = true
}
if (updatedValues.includes('9')) {

View 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"
}
}