mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 07:37: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
@@ -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