Skip to content

Add window support (?) #766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fs_src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ <h1>General Settings</h1>
<select id="sys_mode">
<option id="sys_mode_0" value="0">Switch</option>
<option id="sys_mode_1" value="1">Roller Shutter</option>
<option id="sys_mode_5" value="5">Window</option>
<option id="sys_mode_2" value="2">Garage Door Opener</option>
<option id="sys_mode_3" value="3">RGB</option>
<option id="sys_mode_4" value="4">RGBW</option>
Expand Down
6 changes: 6 additions & 0 deletions fs_src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ function findOrAddContainer(cd) {
sswSetConfig(c);
};
break;
case 12: // Window, or
case 4: // Window Covering
c = el("wc_template").cloneNode(true);
c.id = elId;
Expand Down Expand Up @@ -662,6 +663,7 @@ function updateComponent(cd) {
updateInnerText(el(c, "last_event"), lastEvText);
break;
}
case 12: // Window, or
case 4: { // Window Covering
updateInnerText(el(c, "head"), cd.name);
setValueIfNotModified(el(c, "name"), cd.name);
Expand Down Expand Up @@ -850,6 +852,10 @@ function updateElement(key, value, info) {
updateInnerText(el(key), `${value} ${key.split("_").slice(-1)[0]}`);
}
break;
case "w_avail":
if (value) el("sys_mode_container").style.display = "block";
else if (el("sys_mode_5")) el("sys_mode_5").remove();
break;
case "wc_avail":
if (value) el("sys_mode_container").style.display = "block";
else if (el("sys_mode_1")) el("sys_mode_1").remove();
Expand Down
46 changes: 46 additions & 0 deletions src/Shelly25/shelly_init_components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "shelly_hap_garage_door_opener.hpp"
#include "shelly_hap_input.hpp"
#include "shelly_hap_window.hpp"
#include "shelly_hap_window_covering.hpp"
#include "shelly_main.hpp"

Expand Down Expand Up @@ -72,6 +73,51 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
comps->emplace_back(std::move(wc));
return;
}
// Window mode
if (mgos_sys_config_get_shelly_mode() == 5) {
const int id = 1;
auto *wc_cfg = (struct mgos_config_wc *) mgos_sys_config_get_wc1();
auto im = static_cast<hap::Window::InMode>(wc_cfg->in_mode);
Input *in1 = FindInput(1), *in2 = FindInput(2);
std::unique_ptr<hap::Window> wc(new hap::Window(id, in1, in2, FindOutput(1),
FindOutput(2), FindPM(1),
FindPM(2), wc_cfg));
if (wc == nullptr || !wc->Init().ok()) {
return;
}
wc->set_primary(true);
switch (im) {
case hap::Window::InMode::kSeparateMomentary:
case hap::Window::InMode::kSeparateToggle: {
// Single accessory with a single primary service.
mgos::hap::Accessory *pri_acc = (*accs)[0].get();
pri_acc->SetCategory(kHAPAccessoryCategory_Windows);
pri_acc->AddService(wc.get());
break;
}
case hap::Window::InMode::kSingle:
case hap::Window::InMode::kDetached: {
std::unique_ptr<mgos::hap::Accessory> acc(
new mgos::hap::Accessory(SHELLY_HAP_AID_BASE_WINDOW + id,
kHAPAccessoryCategory_BridgedAccessory,
wc_cfg->name, &AccessoryIdentifyCB, svr));
acc->AddHAPService(&mgos_hap_accessory_information_service);
acc->AddService(wc.get());
accs->push_back(std::move(acc));
if (im == hap::Window::InMode::kDetached) {
hap::CreateHAPInput(1, mgos_sys_config_get_in1(), comps, accs, svr);
hap::CreateHAPInput(2, mgos_sys_config_get_in2(), comps, accs, svr);
} else if (wc_cfg->swap_inputs) {
hap::CreateHAPInput(1, mgos_sys_config_get_in1(), comps, accs, svr);
} else {
hap::CreateHAPInput(2, mgos_sys_config_get_in2(), comps, accs, svr);
}
break;
}
}
comps->emplace_back(std::move(wc));
return;
}
// Garage door opener mode.
if (mgos_sys_config_get_shelly_mode() == 2) {
auto *gdo_cfg = (struct mgos_config_gdo *) mgos_sys_config_get_gdo1();
Expand Down
3 changes: 3 additions & 0 deletions src/shelly_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#define SHELLY_HAP_AID_BASE_VALVE 0x900
#define SHELLY_HAP_AID_BASE_DOORBELL 0xa00
#define SHELLY_HAP_AID_BASE_LIGHTING 0xb00
#define SHELLY_HAP_AID_BASE_WINDOW 0xc00

#define SHELLY_HAP_IID_BASE_SWITCH 0x100
#define SHELLY_HAP_IID_STEP_SWITCH 4
Expand All @@ -59,6 +60,8 @@
#define SHELLY_HAP_IID_BASE_DOORBELL 0xb00
#define SHELLY_HAP_IID_BASE_LIGHTING 0xc00
#define SHELLY_HAP_IID_STEP_LIGHTING 0x10
#define SHELLY_HAP_IID_BASE_WINDOW 0xd00
#define SHELLY_HAP_IID_STEP_WINDOW 0x10

namespace shelly {

Expand Down
1 change: 1 addition & 0 deletions src/shelly_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Component {
kContactSensor = 9,
kDoorbell = 10,
kLightBulb = 11,
kWindow = 12,
kMax,
};

Expand Down
Loading