Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
TwilightHandler Class Reference

#include <cs_TwilightHandler.h>

Inheritance diagram for TwilightHandler:
Collaboration diagram for TwilightHandler:

Public Member Functions

cs_ret_code_t init () override
 Initialize this class: More...
 
void handleEvent (event_t &evt) override
 Computes the twilight state of this crownstone based on the stored behaviours, and then dispatches an event. More...
 
bool update ()
 Acquires the current time and presence information. More...
 
std::optional< uint8_t > getValue ()
 Returns currentIntendedState. More...
 
- Public Member Functions inherited from EventListener
 EventListener ()
 
virtual ~EventListener ()
 unregisters the listener. More...
 
virtual void handleEvent (event_t &event)=0
 Handle events. More...
 
void listen ()
 Registers this with the EventDispatcher. More...
 
- Public Member Functions inherited from Component
template<class T >
T * getComponent (Component *requester=nullptr)
 Returns a component of type T* from _parent->children(), If not found try again with ancestors: _parent-> ... ->_parent->children(). More...
 
virtual cs_ret_code_t init ()
 Components can implement this if they need to get references to sibling or if they need to do specific initialization. More...
 
void parentAllChildren ()
 utility that loops over all elements of getChildren() and setParent on the non-nullptr ones. More...
 
virtual ~Component ()=default
 

Private Member Functions

std::optional< uint8_t > computeIntendedState (Time currentTime)
 Given current time, query the behaviourstore and check if there any valid ones. More...
 

Private Attributes

std::optional< uint8_t > _currentIntendedState = 100
 
bool _isActive = true
 Is this handler active? More...
 
BehaviourStore_behaviourStore = nullptr
 cached reference to the behaviour store. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Component
virtual std::vector< Component * > getChildren ()
 Components with children can override this method to return them. More...
 
cs_ret_code_t initChildren ()
 
void setParent (Component *p)
 Children that are instantiated later can also be added individually. More...
 

Member Function Documentation

◆ computeIntendedState()

std::optional< uint8_t > TwilightHandler::computeIntendedState ( Time  currentTime)
private

Given current time, query the behaviourstore and check if there any valid ones.

Returns an empty optional if time is invalid, or this isActive==false. Else returns a non-empty optional containing the conflict resolved value of all active twilights, defaulting to 100 if none are active.

◆ getValue()

std::optional< uint8_t > TwilightHandler::getValue ( )

Returns currentIntendedState.

◆ handleEvent()

void TwilightHandler::handleEvent ( event_t evt)
overridevirtual

Computes the twilight state of this crownstone based on the stored behaviours, and then dispatches an event.

Events:

  • EVT_PRESENCE_MUTATION
  • EVT_BEHAVIOURSTORE_MUTATION
  • STATE_BEHAVIOUR_SETTINGS

Implements EventListener.

◆ init()

cs_ret_code_t TwilightHandler::init ( )
overridevirtual

Initialize this class:

  • Read settings from flash.
  • Start listening for events.
  • obtain reference to behaviourstore

Reimplemented from Component.

◆ update()

bool TwilightHandler::update ( )

Acquires the current time and presence information.

Checks the intended state by looping over the active behaviours and if the intendedState differs from previousIntendedState dispatch an event to communicate a state update.

if time is not valid, aborts method execution and returns false. returns true when value was updated, false else.

Member Data Documentation

◆ _behaviourStore

BehaviourStore* TwilightHandler::_behaviourStore = nullptr
private

cached reference to the behaviour store.

(obtained at init)

◆ _currentIntendedState

std::optional<uint8_t> TwilightHandler::_currentIntendedState = 100
private

◆ _isActive

bool TwilightHandler::_isActive = true
private

Is this handler active?


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