#include <cs_BehaviourHandler.h>
|
std::optional< uint8_t > | computeIntendedState (Time currenttime, PresenceStateDescription currentpresence) const |
| Given current time/presence, query the behaviourstore and check if there any valid ones. More...
|
|
SwitchBehaviour * | resolveSwitchBehaviour (Time currentTime, PresenceStateDescription currentPresence) const |
| Returns most specific active switch behaviour, resolving conflicts. More...
|
|
void | handleGetBehaviourDebug (event_t &evt) |
|
SwitchBehaviour * | validateSwitchBehaviour (Behaviour *behaviour, Time currentTime, PresenceStateDescription currentPresence) const |
|
TwilightBehaviour * | validateTwilightBehaviour (Behaviour *behaviour, Time currentTime, PresenceStateDescription currentPresence) const |
|
void | onBehaviourSettingsMeshMsg (behaviour_settings_t settings) |
|
void | onBehaviourSettingsChange (behaviour_settings_t settings) |
| To be called when the behaviour settings were changed, and on sync response. More...
|
|
bool | onBehaviourSettingsOutgoingSyncRequest () |
| Returns true when the behaviour settings should be synced. More...
|
|
void | onMeshSyncFailed () |
| Finalizes the behaviour settings sync. More...
|
|
void | tryFinalizeBehaviourSettingsSync () |
| If there was any behaviour settings sync response, the behaviour settings sync will be finalized. More...
|
|
void | onBehaviourSettingsIncomingSyncRequest () |
| Sends a sync response. More...
|
|
◆ ~BehaviourHandler()
virtual BehaviourHandler::~BehaviourHandler |
( |
| ) |
|
|
virtualdefault |
◆ computeIntendedState()
Given current time/presence, query the behaviourstore and check if there any valid ones.
Returns an empty optional when:
- this BehaviourHandler is inactive, or
- _presenceHandler is nullptr, or
- more than one valid behaviours contradicted each other.
Returns a non-empty optional if a valid behaviour is found or multiple agreeing behaviours have been found. In this case its value contains the desired state value. When no behaviours are valid at given time/presence the intended value is 0. (house is 'off' by default)
◆ getValue()
std::optional< uint8_t > BehaviourHandler::getValue |
( |
| ) |
|
Returns currentIntendedState variable and updates the previousIntendedState to currentIntendedState to match previousIntendedState.
◆ handleEvent()
virtual void BehaviourHandler::handleEvent |
( |
event_t & |
evt | ) |
|
|
virtual |
Computes the intended behaviour state of this crownstone based on the stored behaviours, and then dispatches an event for that.
Events:
- EVT_PRESENCE_MUTATION
- EVT_BEHAVIOURSTORE_MUTATION
- STATE_BEHAVIOUR_SETTINGS
- CMD_GET_BEHAVIOUR_DEBUG
Implements EventListener.
◆ handleGetBehaviourDebug()
void BehaviourHandler::handleGetBehaviourDebug |
( |
event_t & |
evt | ) |
|
|
private |
◆ init()
Obtains a pointer to presence handler, if it exists.
Reimplemented from Component.
◆ onBehaviourSettingsChange()
To be called when the behaviour settings were changed, and on sync response.
◆ onBehaviourSettingsIncomingSyncRequest()
void BehaviourHandler::onBehaviourSettingsIncomingSyncRequest |
( |
| ) |
|
|
private |
Sends a sync response.
To be called on a behaviour settings sync request
◆ onBehaviourSettingsMeshMsg()
◆ onBehaviourSettingsOutgoingSyncRequest()
bool BehaviourHandler::onBehaviourSettingsOutgoingSyncRequest |
( |
| ) |
|
|
private |
Returns true when the behaviour settings should be synced.
To be called when a sync request will be sent out.
◆ onMeshSyncFailed()
void BehaviourHandler::onMeshSyncFailed |
( |
| ) |
|
|
private |
Finalizes the behaviour settings sync.
To be called when the overall sync failed.
◆ requiresAbsence()
bool BehaviourHandler::requiresAbsence |
( |
Time |
t | ) |
|
Returns true if a behaviour at given time requires absence.
◆ requiresPresence()
bool BehaviourHandler::requiresPresence |
( |
Time |
t | ) |
|
Returns true if a behaviour at given time requires presence.
◆ resolveSwitchBehaviour()
Returns most specific active switch behaviour, resolving conflicts.
None if no behaviours are active. Requires _behaviourStore to be non-null and currentTime.isValid() == true.
- Parameters
-
currentTime | |
currentPresence | |
- Returns
◆ tryFinalizeBehaviourSettingsSync()
void BehaviourHandler::tryFinalizeBehaviourSettingsSync |
( |
| ) |
|
|
private |
If there was any behaviour settings sync response, the behaviour settings sync will be finalized.
◆ update()
bool BehaviourHandler::update |
( |
| ) |
|
Acquires the current time and presence information.
Checks and updates the currentIntendedState by looping over the active behaviours.
If isActive is false, or _presenceHandler is nullptr, this method has no effect.
Returns true.
◆ validateBehaviour()
bool BehaviourHandler::validateBehaviour |
( |
Behaviour * |
behaviour | ) |
const |
◆ validateSwitchBehaviour()
- Returns
- Switch behaviour if the behaviour is a valid switch behaviour, and active at this time/presence.
-
nullptr otherwise.
◆ validateTwilightBehaviour()
- Returns
- Twilight behaviour if the behaviour is a valid twilight behaviour, and active at this time/presence.
-
nullptr otherwise.
◆ TestAccess< BehaviourHandler >
◆ _behaviourSettingsSynced
bool BehaviourHandler::_behaviourSettingsSynced = false |
|
private |
Whether the behaviour settings are synced.
◆ _behaviourStore
cached reference to the behaviour store.
(obtained at init)
◆ _isActive
bool BehaviourHandler::_isActive = true |
|
private |
setting this to false will result in a BehaviourHandler that will not have an opinion about the state anymore (getValue returns std::nullopt).
◆ _presenceHandler
Cached reference to the presence handler.
(obtained at init)
◆ _receivedBehaviourSettings
Cache the received behaviour settings during syncing.
◆ currentIntendedState
std::optional<uint8_t> BehaviourHandler::currentIntendedState = {} |
|
private |
The last value that was updated by the update method.
◆ previousIntendedState
std::optional<uint8_t> BehaviourHandler::previousIntendedState = {} |
|
private |
The last value returned by getValue.
The documentation for this class was generated from the following file: