added lifelines

This commit is contained in:
Ariel Sosnovsky committed 2023-11-02 12:22:28 -04:00
1 parent 8f0d776e07
commit c3d14b6fec
3 files changed
+91 -11

No files matched your search

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