added lifelines
This commit is contained in:
1 parent
8f0d776e07
commit
c3d14b6fec
3 files changed
+91
-11
No files matched your search
@@ -100,6 +100,7 @@ var ENTITIES = {
|
||||
battery: [
|
||||
"sensor",
|
||||
{
|
||||
expire_after: 5,
|
||||
unit_of_measurement: "%",
|
||||
device_class: "battery"
|
||||
}
|
||||
@@ -107,14 +108,28 @@ var ENTITIES = {
|
||||
batteryLastUpdate: [
|
||||
"sensor",
|
||||
{
|
||||
entity_category: "diagnostic",
|
||||
expire_after: 5,
|
||||
name: "Battery Last Update Time",
|
||||
device_class: "duration",
|
||||
unit_of_measurement: "s"
|
||||
}
|
||||
],
|
||||
lifeline: [
|
||||
"binary_sensor",
|
||||
{
|
||||
entity_category: "diagnostic",
|
||||
expire_after: 5,
|
||||
name: "Flichub Connected",
|
||||
device_class: "connectivity",
|
||||
unit_of_measurement: "s"
|
||||
}
|
||||
],
|
||||
connected: [
|
||||
"binary_sensor",
|
||||
{
|
||||
entity_category: "diagnostic",
|
||||
expire_after: 5,
|
||||
device_class: "connectivity",
|
||||
name: "Connection Established"
|
||||
}
|
||||
@@ -122,6 +137,8 @@ var ENTITIES = {
|
||||
ready: [
|
||||
"binary_sensor",
|
||||
{
|
||||
entity_category: "config",
|
||||
expire_after: 5,
|
||||
device_class: "connectivity",
|
||||
name: "Connection Verified"
|
||||
}
|
||||
@@ -129,12 +146,16 @@ var ENTITIES = {
|
||||
activeDisconnect: [
|
||||
"binary_sensor",
|
||||
{
|
||||
entity_category: "config",
|
||||
expire_after: 5,
|
||||
name: "User Active Disconnect"
|
||||
}
|
||||
],
|
||||
passive: [
|
||||
"binary_sensor",
|
||||
{
|
||||
entity_category: "config",
|
||||
expire_after: 5,
|
||||
name: "Passive Mode"
|
||||
}
|
||||
]
|
||||
@@ -170,6 +191,11 @@ function makeButtonController(ha, buttonModule) {
|
||||
payload_available: "ON",
|
||||
payload_not_available: "OFF",
|
||||
topic: ha.genFlicPrefix(genButtonUniqueId(button.bdaddr), "ready")
|
||||
},
|
||||
{
|
||||
payload_available: "ON",
|
||||
payload_not_available: "OFF",
|
||||
topic: ha.genFlicPrefix(genButtonUniqueId(button.bdaddr), "lifeline")
|
||||
}
|
||||
],
|
||||
availability_mode: "all"
|
||||
@@ -195,6 +221,7 @@ function makeButtonController(ha, buttonModule) {
|
||||
ha.publishState(genButtonUniqueId(button.bdaddr), "ready", button.ready ? "ON" : "OFF");
|
||||
ha.publishState(genButtonUniqueId(button.bdaddr), "activeDisconnect", button.activeDisconnect ? "ON" : "OFF");
|
||||
ha.publishState(genButtonUniqueId(button.bdaddr), "passive", button.activeDisconnect ? "ON" : "OFF");
|
||||
ha.publishState(genButtonUniqueId(button.bdaddr), "lifeline", "ON");
|
||||
};
|
||||
var addBtn = function(eventName) {
|
||||
return function(obj) {
|
||||
@@ -251,7 +278,7 @@ function makeButtonController(ha, buttonModule) {
|
||||
buttonModule.getButtons().forEach(registerButton);
|
||||
setInterval(function() {
|
||||
return buttonModule.getButtons().forEach(publishButtonMeta);
|
||||
}, 1000);
|
||||
}, 3000);
|
||||
logger.info("is up");
|
||||
};
|
||||
return {
|
||||
@@ -432,10 +459,18 @@ var makeIRController = function(ir, ha, mqtt) {
|
||||
]
|
||||
};
|
||||
var nodeId = "".concat(NODE_ID).concat(options.uniqueId);
|
||||
var LIFELINE_SGINAL = ha.genFlicPrefix(nodeId, "lifeline");
|
||||
var RECORD_SIGNAL_SET = ha.genFlicPrefix(nodeId, "record/set");
|
||||
var VALUE_SIGNAL_SET = ha.genFlicPrefix(nodeId, "signal/set");
|
||||
var VALUE_SIGNAL_STATE = ha.genFlicPrefix(nodeId, "signal");
|
||||
var PLAY_SIGNAL_SET = ha.genFlicPrefix(nodeId, "play/set");
|
||||
var availability = [
|
||||
{
|
||||
payload_available: "ON",
|
||||
payload_not_available: "OFF",
|
||||
topic: LIFELINE_SGINAL
|
||||
}
|
||||
];
|
||||
var currentSignal = null;
|
||||
var set_topics = [
|
||||
RECORD_SIGNAL_SET,
|
||||
@@ -447,19 +482,27 @@ var makeIRController = function(ir, ha, mqtt) {
|
||||
start: function start() {
|
||||
logger.info("starting...");
|
||||
logger.debug("setting up entities...");
|
||||
ha.registerEntity("IR Available", "binary_sensor", nodeId, "lifeline", haDevice, {
|
||||
device_class: "connectivity",
|
||||
expire_after: 5,
|
||||
entity_category: "diagnostic"
|
||||
});
|
||||
ha.registerEntity("Record Signal", "switch", nodeId, "record", haDevice, {
|
||||
icon: "mdi:record-rec",
|
||||
command_topic: RECORD_SIGNAL_SET,
|
||||
device_class: "switch"
|
||||
device_class: "switch",
|
||||
availability: availability
|
||||
});
|
||||
ha.registerEntity("Signal", "text", nodeId, "signal", haDevice, {
|
||||
command_topic: VALUE_SIGNAL_SET,
|
||||
icon: "mdi:broadcast",
|
||||
max: 255
|
||||
max: 255,
|
||||
availability: availability
|
||||
});
|
||||
ha.registerEntity("Play Signal", "button", nodeId, "play", haDevice, {
|
||||
icon: "mdi:play",
|
||||
command_topic: PLAY_SIGNAL_SET
|
||||
command_topic: PLAY_SIGNAL_SET,
|
||||
availability: availability
|
||||
});
|
||||
logger.debug("setting default states....");
|
||||
ha.publishState(nodeId, "record", "OFF");
|
||||
@@ -520,6 +563,9 @@ var makeIRController = function(ir, ha, mqtt) {
|
||||
});
|
||||
logger.debug("subscribing to", set_topics);
|
||||
mqtt.subscribe(set_topics);
|
||||
setInterval(function() {
|
||||
ha.publishState(nodeId, "lifeline", "ON");
|
||||
}, 2500);
|
||||
logger.info("is up");
|
||||
}
|
||||
};
|
||||
|
||||
+15
-7
@@ -15,12 +15,13 @@ export const makeOptions = (opt: Partial<ButtonControllerOpt>): ButtonController
|
||||
const ENTITIES: Record<string, [HAComponent, Record<string, any>]> = {
|
||||
"action": ['sensor', { icon: 'mdi:gesture-tap-button', name: "Click Action" }],
|
||||
"state": ['sensor', { icon: 'mdi:radiobox-indeterminate-variant' }],
|
||||
"battery": ['sensor', { unit_of_measurement: '%', device_class: 'battery' }],
|
||||
"batteryLastUpdate": ['sensor', { name: "Battery Last Update Time", device_class: "duration", unit_of_measurement: "s" }],
|
||||
"connected": ['binary_sensor', { device_class: 'connectivity', name: "Connection Established" }],
|
||||
"ready": ['binary_sensor', { device_class: 'connectivity', name: "Connection Verified" }],
|
||||
"activeDisconnect": ['binary_sensor', { name: "User Active Disconnect" }],
|
||||
"passive": ['binary_sensor', { name: "Passive Mode" }],
|
||||
"battery": ['sensor', { expire_after: 5, unit_of_measurement: '%', device_class: 'battery' }],
|
||||
"batteryLastUpdate": ['sensor', { entity_category: "diagnostic", expire_after: 5, name: "Battery Last Update Time", device_class: "duration", unit_of_measurement: "s" }],
|
||||
"lifeline": ['binary_sensor', { entity_category: "diagnostic", expire_after: 5, name: "Flichub Connected", device_class: "connectivity", unit_of_measurement: "s" }],
|
||||
"connected": ['binary_sensor', { entity_category: "diagnostic", expire_after: 5, device_class: 'connectivity', name: "Connection Established" }],
|
||||
"ready": ['binary_sensor', { entity_category: "config", expire_after: 5, device_class: 'connectivity', name: "Connection Verified" }],
|
||||
"activeDisconnect": ['binary_sensor', { entity_category: "config", expire_after: 5, name: "User Active Disconnect" }],
|
||||
"passive": ['binary_sensor', { entity_category: "config", expire_after: 5, name: "Passive Mode" }],
|
||||
}
|
||||
export type ButtonController = ReturnType<typeof makeButtonController>;
|
||||
export function makeButtonController(
|
||||
@@ -61,8 +62,14 @@ export function makeButtonController(
|
||||
payload_not_available: 'OFF',
|
||||
topic: ha.genFlicPrefix(genButtonUniqueId(button.bdaddr), 'ready')
|
||||
},
|
||||
{
|
||||
payload_available: 'ON',
|
||||
payload_not_available: 'OFF',
|
||||
topic: ha.genFlicPrefix(genButtonUniqueId(button.bdaddr), 'lifeline')
|
||||
},
|
||||
],
|
||||
availability_mode: 'all',
|
||||
|
||||
},
|
||||
)
|
||||
});
|
||||
@@ -90,6 +97,7 @@ export function makeButtonController(
|
||||
ha.publishState(genButtonUniqueId(button.bdaddr), 'ready', button.ready ? 'ON' : "OFF");
|
||||
ha.publishState(genButtonUniqueId(button.bdaddr), 'activeDisconnect', button.activeDisconnect ? 'ON' : "OFF");
|
||||
ha.publishState(genButtonUniqueId(button.bdaddr), 'passive', button.activeDisconnect ? 'ON' : "OFF");
|
||||
ha.publishState(genButtonUniqueId(button.bdaddr), 'lifeline', 'ON');
|
||||
}
|
||||
const addBtn = (eventName: string) => (obj: { bdaddr: string }) => {
|
||||
const button = buttonModule.getButton(obj.bdaddr);
|
||||
@@ -142,7 +150,7 @@ export function makeButtonController(
|
||||
});
|
||||
logger.info("Registering all buttons...")
|
||||
buttonModule.getButtons().forEach(registerButton);
|
||||
setInterval(() => buttonModule.getButtons().forEach(publishButtonMeta), 1000);
|
||||
setInterval(() => buttonModule.getButtons().forEach(publishButtonMeta), 3000);
|
||||
logger.info('is up')
|
||||
}
|
||||
|
||||
|
||||
@@ -39,10 +39,18 @@ export const makeIRController = (
|
||||
identifiers: ['FlicHubIR']
|
||||
}
|
||||
const nodeId = `${NODE_ID}${options.uniqueId}`;
|
||||
const LIFELINE_SGINAL = ha.genFlicPrefix(nodeId, 'lifeline');
|
||||
const RECORD_SIGNAL_SET = ha.genFlicPrefix(nodeId, 'record/set');
|
||||
const VALUE_SIGNAL_SET = ha.genFlicPrefix(nodeId, 'signal/set');
|
||||
const VALUE_SIGNAL_STATE = ha.genFlicPrefix(nodeId, 'signal');
|
||||
const PLAY_SIGNAL_SET = ha.genFlicPrefix(nodeId, 'play/set');
|
||||
const availability = [
|
||||
{
|
||||
"payload_available": "ON",
|
||||
"payload_not_available": "OFF",
|
||||
"topic": LIFELINE_SGINAL,
|
||||
}
|
||||
]
|
||||
let currentSignal: string | null = null;
|
||||
|
||||
const set_topics = [
|
||||
@@ -56,6 +64,18 @@ export const makeIRController = (
|
||||
start() {
|
||||
logger.info('starting...')
|
||||
logger.debug('setting up entities...')
|
||||
ha.registerEntity(
|
||||
'IR Available',
|
||||
'binary_sensor',
|
||||
nodeId,
|
||||
'lifeline',
|
||||
haDevice,
|
||||
{
|
||||
device_class: 'connectivity',
|
||||
expire_after: 5,
|
||||
entity_category: "diagnostic",
|
||||
}
|
||||
)
|
||||
ha.registerEntity(
|
||||
'Record Signal',
|
||||
'switch',
|
||||
@@ -66,6 +86,7 @@ export const makeIRController = (
|
||||
icon: 'mdi:record-rec',
|
||||
command_topic: RECORD_SIGNAL_SET,
|
||||
device_class: 'switch',
|
||||
availability,
|
||||
}
|
||||
)
|
||||
ha.registerEntity(
|
||||
@@ -78,6 +99,7 @@ export const makeIRController = (
|
||||
command_topic: VALUE_SIGNAL_SET,
|
||||
icon: 'mdi:broadcast',
|
||||
max: 255,
|
||||
availability,
|
||||
}
|
||||
)
|
||||
ha.registerEntity(
|
||||
@@ -89,6 +111,7 @@ export const makeIRController = (
|
||||
{
|
||||
icon: 'mdi:play',
|
||||
command_topic: PLAY_SIGNAL_SET,
|
||||
availability,
|
||||
}
|
||||
)
|
||||
logger.debug('setting default states....')
|
||||
@@ -140,6 +163,9 @@ export const makeIRController = (
|
||||
|
||||
logger.debug('subscribing to', set_topics)
|
||||
mqtt.subscribe(set_topics)
|
||||
setInterval(() => {
|
||||
ha.publishState(nodeId, 'lifeline', 'ON')
|
||||
}, 2500)
|
||||
logger.info('is up')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user