sonos icon indicating copy to clipboard operation
sonos copied to clipboard

Add create() to Alarm class

Open pkolmann opened this issue 9 months ago • 3 comments

I have added the functionality to add a new Alarm.

Please advise if I can improve this so you can accept it.

pkolmann avatar Mar 01 '25 17:03 pkolmann

Hi @PhilippKolmann thanks very much for your contribution! From memory when I first wrote this class I didn't think it was practical to setup a new alarm from scratch. Hopefully something has changed since, or there was just something I missed! Can you share some sample code on how you're using this to create new alarms?

duncan3dc avatar Mar 07 '25 10:03 duncan3dc

Hi @duncan3dc,

sure I started a small project to be able to change alarms via my Raspi from remote as well. It's currenlty very rough...

I have added a section to add a new alarm:

https://github.com/pkolmann/sonos-alarm-php/blob/2cc583ba14a29b1af674b1054d7ff031189895c1/lib/SonosAlarm.php#L103

Please bear in mind, that this is currently not production ready code ;-)

PS: I was not able to find another way to create a new alarm then to use the same XML that you parse from the sonos controller.

pkolmann avatar Mar 07 '25 11:03 pkolmann

Ah ok I see, let me have a think about it. I think something like $speaker->createAlarm(UriInterface $music): AlarmInterface would be quite nice, and then additional settings can be set on the alarm instance before saving it

duncan3dc avatar Mar 07 '25 11:03 duncan3dc

Hi @duncan3dc,

did you have any chance to think about the proposal? thanks

pkolmann avatar Jul 12 '25 12:07 pkolmann

Hi @pkolmann so sorry for the delay here! I've just released version 2.3.0 that contains a method on the Network class (with the other alarm methods) to create a new alarm, hope this is useful! Thanks for your contribution :slightly_smiling_face:

duncan3dc avatar Jul 12 '25 14:07 duncan3dc