ebaauw / homebridge-p1

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

Feature request: log level management for `Gas` and `Electricity Capacity` #71

Closed wimleers closed 1 year ago

wimleers commented 1 year ago

The Log Level characteristic on Electricity is super handy! 🤩

But unfortunately I cannot do the same for Gas, which is why I have entries like this:

[2/23/2023, 6:09:58 PM] [P1] Gas: Total Consumption: set to 553.963 m³ (from 553.896 m³)
[2/23/2023, 6:10:24 PM] [Sun] Sun is -0.1925437655412774 high at 254.39545177488768
[2/23/2023, 6:15:24 PM] [Sun] Sun is -0.9500694069468312 high at 255.36651172025665
[2/23/2023, 6:16:27 PM] [P1] Gas: Total Consumption: set to 554.051 m³ (from 553.963 m³)
[2/23/2023, 6:20:00 PM] [P1] Gas: Total Consumption: set to 554.061 m³ (from 554.051 m³)

… I'd rather not have those.

I first thought that this sole log level affected all accessories, but that appears to not be the case. I'm running Homebridge with debug mode off (no -D), so that can't be the reason for the above either.

A quick search in the codebase suggests this is why it's happening:

class Electricity extends P1Accessory {
  constructor (platform, data, name = 'Electricity') {
    super(platform, name, data)
    this.service = new P1Service.Electricity(this, data)
    if (name === 'Electricity') {
      this.manageLogLevel(this.service.characteristicDelegate('logLevel'))
    }

combined with this code in homebridge-lib:

  manageLogLevel (delegate, forPlatform = false) {
…
    if (forPlatform) {
      try {
        // TODO handle multiple delegates for platform log level
        //      now platform log level is linked to first delegate only

→ https://github.com/ebaauw/homebridge-lib/blob/v6.3.10/lib/AccessoryDelegate.js#L304-L323

So it seems that the plan is to offer a single platform-wide log level? I'd be fine with individual toggles too — and in fact, that may even be preferable! Perhaps one would be observing Gas consumption closely but not Electricity, or vice versa!

ebaauw commented 1 year ago

So it seems that the plan is to offer a single platform-wide log level?

Yes, the Log Level of the platform and of the other accessories are linked to that on the Electricity accessory.

I could do a separate Log Level per accessory, but there's only one interface to the P1 port. I still haven't figured out how to expose a Log Level for the cross-accessory functions of the plugin (for debug messages on the P1 telegrams) vs a Log Level for an accessory (for the log messages on HomeKit changes and debug messages on changes to the corresponding device).

[2/23/2023, 6:09:58 PM] [P1] Gas: Total Consumption: set to 553.963 m³ (from 553.896 m³)

These are regular log messages (level 1); set Log Level to 0 to suppress them.

wimleers commented 1 year ago

These are regular log messages (level 1); set Log Level to 0 to suppress them.

That's what I did. The Electricity Log Level is set to 0, but Gas and Electricity Delivered continue to log as if it's still at 1!

ebaauw commented 1 year ago

Yes, the Log Level of the platform and of the other accessories are linked to that on the Electricity accessory.

That is, they were originally, but it seems that's broken.

ebaauw commented 1 year ago

Fixed in v1.3.4.

wimleers commented 1 year ago

🥳