feat(notification): add simple SmartThings switch activation (#1902)

Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
Peter J. Milanese
2021-02-07 15:32:18 -05:00
committed by GitHub
parent b20bd4a496
commit c22c960dc1
8 changed files with 100 additions and 1 deletions
+2
View File
@@ -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);
+41
View File
@@ -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;
}
}