From d798052dae2a799197a6051f8805bc9bb0884297 Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Thu, 12 Jan 2023 01:09:34 +0300 Subject: [PATCH] ha: fix uninitialized sensor info and double-check that we really have magnitudes available fix #2572 --- code/espurna/homeassistant.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/code/espurna/homeassistant.cpp b/code/espurna/homeassistant.cpp index 0358bcda..afad4de7 100644 --- a/code/espurna/homeassistant.cpp +++ b/code/espurna/homeassistant.cpp @@ -341,7 +341,8 @@ public: } bool ok() const override { - return (_relays) && (_index < _relays); + return (_relays > 0) + && (_index < _relays); } const String& uniqueId() { @@ -692,7 +693,11 @@ public: explicit SensorDiscovery(Context& ctx) : _ctx(ctx), _magnitudes(magnitudeCount()) - {} + { + if (_magnitudes > 0) { + _info = magnitudeInfo(_index); + } + } JsonObject& root() { if (!_root) { @@ -703,7 +708,8 @@ public: } bool ok() const override { - return _index < _magnitudes; + return (_magnitudes > 0) + && (_index < _magnitudes); } const String& topic() override {