Beispiel #1
0
 def test_update_alarm(self, soco_mock, alarm_mock, *args):
     """Ensuring soco methods called for sonos_set_sleep_timer service."""
     sonos.setup_platform(self.hass, {}, fake_add_device,
                          {'host': '192.0.2.1'})
     device = self.hass.data[sonos.DATA_SONOS][-1]
     device.hass = self.hass
     alarm1 = alarms.Alarm(soco_mock)
     alarm1.configure_mock(_alarm_id="1",
                           start_time=None,
                           enabled=False,
                           include_linked_zones=False,
                           volume=100)
     with mock.patch('soco.alarms.get_alarms', return_value=[alarm1]):
         attrs = {
             'time': datetime.time(12, 00),
             'enabled': True,
             'include_linked_zones': True,
             'volume': 0.30,
         }
         device.update_alarm(alarm_id=2)
         alarm1.save.assert_not_called()
         device.update_alarm(alarm_id=1, **attrs)
         self.assertEqual(alarm1.enabled, attrs['enabled'])
         self.assertEqual(alarm1.start_time, attrs['time'])
         self.assertEqual(alarm1.include_linked_zones,
                          attrs['include_linked_zones'])
         self.assertEqual(alarm1.volume, 30)
         alarm1.save.assert_called_once_with()
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()