ebaauw / homebridge-p1

Homebridge plugin for DSMR end-consumer (P1) interface
Apache License 2.0
54 stars 11 forks source link

The extremest edge case: `homebridge-p1` crashes when gas meter is removed #78

Closed wimleers closed 1 year ago

wimleers commented 1 year ago

Yesterday, my gas meter was removed. I realize this is a pretty extreme edge case 🤓 😅

But this did trigger this plugin crashing:

[7/5/2023, 11:17:13 AM] [P1] warning: TypeError: Cannot read properties of undefined (reading 'consumption')
    at Gas.check (/Users/admin/Desktop/homebridge-p1/lib/P1Service.js:175:36)
    at Gas.check (/Users/admin/Desktop/homebridge-p1/lib/P1Accessory.js:27:18)
    at P1Platform.onData (/Users/admin/Desktop/homebridge-p1/lib/P1Platform.js:211:18)
    at P1Client.<anonymous> (/Users/admin/Desktop/homebridge-p1/lib/P1Platform.js:117:40)
    at P1Client.emit (node:events:513:28)
    at P1Client.parseTelegram (/Users/admin/Desktop/homebridge-p1/lib/P1Client.js:682:12)
    at ReadlineParser.<anonymous> (/Users/admin/Desktop/homebridge-p1/lib/P1Client.js:424:51)
    at ReadlineParser.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:293:11)

A simple reboot fixes it though:

[7/5/2023, 11:18:25 AM] [P1] Restarting child bridge...
[7/5/2023, 11:18:25 AM] Got SIGTERM, shutting down child bridge process...
[7/5/2023, 11:18:30 AM] [P1] Child bridge process ended
[7/5/2023, 11:18:30 AM] [P1] Process Ended. Code: 143, Signal: null
[7/5/2023, 11:18:37 AM] [P1] Restarting Process...
[7/5/2023, 11:18:37 AM] [P1] Launched child bridge with PID 53305
[7/5/2023, 11:18:37 AM] The plugin "homebridge-p1" requires Node.js version of ^18.14.1 which does not satisfy the current Node.js version of v18.14.0. You may need to upgrade your installation of Node.js - see https://homebridge.io/w/JTKEF
[7/5/2023, 11:18:37 AM] Registering platform 'homebridge-p1.P1'
[7/5/2023, 11:18:37 AM] [P1] Loaded homebridge-p1 v1.3.4-0 child bridge successfully
[7/5/2023, 11:18:37 AM] Loaded 3 cached accessories from cachedAccessories.0E981C41ADC8.
[7/5/2023, 11:18:37 AM] [P1] homebridge-p1 v1.3.4-0, node v18.14.0, homebridge v1.6.0, homebridge-lib v6.3.11
[7/5/2023, 11:18:37 AM] [P1] warning: recommended version: node v18.14.2 LTS
[7/5/2023, 11:18:37 AM] Homebridge v1.6.0 (HAP v0.11.0) (P1) is running on port 54199.
[7/5/2023, 11:18:38 AM] [P1] hardware: Mac mini (M1, 2020)
[7/5/2023, 11:18:38 AM] [P1] os: macOS Monterey 12.3.1 (21E258)
[7/5/2023, 11:18:38 AM] [P1] restored 3 accessories from cache
[7/5/2023, 11:18:39 AM] [P1] connected to 192.168.0.219:23
[7/5/2023, 11:18:39 AM] [P1] warning: latest version: homebridge-p1 v1.3.9
[7/5/2023, 11:18:39 AM] [P1] warning: ignoring invalid telegram
[7/5/2023, 11:18:40 AM] [VELUX safe] Setting switch to false
[7/5/2023, 11:18:40 AM] [P1] FLU5\253770234_A v5.0
[7/5/2023, 11:18:40 AM] [P1] Electricity: Electric Current: set to 17.32 A (from 17.47 A)
[7/5/2023, 11:18:40 AM] [P1] Electricity Delivered: Total Consumption: set to 2130.054 kWh (from 2130.035 kWh)
[7/5/2023, 11:18:40 AM] [P1] Electricity Delivered: Total Consumption Normal: set to 1525.085 kWh (from 1525.066 kWh)
[7/5/2023, 11:18:40 AM] [P1] Electricity Delivered: Current Consumption: set to 4205 W (from 4242 W)
ebaauw commented 1 year ago

I don’t see a crash, just a warning message (with stack trace)?

Indeed, removing a meter isn’t a use case I had anticipated, but it’s quite easy to prevent the TypeError.

BTW you’re running an old beta version of Homebridge P1.

wimleers commented 1 year ago

BTW you’re running an old beta version of Homebridge P1.

Yes, I am, because almost every release you make bumps the minimum node version — so I can't update plugins through the Homebridge UI. Out of curiosity: why exactly do you do that? 🤔

On that subject: this plugin is "homebridge verified", but per https://github.com/homebridge/verified#requirements, that means:

The plugin must run on all supported LTS versions of Node.js, at the time of writing this is Node.js v16 and v18.

AFAICT that means that anything other than "node": "^16 || ^18" is in violation of that requirement? 😅

ebaauw commented 1 year ago

I develop and test my plugins against the latest LTS version of NodeJS. Other versions might work, or not. I simply don't have the bandwidth to test these.

Usually a NodeJS release includes security updates, so I would recommend to update NodeJS to the latest version.

wimleers commented 1 year ago

Updated to 1.3.10 by now 👍

Thanks for https://github.com/ebaauw/homebridge-p1/releases/tag/v1.3.10! 🤩

I think this issue can be closed? 😊 Unfortunately I won't be able to re-test this, because I don't have a single meter left 😇