<commit_before># POST /AlarmClock/Control HTTP/1.1
# SOAPACTION: "urn:schemas-upnp-org:service:AlarmClock:1#ListAlarms"

# Request
#<?xml version="1.0" encoding="UTF-8"?>
#<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
#    <s:Body>
#      <u:ListAlarms xmlns:u="urn:schemas-upnp-org:service:AlarmClock:1" />
#    </s:Body>
#</s:Envelope>

# Response
#<?xml version="1.0" encoding="UTF-8"?>
#<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
#  <s:Body>
#    <u:ListAlarmsResponse xmlns:u="urn:schemas-upnp-org:service:AlarmClock:1">
#      <CurrentAlarmList>&lt;Alarms&gt;&lt;Alarm ID="8" StartTime="19:21:00" Duration="02:00:00" Recurrence="ONCE" Enabled="0" RoomUUID="RINCON_000E583564A601400" ProgramURI="x-rincon-buzzer:0" ProgramMetaData="" PlayMode="SHUFFLE_NOREPEAT" Volume="25" IncludeLinkedZones="0"/&gt;&lt;/Alarms&gt;</CurrentAlarmList>
#      <CurrentAlarmListVersion>RINCON_000E583564A601400:26</CurrentAlarmListVersion>
#    </u:ListAlarmsResponse>
#  </s:Body>
#</s:Envelope>

module Sonos::Endpoint::Alarm
  ALARM_CLOCK_ENDPOINT = '/AlarmClock/Control'
  ALARM_CLOCK_XMLNS = 'urn:schemas-upnp-org:service:AlarmClock:1'

  # List the alarms that have been defined
  def list_alarms
    send_alarm_message('ListAlarms')
  end

private

  def alarm_client
    @alarm_client ||= Savon.client endpoint: "http://#{self.ip}:#{Sonos::PORT}#{ALARM_CLOCK_ENDPOINT}", namespace: Sonos::NAMESPACE
  end

  def send_alarm_message(name)
    action = "#{ALARM_CLOCK_XMLNS}##{name}"
    message = %Q{<u:#{name} xmlns:u="#{ALARM_CLOCK_XMLNS}" />}
    alarm_client.call(name, soap_action: action, message: message)
  end
end<commit_msg>Added code to update an alarm.<commit_after># POST /AlarmClock/Control HTTP/1.1
# SOAPACTION: "urn:schemas-upnp-org:service:AlarmClock:1#ListAlarms"

# Request
#<?xml version="1.0" encoding="UTF-8"?>
#<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
#    <s:Body>
#      <u:ListAlarms xmlns:u="urn:schemas-upnp-org:service:AlarmClock:1" />
#    </s:Body>
#</s:Envelope>

# Response
#<?xml version="1.0" encoding="UTF-8"?>
#<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
#  <s:Body>
#    <u:ListAlarmsResponse xmlns:u="urn:schemas-upnp-org:service:AlarmClock:1">
#      <CurrentAlarmList>&lt;Alarms&gt;&lt;Alarm ID="8" StartTime="19:21:00" Duration="02:00:00" Recurrence="ONCE" Enabled="0" RoomUUID="RINCON_000E583564A601400" ProgramURI="x-rincon-buzzer:0" ProgramMetaData="" PlayMode="SHUFFLE_NOREPEAT" Volume="25" IncludeLinkedZones="0"/&gt;&lt;/Alarms&gt;</CurrentAlarmList>
#      <CurrentAlarmListVersion>RINCON_000E583564A601400:26</CurrentAlarmListVersion>
#    </u:ListAlarmsResponse>
#  </s:Body>
#</s:Envelope>

module Sonos::Endpoint::Alarm
  ALARM_CLOCK_ENDPOINT = '/AlarmClock/Control'
  ALARM_CLOCK_XMLNS = 'urn:schemas-upnp-org:service:AlarmClock:1'

  # List the alarms that have been defined
  def list_alarms
    send_alarm_message('ListAlarms')
  end

  def update_alarm
    send_alarm_update_message
  end

  private

  def alarm_client
    @alarm_client ||= Savon.client endpoint: "http://#{self.ip}:#{Sonos::PORT}#{ALARM_CLOCK_ENDPOINT}", namespace: Sonos::NAMESPACE
  end

  def send_alarm_message(name, part = '')
    action = "#{ALARM_CLOCK_XMLNS}##{name}"
    message = %Q{<u:#{name} xmlns:u="#{ALARM_CLOCK_XMLNS}">#{part}</u:#{name}>}
    alarm_client.call(name, soap_action: action, message: message)
  end

  def send_alarm_update_message(options = {})
    options = {:ID => 8, :StartLocalTime => '13:19:00', :Duration => '02:00:00',
               :Recurrence => 'ONCE', :Enabled => 1, :RoomUUID => 'RINCON_000E583564A601400',
               :PlayMode => 'SHUFFLE_NOREPEAT', :Volume => 25, :IncludeLinkedZones => 0}

    updatePart = '<ProgramURI>x-rincon-buzzer:0</ProgramURI><ProgramMetaData></ProgramMetaData>'

    options.each do |optionKey, optionValue|
      updatePart += "<#{optionKey}>#{optionValue}</#{optionKey}>"
    end

    send_alarm_message('UpdateAlarm', updatePart)
  end

end
{'fraction_non_alphanumeric': 0.17674636661978435, 'fraction_numerical': 0.03680262541022035, 'mean_word_length': 5.81629392971246, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 4, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 22}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4768505', 'n_tokens_mistral': 1732, 'n_tokens_neox': 1612, 'n_words': 212}