mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-11 03:42:12 +02:00
Merge 4aad5e5a2e into eb75868adb
This commit is contained in:
commit
ded220dc4d
1 changed files with 29 additions and 10 deletions
39
Somfy.cpp
39
Somfy.cpp
|
|
@ -3751,12 +3751,18 @@ SomfyShade *SomfyShadeController::addShade(JsonObject &obj) {
|
||||||
}
|
}
|
||||||
SomfyShade *SomfyShadeController::addShade() {
|
SomfyShade *SomfyShadeController::addShade() {
|
||||||
uint8_t shadeId = this->getNextShadeId();
|
uint8_t shadeId = this->getNextShadeId();
|
||||||
// So the next shade id will be the first one we run into with an id of 255 so
|
// Shades are packed into the lowest slots when they are loaded, so once one has been
|
||||||
// if it gets deleted in the middle then it will get the first slot that is empty.
|
// deleted a shade's slot no longer matches its id.
|
||||||
// There is no apparent way around this. In the future we might actually add an indexer
|
// In the future we might actually add an indexer
|
||||||
// to it for sorting later. The time has come so the sort order is set below.
|
// to it for sorting later. The time has come so the sort order is set below.
|
||||||
if(shadeId == 255) return nullptr;
|
if(shadeId == 255) return nullptr;
|
||||||
SomfyShade *shade = &this->shades[shadeId - 1];
|
SomfyShade *shade = nullptr;
|
||||||
|
for(uint8_t i = 0; i < SOMFY_MAX_SHADES; i++) {
|
||||||
|
if(this->shades[i].getShadeId() == 255) {
|
||||||
|
shade = &this->shades[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if(shade) {
|
if(shade) {
|
||||||
shade->setShadeId(shadeId);
|
shade->setShadeId(shadeId);
|
||||||
shade->sortOrder = this->getMaxShadeOrder() + 1;
|
shade->sortOrder = this->getMaxShadeOrder() + 1;
|
||||||
|
|
@ -3848,9 +3854,16 @@ SomfyRoom *SomfyShadeController::addRoom(JsonObject &obj) {
|
||||||
}
|
}
|
||||||
SomfyRoom *SomfyShadeController::addRoom() {
|
SomfyRoom *SomfyShadeController::addRoom() {
|
||||||
uint8_t roomId = this->getNextRoomId();
|
uint8_t roomId = this->getNextRoomId();
|
||||||
// So the next room id will be the first one we run into with an id of 0 so
|
// Rooms are packed into the lowest slots when they are loaded, so once one has been
|
||||||
|
// deleted a room's slot no longer matches its id.
|
||||||
if(roomId == 0) return nullptr;
|
if(roomId == 0) return nullptr;
|
||||||
SomfyRoom *room = &this->rooms[roomId - 1];
|
SomfyRoom *room = nullptr;
|
||||||
|
for(uint8_t i = 0; i < SOMFY_MAX_ROOMS; i++) {
|
||||||
|
if(this->rooms[i].roomId == 0) {
|
||||||
|
room = &this->rooms[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if(room) {
|
if(room) {
|
||||||
room->roomId = roomId;
|
room->roomId = roomId;
|
||||||
room->sortOrder = this->getMaxRoomOrder() + 1;
|
room->sortOrder = this->getMaxRoomOrder() + 1;
|
||||||
|
|
@ -3870,12 +3883,18 @@ SomfyGroup *SomfyShadeController::addGroup(JsonObject &obj) {
|
||||||
}
|
}
|
||||||
SomfyGroup *SomfyShadeController::addGroup() {
|
SomfyGroup *SomfyShadeController::addGroup() {
|
||||||
uint8_t groupId = this->getNextGroupId();
|
uint8_t groupId = this->getNextGroupId();
|
||||||
// So the next shade id will be the first one we run into with an id of 255 so
|
// Groups are packed into the lowest slots when they are loaded, so once one has been
|
||||||
// if it gets deleted in the middle then it will get the first slot that is empty.
|
// deleted a group's slot no longer matches its id.
|
||||||
// There is no apparent way around this. In the future we might actually add an indexer
|
// In the future we might actually add an indexer
|
||||||
// to it for sorting later.
|
// to it for sorting later.
|
||||||
if(groupId == 255) return nullptr;
|
if(groupId == 255) return nullptr;
|
||||||
SomfyGroup *group = &this->groups[groupId - 1];
|
SomfyGroup *group = nullptr;
|
||||||
|
for(uint8_t i = 0; i < SOMFY_MAX_GROUPS; i++) {
|
||||||
|
if(this->groups[i].getGroupId() == 255) {
|
||||||
|
group = &this->groups[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if(group) {
|
if(group) {
|
||||||
group->setGroupId(groupId);
|
group->setGroupId(groupId);
|
||||||
group->sortOrder = this->getMaxGroupOrder() + 1;
|
group->sortOrder = this->getMaxGroupOrder() + 1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue