Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2484 lines
72 KiB

8 years ago
7 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
6 years ago
6 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
6 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
6 years ago
6 years ago
5 years ago
5 years ago
5 years ago
5 years ago
8 years ago
8 years ago
6 years ago
6 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
6 years ago
6 years ago
6 years ago
6 years ago
8 years ago
6 years ago
8 years ago
6 years ago
8 years ago
8 years ago
8 years ago
8 years ago
6 years ago
8 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
8 years ago
  1. var debug = false;
  2. var websock;
  3. var password = false;
  4. var maxNetworks;
  5. var messages = [];
  6. var free_size = 0;
  7. var urls = {};
  8. var numChanged = 0;
  9. var numReboot = 0;
  10. var numReconnect = 0;
  11. var numReload = 0;
  12. var configurationSaved = false;
  13. var ws_pingpong;
  14. //removeIf(!light)
  15. var colorPicker;
  16. var useWhite = false;
  17. var useCCT = false;
  18. //endRemoveIf(!light)
  19. var now = 0;
  20. var ago = 0;
  21. //removeIf(!rfm69)
  22. var packets;
  23. var filters = [];
  24. //endRemoveIf(!rfm69)
  25. //removeIf(!sensor)
  26. var Magnitudes = [];
  27. var MagnitudeErrors = {};
  28. var MagnitudeNames = {};
  29. var MagnitudeTypePrefixes = {};
  30. var MagnitudePrefixTypes = {};
  31. //endRemoveIf(!sensor)
  32. // -----------------------------------------------------------------------------
  33. // Messages
  34. // -----------------------------------------------------------------------------
  35. function initMessages() {
  36. messages[1] = "Remote update started";
  37. messages[2] = "OTA update started";
  38. messages[3] = "Error parsing data!";
  39. messages[4] = "The file does not look like a valid configuration backup or is corrupted";
  40. messages[5] = "Changes saved. You should reboot your board now";
  41. messages[7] = "Passwords do not match!";
  42. messages[8] = "Changes saved";
  43. messages[9] = "No changes detected";
  44. messages[10] = "Session expired, please reload page...";
  45. }
  46. // -----------------------------------------------------------------------------
  47. // Utils
  48. // -----------------------------------------------------------------------------
  49. $.fn.enterKey = function (fnc) {
  50. return this.each(function () {
  51. $(this).keypress(function (ev) {
  52. var keycode = parseInt(ev.keyCode ? ev.keyCode : ev.which, 10);
  53. if (13 === keycode) {
  54. return fnc.call(this, ev);
  55. }
  56. });
  57. });
  58. };
  59. function followScroll(id, threshold) {
  60. if (threshold === undefined) {
  61. threshold = 90;
  62. }
  63. var elem = document.getElementById(id);
  64. var offset = (elem.scrollTop + elem.offsetHeight) / elem.scrollHeight * 100;
  65. if (offset > threshold) {
  66. elem.scrollTop = elem.scrollHeight;
  67. }
  68. }
  69. function fromSchema(source, schema) {
  70. if (schema.length !== source.length) {
  71. throw "Schema mismatch!";
  72. }
  73. var target = {};
  74. schema.forEach(function(key, index) {
  75. target[key] = source[index];
  76. });
  77. return target;
  78. }
  79. function keepTime() {
  80. $("span[name='ago']").html(ago);
  81. ago++;
  82. if (0 === now) { return; }
  83. var date = new Date(now * 1000);
  84. var text = date.toISOString().substring(0, 19).replace("T", " ");
  85. $("input[name='now']").val(text);
  86. $("span[name='now']").html(text);
  87. now++;
  88. }
  89. function zeroPad(number, positions) {
  90. return number.toString().padStart(positions, "0");
  91. }
  92. function validatePassword(password) {
  93. // http://www.the-art-of-web.com/javascript/validate-password/
  94. // at least one lowercase and one uppercase letter or number
  95. // at least eight characters (letters, numbers or special characters)
  96. // MUST be 8..63 printable ASCII characters. See:
  97. // https://en.wikipedia.org/wiki/Wi-Fi_Protected_Access#Target_users_(authentication_key_distribution)
  98. // https://github.com/xoseperez/espurna/issues/1151
  99. var re_password = /^(?=.*[A-Z\d])(?=.*[a-z])[\w~!@#$%^&*\(\)<>,.\?;:{}\[\]\\|]{8,63}$/;
  100. return (
  101. (password !== undefined)
  102. && (typeof password === "string")
  103. && (password.length > 0)
  104. && re_password.test(password)
  105. );
  106. }
  107. function validateFormPasswords(form) {
  108. var passwords = $("input[name='adminPass1'],input[name='adminPass2']", form);
  109. var adminPass1 = passwords.first().val(),
  110. adminPass2 = passwords.last().val();
  111. var formValidity = passwords.first()[0].checkValidity();
  112. if (formValidity && (adminPass1.length === 0) && (adminPass2.length === 0)) {
  113. return true;
  114. }
  115. var validPass1 = validatePassword(adminPass1),
  116. validPass2 = validatePassword(adminPass2);
  117. if (formValidity && validPass1 && validPass2) {
  118. return true;
  119. }
  120. if (!formValidity || (adminPass1.length > 0 && !validPass1)) {
  121. alert("The password you have entered is not valid, it must be 8..63 characters and have at least 1 lowercase and 1 uppercase / number!");
  122. }
  123. if (adminPass1 !== adminPass2) {
  124. alert("Passwords are different!");
  125. }
  126. return false;
  127. }
  128. function validateFormHostname(form) {
  129. // RFCs mandate that a hostname's labels may contain only
  130. // the ASCII letters 'a' through 'z' (case-insensitive),
  131. // the digits '0' through '9', and the hyphen.
  132. // Hostname labels cannot begin or end with a hyphen.
  133. // No other symbols, punctuation characters, or blank spaces are permitted.
  134. // Negative lookbehind does not work in Javascript
  135. // var re_hostname = new RegExp('^(?!-)[A-Za-z0-9-]{1,32}(?<!-)$');
  136. var re_hostname = new RegExp('^(?!-)[A-Za-z0-9-]{0,31}[A-Za-z0-9]$');
  137. var hostname = $("input[name='hostname']", form);
  138. if ("true" !== hostname.attr("hasChanged")) {
  139. return true;
  140. }
  141. if (re_hostname.test(hostname.val())) {
  142. return true;
  143. }
  144. alert("Hostname cannot be empty and may only contain the ASCII letters ('A' through 'Z' and 'a' through 'z'), the digits '0' through '9', and the hyphen ('-')! They can neither start or end with an hyphen.");
  145. return false;
  146. }
  147. function validateForm(form) {
  148. return validateFormPasswords(form) && validateFormHostname(form);
  149. }
  150. // Observe all group settings to selectively update originals based on the current data
  151. var groupSettingsObserver = new MutationObserver(function(mutations) {
  152. mutations.forEach(function(mutation) {
  153. // If any new elements are added, set "settings-target" element as changed to forcibly send the data
  154. var targets = $(mutation.target).attr("data-settings-target");
  155. if (targets !== undefined) {
  156. mutation.addedNodes.forEach(function(node) {
  157. var overrides = [];
  158. targets.split(" ").forEach(function(target) {
  159. var elem = $("[name='" + target + "']", node);
  160. if (!elem.length) return;
  161. var value = getValue(elem);
  162. if ((value === null) || (value === elem[0].defaultValue)) {
  163. overrides.push(elem);
  164. }
  165. });
  166. setOriginalsFromValues($("input,select", node));
  167. overrides.forEach(function(elem) {
  168. elem.attr("hasChanged", "true");
  169. if (elem.prop("tagName") === "SELECT") {
  170. elem.prop("value", 0);
  171. }
  172. });
  173. });
  174. }
  175. // If anything was removed, forcibly send **all** of the group to avoid having any outdated keys
  176. // TODO: hide instead of remove?
  177. var changed = $(mutation.target).attr("hasChanged") === "true";
  178. if (changed || mutation.removedNodes.length) {
  179. $(mutation.target).attr("hasChanged", "true");
  180. $("input,select", mutation.target.childNodes).attr("hasChanged", "true");
  181. }
  182. });
  183. });
  184. // These fields will always be a list of values
  185. function isGroupValue(value) {
  186. var names = [
  187. "ssid", "pass", "gw", "mask", "ip", "dns",
  188. "schEnabled", "schSwitch","schAction","schType","schHour","schMinute","schWDs","schUTC",
  189. "relayBoot", "relayPulse", "relayTime", "relayLastSch",
  190. "mqttGroup", "mqttGroupSync", "relayOnDisc",
  191. "dczRelayIdx", "dczMagnitude",
  192. "tspkRelay", "tspkMagnitude",
  193. "ledGPIO", "ledMode", "ledRelay",
  194. "adminPass",
  195. "node", "key", "topic",
  196. "rpnRule", "rpnTopic", "rpnName"
  197. ];
  198. return names.indexOf(value) >= 0;
  199. }
  200. function bitsetToValues(bitset) {
  201. var values = [];
  202. for (var index = 0; index < 31; ++index) {
  203. if (bitset & (1 << index)) {
  204. values.push(String(index));
  205. }
  206. }
  207. return values;
  208. }
  209. function valuesToBitset(values) {
  210. var result = 0;
  211. for (var value of values) {
  212. result |= 1 << parseInt(value);
  213. }
  214. return result;
  215. }
  216. function getValue(element) {
  217. if ($(element).attr("type") === "checkbox") {
  218. return $(element).prop("checked") ? 1 : 0;
  219. } else if ($(element).attr("type") === "radio") {
  220. if (!$(element).prop("checked")) {
  221. return null;
  222. }
  223. } else if ($(element).attr("multiple") !== undefined) {
  224. return valuesToBitset($(element).val());
  225. }
  226. return $(element).val();
  227. }
  228. function addValue(data, name, value) {
  229. if (name in data) {
  230. if (!Array.isArray(data[name])) {
  231. data[name] = [data[name]];
  232. }
  233. data[name].push(value);
  234. } else if (isGroupValue(name)) {
  235. data[name] = [value];
  236. } else {
  237. data[name] = value;
  238. }
  239. }
  240. function getData(form, changed, cleanup) {
  241. // Populate two sets of data, ones that had been changed and ones that stayed the same
  242. var data = {};
  243. var changed_data = [];
  244. if (cleanup === undefined) {
  245. cleanup = true;
  246. }
  247. if (changed === undefined) {
  248. changed = true;
  249. }
  250. $("input,select", form).each(function() {
  251. if ($(this).attr("data-settings-ignore") === "true") {
  252. return;
  253. }
  254. var name = $(this).attr("name");
  255. var real_name = $(this).attr("data-settings-real-name");
  256. if (real_name !== undefined) {
  257. name = real_name;
  258. }
  259. var value = getValue(this);
  260. if (null !== value) {
  261. var haschanged = ("true" === $(this).attr("hasChanged"));
  262. var indexed = changed_data.indexOf(name) >= 0;
  263. if ((haschanged || !changed) && !indexed) {
  264. changed_data.push(name);
  265. }
  266. addValue(data, name, value);
  267. }
  268. });
  269. // Finally, filter out only fields that had changed.
  270. // Note: We need to preserve dynamic lists like schedules, wifi etc.
  271. // so we don't accidentally break when user deletes entry in the middle
  272. var resulting_data = {};
  273. for (var value in data) {
  274. if (changed_data.indexOf(value) >= 0) {
  275. resulting_data[value] = data[value];
  276. }
  277. }
  278. // Hack: clean-up leftover arrays.
  279. // When empty, the receiving side will prune all keys greater than the current one.
  280. if (cleanup) {
  281. $(".group-settings").each(function() {
  282. var haschanged = ("true" === $(this).attr("hasChanged"));
  283. if (haschanged && !this.children.length) {
  284. var targets = this.dataset.settingsTarget;
  285. if (targets === undefined) return;
  286. targets.split(" ").forEach(function(target) {
  287. resulting_data[target] = [];
  288. });
  289. }
  290. });
  291. }
  292. return resulting_data;
  293. }
  294. function randomString(length, args) {
  295. if (typeof args === "undefined") {
  296. args = {
  297. lowercase: true,
  298. uppercase: true,
  299. numbers: true,
  300. special: true
  301. }
  302. }
  303. var mask = "";
  304. if (args.lowercase) { mask += "abcdefghijklmnopqrstuvwxyz"; }
  305. if (args.uppercase) { mask += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; }
  306. if (args.numbers || args.hex) { mask += "0123456789"; }
  307. if (args.hex) { mask += "ABCDEF"; }
  308. if (args.special) { mask += "~`!@#$%^&*()_+-={}[]:\";'<>?,./|\\"; }
  309. var source = new Uint32Array(length);
  310. var result = new Array(length);
  311. window.crypto.getRandomValues(source).forEach(function(value, i) {
  312. result[i] = mask[value % mask.length];
  313. });
  314. return result.join("");
  315. }
  316. function generateAPIKey() {
  317. var apikey = randomString(16, {hex: true});
  318. $("input[name='apiKey']")
  319. .val(apikey)
  320. .attr("original", "-".repeat(16))
  321. .attr("haschanged", "true");
  322. return false;
  323. }
  324. function generatePassword() {
  325. var password = "";
  326. do {
  327. password = randomString(10);
  328. } while (!validatePassword(password));
  329. return password;
  330. }
  331. function toggleVisiblePassword() {
  332. var elem = this.previousElementSibling;
  333. if (elem.type === "password") {
  334. elem.type = "text";
  335. } else {
  336. elem.type = "password";
  337. }
  338. return false;
  339. }
  340. function doGeneratePassword() {
  341. var elems = $("input", $("#formPassword"));
  342. elems
  343. .val(generatePassword())
  344. .attr("haschanged", "true")
  345. .each(function() {
  346. this.type = "text";
  347. });
  348. return false;
  349. }
  350. function getJson(str) {
  351. try {
  352. return JSON.parse(str);
  353. } catch (e) {
  354. return false;
  355. }
  356. }
  357. function moduleVisible(module) {
  358. if (module == "sch") {
  359. $("li.module-" + module).css("display", "inherit");
  360. $("div.module-" + module).css("display", "flex");
  361. return;
  362. }
  363. $(".module-" + module).css("display", "inherit");
  364. }
  365. //removeIf(!thermostat)
  366. function checkTempRangeMin() {
  367. var min = parseInt($("#tempRangeMinInput").val(), 10);
  368. var max = parseInt($("#tempRangeMaxInput").val(), 10);
  369. if (min > max - 1) {
  370. $("#tempRangeMinInput").val(max - 1);
  371. }
  372. }
  373. function checkTempRangeMax() {
  374. var min = parseInt($("#tempRangeMinInput").val(), 10);
  375. var max = parseInt($("#tempRangeMaxInput").val(), 10);
  376. if (max < min + 1) {
  377. $("#tempRangeMaxInput").val(min + 1);
  378. }
  379. }
  380. function doResetThermostatCounters(ask) {
  381. var question = (typeof ask === "undefined" || false === ask) ?
  382. null :
  383. "Are you sure you want to reset burning counters?";
  384. return doAction(question, "thermostat_reset_counters");
  385. }
  386. //endRemoveIf(!thermostat)
  387. function initSelectGPIO(select) {
  388. // TODO: properly lock used GPIOs via locking and apply the mask here
  389. var mapping = [
  390. [153, "NONE"],
  391. [0, "0 (FLASH)"],
  392. [1, "1 (U0TXD)"],
  393. [2, "2 (U1TXD)"],
  394. [3, "3 (U0RXD)"],
  395. [4, "4 (SDA)"],
  396. [5, "5 (SCL)"],
  397. [9, "9 (SDD2)"],
  398. [10, "10 (SDD3)"],
  399. [12, "12 (MTDI)"],
  400. [13, "13 (MTCK)"],
  401. [14, "14 (MTMS)"],
  402. [15, "15 (MTDO)"],
  403. [16, "16 (WAKE)"],
  404. ];
  405. for (n in mapping) {
  406. var elem = $('<option value="' + mapping[n][0] + '">');
  407. elem.html(mapping[n][1]);
  408. elem.appendTo(select);
  409. }
  410. }
  411. // -----------------------------------------------------------------------------
  412. // Actions
  413. // -----------------------------------------------------------------------------
  414. function send(json) {
  415. if (debug) console.log(json);
  416. websock.send(json);
  417. }
  418. function sendAction(action, data) {
  419. send(JSON.stringify({action: action, data: data}));
  420. }
  421. function sendConfig(data) {
  422. send(JSON.stringify({config: data}));
  423. }
  424. function setOriginalsFromValues(elems) {
  425. if (typeof elems == "undefined") {
  426. elems = $("input,select");
  427. }
  428. elems.each(function() {
  429. var value;
  430. if ($(this).attr("type") === "checkbox") {
  431. value = $(this).prop("checked");
  432. } else {
  433. value = $(this).val();
  434. }
  435. $(this).attr("original", value);
  436. hasChanged.call(this);
  437. });
  438. }
  439. function resetOriginals() {
  440. setOriginalsFromValues();
  441. $(".group-settings").attr("haschanged", "false")
  442. numReboot = numReconnect = numReload = 0;
  443. configurationSaved = false;
  444. }
  445. function doReload(milliseconds) {
  446. setTimeout(function() {
  447. window.location.reload();
  448. }, parseInt(milliseconds, 10));
  449. }
  450. /**
  451. * Check a file object to see if it is a valid firmware image
  452. * The file first byte should be 0xE9
  453. * @param {file} file File object
  454. * @param {Function} callback Function to call back with the result
  455. */
  456. function checkFirmware(file, callback) {
  457. var reader = new FileReader();
  458. reader.onloadend = function(evt) {
  459. if (FileReader.DONE === evt.target.readyState) {
  460. var magic = evt.target.result.charCodeAt(0);
  461. if ((0x1F === magic) && (0x8B === evt.target.result.charCodeAt(1))) {
  462. callback(true);
  463. return;
  464. }
  465. if (0xE9 !== magic) {
  466. alert("Binary image does not start with a magic byte");
  467. callback(false);
  468. return;
  469. }
  470. var modes = ['QIO', 'QOUT', 'DIO', 'DOUT'];
  471. var flash_mode = evt.target.result.charCodeAt(2);
  472. if (0x03 !== flash_mode) {
  473. var response = window.confirm("Binary image is using " + modes[flash_mode] + " flash mode! Make sure that the device supports it before proceeding.");
  474. callback(response);
  475. } else {
  476. callback(true);
  477. }
  478. }
  479. };
  480. var blob = file.slice(0, 3);
  481. reader.readAsBinaryString(blob);
  482. }
  483. function doUpgrade() {
  484. var file = $("input[name='upgrade']")[0].files[0];
  485. if (typeof file === "undefined") {
  486. alert("First you have to select a file from your computer.");
  487. return false;
  488. }
  489. if (file.size > free_size) {
  490. alert("Image it too large to fit in the available space for OTA. Consider doing a two-step update.");
  491. return false;
  492. }
  493. checkFirmware(file, function(ok) {
  494. if (!ok) {
  495. return;
  496. }
  497. var data = new FormData();
  498. data.append("upgrade", file, file.name);
  499. var xhr = new XMLHttpRequest();
  500. var msg_ok = "Firmware image uploaded, board rebooting. This page will be refreshed in 5 seconds.";
  501. var msg_err = "There was an error trying to upload the new image, please try again: ";
  502. var network_error = function(e) {
  503. alert(msg_err + " xhr request " + e.type);
  504. };
  505. xhr.addEventListener("error", network_error, false);
  506. xhr.addEventListener("abort", network_error, false);
  507. xhr.addEventListener("load", function(e) {
  508. $("#upgrade-progress").hide();
  509. if ("OK" === xhr.responseText) {
  510. alert(msg_ok);
  511. doReload(5000);
  512. } else {
  513. alert(msg_err + xhr.status.toString() + " " + xhr.statusText + ", " + xhr.responseText);
  514. }
  515. }, false);
  516. xhr.upload.addEventListener("progress", function(e) {
  517. $("#upgrade-progress").show();
  518. if (e.lengthComputable) {
  519. $("progress").attr({ value: e.loaded, max: e.total });
  520. }
  521. }, false);
  522. xhr.open("POST", urls.upgrade.href);
  523. xhr.send(data);
  524. });
  525. return false;
  526. }
  527. function doUpdatePassword() {
  528. var form = $("#formPassword");
  529. if (validateFormPasswords(form)) {
  530. sendConfig(getData(form, true, false));
  531. }
  532. return false;
  533. }
  534. function checkChanges() {
  535. if (numChanged > 0) {
  536. var response = window.confirm("Some changes have not been saved yet, do you want to save them first?");
  537. if (response) {
  538. doUpdate();
  539. }
  540. }
  541. }
  542. function doAction(question, action) {
  543. checkChanges();
  544. if (question) {
  545. var response = window.confirm(question);
  546. if (false === response) {
  547. return false;
  548. }
  549. }
  550. sendAction(action, {});
  551. doReload(5000);
  552. return false;
  553. }
  554. function doReboot(ask) {
  555. var question = (typeof ask === "undefined" || false === ask) ?
  556. null :
  557. "Are you sure you want to reboot the device?";
  558. return doAction(question, "reboot");
  559. }
  560. function doReconnect(ask) {
  561. var question = (typeof ask === "undefined" || false === ask) ?
  562. null :
  563. "Are you sure you want to disconnect from the current WIFI network?";
  564. return doAction(question, "reconnect");
  565. }
  566. function doCheckOriginals() {
  567. var response;
  568. if (numReboot > 0) {
  569. response = window.confirm("You have to reboot the board for the changes to take effect, do you want to do it now?");
  570. if (response) { doReboot(false); }
  571. } else if (numReconnect > 0) {
  572. response = window.confirm("You have to reconnect to the WiFi for the changes to take effect, do you want to do it now?");
  573. if (response) { doReconnect(false); }
  574. } else if (numReload > 0) {
  575. response = window.confirm("You have to reload the page to see the latest changes, do you want to do it now?");
  576. if (response) { doReload(0); }
  577. }
  578. resetOriginals();
  579. }
  580. function waitForSave(){
  581. if (!configurationSaved) {
  582. setTimeout(waitForSave, 1000);
  583. } else {
  584. doCheckOriginals();
  585. }
  586. }
  587. function doUpdate() {
  588. var forms = $(".form-settings");
  589. if (validateForm(forms)) {
  590. // Get data
  591. sendConfig(getData(forms));
  592. // Empty special fields
  593. $(".pwrExpected").val(0);
  594. $("input[name='snsResetCalibration']").prop("checked", false);
  595. $("input[name='pwrResetCalibration']").prop("checked", false);
  596. $("input[name='pwrResetE']").prop("checked", false);
  597. // Change handling
  598. numChanged = 0;
  599. waitForSave();
  600. }
  601. return false;
  602. }
  603. function doBackup() {
  604. document.getElementById("downloader").src = urls.config.href;
  605. return false;
  606. }
  607. function onFileUpload(event) {
  608. var inputFiles = this.files;
  609. if (typeof inputFiles === "undefined" || inputFiles.length === 0) {
  610. return false;
  611. }
  612. var inputFile = inputFiles[0];
  613. this.value = "";
  614. var response = window.confirm("Previous settings will be overwritten. Are you sure you want to restore this settings?");
  615. if (!response) {
  616. return false;
  617. }
  618. var reader = new FileReader();
  619. reader.onload = function(e) {
  620. var data = getJson(e.target.result);
  621. if (data) {
  622. sendAction("restore", data);
  623. } else {
  624. window.alert(messages[4]);
  625. }
  626. };
  627. reader.readAsText(inputFile);
  628. return false;
  629. }
  630. function doRestore() {
  631. if (typeof window.FileReader !== "function") {
  632. alert("The file API isn't supported on this browser yet.");
  633. } else {
  634. $("#uploader").click();
  635. }
  636. return false;
  637. }
  638. function doFactoryReset() {
  639. var response = window.confirm("Are you sure you want to restore to factory settings?");
  640. if (!response) {
  641. return false;
  642. }
  643. sendAction("factory_reset", {});
  644. doReload(5000);
  645. return false;
  646. }
  647. function doToggle(id, value) {
  648. sendAction("relay", {id: id, status: value ? 1 : 0 });
  649. return false;
  650. }
  651. function doScan() {
  652. $("#scanResult").html("");
  653. $("div.scan.loading").show();
  654. $("#button-wifi-scan").attr("disabled", true);
  655. sendAction("scan", {});
  656. return false;
  657. }
  658. function doHAConfig() {
  659. $("#haConfig")
  660. .text("")
  661. .height(0)
  662. .show();
  663. sendAction("haconfig", {});
  664. return false;
  665. }
  666. function doDebugCommand() {
  667. var el = $("input[name='dbgcmd']");
  668. var command = el.val();
  669. el.val("");
  670. sendAction("dbgcmd", {command: command});
  671. followScroll("weblog", 0);
  672. return false;
  673. }
  674. function doDebugClear() {
  675. $("#weblog").text("");
  676. return false;
  677. }
  678. //removeIf(!rfm69)
  679. function doClearCounts() {
  680. sendAction("clear-counts", {});
  681. return false;
  682. }
  683. function doClearMessages() {
  684. packets.clear().draw(false);
  685. return false;
  686. }
  687. function doFilter(e) {
  688. var index = packets.cell(this).index();
  689. if (index == 'undefined') return;
  690. var c = index.column;
  691. var column = packets.column(c);
  692. if (filters[c]) {
  693. filters[c] = false;
  694. column.search("");
  695. $(column.header()).removeClass("filtered");
  696. } else {
  697. filters[c] = true;
  698. var data = packets.row(this).data();
  699. if (e.which == 1) {
  700. column.search('^' + data[c] + '$', true, false );
  701. } else {
  702. column.search('^((?!(' + data[c] + ')).)*$', true, false );
  703. }
  704. $(column.header()).addClass("filtered");
  705. }
  706. column.draw();
  707. return false;
  708. }
  709. function doClearFilters() {
  710. for (var i = 0; i < packets.columns()[0].length; i++) {
  711. if (filters[i]) {
  712. filters[i] = false;
  713. var column = packets.column(i);
  714. column.search("");
  715. $(column.header()).removeClass("filtered");
  716. column.draw();
  717. }
  718. }
  719. return false;
  720. }
  721. //endRemoveIf(!rfm69)
  722. function delParent() {
  723. var parent = $(this).parent().parent();
  724. $(parent).remove();
  725. }
  726. // -----------------------------------------------------------------------------
  727. // Visualization
  728. // -----------------------------------------------------------------------------
  729. function toggleMenu() {
  730. $("#layout").toggleClass("active");
  731. $("#menu").toggleClass("active");
  732. $("#menuLink").toggleClass("active");
  733. }
  734. function showPanel() {
  735. $(".panel").hide();
  736. if ($("#layout").hasClass("active")) { toggleMenu(); }
  737. $("#" + $(this).attr("data")).show();
  738. }
  739. // -----------------------------------------------------------------------------
  740. // Relays & magnitudes mapping
  741. // -----------------------------------------------------------------------------
  742. function createRelayList(data, container, template_name) {
  743. var current = $("#" + container + " > div").length;
  744. if (current > 0) { return; }
  745. var template = $("#" + template_name + " .pure-g")[0];
  746. for (var i in data) {
  747. var line = $(template).clone();
  748. $("label", line).html("Switch #" + i);
  749. $("input", line).attr("tabindex", 40 + i).val(data[i]);
  750. setOriginalsFromValues($("input", line));
  751. line.appendTo("#" + container);
  752. }
  753. }
  754. //removeIf(!sensor)
  755. function createMagnitudeList(data, container, template_name) {
  756. var current = $("#" + container + " > div").length;
  757. if (current > 0) { return; }
  758. var template = $("#" + template_name + " .pure-g")[0];
  759. var size = data.size;
  760. for (var i=0; i<size; ++i) {
  761. var line = $(template).clone();
  762. $("label", line).html(MagnitudeNames[data.type[i]] + " #" + parseInt(data.index[i], 10));
  763. $("div.hint", line).html(Magnitudes[i].description);
  764. $("input", line).attr("tabindex", 40 + i).val(data.idx[i]);
  765. setOriginalsFromValues($("input", line));
  766. line.appendTo("#" + container);
  767. }
  768. }
  769. //endRemoveIf(!sensor)
  770. // -----------------------------------------------------------------------------
  771. // RPN Rules
  772. // -----------------------------------------------------------------------------
  773. function addRPNRule() {
  774. var template = $("#rpnRuleTemplate .pure-g")[0];
  775. var line = $(template).clone();
  776. var tabindex = $("#rpnRules > div").length + 100;
  777. $(line).find("input").each(function() {
  778. $(this).attr("tabindex", tabindex++);
  779. });
  780. $(line).find("button").on('click', delParent);
  781. setOriginalsFromValues($("input", line));
  782. line.appendTo("#rpnRules");
  783. }
  784. function addRPNTopic() {
  785. var template = $("#rpnTopicTemplate .pure-g")[0];
  786. var line = $(template).clone();
  787. var tabindex = $("#rpnTopics > div").length + 120;
  788. $(line).find("input").each(function() {
  789. $(this).attr("tabindex", tabindex++);
  790. });
  791. $(line).find("button").on('click', delParent);
  792. setOriginalsFromValues($("input", line));
  793. line.appendTo("#rpnTopics");
  794. }
  795. // -----------------------------------------------------------------------------
  796. // RFM69
  797. // -----------------------------------------------------------------------------
  798. //removeIf(!rfm69)
  799. function addMapping() {
  800. var template = $("#nodeTemplate .pure-g")[0];
  801. var line = $(template).clone();
  802. var tabindex = $("#mapping > div").length * 3 + 50;
  803. $(line).find("input").each(function() {
  804. $(this).attr("tabindex", tabindex++);
  805. });
  806. $(line).find("button").on('click', delParent);
  807. setOriginalsFromValues($("input", line));
  808. line.appendTo("#mapping");
  809. }
  810. //endRemoveIf(!rfm69)
  811. // -----------------------------------------------------------------------------
  812. // Wifi
  813. // -----------------------------------------------------------------------------
  814. function numNetworks() {
  815. return $("#networks > div").length;
  816. }
  817. function delNetwork() {
  818. var parent = $(this).parents(".pure-g");
  819. $(parent).remove();
  820. }
  821. function moreNetwork() {
  822. var parent = $(this).parents(".pure-g");
  823. $(".more", parent).toggle();
  824. }
  825. function addNetwork(network) {
  826. var number = numNetworks();
  827. if (number >= maxNetworks) {
  828. alert("Max number of networks reached");
  829. return null;
  830. }
  831. if (network === undefined) {
  832. network = {};
  833. }
  834. var tabindex = 200 + number * 10;
  835. var template = $("#networkTemplate").children();
  836. var line = $(template).clone();
  837. $(line).find("input").each(function() {
  838. $(this).attr("tabindex", tabindex);
  839. tabindex++;
  840. });
  841. $(".password-reveal", line).on("click", toggleVisiblePassword);
  842. $(line).find(".button-del-network").on("click", delNetwork);
  843. $(line).find(".button-more-network").on("click", moreNetwork);
  844. Object.entries(network).forEach(function(pair) {
  845. // XXX: UI deleting this network will only re-use stored values.
  846. var key = pair[0],
  847. val = pair[1];
  848. if (key === "stored") {
  849. $(line).find(".button-del-network").prop("disabled", val);
  850. return;
  851. }
  852. $("input[name='" + key + "']", line).val(val);
  853. });
  854. line.appendTo("#networks");
  855. return line;
  856. }
  857. // -----------------------------------------------------------------------------
  858. // Relays scheduler
  859. // -----------------------------------------------------------------------------
  860. function numSchedules() {
  861. return $("#schedules > div").length;
  862. }
  863. function maxSchedules() {
  864. var value = $("#schedules").attr("data-settings-max");
  865. return parseInt(value === undefined ? 0 : value, 10);
  866. }
  867. function delSchedule() {
  868. var parent = $(this).parents(".pure-g");
  869. $(parent).remove();
  870. }
  871. function moreSchedule() {
  872. var parent = $(this).parents(".pure-g");
  873. $("div.more", parent).toggle();
  874. }
  875. function addSchedule(values) {
  876. var schedules = numSchedules();
  877. if (schedules >= maxSchedules()) {
  878. alert("Max number of schedules reached");
  879. return null;
  880. }
  881. if (values === undefined) {
  882. values = {};
  883. }
  884. var tabindex = 200 + schedules * 10;
  885. var template = $("#scheduleTemplate").children();
  886. var line = $(template).clone();
  887. var type = "none";
  888. switch(values.schType) {
  889. case 1:
  890. type = "switch";
  891. break;
  892. case 2:
  893. type = "light";
  894. break;
  895. case 3:
  896. type = "curtain";
  897. break;
  898. }
  899. template = $("#" + type + "ActionTemplate").children();
  900. $(line).find("#schActionDiv").append(template.clone());
  901. $(line).find("input").each(function() {
  902. $(this).attr("tabindex", tabindex);
  903. tabindex++;
  904. });
  905. $(line).find(".button-del-schedule").on("click", delSchedule);
  906. $(line).find(".button-more-schedule").on("click", moreSchedule);
  907. var schUTC_id = "schUTC" + schedules;
  908. $(line).find("input[name='schUTC']").prop("id", schUTC_id).next().prop("for", schUTC_id);
  909. var schEnabled_id = "schEnabled" + schedules;
  910. $(line).find("input[name='schEnabled']").prop("id", schEnabled_id).next().prop("for", schEnabled_id);
  911. $(line).find("input[type='checkbox']").prop("checked", false);
  912. Object.entries(values).forEach(function(kv) {
  913. var key = kv[0], value = kv[1];
  914. $("input[name='" + key + "']", line).val(value);
  915. $("select[name='" + key + "']", line).prop("value", value);
  916. $("input[type='checkbox'][name='" + key + "']", line).prop("checked", value);
  917. });
  918. line.appendTo("#schedules");
  919. return line;
  920. }
  921. // -----------------------------------------------------------------------------
  922. // Relays
  923. // -----------------------------------------------------------------------------
  924. function initRelayFromSchema(id, relay, schema) {
  925. var result = fromSchema(relay, schema)
  926. if (!result.name.length) {
  927. result.name = "Switch #" + id;
  928. }
  929. return result;
  930. }
  931. function initRelays(data) {
  932. var current = $("#relays > div").length;
  933. if (current > 0) { return; }
  934. var schema = data.schema;
  935. var template = $("#relayTemplate .pure-g")[0];
  936. data["relays"].forEach(function(relay, id) {
  937. var _relay = initRelayFromSchema(id, relay, schema);
  938. var line = $(template).clone();
  939. $("span.relay-name", line)
  940. .text(_relay.name)
  941. .attr("data", id);
  942. $("input[type='checkbox']", line)
  943. .prop('checked', false)
  944. .prop('disabled', true)
  945. .attr("data", id)
  946. .prop("id", "relay" + id)
  947. .on("change", function (event) {
  948. var target= parseInt($(event.target).attr("data"), 10);
  949. var status = $(event.target).prop("checked");
  950. doToggle(target, status);
  951. });
  952. $("label.toggle", line)
  953. .prop("for", "relay" + id);
  954. line.appendTo("#relays");
  955. });
  956. }
  957. function updateRelays(data) {
  958. var size = data.size;
  959. for (var i=0; i<size; ++i) {
  960. var elem = $("input[name='relay'][data='" + i + "']");
  961. elem.prop("checked", data.status[i]);
  962. var lock = {
  963. 0: false,
  964. 1: !data.status[i],
  965. 2: data.status[i]
  966. };
  967. elem.prop("disabled", lock[data.lock[i]]); // RELAY_LOCK_DISABLED=0
  968. }
  969. }
  970. function createCheckboxes() {
  971. $("input[type='checkbox']").each(function() {
  972. if($(this).prop("name"))$(this).prop("id", $(this).prop("name"));
  973. $(this).parent().addClass("toggleWrapper");
  974. $(this).after('<label for="' + $(this).prop("name") + '" class="toggle"><span class="toggle__handler"></span></label>')
  975. });
  976. }
  977. function initRelayConfig(data) {
  978. var current = $("#relayConfig > legend").length; // there is a legend per relay
  979. if (current > 0) { return; }
  980. var template = $("#relayConfigTemplate").children();
  981. var schema = data.schema;
  982. data["relays"].forEach(function(relay, id) {
  983. var _relay = initRelayFromSchema(id, relay, schema);
  984. var line = $(template).clone();
  985. $("span.name", line).html(_relay.name);
  986. $("span.prov", line).html(_relay.prov);
  987. $("select[name='relayBoot']", line).val(_relay.boot);
  988. $("select[name='relayPulse']", line).val(_relay.pulse);
  989. $("input[name='relayTime']", line).val(_relay.pulse_time);
  990. if (schema.includes("sch_last")) {
  991. $("input[name='relayLastSch']", line)
  992. .prop("checked", _relay.sch_last)
  993. .attr("id", "relayLastSch" + id)
  994. .attr("name", "relayLastSch" + id)
  995. .next().attr("for","relayLastSch" + (id));
  996. }
  997. if (schema.includes("group")) {
  998. $("input[name='mqttGroup']", line).val(_relay.group);
  999. }
  1000. if (schema.includes("group_sync")) {
  1001. $("select[name='mqttGroupSync']", line).val(_relay.group_sync);
  1002. }
  1003. if (schema.includes("on_disc")) {
  1004. $("select[name='relayOnDisc']", line).val(_relay.on_disc);
  1005. }
  1006. setOriginalsFromValues($("input,select", line));
  1007. line.appendTo("#relayConfig");
  1008. // Populate the relay SELECTs on the configuration panel
  1009. $("select.isrelay").append(
  1010. $("<option></option>")
  1011. .attr("value", id)
  1012. .text(name)
  1013. );
  1014. ++id;
  1015. });
  1016. }
  1017. // -----------------------------------------------------------------------------
  1018. // Sensors & Magnitudes
  1019. // -----------------------------------------------------------------------------
  1020. //removeIf(!sensor)
  1021. function initMagnitudes(data) {
  1022. // check if already initialized (each magnitude is inside div.pure-g)
  1023. var done = $("#magnitudes > div").length;
  1024. if (done > 0) { return; }
  1025. var size = data.size;
  1026. // add templates
  1027. var template = $("#magnitudeTemplate").children();
  1028. for (var i=0; i<size; ++i) {
  1029. var magnitude = {
  1030. "name": MagnitudeNames[data.type[i]] + " #" + parseInt(data.index[i], 10),
  1031. "units": data.units[i],
  1032. "description": data.description[i]
  1033. };
  1034. Magnitudes.push(magnitude);
  1035. var line = $(template).clone();
  1036. $("label", line).html(magnitude.name);
  1037. $("input", line).attr("data", i);
  1038. $("div.sns-desc", line).html(magnitude.description);
  1039. $("div.sns-info", line).hide();
  1040. line.appendTo("#magnitudes");
  1041. }
  1042. }
  1043. //endRemoveIf(!sensor)
  1044. // -----------------------------------------------------------------------------
  1045. // Curtains
  1046. // -----------------------------------------------------------------------------
  1047. //removeIf(!curtain)
  1048. //Create the controls for one curtain. It is called when curtain is updated (so created the first time)
  1049. //Let this there as we plan to have more than one curtain per switch
  1050. function initCurtain(data) {
  1051. var current = $("#curtains > div").length;
  1052. if (current > 0) { return; }
  1053. // add curtain template (prepare multi switches)
  1054. var template = $("#curtainTemplate").children();
  1055. var line = $(template).clone();
  1056. // init curtain button
  1057. $(line).find(".button-curtain-open").on("click", function() {
  1058. sendAction("curtainAction", {button: 1});
  1059. $(this).css('background', 'red');
  1060. });
  1061. $(line).find(".button-curtain-pause").on("click", function() {
  1062. sendAction("curtainAction", {button: 0});
  1063. $(this).css('background', 'red');
  1064. });
  1065. $(line).find(".button-curtain-close").on("click", function() {
  1066. sendAction("curtainAction", {button: 2});
  1067. $(this).css('background', 'red');
  1068. });
  1069. line.appendTo("#curtains");
  1070. // init curtain slider
  1071. $("#curtainSet").on("change", function() {
  1072. var value = $(this).val();
  1073. var parent = $(this).parents(".pure-g");
  1074. $("span", parent).html(value);
  1075. sendAction("curtainAction", {position: value});
  1076. });
  1077. }
  1078. function initCurtainConfig(data) {
  1079. var current = $("#curtainConfig > legend").length; // there is a legend per relay
  1080. if (current > 0) { return; }
  1081. // Populate the curtain select
  1082. $("select.iscurtain").append(
  1083. $("<option></option>")
  1084. .attr("value", "0")
  1085. .text("Curtain #" + "0")
  1086. );
  1087. }
  1088. //endRemoveIf(!curtain)
  1089. // -----------------------------------------------------------------------------
  1090. // Lights
  1091. // -----------------------------------------------------------------------------
  1092. //removeIf(!light)
  1093. function colorToHsvString(color) {
  1094. var h = String(Math.round(color.hsv.h));
  1095. var s = String(Math.round(color.hsv.s));
  1096. var v = String(Math.round(color.hsv.v));
  1097. return h + "," + s + "," + v;
  1098. }
  1099. function hsvStringToColor(hsv) {
  1100. var parts = hsv.split(",");
  1101. return {
  1102. h: parseInt(parts[0]),
  1103. s: parseInt(parts[1]),
  1104. v: parseInt(parts[2])
  1105. };
  1106. }
  1107. function colorSlider(type) {
  1108. return {component: iro.ui.Slider, options: {sliderType: type}};
  1109. }
  1110. function colorWheel() {
  1111. return {component: iro.ui.Wheel, options: {}};
  1112. }
  1113. function colorBox() {
  1114. return {component: iro.ui.Box, options: {}};
  1115. }
  1116. function updateColor(mode, value) {
  1117. if (colorPicker) {
  1118. if (mode === "rgb") {
  1119. colorPicker.color.hexString = value;
  1120. } else if (mode === "hsv") {
  1121. colorPicker.color.hsv = hsvStringToColor(value);
  1122. }
  1123. return;
  1124. }
  1125. // TODO: useRGB -> ltWheel?
  1126. // TODO: always show wheel + sliders like before?
  1127. var layout = []
  1128. if (mode === "rgb") {
  1129. layout.push(colorWheel());
  1130. layout.push(colorSlider("value"));
  1131. } else if (mode === "hsv") {
  1132. layout.push(colorBox());
  1133. layout.push(colorSlider("hue"));
  1134. }
  1135. var options = {
  1136. color: (mode === "rgb") ? value : hsvStringToColor(value),
  1137. layout: layout
  1138. };
  1139. colorPicker = new iro.ColorPicker("#color", options);
  1140. colorPicker.on("input:change", function(color) {
  1141. if (mode === "rgb") {
  1142. sendAction("color", {rgb: color.hexString});
  1143. } else if (mode === "hsv") {
  1144. sendAction("color", {hsv: colorToHsvString(color)});
  1145. }
  1146. });
  1147. }
  1148. function initCCT() {
  1149. // check if already initialized
  1150. var done = $("#cct > div").length;
  1151. if (done > 0) { return; }
  1152. $("#miredsTemplate").children().clone().appendTo("#cct");
  1153. $("#mireds").on("change", function() {
  1154. var value = $(this).val();
  1155. var parent = $(this).parents(".pure-g");
  1156. $("span", parent).html(value);
  1157. sendAction("mireds", {mireds: value});
  1158. });
  1159. }
  1160. function initChannels(num) {
  1161. // check if already initialized
  1162. var done = $("#channels > div").length > 0;
  1163. if (done) { return; }
  1164. // calculate channels to create
  1165. var max = num;
  1166. if (colorPicker) {
  1167. max = num % 3;
  1168. if ((max > 0) & useWhite) {
  1169. max--;
  1170. if (useCCT) {
  1171. max--;
  1172. }
  1173. }
  1174. }
  1175. var start = num - max;
  1176. var onChannelSliderChange = function() {
  1177. var id = $(this).attr("data");
  1178. var value = $(this).val();
  1179. var parent = $(this).parents(".pure-g");
  1180. $("span", parent).html(value);
  1181. sendAction("channel", {id: id, value: value});
  1182. };
  1183. // add channel templates
  1184. var i = 0;
  1185. var template = $("#channelTemplate").children();
  1186. for (i=0; i<max; i++) {
  1187. var channel_id = start + i;
  1188. var line = $(template).clone();
  1189. $("span.slider", line).attr("data", channel_id);
  1190. $("input.slider", line).attr("data", channel_id).on("change", onChannelSliderChange);
  1191. $("label", line).html("Channel #" + channel_id);
  1192. line.appendTo("#channels");
  1193. }
  1194. // Init channel dropdowns
  1195. for (i=0; i<num; i++) {
  1196. $("select.islight").append(
  1197. $("<option></option>").attr("value",i).text("Channel #" + i));
  1198. }
  1199. // add brightness template
  1200. var template = $("#brightnessTemplate").children();
  1201. var line = $(template).clone();
  1202. line.appendTo("#channels");
  1203. // init bright slider
  1204. $("#brightness").on("change", function() {
  1205. var value = $(this).val();
  1206. var parent = $(this).parents(".pure-g");
  1207. $("span", parent).html(value);
  1208. sendAction("brightness", {value: value});
  1209. });
  1210. }
  1211. //endRemoveIf(!light)
  1212. // -----------------------------------------------------------------------------
  1213. // RFBridge
  1214. // -----------------------------------------------------------------------------
  1215. //removeIf(!rfbridge)
  1216. function rfbLearn() {
  1217. var parent = $(this).parents(".pure-g");
  1218. var input = $("input", parent);
  1219. sendAction("rfblearn", {id: input.attr("data-id"), status: input.attr("data-status")});
  1220. }
  1221. function rfbForget() {
  1222. var parent = $(this).parents(".pure-g");
  1223. var input = $("input", parent);
  1224. sendAction("rfbforget", {id: input.attr("data-id"), status: input.attr("data-status")});
  1225. }
  1226. function rfbSend() {
  1227. var parent = $(this).parents(".pure-g");
  1228. var input = $("input", parent);
  1229. sendAction("rfbsend", {id: input.attr("data-id"), status: input.attr("data-status"), data: input.val()});
  1230. }
  1231. function addRfbNode() {
  1232. var numNodes = $("#rfbNodes > legend").length;
  1233. var template = $("#rfbNodeTemplate").children();
  1234. var line = $(template).clone();
  1235. $("span", line).html(numNodes);
  1236. $(line).find("input").each(function() {
  1237. this.dataset["id"] = numNodes;
  1238. });
  1239. $(line).find(".button-rfb-learn").on("click", rfbLearn);
  1240. $(line).find(".button-rfb-forget").on("click", rfbForget);
  1241. $(line).find(".button-rfb-send").on("click", rfbSend);
  1242. line.appendTo("#rfbNodes");
  1243. return line;
  1244. }
  1245. //endRemoveIf(!rfbridge)
  1246. // -----------------------------------------------------------------------------
  1247. // LightFox
  1248. // -----------------------------------------------------------------------------
  1249. //removeIf(!lightfox)
  1250. function lightfoxLearn() {
  1251. sendAction("lightfoxLearn", {});
  1252. }
  1253. function lightfoxClear() {
  1254. sendAction("lightfoxClear", {});
  1255. }
  1256. function initLightfox(data, relayCount) {
  1257. var numNodes = data.length;
  1258. var template = $("#lightfoxNodeTemplate").children();
  1259. var i, j;
  1260. for (i=0; i<numNodes; i++) {
  1261. var $line = $(template).clone();
  1262. $line.find("label > span").text(data[i]["id"]);
  1263. $line.find("select").each(function() {
  1264. $(this).attr("name", "btnRelay" + data[i]["id"]);
  1265. for (j=0; j < relayCount; j++) {
  1266. $(this).append($("<option >").attr("value", j).text("Switch #" + j));
  1267. }
  1268. $(this).val(data[i]["relay"]);
  1269. status = !status;
  1270. });
  1271. setOriginalsFromValues($("input,select", $line));
  1272. $line.appendTo("#lightfoxNodes");
  1273. }
  1274. var $panel = $("#panel-lightfox")
  1275. $(".button-lightfox-learn").off("click").click(lightfoxLearn);
  1276. $(".button-lightfox-clear").off("click").click(lightfoxClear);
  1277. }
  1278. //endRemoveIf(!lightfox)
  1279. // -----------------------------------------------------------------------------
  1280. // Processing
  1281. // -----------------------------------------------------------------------------
  1282. function processData(data) {
  1283. if (debug) console.log(data);
  1284. // title
  1285. if ("app_name" in data) {
  1286. var title = data.app_name;
  1287. if ("app_version" in data) {
  1288. $("span[name=title]").html(data.app_version);
  1289. title = title + " " + data.app_version;
  1290. }
  1291. if ("hostname" in data) {
  1292. title = data.hostname + " - " + title;
  1293. }
  1294. document.title = title;
  1295. }
  1296. Object.keys(data).forEach(function(key) {
  1297. var i;
  1298. var value = data[key];
  1299. // ---------------------------------------------------------------------
  1300. // Web mode
  1301. // ---------------------------------------------------------------------
  1302. if ("webMode" === key) {
  1303. password = (1 === value);
  1304. $("#layout").toggle(!password);
  1305. $("#password").toggle(password);
  1306. }
  1307. // ---------------------------------------------------------------------
  1308. // Actions
  1309. // ---------------------------------------------------------------------
  1310. if ("action" === key) {
  1311. if ("reload" === data.action) { doReload(1000); }
  1312. return;
  1313. }
  1314. // ---------------------------------------------------------------------
  1315. // RFBridge
  1316. // ---------------------------------------------------------------------
  1317. //removeIf(!rfbridge)
  1318. if ("rfbCount" === key) {
  1319. for (i=0; i<data.rfbCount; i++) { addRfbNode(); }
  1320. return;
  1321. }
  1322. if ("rfb" === key) {
  1323. var rfb = data.rfb;
  1324. var size = rfb.size;
  1325. var start = rfb.start;
  1326. var processOn = ((rfb.on !== undefined) && (rfb.on.length > 0));
  1327. var processOff = ((rfb.off !== undefined) && (rfb.off.length > 0));
  1328. for (var i=0; i<size; ++i) {
  1329. if (processOn) $("input[name='rfbcode'][data-id='" + (i + start) + "'][data-status='1']").val(rfb.on[i]);
  1330. if (processOff) $("input[name='rfbcode'][data-id='" + (i + start) + "'][data-status='0']").val(rfb.off[i]);
  1331. }
  1332. return;
  1333. }
  1334. //endRemoveIf(!rfbridge)
  1335. // ---------------------------------------------------------------------
  1336. // LightFox
  1337. // ---------------------------------------------------------------------
  1338. //removeIf(!lightfox)
  1339. if ("lightfoxButtons" === key) {
  1340. initLightfox(data["lightfoxButtons"], data["lightfoxRelayCount"]);
  1341. return;
  1342. }
  1343. //endRemoveIf(!lightfox)
  1344. // ---------------------------------------------------------------------
  1345. // RFM69
  1346. // ---------------------------------------------------------------------
  1347. //removeIf(!rfm69)
  1348. if (key == "packet") {
  1349. var packet = data.packet;
  1350. var d = new Date();
  1351. packets.row.add([
  1352. d.toLocaleTimeString('en-US', { hour12: false }),
  1353. packet.senderID,
  1354. packet.packetID,
  1355. packet.targetID,
  1356. packet.key,
  1357. packet.value,
  1358. packet.rssi,
  1359. packet.duplicates,
  1360. packet.missing,
  1361. ]).draw(false);
  1362. return;
  1363. }
  1364. if (key == "mapping") {
  1365. for (var i in data.mapping) {
  1366. // add a new row
  1367. addMapping();
  1368. // get group
  1369. var line = $("#mapping .pure-g")[i];
  1370. // fill in the blanks
  1371. var mapping = data.mapping[i];
  1372. Object.keys(mapping).forEach(function(key) {
  1373. var id = "input[name=" + key + "]";
  1374. if ($(id, line).length) $(id, line).val(mapping[key]);
  1375. });
  1376. setOriginalsFromValues($("input", line));
  1377. }
  1378. return;
  1379. }
  1380. //endRemoveIf(!rfm69)
  1381. // ---------------------------------------------------------------------
  1382. // RPN Rules
  1383. // ---------------------------------------------------------------------
  1384. if (key == "rpnRules") {
  1385. for (var i in data.rpnRules) {
  1386. // add a new row
  1387. addRPNRule();
  1388. // get group
  1389. var line = $("#rpnRules .pure-g")[i];
  1390. // fill in the blanks
  1391. var rule = data.rpnRules[i];
  1392. $("input", line).val(rule);
  1393. setOriginalsFromValues($("input", line));
  1394. }
  1395. return;
  1396. }
  1397. if (key == "rpnTopics") {
  1398. for (var i in data.rpnTopics) {
  1399. // add a new row
  1400. addRPNTopic();
  1401. // get group
  1402. var line = $("#rpnTopics .pure-g")[i];
  1403. // fill in the blanks
  1404. var topic = data.rpnTopics[i];
  1405. var name = data.rpnNames[i];
  1406. $("input[name='rpnTopic']", line).val(topic);
  1407. $("input[name='rpnName']", line).val(name);
  1408. setOriginalsFromValues($("input", line));
  1409. }
  1410. return;
  1411. }
  1412. if (key == "rpnNames") return;
  1413. // ---------------------------------------------------------------------
  1414. // Curtains
  1415. // ---------------------------------------------------------------------
  1416. //removeIf(!curtain)
  1417. function applyCurtain(a, b) {
  1418. $("#curtainGetPicture").css('background', 'linear-gradient(' + a + ', black ' + b + '%, #a0d6ff ' + b + '%)');
  1419. }
  1420. if ("curtainState" === key) {
  1421. initCurtain();
  1422. switch(value.type) {
  1423. case '0': //Roller
  1424. default:
  1425. applyCurtain('180deg', value.get);
  1426. break;
  1427. case '1': //One side left to right
  1428. applyCurtain('90deg', value.get);
  1429. break;
  1430. case '2': //One side right to left
  1431. applyCurtain('270deg', value.get);
  1432. break;
  1433. case '3': //Two sides
  1434. $("#curtainGetPicture").css('background', 'linear-gradient(90deg, black ' + value.get/2 + '%, #a0d6ff ' + value.get/2 + '% ' + (100 - value.get/2) + '%, black ' + (100 - value.get/2) + '%)');
  1435. break;
  1436. }
  1437. $("#curtainSet").val(value.set);
  1438. if(!value.moving) {
  1439. $("button.curtain-button").css('background', 'rgb(66, 184, 221)');
  1440. } else {
  1441. if(!value.button)
  1442. $("button.button-curtain-pause").css('background', 'rgb(192, 0, 0)');
  1443. else if(value.button == 1) {
  1444. $("button.button-curtain-close").css('background', 'rgb(66, 184, 221)');
  1445. $("button.button-curtain-open").css('background', 'rgb(192, 0, 0)');
  1446. }
  1447. else if(value.button == 2) {
  1448. $("button.button-curtain-open").css('background', 'rgb(66, 184, 221)');
  1449. $("button.button-curtain-close").css('background', 'rgb(192, 0, 0)');
  1450. }
  1451. }
  1452. return;
  1453. }
  1454. //endRemoveIf(!curtain)
  1455. // ---------------------------------------------------------------------
  1456. // Lights
  1457. // ---------------------------------------------------------------------
  1458. //removeIf(!light)
  1459. if ("lightstate" === key) {
  1460. $("#color").toggle(value);
  1461. return;
  1462. }
  1463. if (("rgb" === key) || ("hsv" === key)) {
  1464. updateColor(key, value);
  1465. return;
  1466. }
  1467. if ("brightness" === key) {
  1468. $("#brightness").val(value);
  1469. $("span.brightness").html(value);
  1470. return;
  1471. }
  1472. if ("channels" === key) {
  1473. var len = value.length;
  1474. initChannels(len);
  1475. for (i in value) {
  1476. var ch = value[i];
  1477. $("input.slider[data=" + i + "]").val(ch);
  1478. $("span.slider[data=" + i + "]").html(ch);
  1479. }
  1480. return;
  1481. }
  1482. if ("mireds" === key) {
  1483. $("#mireds").attr("min", value["cold"]);
  1484. $("#mireds").attr("max", value["warm"]);
  1485. $("#mireds").val(value["value"]);
  1486. $("span.mireds").html(value["value"]);
  1487. return;
  1488. }
  1489. if ("useWhite" === key) {
  1490. useWhite = value;
  1491. }
  1492. if ("useCCT" === key) {
  1493. initCCT();
  1494. useCCT = value;
  1495. }
  1496. //endRemoveIf(!light)
  1497. // ---------------------------------------------------------------------
  1498. // Sensors & Magnitudes
  1499. // ---------------------------------------------------------------------
  1500. //removeIf(!sensor)
  1501. {
  1502. var position = key.indexOf("Correction");
  1503. if (position > 0 && position === key.length - 10) {
  1504. var template = $("#magnitudeCorrectionTemplate > div")[0];
  1505. var elem = $(template).clone();
  1506. var prefix = key.slice(0, position);
  1507. $("label", elem).html(MagnitudeNames[MagnitudePrefixTypes[prefix]]);
  1508. $("input", elem).attr("name", key).val(value);
  1509. setOriginalsFromValues($("input", elem));
  1510. elem.appendTo("#magnitude-corrections");
  1511. moduleVisible("magnitude-corrections");
  1512. return;
  1513. }
  1514. }
  1515. if ("snsErrors" === key) {
  1516. for (var index in value) {
  1517. var type = value[index][0];
  1518. var name = value[index][1];
  1519. MagnitudeErrors[type] = name;
  1520. }
  1521. return;
  1522. }
  1523. if ("snsMagnitudes" === key) {
  1524. for (var index in value) {
  1525. var type = value[index][0];
  1526. var prefix = value[index][1];
  1527. var name = value[index][2];
  1528. MagnitudeNames[type] = name;
  1529. MagnitudeTypePrefixes[type] = prefix;
  1530. MagnitudePrefixTypes[prefix] = type;
  1531. moduleVisible(prefix);
  1532. }
  1533. return;
  1534. }
  1535. if ("magnitudesConfig" === key) {
  1536. initMagnitudes(value);
  1537. return;
  1538. }
  1539. if ("magnitudes" === key) {
  1540. for (var i=0; i<value.size; ++i) {
  1541. var inputElem = $("input[name='magnitude'][data='" + i + "']");
  1542. var infoElem = inputElem.parent().parent().find("div.sns-info");
  1543. var error = value.error[i] || 0;
  1544. var text = (0 === error)
  1545. ? value.value[i] + Magnitudes[i].units
  1546. : MagnitudeErrors[error];
  1547. inputElem.val(text);
  1548. if (value.info !== undefined) {
  1549. var info = value.info[i] || 0;
  1550. infoElem.toggle(info != 0);
  1551. infoElem.text(info);
  1552. }
  1553. }
  1554. return;
  1555. }
  1556. if ("pzemVisible" === key) {
  1557. $("input[name='snsSave']").prop("disabled", true);
  1558. $("input[name='snsSave']")
  1559. .parent().parent().find(".hint")
  1560. .text("PZEM004 module saves the energy data on it's own")
  1561. return;
  1562. }
  1563. //endRemoveIf(!sensor)
  1564. // ---------------------------------------------------------------------
  1565. // WiFi
  1566. // ---------------------------------------------------------------------
  1567. if ("wifi" === key) {
  1568. maxNetworks = parseInt(value["max"], 10);
  1569. value["networks"].forEach(function(network) {
  1570. addNetwork(fromSchema(network, value.schema));
  1571. });
  1572. return;
  1573. }
  1574. if ("scanResult" === key) {
  1575. $("div.scan.loading").hide();
  1576. $("#button-wifi-scan").attr("disabled", false);
  1577. $("#scanResult").show();
  1578. }
  1579. // -----------------------------------------------------------------------------
  1580. // Home Assistant
  1581. // -----------------------------------------------------------------------------
  1582. if ("haConfig" === key) {
  1583. send("{}");
  1584. $("#haConfig")
  1585. .append(new Text(value))
  1586. .height($("#haConfig")[0].scrollHeight);
  1587. return;
  1588. }
  1589. // -----------------------------------------------------------------------------
  1590. // Relays scheduler
  1591. // -----------------------------------------------------------------------------
  1592. if ("schedules" === key) {
  1593. $("#schedules").attr("data-settings-max", value.max);
  1594. for (var i=0; i<value.size; ++i) {
  1595. // XXX: no
  1596. var sch_map = {};
  1597. Object.keys(value).forEach(function(key) {
  1598. if ("size" == key) return;
  1599. if ("max" == key) return;
  1600. sch_map[key] = value[key][i];
  1601. });
  1602. addSchedule(sch_map);
  1603. }
  1604. return;
  1605. }
  1606. // ---------------------------------------------------------------------
  1607. // Relays
  1608. // ---------------------------------------------------------------------
  1609. if ("relayConfig" === key) {
  1610. initRelays(value);
  1611. initRelayConfig(value);
  1612. return;
  1613. }
  1614. if ("relayState" === key) {
  1615. updateRelays(value);
  1616. return;
  1617. }
  1618. // ---------------------------------------------------------------------
  1619. // Curtain(s)
  1620. // ---------------------------------------------------------------------
  1621. //removeIf(!curtain)
  1622. // Relay configuration
  1623. if ("curtainConfig" === key) {
  1624. initCurtainConfig(value);
  1625. return;
  1626. }
  1627. //endRemoveIf(!curtain)
  1628. // ---------------------------------------------------------------------
  1629. // LEDs
  1630. // ---------------------------------------------------------------------
  1631. if ("led" === key) {
  1632. if($("#ledConfig > div").length > 0) return;
  1633. var schema = value["schema"];
  1634. value["list"].forEach(function(led_data, index) {
  1635. var line = $($("#ledConfigTemplate").children()).clone();
  1636. $("span.id", line).html(index);
  1637. $("select", line).attr("data", index);
  1638. $("input", line).attr("data", index);
  1639. var led = fromSchema(led_data, schema);
  1640. $("select[name='ledGPIO']", line).val(led.GPIO);
  1641. // XXX: checkbox implementation depends on unique id
  1642. // $("input[name='ledInv']", line).val(led.Inv);
  1643. $("select[name='ledMode']", line).val(led.Mode);
  1644. $("input[name='ledRelay']", line).val(led.Relay);
  1645. setOriginalsFromValues($("input,select", line));
  1646. line.appendTo("#ledConfig");
  1647. });
  1648. return;
  1649. }
  1650. // ---------------------------------------------------------------------
  1651. // Domoticz
  1652. // ---------------------------------------------------------------------
  1653. // Domoticz - Relays
  1654. if ("dczRelays" === key) {
  1655. createRelayList(value, "dczRelays", "dczRelayTemplate");
  1656. return;
  1657. }
  1658. // Domoticz - Magnitudes
  1659. //removeIf(!sensor)
  1660. if ("dczMagnitudes" === key) {
  1661. createMagnitudeList(value, "dczMagnitudes", "dczMagnitudeTemplate");
  1662. return;
  1663. }
  1664. //endRemoveIf(!sensor)
  1665. // ---------------------------------------------------------------------
  1666. // Thingspeak
  1667. // ---------------------------------------------------------------------
  1668. // Thingspeak - Relays
  1669. if ("tspkRelays" === key) {
  1670. createRelayList(value, "tspkRelays", "tspkRelayTemplate");
  1671. return;
  1672. }
  1673. // Thingspeak - Magnitudes
  1674. //removeIf(!sensor)
  1675. if ("tspkMagnitudes" === key) {
  1676. createMagnitudeList(value, "tspkMagnitudes", "tspkMagnitudeTemplate");
  1677. return;
  1678. }
  1679. //endRemoveIf(!sensor)
  1680. // ---------------------------------------------------------------------
  1681. // HTTP API
  1682. // ---------------------------------------------------------------------
  1683. // Auto generate an APIKey if none defined yet
  1684. if ("apiVisible" === key) {
  1685. if (data.apiKey === undefined || data.apiKey === "") {
  1686. generateAPIKey();
  1687. }
  1688. }
  1689. // ---------------------------------------------------------------------
  1690. // General
  1691. // ---------------------------------------------------------------------
  1692. // Messages
  1693. if ("message" === key) {
  1694. if (value == 8) {
  1695. configurationSaved = true;
  1696. }
  1697. window.alert(messages[value]);
  1698. return;
  1699. }
  1700. // Web log
  1701. if ("weblog" === key) {
  1702. send("{}");
  1703. var msg = value["msg"];
  1704. var pre = value["pre"];
  1705. for (var i=0; i < msg.length; ++i) {
  1706. if (pre[i]) {
  1707. $("#weblog").append(new Text(pre[i]));
  1708. }
  1709. $("#weblog").append(new Text(msg[i]));
  1710. }
  1711. followScroll("weblog");
  1712. return;
  1713. }
  1714. // Enable options
  1715. var position = key.indexOf("Visible");
  1716. if (position > 0 && position === key.length - 7) {
  1717. var module = key.slice(0,-7);
  1718. moduleVisible(module);
  1719. return;
  1720. }
  1721. if ("deviceip" === key) {
  1722. var a_href = $("span[name='" + key + "']").parent();
  1723. a_href.attr("href", "//" + value);
  1724. a_href.next().attr("href", "telnet://" + value);
  1725. }
  1726. if ("now" === key) {
  1727. now = value;
  1728. return;
  1729. }
  1730. if ("free_size" === key) {
  1731. free_size = parseInt(value, 10);
  1732. }
  1733. // Pre-process
  1734. if ("mqttStatus" === key) {
  1735. value = value ? "CONNECTED" : "NOT CONNECTED";
  1736. }
  1737. if ("ntpStatus" === key) {
  1738. value = value ? "SYNC'D" : "NOT SYNC'D";
  1739. }
  1740. if ("uptime" === key) {
  1741. ago = 0;
  1742. var uptime = parseInt(value, 10);
  1743. var seconds = uptime % 60; uptime = parseInt(uptime / 60, 10);
  1744. var minutes = uptime % 60; uptime = parseInt(uptime / 60, 10);
  1745. var hours = uptime % 24; uptime = parseInt(uptime / 24, 10);
  1746. var days = uptime;
  1747. value = days + "d " + zeroPad(hours, 2) + "h " + zeroPad(minutes, 2) + "m " + zeroPad(seconds, 2) + "s";
  1748. }
  1749. //removeIf(!thermostat)
  1750. if ("tmpUnits" == key) {
  1751. $("span.tmpUnit").html(data[key] == 3 ? "ºF" : "ºC");
  1752. }
  1753. //endRemoveIf(!thermostat)
  1754. // ---------------------------------------------------------------------
  1755. // Matching
  1756. // ---------------------------------------------------------------------
  1757. var elems = [];
  1758. var pre;
  1759. var post;
  1760. // Look for INPUTs
  1761. var input = $("input[name='" + key + "']");
  1762. if (input.length > 0) {
  1763. if (input.attr("type") === "checkbox") {
  1764. input.prop("checked", value);
  1765. } else if (input.attr("type") === "radio") {
  1766. input.val([value]);
  1767. } else {
  1768. pre = input.attr("pre") || "";
  1769. post = input.attr("post") || "";
  1770. input.val(pre + value + post);
  1771. }
  1772. elems.push(input);
  1773. }
  1774. // Look for SPANs
  1775. var span = $("span[name='" + key + "']");
  1776. if (span.length > 0) {
  1777. if (Array.isArray(value)) {
  1778. value.forEach(function(elem) {
  1779. span.append(elem);
  1780. span.append('</br>');
  1781. elems.push(span);
  1782. });
  1783. } else {
  1784. pre = span.attr("pre") || "";
  1785. post = span.attr("post") || "";
  1786. span.html(pre + value + post);
  1787. elems.push(span);
  1788. }
  1789. }
  1790. // Look for SELECTs
  1791. var select = $("select[name='" + key + "']");
  1792. if (select.length > 0) {
  1793. if (select.attr("multiple") !== undefined) {
  1794. select.val(bitsetToValues(value));
  1795. } else {
  1796. select.val(value);
  1797. }
  1798. elems.push(select);
  1799. }
  1800. setOriginalsFromValues($(elems));
  1801. });
  1802. }
  1803. function hasChanged() {
  1804. var newValue, originalValue;
  1805. if ($(this).attr("type") === "checkbox") {
  1806. newValue = $(this).prop("checked");
  1807. originalValue = ($(this).attr("original") === "true");
  1808. } else {
  1809. newValue = $(this).val();
  1810. originalValue = $(this).attr("original");
  1811. }
  1812. if ($(this).attr("multiple") !== undefined) {
  1813. newValue = newValue.join(",");
  1814. }
  1815. var hasChanged = ("true" === $(this).attr("hasChanged"));
  1816. var action = $(this).attr("action");
  1817. if (typeof originalValue === "undefined") { return; }
  1818. if ("none" === action) { return; }
  1819. if (newValue !== originalValue) {
  1820. if (!hasChanged) {
  1821. ++numChanged;
  1822. if ("reconnect" === action) { ++numReconnect; }
  1823. if ("reboot" === action) { ++numReboot; }
  1824. if ("reload" === action) { ++numReload; }
  1825. }
  1826. $(this).attr("hasChanged", true);
  1827. } else {
  1828. if (hasChanged) {
  1829. --numChanged;
  1830. if ("reconnect" === action) { --numReconnect; }
  1831. if ("reboot" === action) { --numReboot; }
  1832. if ("reload" === action) { --numReload; }
  1833. }
  1834. $(this).attr("hasChanged", false);
  1835. }
  1836. }
  1837. // -----------------------------------------------------------------------------
  1838. // Init & connect
  1839. // -----------------------------------------------------------------------------
  1840. function initUrls(root) {
  1841. var paths = ["ws", "upgrade", "config", "auth"];
  1842. urls["root"] = root;
  1843. paths.forEach(function(path) {
  1844. urls[path] = new URL(path, root);
  1845. urls[path].protocol = root.protocol;
  1846. });
  1847. if (root.protocol == "https:") {
  1848. urls.ws.protocol = "wss:";
  1849. } else {
  1850. urls.ws.protocol = "ws:";
  1851. }
  1852. }
  1853. function connectToURL(url) {
  1854. initUrls(url);
  1855. fetch(urls.auth.href, {
  1856. 'method': 'GET',
  1857. 'cors': true,
  1858. 'credentials': 'same-origin'
  1859. }).then(function(response) {
  1860. // Nothing to do, reload page and retry
  1861. if (response.status != 200) {
  1862. doReload(5000);
  1863. return;
  1864. }
  1865. // update websock object
  1866. if (websock) { websock.close(); }
  1867. websock = new WebSocket(urls.ws.href);
  1868. websock.onmessage = function(evt) {
  1869. var data = getJson(evt.data.replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t"));
  1870. if (data) {
  1871. processData(data);
  1872. }
  1873. };
  1874. websock.onclose = function(evt) {
  1875. clearInterval(ws_pingpong);
  1876. if (window.confirm("Connection lost with the device, click OK to refresh the page")) {
  1877. $("#layout").toggle(false);
  1878. window.location.reload();
  1879. }
  1880. }
  1881. websock.onopen = function(evt) {
  1882. ws_pingpong = setInterval(function() { sendAction("ping", {}); }, 5000);
  1883. }
  1884. }).catch(function(error) {
  1885. console.log(error);
  1886. doReload(5000);
  1887. });
  1888. }
  1889. function connect(host) {
  1890. if (!host.startsWith("http:") && !host.startsWith("https:")) {
  1891. host = "http://" + host;
  1892. }
  1893. connectToURL(new URL(host));
  1894. }
  1895. function connectToCurrentURL() {
  1896. connectToURL(new URL(window.location));
  1897. }
  1898. $(function() {
  1899. initMessages();
  1900. createCheckboxes();
  1901. setInterval(function() { keepTime(); }, 1000);
  1902. $(".password-reveal").on("click", toggleVisiblePassword);
  1903. $("#menuLink").on("click", toggleMenu);
  1904. $(".pure-menu-link").on("click", showPanel);
  1905. $("progress").attr({ value: 0, max: 100 });
  1906. $("#button-wifi-scan").on("click", doScan);
  1907. $(".button-update").on("click", doUpdate);
  1908. $(".button-update-password").on("click", doUpdatePassword);
  1909. $(".button-generate-password").on("click", doGeneratePassword);
  1910. $(".button-reboot").on("click", doReboot);
  1911. $(".button-reconnect").on("click", doReconnect);
  1912. $(".button-ha-config").on("click", doHAConfig);
  1913. $(".button-dbgcmd").on("click", doDebugCommand);
  1914. $("input[name='dbgcmd']").enterKey(doDebugCommand);
  1915. $(".button-dbg-clear").on("click", doDebugClear);
  1916. $(".button-settings-backup").on("click", doBackup);
  1917. $(".button-settings-restore").on("click", doRestore);
  1918. $(".button-settings-factory").on("click", doFactoryReset);
  1919. $("#uploader").on("change", onFileUpload);
  1920. $(".button-upgrade").on("click", doUpgrade);
  1921. //removeIf(!garland)
  1922. $(".checkbox-garland-enable").on("change", function() {
  1923. sendAction("garland_switch", {status: $(this).prop("checked") ? 1 : 0});
  1924. });
  1925. $(".slider-garland-brightness").on("change", function() {
  1926. sendAction("garland_set_brightness", {brightness: $(this)[0].value});
  1927. });
  1928. $(".slider-garland-speed").on("change", function() {
  1929. sendAction("garland_set_speed", {speed: $(this)[0].value});
  1930. });
  1931. $(".button-garland-set-default").on("click", function() {
  1932. sendAction("garland_set_default", {});
  1933. });
  1934. //endRemoveIf(!garland)
  1935. //removeIf(!thermostat)
  1936. $(".button-thermostat-reset-counters").on('click', doResetThermostatCounters);
  1937. //endRemoveIf(!thermostat)
  1938. $(".button-apikey").on("click", generateAPIKey);
  1939. $(".button-upgrade-browse").on("click", function() {
  1940. $("input[name='upgrade']")[0].click();
  1941. return false;
  1942. });
  1943. $("input[name='upgrade']").change(function (){
  1944. var file = this.files[0];
  1945. $("input[name='filename']").val(file.name);
  1946. });
  1947. $(".button-add-network").on("click", function() {
  1948. $(".more", addNetwork()).toggle();
  1949. });
  1950. $(".button-add-switch-schedule").on("click", function() {
  1951. addSchedule({schType: 1, schSwitch: -1});
  1952. });
  1953. //removeIf(!light)
  1954. $(".button-add-light-schedule").on("click", function() {
  1955. addSchedule({schType: 2, schSwitch: -1});
  1956. });
  1957. //endRemoveIf(!light)
  1958. //removeIf(!curtain)
  1959. $(".button-add-curtain-schedule").on("click", function() {
  1960. addSchedule({schType: 3, schSwitch: -1});
  1961. });
  1962. //endRemoveIf(!curtain)
  1963. $(".button-add-rpnrule").on('click', addRPNRule);
  1964. $(".button-add-rpntopic").on('click', addRPNTopic);
  1965. $(".button-del-parent").on('click', delParent);
  1966. //removeIf(!rfm69)
  1967. $(".button-add-mapping").on('click', addMapping);
  1968. $(".button-clear-counts").on('click', doClearCounts);
  1969. $(".button-clear-messages").on('click', doClearMessages);
  1970. $(".button-clear-filters").on('click', doClearFilters);
  1971. $('#packets tbody').on('mousedown', 'td', doFilter);
  1972. packets = $('#packets').DataTable({
  1973. "paging": false
  1974. });
  1975. for (var i = 0; i < packets.columns()[0].length; i++) {
  1976. filters[i] = false;
  1977. }
  1978. //endRemoveIf(!rfm69)
  1979. $(".gpio-select").each(function(_, elem) {
  1980. initSelectGPIO(elem)
  1981. });
  1982. $(document).on("change", "input", hasChanged);
  1983. $(document).on("change", "select", hasChanged);
  1984. $("textarea").on("dblclick", function() { this.select(); });
  1985. resetOriginals();
  1986. $(".group-settings").each(function() {
  1987. groupSettingsObserver.observe(this, {childList: true});
  1988. });
  1989. // don't autoconnect when opening from filesystem
  1990. if (window.location.protocol === "file:") {
  1991. processData({"webMode": 0});
  1992. return;
  1993. }
  1994. // Check host param in query string
  1995. var search = new URLSearchParams(window.location.search),
  1996. host = search.get("host");
  1997. if (host !== null) {
  1998. connect(host);
  1999. } else {
  2000. connectToCurrentURL();
  2001. }
  2002. });