Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stas-dovgodko/openhab-proxy-pattern
https://github.com/stas-dovgodko/openhab-proxy-pattern
Last synced: 26 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/stas-dovgodko/openhab-proxy-pattern
- Owner: stas-dovgodko
- Created: 2022-01-09T17:53:41.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-27T10:15:36.000Z (over 1 year ago)
- Last Synced: 2024-04-29T21:11:49.755Z (9 months ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
JS wrapper to implement common used Proxy Item pattern
[Pattern explanation](https://community.openhab.org/t/design-pattern-proxy-item/15991)
# Usage examples
```js
let proxy = require('openhab-proxy-pattern');/*
proxy.bind(proxy_item_name, hardware_item_name).update([callback]).forward([callback]);
*/// one direction proxy
proxy.bind('Equipment_WF_OutTemperature', 'SmartMAC_D105_1_T2').update();// bi-directional proxy
proxy.bind("GF_Toilet_MirrorLight", "Shelly_25R_3_1Output")
.forward()
.update();// proxy with custom values
proxy.bind('Equipment_ElectricityInverterBattery_Voltage', 'PZEM_1_Voltage')
.update(function(value) {if (typeof value == 'string') {
const v = parseInt(value) / 100;
return `${v} V`;
} else {
return undefined;
}
});// wide-options proxy
const v = function(value) {
if (typeof value == 'string') {
const v = parseInt(value);
return `${v} V`;
} else return undefined;
};['A', 'B', 'C'].forEach(function(phase) {
proxy.bind(`Equipment_ElectricityHomeV${phase}`, `Shelly_EM3_2_${phase}Voltage`, 15)
.update(v, 15); // 15 seconds gap between updates. For too-fast hardware
});
```