Пример #1
0
 def set_alarm(
     self,
     alarm_id: int,
     time: datetime.datetime | None = None,
     volume: float | None = None,
     enabled: bool | None = None,
     include_linked_zones: bool | None = None,
 ) -> None:
     """Set the alarm clock on the player."""
     alarm = None
     for one_alarm in alarms.get_alarms(self.coordinator.soco):
         if one_alarm.alarm_id == str(alarm_id):
             alarm = one_alarm
     if alarm is None:
         _LOGGER.warning("Did not find alarm with id %s", alarm_id)
         return
     if time is not None:
         alarm.start_time = time
     if volume is not None:
         alarm.volume = int(volume * 100)
     if enabled is not None:
         alarm.enabled = enabled
     if include_linked_zones is not None:
         alarm.include_linked_zones = include_linked_zones
     alarm.save()
Пример #2
0
def replace_alarm(device, time):
    """
    remove all alarms and set new one-time-occurring alarm at time (str with 'HH::MM')
    """
    from soco import alarms
    import datetime

    t = datetime.datetime.strptime(time, "%H:%M").time()
    for a in list(alarms.get_alarms(zone=device)):
        a.remove()
    a = alarms.Alarm(device, t, None, 'ONCE')
    a.save()
Пример #3
0
 def get_alarms(self):
     """
     Gets all alarms for the speaker
     :return:
     """
     try:
         values = get_alarms(self.soco)
     except:
         return {}
     alarm_dict = {}
     for alarm in values:
         if alarm.zone.uid.lower() != self.uid.lower():
             continue
         dict = SonosSpeaker.alarm_to_dict(alarm)
         alarm_dict[alarm._alarm_id] = dict
     self.alarms = alarm_dict
Пример #4
0
 def get_alarms(self):
     """
     Gets all alarms for the speaker
     :return:
     """
     try:
         values = get_alarms(self.soco)
     except:
         return {}
     alarm_dict = {}
     for alarm in values:
         if alarm.zone.uid.lower() != self.uid.lower():
             continue
         dict = SonosSpeaker.alarm_to_dict(alarm)
         alarm_dict[alarm._alarm_id] = dict
     self.alarms = alarm_dict
Пример #5
0
    def update_cache(self, soco: SoCo) -> set[Alarm]:
        """Populate cache of known alarms.

        Prune deleted alarms and return new alarms.
        """
        soco_alarms = get_alarms(soco)
        new_alarms = set()

        for alarm in soco_alarms:
            if alarm.alarm_id not in self._alarms:
                new_alarms.add(alarm)
                self._alarms[alarm.alarm_id] = alarm

        for alarm_id, alarm in list(self._alarms.items()):
            if alarm not in soco_alarms:
                self._alarms.pop(alarm_id)

        return new_alarms
Пример #6
0
 def set_alarm(self, **data):
     """Set the alarm clock on the player."""
     from soco import alarms
     alarm = None
     for one_alarm in alarms.get_alarms(self.soco):
         # pylint: disable=protected-access
         if one_alarm._alarm_id == str(data[ATTR_ALARM_ID]):
             alarm = one_alarm
     if alarm is None:
         _LOGGER.warning("did not find alarm with id %s",
                         data[ATTR_ALARM_ID])
         return
     if ATTR_TIME in data:
         alarm.start_time = data[ATTR_TIME]
     if ATTR_VOLUME in data:
         alarm.volume = int(data[ATTR_VOLUME] * 100)
     if ATTR_ENABLED in data:
         alarm.enabled = data[ATTR_ENABLED]
     if ATTR_INCLUDE_LINKED_ZONES in data:
         alarm.include_linked_zones = data[ATTR_INCLUDE_LINKED_ZONES]
     alarm.save()
 def set_alarm(self, **data):
     """Set the alarm clock on the player."""
     from soco import alarms
     alarm = None
     for one_alarm in alarms.get_alarms(self.soco):
         # pylint: disable=protected-access
         if one_alarm._alarm_id == str(data[ATTR_ALARM_ID]):
             alarm = one_alarm
     if alarm is None:
         _LOGGER.warning("did not find alarm with id %s",
                         data[ATTR_ALARM_ID])
         return
     if ATTR_TIME in data:
         alarm.start_time = data[ATTR_TIME]
     if ATTR_VOLUME in data:
         alarm.volume = int(data[ATTR_VOLUME] * 100)
     if ATTR_ENABLED in data:
         alarm.enabled = data[ATTR_ENABLED]
     if ATTR_INCLUDE_LINKED_ZONES in data:
         alarm.include_linked_zones = data[ATTR_INCLUDE_LINKED_ZONES]
     alarm.save()
Пример #8
0
 def get_alarms(self):
     self.alarms = soco_alarms.get_alarms(soco=self.coordinator)