Skip to content

Commit

Permalink
ha: fix uninitialized sensor info
Browse files Browse the repository at this point in the history
and double-check that we really have magnitudes available
fix #2572
  • Loading branch information
mcspr committed Jan 11, 2023
1 parent 94fff47 commit d798052
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions code/espurna/homeassistant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ class RelayDiscovery : public Discovery {
}

bool ok() const override {
return (_relays) && (_index < _relays);
return (_relays > 0)
&& (_index < _relays);
}

const String& uniqueId() {
Expand Down Expand Up @@ -692,7 +693,11 @@ class SensorDiscovery : public Discovery {
explicit SensorDiscovery(Context& ctx) :
_ctx(ctx),
_magnitudes(magnitudeCount())
{}
{
if (_magnitudes > 0) {
_info = magnitudeInfo(_index);
}
}

JsonObject& root() {
if (!_root) {
Expand All @@ -703,7 +708,8 @@ class SensorDiscovery : public Discovery {
}

bool ok() const override {
return _index < _magnitudes;
return (_magnitudes > 0)
&& (_index < _magnitudes);
}

const String& topic() override {
Expand Down

0 comments on commit d798052

Please sign in to comment.