Skip to content

Commit

Permalink
gdo: fix pairing (gdo cannot be bridged)
Browse files Browse the repository at this point in the history
  • Loading branch information
markirb committed Jun 15, 2024
1 parent 3182eb3 commit 6a7c373
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Shelly1/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
if (gdo_mode) {
hap::CreateHAPGDO(1, FindInput(1), FindInput(2), FindOutput(1),
FindOutput(1), mgos_sys_config_get_gdo1(), comps, accs,
svr, single_accessory);
svr, true);
} else {
CreateHAPSwitch(1, mgos_sys_config_get_sw1(), mgos_sys_config_get_in1(),
comps, accs, svr, single_accessory);
Expand Down
2 changes: 1 addition & 1 deletion src/Shelly1PM/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
if (gdo_mode) {
hap::CreateHAPGDO(1, FindInput(1), FindInput(2), FindOutput(1),
FindOutput(1), mgos_sys_config_get_gdo1(), comps, accs,
svr, single_accessory);
svr, true);
} else {
CreateHAPSwitch(1, mgos_sys_config_get_sw1(), mgos_sys_config_get_in1(),
comps, accs, svr, single_accessory);
Expand Down
2 changes: 1 addition & 1 deletion src/ShellyPlus1/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
if (gdo_mode) {
hap::CreateHAPGDO(1, FindInput(1), FindInput(2), FindOutput(1),
FindOutput(1), mgos_sys_config_get_gdo1(), comps, accs,
svr, single_accessory);
svr, true);
} else {
CreateHAPSwitch(1, mgos_sys_config_get_sw1(), mgos_sys_config_get_in1(),
comps, accs, svr, single_accessory);
Expand Down
2 changes: 1 addition & 1 deletion src/ShellyPlus1PM/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
if (gdo_mode) {
hap::CreateHAPGDO(1, FindInput(1), FindInput(2), FindOutput(1),
FindOutput(1), mgos_sys_config_get_gdo1(), comps, accs,
svr, single_accessory);
svr, true);
} else {
CreateHAPSwitch(1, mgos_sys_config_get_sw1(), mgos_sys_config_get_in1(),
comps, accs, svr, single_accessory);
Expand Down
12 changes: 4 additions & 8 deletions src/ShellyPlus2PM/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,10 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
FindOutput(2), FindPM(1), FindPM(2),
mgos_sys_config_get_wc1(), mgos_sys_config_get_in1(),
mgos_sys_config_get_in2(), comps, accs, svr);
return;
}

bool additional_input_digital = (FindInput(3) != nullptr);
bool single_accessory = sensors.empty() and !additional_input_digital;

if (mgos_sys_config_get_shelly_mode() == (int) Mode::kGarageDoor) {
} else if (mgos_sys_config_get_shelly_mode() == (int) Mode::kGarageDoor) {
hap::CreateHAPGDO(1, FindInput(1), FindInput(2), FindOutput(1),
FindOutput(2), mgos_sys_config_get_gdo1(), comps, accs,
svr, single_accessory);
svr, true);
} else {
CreateHAPSwitch(1, mgos_sys_config_get_sw1(), mgos_sys_config_get_in1(),
comps, accs, svr, false /* to_pri_acc */);
Expand All @@ -261,6 +255,8 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
if (!sensors.empty()) {
CreateHAPSensors(&sensors, comps, accs, svr);
}

bool additional_input_digital = (FindInput(3) != nullptr);
if (additional_input_digital) {
hap::CreateHAPInput(3, mgos_sys_config_get_in3(), comps, accs, svr);
}
Expand Down
17 changes: 3 additions & 14 deletions src/shelly_hap_garage_door_opener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,6 @@ void CreateHAPGDO(int id, Input *in_close, Input *in_open, Output *out_close,
std::vector<std::unique_ptr<Component>> *comps,
std::vector<std::unique_ptr<mgos::hap::Accessory>> *accs,
HAPAccessoryServerRef *svr, bool to_pri_acc) {
uint64_t aid = 0;

struct mgos_config_gdo *gdo2_cfg = (struct mgos_config_gdo *) gdo_cfg;

std::unique_ptr<hap::GarageDoorOpener> gdo(new hap::GarageDoorOpener(
Expand All @@ -430,18 +428,9 @@ void CreateHAPGDO(int id, Input *in_close, Input *in_open, Output *out_close,
comps->push_back(std::move(gdo));
mgos::hap::Accessory *pri_acc = accs->front().get();

if (to_pri_acc) {
gdo2->set_primary(true);
pri_acc->SetCategory(kHAPAccessoryCategory_GarageDoorOpeners);
pri_acc->AddService(gdo2);
} else {
std::unique_ptr<mgos::hap::Accessory> acc(
new mgos::hap::Accessory(aid, kHAPAccessoryCategory_BridgedAccessory,
gdo_cfg->name, GetIdentifyCB(), svr));
acc->AddHAPService(&mgos_hap_accessory_information_service);
acc->AddService(gdo2);
accs->push_back(std::move(acc));
}
gdo2->set_primary(to_pri_acc);
pri_acc->SetCategory(kHAPAccessoryCategory_GarageDoorOpeners);
pri_acc->AddService(gdo2);
}

} // namespace hap
Expand Down

0 comments on commit 6a7c373

Please sign in to comment.