supla-device
Loading...
Searching...
No Matches
Supla::Element Class Reference

Base class for all elements of SuplaDevice. More...

#include <element.h>

Inheritance diagram for Supla::Element:
Collaboration diagram for Supla::Element:

Public Member Functions

Elementnext ()
 Returns next Element from the list.
 
virtual void onLoadConfig (SuplaDeviceClass *sdc)
 First method called on element in SuplaDevice.begin().
 
virtual void purgeConfig ()
 Removes all configration data related to the element from Storage::Config.
 
virtual void onLoadState ()
 Second method called on element in SuplaDevice.begin().
 
virtual void onInit ()
 Third method called on element in SuplaDevice.begin()
 
virtual void onSaveState ()
 Method called periodically during SuplaDevice iteration.
 
virtual void onRegistered (Supla::Protocol::SuplaSrpc *suplaSrpc=nullptr)
 Method called each time when device successfully registers to Supla server.
 
virtual void iterateAlways ()
 Method called on each SuplaDevice iteration.
 
virtual bool iterateConnected ()
 Method called on each SuplaDevice iteration when device is connected and registered to Supla server or other protocol.
 
virtual bool iterateConnected (void *ptr)
 deprecated
 
virtual void onTimer ()
 Method called on timer interupt.
 
virtual void onFastTimer ()
 Method called on fast timer interupt.
 
virtual void onSoftReset ()
 Method called when device soft restart is triggered.
 
virtual void onDeviceConfigChange (uint64_t fieldBit)
 Method called when device config is changed.
 
virtual int32_t handleNewValueFromServer (TSD_SuplaChannelNewValue *newValue)
 Handles "new value" request from server.
 
virtual void fillSuplaChannelNewValue (TSD_SuplaChannelNewValue *value)
 Fills TSD_SuplaChannelNewValue based on current state.
 
virtual void handleGetChannelState (TDSC_ChannelState *channelState)
 Handles "get channel state (i)" request from server.
 
virtual int handleCalcfgFromServer (TSD_DeviceCalCfgRequest *request)
 Handles CALCFG requests from server.
 
virtual uint8_t handleChannelConfig (TSD_ChannelConfig *newChannelConfig, bool local=false)
 Handles "set channel config" request from server.
 
virtual uint8_t handleWeeklySchedule (TSD_ChannelConfig *newWeeklySchedule, bool altSchedule=false, bool local=false)
 Handles "set channel config" with "weekly schedule" type request from server.
 
virtual void handleSetChannelConfigResult (TSDS_SetChannelConfigResult *result)
 Handles "set channel config" reply from server.
 
virtual void handleChannelConfigFinished ()
 Handles "channel config finished" message from server.
 
int getChannelNumber () const
 Returns channel number.
 
int getSecondaryChannelNumber () const
 Returns secondary channel number.
 
virtual bool isOwnerOfSubDeviceId (int subDeviceId) const
 Returns true if element is owner of subDeviceId.
 
virtual const ChannelgetChannel () const
 Returns pointer to main channel.
 
virtual ChannelgetChannel ()
 
virtual const ChannelgetSecondaryChannel () const
 Returns pointer to secondary channel.
 
virtual ChannelgetSecondaryChannel ()
 
virtual void generateKey (char *output, const char *key) const
 Generates key used for Config.
 
ElementdisableChannelState ()
 Disables channel state (i) function.
 
bool isChannelStateEnabled () const
 Returns true if channel state (i) function is enabled.
 
virtual bool isAnyUpdatePending ()
 Returns true if any update is pending.
 
void setInitialCaption (const char *caption, bool secondaryChannel=false)
 Sets initial caption.
 
void setDefaultFunction (int32_t defaultFunction)
 Sets default channel's function.
 

Static Public Member Functions

static Elementbegin ()
 Returns first Element (based on creation order)
 
static Elementlast ()
 Returns last Element (based on creation order)
 
static ElementgetElementByChannelNumber (int channelNumber)
 Returns Element by channel number.
 
static ElementgetOwnerOfSubDeviceId (int subDeviceId)
 Returns Element which owns given subDeviceId.
 
static bool IsAnyUpdatePending ()
 Checks if any element has pending update for remote server.
 
static void NotifyElementsAboutConfigChange (uint64_t fieldBit)
 Notifies all elements about device config change.
 
static bool IsInvalidPtrSet ()
 When "invalid pointer" is set, previously obtained Element pointer may be invalid.
 
static void ClearInvalidPtr ()
 Clears "invalid pointer" flag.
 

Protected Attributes

ElementnextPtr = nullptr
 

Static Protected Attributes

static ElementfirstPtr = nullptr
 
static bool invalidatePtr = false
 

Detailed Description

Base class for all elements of SuplaDevice.

Member Function Documentation

◆ begin()

Element * Supla::Element::begin ( )
static

Returns first Element (based on creation order)

Returns
first Element

◆ disableChannelState()

Element & Supla::Element::disableChannelState ( )

Disables channel state (i) function.

Returns
reference to self

◆ fillSuplaChannelNewValue()

void Supla::Element::fillSuplaChannelNewValue ( TSD_SuplaChannelNewValue * value)
virtual

Fills TSD_SuplaChannelNewValue based on current state.

Parameters
valuepointer to TSD_SuplaChannelNewValue which should be filled

Reimplemented in Relay, RollerShutterInterface, Supla::Control::Relay, Supla::Control::RGBWBase, and Supla::Control::RollerShutterInterface.

◆ generateKey()

void Supla::Element::generateKey ( char * output,
const char * key ) const
virtual

Generates key used for Config.

Adds "x_" prefix to the key where x is a channel number. Output is written to output buffer and limitted to SUPLA_CONFIG_MAX_KEY_SIZE.

Parameters
outputoutput buffer (should be at least SUPLA_CONFIG_MAX_KEY_SIZE)
keykey

◆ getChannel()

const Channel * Supla::Element::getChannel ( ) const
virtual

Returns pointer to main channel.

Returns
pointer to main channel, nullptr if element has no channel

Reimplemented in BinaryBase, ElectricityMeter, Supla::ChannelElement, Supla::Control::ActionTrigger, Supla::Sensor::BinaryBase, and Supla::Sensor::ElectricityMeter.

◆ getChannelNumber()

int Supla::Element::getChannelNumber ( ) const

Returns channel number.

Returns
channel number related to main channel in element. Value -1 is returned if element has no channel

◆ getElementByChannelNumber()

Element * Supla::Element::getElementByChannelNumber ( int channelNumber)
static

Returns Element by channel number.

Parameters
channelNumberof existing channel
Returns
pointer to Element which handles this channel

◆ getOwnerOfSubDeviceId()

Element * Supla::Element::getOwnerOfSubDeviceId ( int subDeviceId)
static

Returns Element which owns given subDeviceId.

Parameters
subDeviceIdid of subdevice
Returns
pointer to Element which owns given subDeviceId

◆ getSecondaryChannel()

const Channel * Supla::Element::getSecondaryChannel ( ) const
virtual

Returns pointer to secondary channel.

Returns
pointer to secondary channel, nullptr if element has no secondary channel

Reimplemented in Supla::Sensor::ThermHygroPressMeter.

◆ getSecondaryChannelNumber()

int Supla::Element::getSecondaryChannelNumber ( ) const

Returns secondary channel number.

Returns
channel number related to secondary channel in element. Value -1 is returned if element has no secondary channel

◆ handleCalcfgFromServer()

◆ handleChannelConfig()

uint8_t Supla::Element::handleChannelConfig ( TSD_ChannelConfig * newChannelConfig,
bool local = false )
virtual

Handles "set channel config" request from server.

Parameters
newChannelConfigpointer to new channel configuration
localtrue if request is local (issued by device itself), false when requests originates from server.
Returns
SUPLA_RESULTCODE_* (see proto.h)

Reimplemented in HvacBase, Supla::Control::ActionTrigger, Supla::Control::HvacBase, and Supla::ElementWithChannelActions.

◆ handleChannelConfigFinished()

void Supla::Element::handleChannelConfigFinished ( )
virtual

Handles "channel config finished" message from server.

This message informs device that server finished sending channel config for this element.

Reimplemented in BinaryBase, HvacBase, Supla::Control::HvacBase, Supla::ElementWithChannelActions, and Supla::Sensor::BinaryBase.

◆ handleGetChannelState()

void Supla::Element::handleGetChannelState ( TDSC_ChannelState * channelState)
virtual

Handles "get channel state (i)" request from server.

Parameters
channelStatepointer to TDSC_ChannelState which should be filled. channelState is prefilled with network and device info.

Reimplemented in Supla::Control::LightRelay.

◆ handleNewValueFromServer()

int32_t Supla::Element::handleNewValueFromServer ( TSD_SuplaChannelNewValue * newValue)
virtual

Handles "new value" request from server.

Parameters
newValuepointer to TSD_SuplaChannelNewValue
Returns
-1 - don't send reply to server 0 - success==false 1 - success==true

Reimplemented in HvacBase, Relay, RollerShutterInterface, Supla::Control::BistableRelay, Supla::Control::HvacBase, Supla::Control::Relay, Supla::Control::RGBWBase, Supla::Control::RollerShutterInterface, Supla::Control::ValveBase, and ValveBase.

◆ handleSetChannelConfigResult()

void Supla::Element::handleSetChannelConfigResult ( TSDS_SetChannelConfigResult * result)
virtual

Handles "set channel config" reply from server.

All types of channel config should be handled here (including weekly schedule, default config, etc).

Parameters
result

Reimplemented in HvacBase, Supla::Control::HvacBase, and Supla::ElementWithChannelActions.

◆ handleWeeklySchedule()

uint8_t Supla::Element::handleWeeklySchedule ( TSD_ChannelConfig * newWeeklySchedule,
bool altSchedule = false,
bool local = false )
virtual

Handles "set channel config" with "weekly schedule" type request from server.

Parameters
newWeeklySchedulepointer to new weekly schedule
altScheduletrue if request is for alternative schedule (for cooling)
localtrue if request is local (issued by device itself), false when requests originates from server.
Returns
SUPLA_RESULTCODE_* (see proto.h)

Reimplemented in HvacBase, and Supla::Control::HvacBase.

◆ IsAnyUpdatePending()

bool Supla::Element::IsAnyUpdatePending ( )
static

Checks if any element has pending update for remote server.

This method is usually used by device which supports sleeping. It will call it to check if there is any more update to be send to the server before disconnecting and going to sleep.

Returns
true if any Element has pending update

◆ isAnyUpdatePending()

bool Supla::Element::isAnyUpdatePending ( )
virtual

Returns true if any update is pending.

Returns
true if any update is pending

Reimplemented in Supla::ElementWithChannelActions.

◆ isChannelStateEnabled()

bool Supla::Element::isChannelStateEnabled ( ) const

Returns true if channel state (i) function is enabled.

Returns
true if channel state (i) function is enabled

◆ IsInvalidPtrSet()

bool Supla::Element::IsInvalidPtrSet ( )
static

When "invalid pointer" is set, previously obtained Element pointer may be invalid.

In such case, new pointer should be generated by begin() method and Element's iteration should be started again.

Returns
true if "invalid pointer" is set

◆ isOwnerOfSubDeviceId()

bool Supla::Element::isOwnerOfSubDeviceId ( int subDeviceId) const
virtual

Returns true if element is owner of subDeviceId.

Parameters
subDeviceId
Returns
true if element is owner of subDeviceId

◆ iterateAlways()

void Supla::Element::iterateAlways ( )
virtual

◆ iterateConnected()

bool Supla::Element::iterateConnected ( )
virtual

Method called on each SuplaDevice iteration when device is connected and registered to Supla server or other protocol.

Returns
false when element didn't communicate with server and next element should be iterated instead. true otherwise.

Reimplemented in HvacBase, OcrImpulseCounter, Relay, Supla::Clock, Supla::Control::HvacBase, Supla::Control::Relay, Supla::ElementWithChannelActions, Supla::PV::Afore, Supla::PV::Fronius, Supla::PV::SolarEdge, Supla::Sensor::OcrImpulseCounter, and Supla::Sensor::ThermHygroPressMeter.

◆ last()

Element * Supla::Element::last ( )
static

Returns last Element (based on creation order)

Returns
last Element

◆ next()

Element * Supla::Element::next ( )

Returns next Element from the list.

Returns
pointer to the next Element

◆ NotifyElementsAboutConfigChange()

void Supla::Element::NotifyElementsAboutConfigChange ( uint64_t fieldBit)
static

Notifies all elements about device config change.

Parameters
fieldBitbit mask of changed field (see SUPLA_DEVICE_CONFIG_FIELD_ in proto.h)

◆ onDeviceConfigChange()

void Supla::Element::onDeviceConfigChange ( uint64_t fieldBit)
virtual

Method called when device config is changed.

Parameters
fieldBitbit mask of changed field

Reimplemented in Supla::Clock, and Supla::Device::StatusLed.

◆ onFastTimer()

void Supla::Element::onFastTimer ( )
virtual

Method called on fast timer interupt.

It should provide all actions that have to be executed periodically regardless of other SuplaDevice activities. It is usually called every 1 ms (or 0.5 ms for Arduino Mega).

Reimplemented in ImpulseCounter, Supla::Control::RGBWBase, and Supla::Sensor::ImpulseCounter.

◆ onInit()

void Supla::Element::onInit ( )
virtual

Third method called on element in SuplaDevice.begin()

Method called during SuplaDevice initialization. I.e. load initial state, initialize pins etc.

Reimplemented in BlinkingLed, Button, ElectricityMeter, GeneralPurposeChannelBase, GroupButtonControlRgbw, HvacBase, ImpulseCounter, OcrImpulseCounter, Relay, RollerShutterInterface, SimpleButton, Supla::Control::ActionTrigger, Supla::Control::BistableRelay, Supla::Control::BlinkingLed, Supla::Control::Button, Supla::Control::DimmerLeds, Supla::Control::GroupButtonControlRgbw, Supla::Control::HvacBase, Supla::Control::InternalPinOutput, Supla::Control::PinStatusLed, Supla::Control::Relay, Supla::Control::RGBLeds, Supla::Control::RGBWBase, Supla::Control::RGBWLeds, Supla::Control::RollerShutter, Supla::Control::RollerShutterInterface, Supla::Control::SimpleButton, Supla::Control::TrippleButtonRollerShutter, Supla::Control::ValveBase, Supla::Control::VirtualRelay, Supla::Device::FactoryTest, Supla::DS1307RTC, Supla::DS3231RTC, Supla::Sensor::AHT, Supla::Sensor::Bh1750, Supla::Sensor::Binary, Supla::Sensor::BME280, Supla::Sensor::ElectricityMeter, Supla::Sensor::EspFreeHeap, Supla::Sensor::GeneralPurposeChannelBase, Supla::Sensor::HC_SR04, Supla::Sensor::HX711, Supla::Sensor::ImpulseCounter, Supla::Sensor::Max44009, Supla::Sensor::NTC10k, Supla::Sensor::OcrImpulseCounter, Supla::Sensor::OnePhaseElectricityMeter, Supla::Sensor::PZEMv2, Supla::Sensor::PZEMv3, Supla::Sensor::SHT3x, Supla::Sensor::Si7021, Supla::Sensor::TemperatureDropSensor, Supla::Sensor::ThermHygroMeter, Supla::Sensor::Thermometer, Supla::Sensor::ThreePhasePZEMv3, Supla::Sensor::ThreePhasePZEMv3_ADDR, Supla::Sensor::VirtualBinary, Supla::Sensor::VirtualImpulseCounter, TemperatureDropSensor, Thermometer, ValveBase, and VirtualImpulseCounter.

◆ onLoadConfig()

◆ onLoadState()

◆ onRegistered()

void Supla::Element::onRegistered ( Supla::Protocol::SuplaSrpc * suplaSrpc = nullptr)
virtual

◆ onSaveState()

◆ onTimer()

void Supla::Element::onTimer ( )
virtual

Method called on timer interupt.

It should provide all actions that have to be executed periodically regardless of other SuplaDevice activities. It is usually called every 10 ms.

Reimplemented in BlinkingLed, Button, SimpleButton, Supla::Clock, Supla::Control::BistableRollerShutter, Supla::Control::BlinkingLed, Supla::Control::Button, Supla::Control::PinStatusLed, Supla::Control::RollerShutter, Supla::Control::SequenceButton, and Supla::Control::SimpleButton.

◆ purgeConfig()

◆ setDefaultFunction()

void Supla::Element::setDefaultFunction ( int32_t defaultFunction)

Sets default channel's function.

Parameters
defaultFunctionSUPLA_CHANNELFNC_* see proto.h

◆ setInitialCaption()

void Supla::Element::setInitialCaption ( const char * caption,
bool secondaryChannel = false )

Sets initial caption.

Initial caption is used as channel's caption when it is registered on server for the first time.

Parameters
captioncaption
secondaryChanneltrue if caption is for secondary channel, false otherwise

The documentation for this class was generated from the following files: