added lifelines
This commit is contained in:
1 parent
8f0d776e07
commit
c3d14b6fec
3 files changed
+91
-11
No files matched your search
+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