Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. import 'dotenv/config'
  2. import { RingApi } from 'ring-client-api'
  3. import { skip } from 'rxjs/operators'
  4.  
  5. async function example() {
  6. const { env } = process,
  7. ringApi = new RingApi({
  8. // Replace with your ring email/password
  9. // without 2fa
  10. email: EMAIL,
  11. password: PASSS,
  12. // Listen for dings and motion events
  13. cameraDingsPollingSeconds: 2
  14. }),
  15. locations = await ringApi.getLocations(),
  16. allCameras = await ringApi.getCameras()
  17.  
  18. console.log(
  19. `Found ${locations.length} location(s) with ${allCameras.length} camera(s).`
  20. )
  21.  
  22. for (const location of locations) {
  23. location.onConnected.pipe(skip(1)).subscribe(connected => {
  24. const status = connected ? 'Connected to' : 'Disconnected from'
  25. console.log(
  26. `**** ${status} location ${location.locationDetails.name} - ${location.locationId}`
  27. )
  28. })
  29. }
  30.  
  31. for (const location of locations) {
  32. const cameras = location.cameras,
  33. devices = await location.getDevices()
  34.  
  35. console.log(
  36. `\nLocation ${location.locationDetails.name} has the following ${cameras.length} camera(s):`
  37. )
  38.  
  39. for (const camera of cameras) {
  40. console.log(`- ${camera.id}: ${camera.name} (${camera.deviceType})`)
  41. }
  42.  
  43. console.log(
  44. `\nLocation ${location.locationDetails.name} has the following ${devices.length} device(s):`
  45. )
  46.  
  47. for (const device of devices) {
  48. console.log(`- ${device.zid}: ${device.name} (${device.deviceType})`)
  49. }
  50. }
  51.  
  52. // if (allCameras.length) {
  53. // allCameras.forEach(camera => {
  54. // camera.onNewDing.subscribe(ding => {
  55. // const event =
  56. // ding.kind === 'motion'
  57. // ? 'Motion detected'
  58. // : ding.kind === 'ding'
  59. // ? 'Doorbell pressed'
  60. // : `Video started (${ding.kind})`
  61.  
  62. // console.log(
  63. // `${event} on ${camera.name} camera. Ding id ${
  64. // ding.id_str
  65. // }. Received at ${new Date()}`
  66. // )
  67. // })
  68. // })
  69.  
  70. // console.log('Listening for motion and doorbell presses on your cameras.')
  71. // }
  72. }
  73.  
  74. example()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement