-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notification): add simple SmartThings switch activation (#1902)
Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
- Loading branch information
Showing
8 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"extends": "./node_modules/gts/" | ||
"extends": "./node_modules/gts/", | ||
"rules": { "prettier/prettier": ["error", { "endOfLine": "auto" }] } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |