Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HomeAssistant Compatibility: Core Changes #533

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions nodemanager/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ void NodeManager::presentation() {
sensor->presentation();
sleepBetweenSend();
}

// wait a bit before leaving this function
sleepBetweenSend();
sleepBetweenSend();
Expand Down Expand Up @@ -280,6 +281,14 @@ void NodeManager::loop() {
Sensor* sensor = *itr;
// skip the sensor if not enabled
if (! sensor->getEnabled()) continue;
/* Entities won't show up for some controllers (e.g. HomeAssistant) unless we send initial states */
if (sensor->getFirstRun()) {
for (List<Child*>::iterator citr = sensor->children.begin(); citr != sensor->children.end(); ++citr) {
Child* child = *citr;
child->sendValue(true);
sleepBetweenSend();
}
}
// clear the MyMessage so will be ready to be used for the sensor
_message.clear();
#if NODEMANAGER_INTERRUPTS == ON
Expand Down
17 changes: 15 additions & 2 deletions nodemanager/Sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ Child* Sensor::getChild(uint8_t child_id) {
return nullptr;
}

Child* Sensor::getChild(uint8_t child_id, uint8_t ctype) {
for (List<Child*>::iterator itr = children.begin(); itr != children.end(); ++itr) {
Child* child = *itr;
if ((child->getChildId() == child_id) && (child->getType() == ctype))
return child;
}
return nullptr;
}

// present the sensor to the gateway and controller
void Sensor::presentation() {
for (List<Child*>::iterator itr = children.begin(); itr != children.end(); ++itr) {
Expand Down Expand Up @@ -208,7 +217,11 @@ void Sensor::loop(MyMessage* message) {
for (List<Child*>::iterator itr = children.begin(); itr != children.end(); ++itr) {
Child* child = *itr;
// if a specific child is requested from receive(), skip all the others
if (message != nullptr && message->sensor != child->getChildId()) continue;
if (message != nullptr &&
((message->sensor != child->getChildId()) ||
(message->type != child->getType()))) {
continue;
}
// collect multiple samples if needed
for (unsigned int i = 0; i < _samples; i++) {
// we've been called from receive(), pass the message along
Expand Down Expand Up @@ -342,7 +355,7 @@ void Sensor::onLoop(Child* /*child*/){}

// by default when a child receive a REQ message and the type matches the type of the request, executes its onLoop function
void Sensor::onReceive(MyMessage* message){
Child* child = getChild(message->sensor);
Child* child = getChild(message->sensor, message->type);
if (child == nullptr) return;
if (message->getCommand() == C_REQ && message->type == child->getType()) onLoop(child);
}
Expand Down
1 change: 1 addition & 0 deletions nodemanager/Sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Sensor {
List<Child*> children;
// return the child object based on the provided child_id
Child* getChild(uint8_t child_id);
Child* getChild(uint8_t child_id, uint8_t ctype);
// register a child
void registerChild(Child* child);
// [28] enabler/disable the sensor (default: true)
Expand Down