potrudeau / homebridge-messenger

Send HomeKit messages with HomeBridge (Pushover / IFTTT / Email)
MIT License
105 stars 9 forks source link

Pushover custom sounds #25

Open cgilis opened 3 years ago

cgilis commented 3 years ago

Hi!

Pushover has custom sounds now, any idea you could implement this? :-)

Thx!

vitaliy-kozlov commented 3 years ago

Yep! it would be really cool to do this!

ACWAKKERMANS commented 3 years ago

Yup, I have tried to use custom sounds and found that this does not work and plays the default Pushover sounds instead. According to the Pushover API pages (https://pushover.net/api#sounds) this may be because this plug-in has hardcoded the list of sounds available. They suggest the following setup instead:

API call may be made to retrieve the list of current sounds and their descriptions by sending a GET request to:

https://api.pushover.net/1/sounds.json?token=(your app token) Include your application's token as the token parameter. This API call returns a sounds hash with each key being the actual sound parameter to store for the user and send to our API, with its value describing the sound.

Is this something which could be implemented?

JollyRoger8X commented 3 years ago

I tried specifying a custom sound name by manually editing the JSON config, but no go. πŸ˜•

Would love to see this implemented!

JollyRoger8X commented 3 years ago

Note: It looks like this is already implemented in the downstream dependency "pushover-notifications" node-pushover project (see the updateSounds method there).

jerle69 commented 2 years ago

Bumping... would like to see this too

JollyRoger8X commented 2 years ago

Ok so I'm not very familiar with this code, but it seems like in lib/pushover.js line 39, the code sets the message_sound instance variable to "pushover" if it isn't in a hard-coded list of default sound names:

if (!["pushover", "bike", "bugle", "cashregister", "classical", "cosmic", "falling", "gamelan", 
  "incoming", "intermission", "magic", "mechanical", "pianobar", "siren", "spacealarm", "tugboat", 
  "alien", "climb", "persistent", "echo", "updown", "none"].includes(this.message_sound))
    this.message_sound = "pushover";

Would simply commenting out / removing this line allow for custom sounds to be specified?

JollyRoger8X commented 2 years ago

Good news. I went ahead and commented out lines 39 through 42 in /usr/local/lib/node_modules/homebridge-messenger/lib/pushover.js on my machine, and tested using a custom sound in my HomeBridge Messenger config:

{
  "name": "Motion",
   "type": "pushover",
  "text": "Motion detected!",
  "device": "my-iphone, wifes-iphone",
  "priority": 2,
  "sound": "doorbell"
}

And it worked fine. πŸ™‚πŸ‘πŸΌ

Really easy fix. Just remove some code.

JollyRoger8X commented 2 years ago

@potrudeau mentioned in an email that while removing that code does allow you to specify custom sound names in the JSON config, it doesn't allow Homebridge to display the custom sounds in the UI.

So the real issue is communicating the complete sound list β€” including any custom sounds the user may have added β€” to Homebridge to display in the UI settings panel.

You can get a list of all sounds (including any custom sounds) programmatically through the Pushover API by doing a GET to:

https://api.pushover.net/1/sounds.json?token=TOKENHERE

The payload looks like this:

{
  "sounds": {
    "doorbell": "Doorbell chime x2",
    "pushover": "Pushover (default)",
    "bike": "Bike",
    "bugle": "Bugle",
    "cashregister": "Cash Register",
    "classical": "Classical",
    "cosmic": "Cosmic",
    "falling": "Falling",
    "gamelan": "Gamelan",
    "incoming": "Incoming",
    "intermission": "Intermission",
    "magic": "Magic",
    "mechanical": "Mechanical",
    "pianobar": "Piano Bar",
    "siren": "Siren",
    "spacealarm": "Space Alarm",
    "tugboat": "Tug Boat",
    "alien": "Alien Alarm (long)",
    "climb": "Climb (long)",
    "persistent": "Persistent (long)",
    "echo": "Pushover Echo (long)",
    "updown": "Up Down (long)",
    "vibrate": "Vibrate Only",
    "none": "None (silent)"
  },
  "status": 1,
  "request": "692aca19-7485-4920-8a40-e119d7a38d02"
}

Notice that β€œdoorbell” is a custom sound I have added to my Pushover account.

The question is would there be an opportunity for homebridge-messenger to modify the sound list in config.schema.json accordingly so they appear in the Homebridge UI?

JollyRoger8X commented 2 years ago

I see that the downstream dependency pushover-notifications (aka node-pushover) has an updateSounds method that makes the API call to the Pushover api.pushover.net/1/sounds.json endpoint to get the complete list of sounds.

Could the index.js > HomebridgeMessenger constructor use that method to get the list of sounds and then populate the config.schema.json with them?

JollyRoger8X commented 2 years ago

Update: I've looked at the Homebridge API docs, and according to Advanced Requirements, it looks like the standard config.schema.json syntax doesn't allow for the list of sounds to be dynamically obtained. Instead, homebridge-messenger would need to be changed to use a custom configuration user interface using the @homebridge/plugin-ui-utils tools.