mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 01:47:39 +00:00
feat(notification): add simple SmartThings switch activation (#1902)
Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
committed by
GitHub
parent
b20bd4a496
commit
c22c960dc1
+2
-1
@@ -1,3 +1,4 @@
|
||||
{
|
||||
"extends": "./node_modules/gts/"
|
||||
"extends": "./node_modules/gts/",
|
||||
"rules": { "prettier/prettier": ["error", { "endOfLine": "auto" }] }
|
||||
}
|
||||
|
||||
@@ -156,6 +156,15 @@ Generate token at [pushover.net/apps/build](https://pushover.net/apps/build).
|
||||
| `SLACK_CHANNEL` | Channel for posting |
|
||||
| `SLACK_TOKEN` | API token |
|
||||
|
||||
## SmartThings
|
||||
|
||||
Generate token at [account.smartthings.com/tokens](https://account.smartthings.com/tokens).
|
||||
|
||||
| Environment variable | Description |
|
||||
|:---:|---|
|
||||
| `SMARTTHINGS_TOKEN` | Access token |
|
||||
| `SMARTTHINGS_SWITCH_LABEL` | Switch Label of switch to activate|
|
||||
|
||||
## Telegram
|
||||
|
||||
| Environment variable | Description |
|
||||
|
||||
@@ -94,6 +94,8 @@ SHOW_ONLY_MODELS=
|
||||
SHOW_ONLY_SERIES=
|
||||
SLACK_CHANNEL=
|
||||
SLACK_TOKEN=
|
||||
SMARTTHINGS_TOKEN=
|
||||
SMARTTHINGS_SWITCH_LABEL=
|
||||
SMTP_ADDRESS=
|
||||
SMTP_PORT=
|
||||
STORES=
|
||||
|
||||
Generated
+39
@@ -87,6 +87,45 @@
|
||||
"integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==",
|
||||
"dev": true
|
||||
},
|
||||
"@bridgerakol/samsung-smart-api": {
|
||||
"version": "2.8.1",
|
||||
"resolved": "https://registry.npmjs.org/@bridgerakol/samsung-smart-api/-/samsung-smart-api-2.8.1.tgz",
|
||||
"integrity": "sha512-Ue7o8GT/ph00kejX3h8w6kVh2LuRmIpLyhwZ8d0eJGcCNmn4mKGXJWZO5iMq8j1iqGozsmIa50lj79ZkDxTIRw==",
|
||||
"requires": {
|
||||
"axios": "^0.19.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
|
||||
"integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
|
||||
"requires": {
|
||||
"follow-redirects": "1.5.10"
|
||||
}
|
||||
},
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.5.10",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
|
||||
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
|
||||
"requires": {
|
||||
"debug": "=3.1.0"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@cliqz/adblocker": {
|
||||
"version": "1.19.0",
|
||||
"resolved": "https://registry.npmjs.org/@cliqz/adblocker/-/adblocker-1.19.0.tgz",
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/jef/streetmerchant#readme",
|
||||
"dependencies": {
|
||||
"@bridgerakol/samsung-smart-api": "^2.8.1",
|
||||
"@doridian/puppeteer-page-proxy": "^1.2.11",
|
||||
"@jef/pushbullet": "^2.4.3",
|
||||
"@slack/web-api": "^6.0.0",
|
||||
|
||||
@@ -303,6 +303,10 @@ const notifications = {
|
||||
channel: envOrString(process.env.SLACK_CHANNEL),
|
||||
token: envOrString(process.env.SLACK_TOKEN),
|
||||
},
|
||||
smartthings: {
|
||||
token: envOrString(process.env.SMARTTHINGS_TOKEN),
|
||||
device: envOrString(process.env.SMARTTHINGS_SWITCH_LABEL),
|
||||
},
|
||||
soundPlayer: envOrString(process.env.SOUND_PLAYER),
|
||||
telegram: {
|
||||
accessToken: envOrString(process.env.TELEGRAM_ACCESS_TOKEN),
|
||||
|
||||
@@ -15,6 +15,7 @@ import {sendTweet} from './twitter';
|
||||
import {sendTwilioMessage} from './twilio';
|
||||
import {sendTwitchMessage} from './twitch';
|
||||
import {updateRedis} from './redis';
|
||||
import {activateSmartthingsSwitch} from './smartthings';
|
||||
|
||||
export function sendNotification(link: Link, store: Store) {
|
||||
// Priority
|
||||
@@ -24,6 +25,7 @@ export function sendNotification(link: Link, store: Store) {
|
||||
sendEmail(link, store);
|
||||
sendSms(link, store);
|
||||
// Non-priority
|
||||
activateSmartthingsSwitch();
|
||||
adjustPhilipsHueLights();
|
||||
sendMqttMessage(link, store);
|
||||
sendPagerDutyNotification(link, store);
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import {SmartThings} from '@bridgerakol/samsung-smart-api';
|
||||
import {logger} from '../logger';
|
||||
import {config} from '../config';
|
||||
|
||||
const {smartthings} = config.notifications;
|
||||
|
||||
export async function activateSmartthingsSwitch() {
|
||||
if (!smartthings.token || !smartthings.device) {
|
||||
return;
|
||||
}
|
||||
const st = new SmartThings(smartthings.token);
|
||||
let match = false;
|
||||
try {
|
||||
await st.devices.getList().then(res => {
|
||||
res.data.items.forEach(
|
||||
async (item: {label: string; deviceId: string}) => {
|
||||
if (smartthings.device === item.label) {
|
||||
match = true;
|
||||
const device_status = (await st.devices.getStatus(item.deviceId))
|
||||
.data.components.main.switch.switch.value;
|
||||
if (device_status !== 'on') {
|
||||
logger.debug(`Turning on ${smartthings.device}`);
|
||||
st.devices.commands(item.deviceId, 'on');
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
} catch (TypeError) {
|
||||
logger.warn(
|
||||
'SmartThings : Problem getting data from hub, check SMARTTHINGS_TOKEN'
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!match) {
|
||||
logger.warn(
|
||||
`SmartThings : No switch called ${smartthings.device}, check SMARTTHINGS_SWITCH_LABEL`
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user