mirror of
https://github.com/koush/scrypted.git
synced 2026-09-17 09:10:38 +01:00
mqtt: add temp, humidity, flood
This commit is contained in:
4
plugins/mqtt/package-lock.json
generated
4
plugins/mqtt/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@scrypted/mqtt",
|
||||
"version": "0.0.72",
|
||||
"version": "0.0.74",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@scrypted/mqtt",
|
||||
"version": "0.0.72",
|
||||
"version": "0.0.74",
|
||||
"dependencies": {
|
||||
"@types/node": "^16.6.1",
|
||||
"aedes": "^0.46.1",
|
||||
|
||||
@@ -41,5 +41,5 @@
|
||||
"@scrypted/common": "file:../../common",
|
||||
"@types/nunjucks": "^3.2.0"
|
||||
},
|
||||
"version": "0.0.72"
|
||||
"version": "0.0.74"
|
||||
}
|
||||
|
||||
@@ -349,11 +349,8 @@ interface AutoDiscoveryConfig {
|
||||
|
||||
const autoDiscoveryMap = new Map<string, AutoDiscoveryConfig>();
|
||||
|
||||
function createBinarySensorConfig(mqttId: string, device: MixinDeviceBase<any>, prop: ScryptedInterfaceProperty, topic: string) {
|
||||
function getAutoDiscoveryDevice(device: MixinDeviceBase<any>, mqttId: string) {
|
||||
return {
|
||||
state_topic: `${topic}/${prop}`,
|
||||
payload_on: 'true',
|
||||
payload_off: 'false',
|
||||
dev: {
|
||||
name: device.name,
|
||||
// what the hell is this
|
||||
@@ -365,6 +362,15 @@ function createBinarySensorConfig(mqttId: string, device: MixinDeviceBase<any>,
|
||||
}
|
||||
}
|
||||
|
||||
function createBinarySensorConfig(mqttId: string, device: MixinDeviceBase<any>, prop: ScryptedInterfaceProperty, topic: string) {
|
||||
return {
|
||||
state_topic: `${topic}/${prop}`,
|
||||
payload_on: 'true',
|
||||
payload_off: 'false',
|
||||
...getAutoDiscoveryDevice(device, mqttId),
|
||||
}
|
||||
}
|
||||
|
||||
function addBinarySensor(iface: ScryptedInterface, prop: ScryptedInterfaceProperty) {
|
||||
autoDiscoveryMap.set(iface, {
|
||||
component: 'binary_sensor',
|
||||
@@ -377,8 +383,33 @@ function addBinarySensor(iface: ScryptedInterface, prop: ScryptedInterfaceProper
|
||||
addBinarySensor(ScryptedInterface.MotionSensor, ScryptedInterfaceProperty.motionDetected);
|
||||
addBinarySensor(ScryptedInterface.BinarySensor, ScryptedInterfaceProperty.binaryState);
|
||||
addBinarySensor(ScryptedInterface.OccupancySensor, ScryptedInterfaceProperty.occupied);
|
||||
addBinarySensor(ScryptedInterface.FloodSensor, ScryptedInterfaceProperty.flooded);
|
||||
addBinarySensor(ScryptedInterface.AudioSensor, ScryptedInterfaceProperty.audioDetected);
|
||||
|
||||
autoDiscoveryMap.set(ScryptedInterface.Thermometer, {
|
||||
component: 'sensor',
|
||||
create(mqttId, device, topic) {
|
||||
return {
|
||||
state_topic: `${topic}/${ScryptedInterfaceProperty.temperature}`,
|
||||
value_template: '{{ value_json }}',
|
||||
unit_of_measurement: 'C',
|
||||
...getAutoDiscoveryDevice(device, mqttId),
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
autoDiscoveryMap.set(ScryptedInterface.HumiditySensor, {
|
||||
component: 'sensor',
|
||||
create(mqttId, device, topic) {
|
||||
return {
|
||||
state_topic: `${topic}/${ScryptedInterfaceProperty.humidity}`,
|
||||
value_template: '{{ value_json }}',
|
||||
unit_of_measurement: '%',
|
||||
...getAutoDiscoveryDevice(device, mqttId),
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export function publishAutoDiscovery(mqttId: string, client: Client, device: MixinDeviceBase<any>, topic: string, autoDiscoveryPrefix = 'homeassistant') {
|
||||
for (const iface of device.interfaces) {
|
||||
const found = autoDiscoveryMap.get(iface);
|
||||
|
||||
Reference in New Issue
Block a user