Skip to content

Commit

Permalink
specify Pushcut devices
Browse files Browse the repository at this point in the history
  • Loading branch information
MTry committed Apr 19, 2021
1 parent 2df8bf0 commit 3690d9d
Show file tree
Hide file tree
Showing 9 changed files with 406 additions and 94 deletions.
14 changes: 14 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"rules": {
}
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log
All meaningful changes will be logged here.

## **1.5.0 [19-04-2021]**

### *Added:*
- Ability to specify receiving devices with Pushcut

## **1.4.1 [19-04-2021]**

### *Added:*
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ Start times will vary daily as a result of changing sunrise times as well as the
"devicePO": "iphone",
"priorityPO": 0,
"soundPO": "pushover",
"pcEnable": true,
"pcKey": "abcdXXXXabcd",
"pcDevices": "iPad,iPhone",
"pcWeatherChecked": "Test Checked",
"pcWeatherCheckedSound": "system",
"pcWateringStart": "Test Start",
"pcWateringStartSound": "system",
"pcWateringEnd": "Test End",
"pcWateringEndSound": "jobDone",
"JanRad": 5.4,
"FebRad": 6.3,
"MarRad": 7,
Expand Down Expand Up @@ -281,6 +290,7 @@ Push notifications using [Pushcut](https://www.pushcut.io/) are supported. While
| --- | --- | --- |
| `pcEnable` | Enable Pushcut Notifications | `false` |
| `pcKey` | Your API key | N/A |
| `pcDevices` | Device list seperated by comma - **WITHOUT SPACE after comma!** | `all` |
| `pcWeatherChecked` | Your "Weather Checked" notification name | N/A |
| `pcWeatherCheckedSound` | Notification sound | `system` |
| `pcWateringStart` | Your "Watering Start" notification name | N/A |
Expand Down
20 changes: 17 additions & 3 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,14 @@
"type": "string",
"required": true,
"placeholder": "API key"
},
},
"pcDevices": {
"title": "Pushcut Devices(leave blank for all):",
"type": "string",
"required": false,
"placeholder": "device1,device2,...",
"description": "Device list seperated by comma - WITHOUT SPACE after comma!"
},
"pcWeatherChecked": {
"title": "Weather Checked Notification:",
"type": "string",
Expand Down Expand Up @@ -969,18 +976,25 @@
"items": [
{
"type": "section",
"htmlClass": "col-xs-4",
"htmlClass": "col-xs-3",
"items": [
"pcEnable"
]
},
{
"type": "section",
"htmlClass": "col-xs-6",
"htmlClass": "col-xs-4",
"items": [
"pcKey"
]
},
{
"type": "section",
"htmlClass": "col-xs-4",
"items": [
"pcDevices"
]
},
{
"type": "section",
"htmlClass": "col-xs-6",
Expand Down
16 changes: 12 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable no-unused-vars */
/* eslint-disable no-undef */

'use strict'
let Service, Characteristic
const packageJson = require('./package.json')
Expand Down Expand Up @@ -107,6 +110,7 @@ function SmartSprinklers (log, config) {
this.soundPO = config.soundPO || 'pushover'
this.pcEnable = config.pcEnable || false
this.pcKey = config.pcKey || ''
this.pcDevices = config.pcDevices || ''
this.pcWeatherChecked = config.pcWeatherChecked || ''
this.pcWeatherCheckedSound = config.pcWeatherCheckedSound || 'system'
this.pcWateringStart = config.pcWateringStart || ''
Expand Down Expand Up @@ -181,6 +185,10 @@ SmartSprinklers.prototype = {
let pushTitle = ''
let pushMessage = ''
let pushcutMessage = ''
let pcDevices = []
if (this.pcDevices !== '') {
pcDevices = this.pcDevices.split(',')
}

const pushover = new Pushover(this.userPO, this.tokenPO)
pushover
Expand Down Expand Up @@ -315,7 +323,7 @@ SmartSprinklers.prototype = {
pushover.send(pushTitle, pushMessage).then(msj => { this.log('Pushover notification sent') }).catch(err => { this.log.warn('Pushover Error - Recheck config: ', err.message) })
}
if (this.pcEnable) {
got.post(pcURL + this.pcWateringStart, { json: { text: pushMessage, title: pushTitle, sound: this.pcWateringStartSound, input: format.minTommss(wateringTime[zDay]).toString(), image: pcImage }, headers: { 'API-Key': this.pcKey }, responseType: 'json' })
got.post(pcURL + this.pcWateringStart, { json: { text: pushMessage, title: pushTitle, sound: this.pcWateringStartSound, input: format.minTommss(wateringTime[zDay]).toString(), devices: pcDevices, image: pcImage }, headers: { 'API-Key': this.pcKey }, responseType: 'json' })
.then(res => {
this.log('Pushcut notification sent')
})
Expand All @@ -338,7 +346,7 @@ SmartSprinklers.prototype = {
pushover.send(pushTitle, pushMessage).then(msj => { this.log('Pushover notification sent') }).catch(err => { this.log.warn('Pushover Error - Recheck config: ', err.message) })
}
if (this.pcEnable) {
got.post(pcURL + this.pcWeatherChecked, { json: { text: pushcutMessage, title: mailSubject, input: 'Scheduled', sound: this.pcWeatherCheckedSound, image: pcImage }, headers: { 'API-Key': this.pcKey }, responseType: 'json' })
got.post(pcURL + this.pcWeatherChecked, { json: { text: pushcutMessage, title: mailSubject, input: 'Scheduled', sound: this.pcWeatherCheckedSound, devices: pcDevices, image: pcImage }, headers: { 'API-Key': this.pcKey }, responseType: 'json' })
.then(res => {
this.log('Pushcut notification sent')
})
Expand Down Expand Up @@ -398,7 +406,7 @@ SmartSprinklers.prototype = {
pushover.send(pushTitle, pushMessage).then(msj => { this.log('Pushover notification sent') }).catch(err => { this.log.warn('Pushover Error - Recheck config: ', err.message) })
}
if (this.pcEnable) {
got.post(pcURL + this.pcWeatherChecked, { json: { text: pushcutMessage, title: mailSubject, input: 'Not Scheduled', sound: this.pcWeatherCheckedSound, image: pcImage }, headers: { 'API-Key': this.pcKey }, responseType: 'json' })
got.post(pcURL + this.pcWeatherChecked, { json: { text: pushcutMessage, title: mailSubject, input: 'Not Scheduled', sound: this.pcWeatherCheckedSound, devices: pcDevices, image: pcImage }, headers: { 'API-Key': this.pcKey }, responseType: 'json' })
.then(res => {
this.log('Pushcut notification sent')
})
Expand Down Expand Up @@ -445,7 +453,7 @@ SmartSprinklers.prototype = {
this.log('Watering finished')
wateringDone = true
if (this.pcEnable) {
got.post(pcURL + this.pcWateringEnd, { json: { text: 'The scheduled irrigation has been completed', title: '✅ Watering Finished!', sound: this.pcWateringEndSound, image: pcImage }, headers: { 'API-Key': this.pcKey }, responseType: 'json' })
got.post(pcURL + this.pcWateringEnd, { json: { text: 'The scheduled irrigation has been completed', title: '✅ Watering Finished!', sound: this.pcWateringEndSound, devices: pcDevices, image: pcImage }, headers: { 'API-Key': this.pcKey }, responseType: 'json' })
.then(res => {
this.log('Pushcut Watering End notification sent')
})
Expand Down
3 changes: 3 additions & 0 deletions lib/eto.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint no-undef: "error" */
/* eslint-env node */

function calculate (climate, solarRad, alt, lat) {
const tMean = (climate.max + climate.min) / 2
const rS = solarRad * 3.6
Expand Down
3 changes: 3 additions & 0 deletions lib/format.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint no-undef: "error" */
/* eslint-env node */

function minTommss (minutes) {
const sign = minutes < 0 ? '-' : ''
const min = Math.floor(Math.abs(minutes))
Expand Down
Loading

0 comments on commit 3690d9d

Please sign in to comment.