Skip to content

Commit

Permalink
Create switch 2, then switch 1 in compat mode
Browse files Browse the repository at this point in the history
But maintain components list in the original order.

This is all in order to generate exactly identical service description as 2.0.x
  • Loading branch information
rojer committed Sep 18, 2020
1 parent ba2fd0b commit a5617dd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
2 changes: 1 addition & 1 deletion mos.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
author: 'Deomid "rojer" Ryabkov'
description: A HomeKit firmware for Shelly switches
version: 2.1.6
version: 2.1.7
platform: esp8266

libs_version: latest
Expand Down
26 changes: 18 additions & 8 deletions src/Shelly2/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

#include <algorithm>

#include "shelly_main.hpp"

namespace shelly {
Expand All @@ -36,15 +38,23 @@ void CreatePeripherals(std::vector<std::unique_ptr<Input>> *inputs,
void CreateComponents(std::vector<Component *> *comps,
std::vector<std::unique_ptr<hap::Accessory>> *accs,
HAPAccessoryServerRef *svr) {
// Use legacy layout if upgraded from older version.
// Use legacy layout if upgraded from an older version (pre-2.1).
// However, presence of detached inputs overrides it.
bool to_pri_acc = (mgos_sys_config_get_shelly_legacy_hap_layout() &&
mgos_sys_config_get_sw1_in_mode() != 3 &&
mgos_sys_config_get_sw2_in_mode() != 3);
CreateHAPSwitch(1, mgos_sys_config_get_sw1(), mgos_sys_config_get_ssw1(),
comps, accs, svr, to_pri_acc);
CreateHAPSwitch(2, mgos_sys_config_get_sw2(), mgos_sys_config_get_ssw2(),
comps, accs, svr, to_pri_acc);
bool compat_20 = (mgos_sys_config_get_shelly_legacy_hap_layout() &&
mgos_sys_config_get_sw1_in_mode() != 3 &&
mgos_sys_config_get_sw2_in_mode() != 3);
if (!compat_20) {
CreateHAPSwitch(1, mgos_sys_config_get_sw1(), mgos_sys_config_get_ssw1(),
comps, accs, svr, false /* to_pri_acc */);
CreateHAPSwitch(2, mgos_sys_config_get_sw2(), mgos_sys_config_get_ssw2(),
comps, accs, svr, false /* to_pri_acc */);
} else {
CreateHAPSwitch(2, mgos_sys_config_get_sw2(), mgos_sys_config_get_ssw2(),
comps, accs, svr, true /* to_pri_acc */);
CreateHAPSwitch(1, mgos_sys_config_get_sw1(), mgos_sys_config_get_ssw1(),
comps, accs, svr, true /* to_pri_acc */);
std::reverse(comps->begin(), comps->end());
}
}

} // namespace shelly
26 changes: 18 additions & 8 deletions src/Shelly25/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

#include <algorithm>

#include "shelly_main.hpp"

namespace shelly {
Expand All @@ -40,15 +42,23 @@ void CreatePeripherals(std::vector<std::unique_ptr<Input>> *inputs,
void CreateComponents(std::vector<Component *> *comps,
std::vector<std::unique_ptr<hap::Accessory>> *accs,
HAPAccessoryServerRef *svr) {
// Use legacy layout if upgraded from older version.
// Use legacy layout if upgraded from an older version (pre-2.1).
// However, presence of detached inputs overrides it.
bool to_pri_acc = (mgos_sys_config_get_shelly_legacy_hap_layout() &&
mgos_sys_config_get_sw1_in_mode() != 3 &&
mgos_sys_config_get_sw2_in_mode() != 3);
CreateHAPSwitch(1, mgos_sys_config_get_sw1(), mgos_sys_config_get_ssw1(),
comps, accs, svr, to_pri_acc);
CreateHAPSwitch(2, mgos_sys_config_get_sw2(), mgos_sys_config_get_ssw2(),
comps, accs, svr, to_pri_acc);
bool compat_20 = (mgos_sys_config_get_shelly_legacy_hap_layout() &&
mgos_sys_config_get_sw1_in_mode() != 3 &&
mgos_sys_config_get_sw2_in_mode() != 3);
if (!compat_20) {
CreateHAPSwitch(1, mgos_sys_config_get_sw1(), mgos_sys_config_get_ssw1(),
comps, accs, svr, false /* to_pri_acc */);
CreateHAPSwitch(2, mgos_sys_config_get_sw2(), mgos_sys_config_get_ssw2(),
comps, accs, svr, false /* to_pri_acc */);
} else {
CreateHAPSwitch(2, mgos_sys_config_get_sw2(), mgos_sys_config_get_ssw2(),
comps, accs, svr, true /* to_pri_acc */);
CreateHAPSwitch(1, mgos_sys_config_get_sw1(), mgos_sys_config_get_ssw1(),
comps, accs, svr, true /* to_pri_acc */);
std::reverse(comps->begin(), comps->end());
}
}

} // namespace shelly

0 comments on commit a5617dd

Please sign in to comment.