From a5617dd76e4fe0bcc623857b9dec4d745888abe3 Mon Sep 17 00:00:00 2001 From: "Deomid \"rojer\" Ryabkov" Date: Fri, 18 Sep 2020 21:48:51 +0100 Subject: [PATCH] Create switch 2, then switch 1 in compat mode But maintain components list in the original order. This is all in order to generate exactly identical service description as 2.0.x --- mos.yml | 2 +- src/Shelly2/shelly_init.cpp | 26 ++++++++++++++++++-------- src/Shelly25/shelly_init.cpp | 26 ++++++++++++++++++-------- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/mos.yml b/mos.yml index 74364036..3524d4af 100644 --- a/mos.yml +++ b/mos.yml @@ -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 diff --git a/src/Shelly2/shelly_init.cpp b/src/Shelly2/shelly_init.cpp index 3e04b878..8a274892 100644 --- a/src/Shelly2/shelly_init.cpp +++ b/src/Shelly2/shelly_init.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#include + #include "shelly_main.hpp" namespace shelly { @@ -36,15 +38,23 @@ void CreatePeripherals(std::vector> *inputs, void CreateComponents(std::vector *comps, std::vector> *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 diff --git a/src/Shelly25/shelly_init.cpp b/src/Shelly25/shelly_init.cpp index 58cb74d6..4de75509 100644 --- a/src/Shelly25/shelly_init.cpp +++ b/src/Shelly25/shelly_init.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#include + #include "shelly_main.hpp" namespace shelly { @@ -40,15 +42,23 @@ void CreatePeripherals(std::vector> *inputs, void CreateComponents(std::vector *comps, std::vector> *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