Skip to content

Commit

Permalink
fix detatched input
Browse files Browse the repository at this point in the history
  • Loading branch information
markirb committed Jun 14, 2024
1 parent 51cf40f commit f58ed70
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 36 deletions.
10 changes: 5 additions & 5 deletions src/Shelly1/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
HAPAccessoryServerRef *svr) {
bool gdo_mode = mgos_sys_config_get_shelly_mode() == (int) Mode::kGarageDoor;
bool ext_sensor_switch = (FindInput(2) != nullptr);
bool detatched_sensor =
(mgos_sys_config_get_sw1_in_mode() != (int) InMode::kDetached) &&
!gdo_mode && ext_sensor_switch;
bool single_accessory = sensors.empty() && !detatched_sensor;
bool addon_input = !gdo_mode && ext_sensor_switch;
bool single_accessory =
sensors.empty() && !addon_input &&
(mgos_sys_config_get_sw1_in_mode() != (int) InMode::kDetached);
if (gdo_mode) {
hap::CreateHAPGDO(1, FindInput(1), FindInput(2), FindOutput(1),
FindOutput(1), mgos_sys_config_get_gdo1(), comps, accs,
Expand All @@ -79,7 +79,7 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,

if (!sensors.empty()) {
CreateHAPSensors(&sensors, comps, accs, svr);
} else if (detatched_sensor) {
} else if (addon_input) {
hap::CreateHAPInput(2, mgos_sys_config_get_in2(), comps, accs, svr);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Shelly1PM/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
HAPAccessoryServerRef *svr) {
bool gdo_mode = mgos_sys_config_get_shelly_mode() == (int) Mode::kGarageDoor;
bool ext_sensor_switch = (FindInput(2) != nullptr);
bool detatched_sensor =
(mgos_sys_config_get_sw1_in_mode() != (int) InMode::kDetached) &&
!gdo_mode && ext_sensor_switch;
bool single_accessory = sensors.empty() && !detatched_sensor;
bool addon_input = !gdo_mode && ext_sensor_switch;
bool single_accessory =
sensors.empty() && !addon_input &&
(mgos_sys_config_get_sw1_in_mode() != (int) InMode::kDetached);
if (gdo_mode) {
hap::CreateHAPGDO(1, FindInput(1), FindInput(2), FindOutput(1),
FindOutput(1), mgos_sys_config_get_gdo1(), comps, accs,
Expand All @@ -96,7 +96,7 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,

if (!sensors.empty()) {
CreateHAPSensors(&sensors, comps, accs, svr);
} else if (detatched_sensor) {
} else if (addon_input) {
hap::CreateHAPInput(2, mgos_sys_config_get_in2(), comps, accs, svr);
}
}
Expand Down
21 changes: 5 additions & 16 deletions src/Shelly2/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,13 @@ void CreatePeripherals(std::vector<std::unique_ptr<Input>> *inputs,
void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
std::vector<std::unique_ptr<mgos::hap::Accessory>> *accs,
HAPAccessoryServerRef *svr) {
// Garage door opener mode.
if (mgos_sys_config_get_shelly_mode() == 2) {
auto *gdo_cfg = (struct mgos_config_gdo *) mgos_sys_config_get_gdo1();
std::unique_ptr<hap::GarageDoorOpener> gdo(new hap::GarageDoorOpener(
1, FindInput(1), FindInput(2), FindOutput(1), FindOutput(2), gdo_cfg));
if (gdo == nullptr) return;
auto st = gdo->Init();
if (!st.ok()) {
LOG(LL_ERROR, ("GDO init failed: %s", st.ToString().c_str()));
return;
}
gdo->set_primary(true);
mgos::hap::Accessory *pri_acc = (*accs)[0].get();
pri_acc->SetCategory(kHAPAccessoryCategory_GarageDoorOpeners);
pri_acc->AddService(gdo.get());
comps->emplace_back(std::move(gdo));
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, true /* single accessory */);
return;
}

// Use legacy layout if upgraded from an older version (pre-2.1).
// However, presence of detached inputs overrides it.
bool compat_20 = (mgos_sys_config_get_shelly_legacy_hap_layout() &&
Expand Down
10 changes: 5 additions & 5 deletions src/ShellyPlus1/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
HAPAccessoryServerRef *svr) {
bool gdo_mode = mgos_sys_config_get_shelly_mode() == (int) Mode::kGarageDoor;
bool ext_sensor_switch = (FindInput(2) != nullptr);
bool detatched_sensor =
(mgos_sys_config_get_sw1_in_mode() == (int) InMode::kDetached) &&
!gdo_mode && ext_sensor_switch;
bool single_accessory = sensors.empty() && !detatched_sensor;
bool addon_input = !gdo_mode && ext_sensor_switch;
bool single_accessory =
sensors.empty() && !addon_input &&
(mgos_sys_config_get_sw1_in_mode() != (int) InMode::kDetached);
if (gdo_mode) {
hap::CreateHAPGDO(1, FindInput(1), FindInput(2), FindOutput(1),
FindOutput(1), mgos_sys_config_get_gdo1(), comps, accs,
Expand All @@ -83,7 +83,7 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
if (!sensors.empty()) {
CreateHAPSensors(&sensors, comps, accs, svr);
}
if (ext_sensor_switch && !gdo_mode) {
if (addon_input) {
hap::CreateHAPInput(2, mgos_sys_config_get_in2(), comps, accs, svr);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/ShellyPlus1PM/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
HAPAccessoryServerRef *svr) {
bool gdo_mode = mgos_sys_config_get_shelly_mode() == (int) Mode::kGarageDoor;
bool ext_sensor_switch = (FindInput(2) != nullptr);
bool detatched_sensor =
(mgos_sys_config_get_sw1_in_mode() == (int) InMode::kDetached) &&
!gdo_mode && ext_sensor_switch;
bool single_accessory = sensors.empty() && !detatched_sensor;
bool addon_input = !gdo_mode && ext_sensor_switch;
bool single_accessory =
sensors.empty() && !addon_input &&
(mgos_sys_config_get_sw1_in_mode() != (int) InMode::kDetached);
if (gdo_mode) {
hap::CreateHAPGDO(1, FindInput(1), FindInput(2), FindOutput(1),
FindOutput(1), mgos_sys_config_get_gdo1(), comps, accs,
Expand All @@ -145,7 +145,7 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
if (!sensors.empty()) {
CreateHAPSensors(&sensors, comps, accs, svr);
}
if (ext_sensor_switch && !gdo_mode) {
if (addon_input) {
hap::CreateHAPInput(2, mgos_sys_config_get_in2(), comps, accs, svr);
}
}
Expand Down

0 comments on commit f58ed70

Please sign in to comment.