Compare commits

..
7 Commits
Author SHA1 Message Date
Zachary Wander 2935827f60 Properly reference flicIR.debug (#5) 2025-03-22 18:55:35 -04:00
Zachary Wander bf4e69e2ce Fix StackOverflow avoidance (#4) 2025-03-17 19:07:55 -04:00
Ari Sosnovsky df74989fdd Merge pull request #1 from zacharee/fix-stackoverflow
Avoid a StackOverflow when re-emitting packets
2025-01-01 13:58:39 -05:00
Zachary Wander 969b8bd0e2 Avoid a StackOverflow when re-emitting packets 2024-09-16 16:36:58 -04:00
Ari Sosnovsky ec295d3f8a Update README.md 2024-07-03 16:07:15 -04:00
Ariel Sosnovsky c97c9c494c images 2023-11-02 16:50:07 -04:00
Ariel Sosnovsky ecc223d6e0 images 2023-11-02 16:48:32 -04:00
9 changed files with 479 additions and 446 deletions

No files matched your search

+5 -2
View File
@@ -1,12 +1,15 @@
# Flic2Hass ![GitHub package.json version (subfolder of monorepo)](https://img.shields.io/github/package-json/v/asosnovsky/flic2hass) # Flic2Hass ![GitHub package.json version (subfolder of monorepo)](https://img.shields.io/github/package-json/v/asosnovsky/flic2hass)
> <a href='https://ko-fi.com/J3J8C4RB7' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi1.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
This is a complete refactor of various previous versions of flic2hass. This version provides more features and even supports the onboard IR module! This is a complete refactor of various previous versions of flic2hass. This version provides more features and even supports the onboard IR module!
## Features ## Features
### Complete Overview of Buttons ### Complete Overview of Buttons
![Alt text](images/btn.png) ![Alt text](images/button-eg.png)
* Show connectivity state * Show connectivity state
* Show click action types: `click` `hold` `double_click` * Show click action types: `click` `hold` `double_click`
@@ -20,7 +23,7 @@ This is a complete refactor of various previous versions of flic2hass. This vers
* Record remote signals * Record remote signals
* Send remote signals * Send remote signals
![Alt text](images/ir.png) ![Alt text](images/ir-eg.png)
Requirements: Requirements:
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 KiB

+11 -6
View File
@@ -705,7 +705,7 @@ Uint8Array.prototype.charCodeAt = function(a, b) {
this.client = false; this.client = false;
this.connected = false; this.connected = false;
/* if keep_alive is less than the ping interval we need to use /* if keep_alive is less than the ping interval we need to use
a shorter ping interval, otherwise we'll just time out! */ this.ping_interval = this.keep_alive < this.C.PING_INTERVAL ? this.keep_alive - 5 : this.C.PING_INTERVAL; a shorter ping interval, otherwise we'll just time out! */ this.ping_interval = this.keep_alive < this.C.PING_INTERVAL ? this.keep_alive - 5 : this.C.PING_INTERVAL;
this.protocol_name = options.protocol_name || "MQTT"; this.protocol_name = options.protocol_name || "MQTT";
this.protocol_level = options.protocol_level || C.PROTOCOL_LEVEL; this.protocol_level = options.protocol_level || C.PROTOCOL_LEVEL;
if (typeof this.client_id == "string") { if (typeof this.client_id == "string") {
@@ -926,6 +926,11 @@ MQTT.prototype.packetHandler = function(data) {
this.partData = data; this.partData = data;
return; return;
} }
// Allow zero-size pData, but detect if its indexes
// will go out of bounds.
if (1 + dLen.lenBy >= data.length) {
return;
}
// Get the data for this packet // Get the data for this packet
var pData = data.slice(1 + dLen.lenBy, pLen); var pData = data.slice(1 + dLen.lenBy, pLen);
// more than one packet? re-emit it so we handle it later // more than one packet? re-emit it so we handle it later
@@ -1084,11 +1089,11 @@ MQTT.prototype.packetHandler = function(data) {
this.client = false; this.client = false;
}; };
/** Publish message using specified topic. /** Publish message using specified topic.
opts = { opts = {
retain: bool // the server should retain this message and send it out again to new subscribers retain: bool // the server should retain this message and send it out again to new subscribers
dup : bool // indicate the message is a duplicate because original wasn't ACKed (QoS > 0 only) dup : bool // indicate the message is a duplicate because original wasn't ACKed (QoS > 0 only)
} }
*/ MQTT.prototype.publish = function(topic, message, opts) { */ MQTT.prototype.publish = function(topic, message, opts) {
if (!this.client) return; if (!this.client) return;
opts = opts || {}; opts = opts || {};
try { try {
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "flic2hass", "name": "flic2hass",
"version": "1.0.0", "version": "1.1.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "flic2hass", "name": "flic2hass",
"version": "1.0.0", "version": "1.1.0",
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"@swc/cli": "^0.1.62", "@swc/cli": "^0.1.62",
+20 -19
View File
@@ -1,9 +1,10 @@
import { ButtonControllerOpt, makeButtonController } from "./ButtonController"; import {ButtonControllerOpt, makeButtonController} from "./ButtonController";
import { HAmqttOptions, makeHAmqtt } from './HAmqtt'; import {HAmqttOptions, makeHAmqtt} from './HAmqtt';
import { IRControllerOpt, makeIRController } from "./IRController"; import {IRControllerOpt, makeIRController} from "./IRController";
import { makeLogger } from "./Logger"; import {makeLogger} from "./Logger";
import { ButtonModule, IRModule } from './flicTypes'; import {ButtonModule, IRModule} from './flicTypes';
import * as mqtt from './mqtt'; import * as mqtt from './mqtt';
export type MQTTOpt = { export type MQTTOpt = {
host: string; host: string;
port: number; port: number;
@@ -27,18 +28,18 @@ export const start = (
) => { ) => {
const mqttServer = mqtt.create( const mqttServer = mqtt.create(
options.mqtt.host, options.mqtt.host,
{ ...options.mqtt, keep_alive: true }, {...options.mqtt, keep_alive: true},
); );
const logger = makeLogger('root', options.debug ?? false); const logger = makeLogger('root', options.debug ?? false);
options.ha = options.ha ?? {} options.ha = options.ha ?? {};
options.flicBtns = options.flicBtns ?? {} options.flicBtns = options.flicBtns ?? {};
options.flicIR = options.flicIR ?? {} options.flicIR = options.flicIR ?? {};
options.ha.debug = options.ha.debug ?? options.debug ?? false options.ha.debug = options.ha.debug ?? options.debug ?? false;
options.flicBtns.debug = options.flicBtns.debug ?? options.debug ?? false options.flicBtns.debug = options.flicBtns.debug ?? options.debug ?? false;
options.flicIR.debug = options.flicBtns.debug ?? options.debug ?? false options.flicIR.debug = options.flicIR.debug ?? options.debug ?? false;
const ha = makeHAmqtt(mqttServer, options.ha); const ha = makeHAmqtt(mqttServer, options.ha);
mqttServer.on('connected', () => { mqttServer.on('connected', () => {
logger.info("connected to mqtt") logger.info("connected to mqtt");
if (!options.flicBtns?.disabled) { if (!options.flicBtns?.disabled) {
makeButtonController( makeButtonController(
ha, buttonModule, options.flicBtns, ha, buttonModule, options.flicBtns,
@@ -52,25 +53,25 @@ export const start = (
options.flicIR, options.flicIR,
).start(); ).start();
} }
logger.info("all services up!") logger.info("all services up!");
}); });
mqttServer.on('error', function (err) { mqttServer.on('error', function (err) {
logger.info("'Error' event", JSON.stringify(err)); logger.info("'Error' event", JSON.stringify(err));
setTimeout(function () { setTimeout(function () {
throw new Error("Crashed") throw new Error("Crashed");
}, 1000); }, 1000);
}); });
mqttServer.on("disconnected", function (err) { mqttServer.on("disconnected", function (err) {
logger.info("'Error' disconnected", JSON.stringify(err)); logger.info("'Error' disconnected", JSON.stringify(err));
setTimeout(function () { setTimeout(function () {
throw new Error("Crashed") throw new Error("Crashed");
}, 1000); }, 1000);
}); });
mqttServer.on("close", function (err) { mqttServer.on("close", function (err) {
logger.info("'Error' close", JSON.stringify(err)); logger.info("'Error' close", JSON.stringify(err));
setTimeout(function () { setTimeout(function () {
throw new Error("Crashed") throw new Error("Crashed");
}, 1000); }, 1000);
}); });
mqttServer.connect() mqttServer.connect();
} };
+441 -417
View File
File diff suppressed because it is too large. Load diff