Skip to content

Commit

Permalink
Fix ignored devices
Browse files Browse the repository at this point in the history
  • Loading branch information
santam85 committed Jan 27, 2023
1 parent c14cbe1 commit a3c0679
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 169 deletions.
164 changes: 163 additions & 1 deletion warema-bridge/srv/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const warema = require('./warema-wms-venetian-blinds');
const {registerDevice, devices} = require('./register-device');
const log = require('./logger');
const mqtt = require('mqtt');

Expand All @@ -20,6 +19,169 @@ const settingsPar = {
wmsSerialPort: process.env.WMS_SERIAL_PORT || '/dev/ttyUSB0',
};

function registerDevice(element) {
log.info('Registering ' + element.snr)
var topic = 'homeassistant/cover/' + element.snr + '/' + element.snr + '/config'
var availability_topic = 'warema/' + element.snr + '/availability'

var base_payload = {
name: element.snr,
availability: [
{topic: 'warema/bridge/state'},
{topic: availability_topic}
],
unique_id: element.snr
}

var base_device = {
identifiers: element.snr,
manufacturer: "Warema",
name: element.snr
}

var model
var payload
switch (parseInt(element.type)) {
case 6:
model = 'Weather station eco'
payload = {
...base_payload,
device: {
...base_device,
model: model
}
}

var illuminance_payload = {
...payload,
state_topic: 'warema/' + element.snr + '/illuminance/state',
device_class: 'illuminance',
unique_id: element.snr + '_illuminance',
unit_of_measurement: 'lm',
}
client.publish('homeassistant/sensor/' + element.snr + '/illuminance/config', JSON.stringify(illuminance_payload), {retain: true})

//No temp on weather station eco
var temperature_payload = {
...payload,
state_topic: 'warema/' + element.snr + '/temperature/state',
device_class: 'temperature',
unique_id: element.snr + '_temperature',
unit_of_measurement: 'C',
}
client.publish('homeassistant/sensor/' + element.snr + '/temperature/config', JSON.stringify(temperature_payload), {retain: true})

var wind_payload = {
...payload,
state_topic: 'warema/' + element.snr + '/wind/state',
device_class: 'wind_speed',
unique_id: element.snr + '_wind',
unit_of_measurement: 'm/s',
}
client.publish('homeassistant/sensor/' + element.snr + '/wind/config', JSON.stringify(wind_payload), {retain: true})

//No rain on weather station eco
var rain_payload = {
...payload,
state_topic: 'warema/' + element.snr + '/rain/state',
device_class: 'moisture',
unique_id: element.snr + '_rain'
}
client.publish('homeassistant/binary_sensor/' + element.snr + '/rain/config', JSON.stringify(rain_payload), {retain: true})

client.publish(availability_topic, 'online', {retain: true})

devices[element.snr] = {};
// No need to add to stick, updates are broadcasted

return;
case 7:
// WMS Remote pro
return;
case 9:
// WMS WebControl Pro - while part of the network, we have no business to do with it.
return;
case 20:
model = 'Plug receiver'
payload = {
...base_payload,
device: {
...base_device,
model: model
},
position_open: 0,
position_closed: 100,
command_topic: 'warema/' + element.snr + '/set',
state_topic: 'warema/' + element.snr + '/state',
position_topic: 'warema/' + element.snr + '/position',
tilt_status_topic: 'warema/' + element.snr + '/tilt',
set_position_topic: 'warema/' + element.snr + '/set_position',
tilt_command_topic: 'warema/' + element.snr + '/set_tilt',
tilt_closed_value: -100,
tilt_opened_value: 100,
tilt_min: -100,
tilt_max: 100,
}
break;
case 21:
model = 'Actuator UP'
payload = {
...base_payload,
device: {
...base_device,
model: model
},
position_open: 0,
position_closed: 100,
command_topic: 'warema/' + element.snr + '/set',
position_topic: 'warema/' + element.snr + '/position',
tilt_status_topic: 'warema/' + element.snr + '/tilt',
set_position_topic: 'warema/' + element.snr + '/set_position',
tilt_command_topic: 'warema/' + element.snr + '/set_tilt',
tilt_closed_value: -100,
tilt_opened_value: 100,
tilt_min: -100,
tilt_max: 100,
}

break;
case 25:
model = 'Vertical awning'
payload = {
...base_payload,
device: {
...base_device,
model: model
},
position_open: 0,
position_closed: 100,
state_topic: 'warema/' + element.snr + '/state',
command_topic: 'warema/' + element.snr + '/set',
position_topic: 'warema/' + element.snr + '/position',
set_position_topic: 'warema/' + element.snr + '/set_position',
}

break;
default:
log.info('Unrecognized device type: ' + element.type)
model = 'Unknown model ' + element.type
return
}

if (ignoredDevices.includes(element.snr.toString())) {
log.info('Ignoring and removing device ' + element.snr + ' (type ' + element.type + ')')
} else {
log.info('Adding device ' + element.snr + ' (type ' + element.type + ')')

stickUsb.vnBlindAdd(parseInt(element.snr), element.snr.toString());

devices[element.snr] = {};

client.publish(availability_topic, 'online', {retain: true})
client.publish(topic, JSON.stringify(payload), {retain: true})
}
}

function callback(err, msg) {
if (err) {
log.error(err);
Expand Down
168 changes: 0 additions & 168 deletions warema-bridge/srv/register-device.js

This file was deleted.

0 comments on commit a3c0679

Please sign in to comment.