Browse Source

ha: fix uninitialized sensor info

and double-check that we really have magnitudes available
fix #2572
pull/2575/head
Maxim Prokhorov 1 year ago
parent
commit
d798052dae
1 changed files with 9 additions and 3 deletions
  1. +9
    -3
      code/espurna/homeassistant.cpp

+ 9
- 3
code/espurna/homeassistant.cpp View File

@ -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 {


Loading…
Cancel
Save