def test_intervals(self):
        """Test timing intervals of sensors."""
        device = time_date.TimeDateSensor(self.hass, 'time')
        now = dt_util.utc_from_timestamp(45)
        next_time = device.get_next_interval(now)
        assert next_time == dt_util.utc_from_timestamp(60)

        device = time_date.TimeDateSensor(self.hass, 'date')
        now = dt_util.utc_from_timestamp(12345)
        next_time = device.get_next_interval(now)
        assert next_time == dt_util.utc_from_timestamp(86400)

        device = time_date.TimeDateSensor(self.hass, 'beat')
        now = dt_util.utc_from_timestamp(29)
        next_time = device.get_next_interval(now)
        assert next_time == dt_util.utc_from_timestamp(86.4)

        device = time_date.TimeDateSensor(self.hass, 'date_time')
        now = dt_util.utc_from_timestamp(1495068899)
        next_time = device.get_next_interval(now)
        assert next_time == dt_util.utc_from_timestamp(1495068900)

        now = dt_util.utcnow()
        device = time_date.TimeDateSensor(self.hass, 'time_date')
        next_time = device.get_next_interval()
        assert next_time > now
Ejemplo n.º 2
0
 def test_icons(self):
     """Test attributes of sensors."""
     device = time_date.TimeDateSensor(self.hass, 'time')
     assert device.icon == "mdi:clock"
     device = time_date.TimeDateSensor(self.hass, 'date')
     assert device.icon == "mdi:calendar"
     device = time_date.TimeDateSensor(self.hass, 'date_time')
     assert device.icon == "mdi:calendar-clock"
Ejemplo n.º 3
0
 def test_timezone_intervals_empty_parameter(self, _):
     """Test get_interval() without parameters."""
     new_tz = dt_util.get_time_zone('America/Edmonton')
     assert new_tz is not None
     dt_util.set_default_time_zone(new_tz)
     device = time_date.TimeDateSensor(self.hass, 'date')
     next_time = device.get_next_interval()
     assert (next_time.timestamp() == dt_util.as_timestamp(
         '2017-11-14 00:00:00-07:00'))
Ejemplo n.º 4
0
    def test_states(self):
        """Test states of sensors."""
        now = dt_util.utc_from_timestamp(1495068856)
        device = time_date.TimeDateSensor(self.hass, 'time')
        device._update_internal_state(now)
        assert device.state == "00:54"

        device = time_date.TimeDateSensor(self.hass, 'date')
        device._update_internal_state(now)
        assert device.state == "2017-05-18"

        device = time_date.TimeDateSensor(self.hass, 'time_utc')
        device._update_internal_state(now)
        assert device.state == "00:54"

        device = time_date.TimeDateSensor(self.hass, 'beat')
        device._update_internal_state(now)
        assert device.state == "@079"
Ejemplo n.º 5
0
    def test_timezone_intervals(self):
        """Test date sensor behavior in a timezone besides UTC."""
        new_tz = dt_util.get_time_zone('America/New_York')
        assert new_tz is not None
        dt_util.set_default_time_zone(new_tz)

        device = time_date.TimeDateSensor(self.hass, 'date')
        now = dt_util.utc_from_timestamp(50000)
        next_time = device.get_next_interval(now)
        # start of local day in EST was 18000.0
        # so the second day was 18000 + 86400
        assert next_time.timestamp() == 104400

        new_tz = dt_util.get_time_zone('America/Edmonton')
        assert new_tz is not None
        dt_util.set_default_time_zone(new_tz)
        now = dt_util.parse_datetime('2017-11-13 19:47:19-07:00')
        device = time_date.TimeDateSensor(self.hass, 'date')
        next_time = device.get_next_interval(now)
        assert (next_time.timestamp() == dt_util.as_timestamp(
            '2017-11-14 00:00:00-07:00'))