Skip to content

Commit

Permalink
server: DecoderFunction do not check timout variable directly
Browse files Browse the repository at this point in the history
- This allows in future to have more checks
  • Loading branch information
gfgit committed Aug 17, 2024
1 parent d49b82e commit 8facf5b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions server/src/hardware/decoder/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ void Decoder::changed(DecoderChangeFlags changes, uint32_t functionNumber)
// Stop scheduled unlatch for current function, check other functions
rescheduleLatchedFunctionTimer();
}
else if(f && f->value == true && f->timeoutSeconds.value() > 0)
else if(f && f->value == true && f->hasTimeout() > 0)
{
if(m_currentLatchedFunction == NO_FUNCTION)
{
Expand Down Expand Up @@ -482,7 +482,7 @@ void Decoder::rescheduleLatchedFunctionTimer()

for(const auto& f : *functions)
{
if(f->timeoutSeconds.value() > 0 && f->value == true)
if(f->hasTimeout() > 0 && f->value == true)
{
const auto scheduledTimout = f->getScheduledTimeout();
if(m_currentLatchedFunction == NO_FUNCTION || scheduledTimout < m_firstTimeout)
Expand Down
2 changes: 1 addition & 1 deletion server/src/hardware/decoder/decoderfunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ DecoderFunction::DecoderFunction(Decoder& decoder, uint8_t _number) :
value{this, "value", false, PropertyFlags::ReadWrite | PropertyFlags::StoreState,
[this](bool newValue)
{
if(timeoutSeconds.value() > 0 && newValue)
if(hasTimeout() > 0 && newValue)
m_scheduledTimeout = std::chrono::steady_clock::now() + std::chrono::seconds(timeoutSeconds.value());
else
m_scheduledTimeout = {};
Expand Down
2 changes: 2 additions & 0 deletions server/src/hardware/decoder/decoderfunction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class DecoderFunction : public Object
{
return m_scheduledTimeout;
}

inline bool hasTimeout() const { return timeoutSeconds.value() > 0; }
};

#endif

0 comments on commit 8facf5b

Please sign in to comment.