Exemple #1
0
 def test_omer_sensor(
     self,
     now,
     candle_lighting,
     havdalah,
     diaspora,
     tzname,
     latitude,
     longitude,
     result,
 ):
     """Test Omer Count sensor output."""
     time_zone = get_time_zone(tzname)
     set_default_time_zone(time_zone)
     test_time = time_zone.localize(now)
     self.hass.config.latitude = latitude
     self.hass.config.longitude = longitude
     sensor = JewishCalSensor(
         name="test",
         language="english",
         sensor_type="omer_count",
         latitude=latitude,
         longitude=longitude,
         timezone=time_zone,
         diaspora=diaspora,
     )
     sensor.hass = self.hass
     with patch("homeassistant.util.dt.now", return_value=test_time):
         run_coroutine_threadsafe(sensor.async_update(),
                                  self.hass.loop).result()
         assert sensor.state == result
Exemple #2
0
    def test_shabbat_times_sensor(
        self,
        now,
        candle_lighting,
        havdalah,
        diaspora,
        tzname,
        latitude,
        longitude,
        result,
    ):
        """Test sensor output for upcoming shabbat/yomtov times."""
        time_zone = get_time_zone(tzname)
        set_default_time_zone(time_zone)
        test_time = time_zone.localize(now)
        for sensor_type, value in result.items():
            if isinstance(value, dt):
                result[sensor_type] = time_zone.localize(value)
        self.hass.config.latitude = latitude
        self.hass.config.longitude = longitude

        if ("upcoming_shabbat_candle_lighting" in result
                and "upcoming_candle_lighting" not in result):
            result["upcoming_candle_lighting"] = result[
                "upcoming_shabbat_candle_lighting"]
        if "upcoming_shabbat_havdalah" in result and "upcoming_havdalah" not in result:
            result["upcoming_havdalah"] = result["upcoming_shabbat_havdalah"]

        for sensor_type, result_value in result.items():
            language = "english"
            if sensor_type.startswith("hebrew_"):
                language = "hebrew"
                sensor_type = sensor_type.replace("hebrew_", "")
            sensor = JewishCalSensor(
                name="test",
                language=language,
                sensor_type=sensor_type,
                latitude=latitude,
                longitude=longitude,
                timezone=time_zone,
                diaspora=diaspora,
                havdalah_offset=havdalah,
                candle_lighting_offset=candle_lighting,
            )
            sensor.hass = self.hass
            with patch("homeassistant.util.dt.now", return_value=test_time):
                run_coroutine_threadsafe(sensor.async_update(),
                                         self.hass.loop).result()
                assert sensor.state == result_value, "Value for {}".format(
                    sensor_type)
 def test_jewish_calendar_sensor(self, cur_time, tzname, latitude,
                                 longitude, language, sensor, diaspora,
                                 result):
     """Test Jewish calendar sensor output."""
     time_zone = get_time_zone(tzname)
     set_default_time_zone(time_zone)
     test_time = time_zone.localize(cur_time)
     self.hass.config.latitude = latitude
     self.hass.config.longitude = longitude
     sensor = JewishCalSensor(
         name='test', language=language, sensor_type=sensor,
         latitude=latitude, longitude=longitude,
         timezone=time_zone, diaspora=diaspora)
     sensor.hass = self.hass
     with patch('homeassistant.util.dt.now', return_value=test_time):
         run_coroutine_threadsafe(
             sensor.async_update(),
             self.hass.loop).result()
         assert sensor.state == result
 def test_issur_melacha_sensor(self, now, candle_lighting, havdalah,
                               diaspora, tzname, latitude, longitude,
                               result):
     """Test Issur Melacha sensor output."""
     time_zone = get_time_zone(tzname)
     set_default_time_zone(time_zone)
     test_time = time_zone.localize(now)
     self.hass.config.latitude = latitude
     self.hass.config.longitude = longitude
     sensor = JewishCalSensor(
         name='test', language='english',
         sensor_type='issur_melacha_in_effect',
         latitude=latitude, longitude=longitude,
         timezone=time_zone, diaspora=diaspora, havdalah_offset=havdalah,
         candle_lighting_offset=candle_lighting)
     sensor.hass = self.hass
     with patch('homeassistant.util.dt.now', return_value=test_time):
         run_coroutine_threadsafe(
             sensor.async_update(),
             self.hass.loop).result()
         assert sensor.state == result
 def test_jewish_calendar_sensor(self, cur_time, tzname, latitude,
                                 longitude, language, sensor, diaspora,
                                 result):
     """Test Jewish calendar sensor output."""
     time_zone = get_time_zone(tzname)
     set_default_time_zone(time_zone)
     test_time = time_zone.localize(cur_time)
     self.hass.config.latitude = latitude
     self.hass.config.longitude = longitude
     sensor = JewishCalSensor(name='test',
                              language=language,
                              sensor_type=sensor,
                              latitude=latitude,
                              longitude=longitude,
                              timezone=time_zone,
                              diaspora=diaspora)
     sensor.hass = self.hass
     with patch('homeassistant.util.dt.now', return_value=test_time):
         run_coroutine_threadsafe(sensor.async_update(),
                                  self.hass.loop).result()
         assert sensor.state == result
    def test_shabbat_times_sensor(self, now, candle_lighting, havdalah,
                                  diaspora, tzname, latitude, longitude,
                                  result):
        """Test sensor output for upcoming shabbat/yomtov times."""
        time_zone = get_time_zone(tzname)
        set_default_time_zone(time_zone)
        test_time = time_zone.localize(now)
        for sensor_type, value in result.items():
            if isinstance(value, dt):
                result[sensor_type] = time_zone.localize(value)
        self.hass.config.latitude = latitude
        self.hass.config.longitude = longitude

        if ('upcoming_shabbat_candle_lighting' in result
                and 'upcoming_candle_lighting' not in result):
            result['upcoming_candle_lighting'] = \
                result['upcoming_shabbat_candle_lighting']
        if ('upcoming_shabbat_havdalah' in result
                and 'upcoming_havdalah' not in result):
            result['upcoming_havdalah'] = result['upcoming_shabbat_havdalah']

        for sensor_type, result_value in result.items():
            language = 'english'
            if sensor_type.startswith('hebrew_'):
                language = 'hebrew'
                sensor_type = sensor_type.replace('hebrew_', '')
            sensor = JewishCalSensor(
                name='test', language=language, sensor_type=sensor_type,
                latitude=latitude, longitude=longitude,
                timezone=time_zone, diaspora=diaspora,
                havdalah_offset=havdalah,
                candle_lighting_offset=candle_lighting)
            sensor.hass = self.hass
            with patch('homeassistant.util.dt.now', return_value=test_time):
                run_coroutine_threadsafe(
                    sensor.async_update(),
                    self.hass.loop).result()
                assert sensor.state == result_value, "Value for {}".format(
                    sensor_type)
 def test_issur_melacha_sensor(self, now, candle_lighting, havdalah,
                               diaspora, tzname, latitude, longitude,
                               result):
     """Test Issur Melacha sensor output."""
     time_zone = get_time_zone(tzname)
     set_default_time_zone(time_zone)
     test_time = time_zone.localize(now)
     self.hass.config.latitude = latitude
     self.hass.config.longitude = longitude
     sensor = JewishCalSensor(name='test',
                              language='english',
                              sensor_type='issur_melacha_in_effect',
                              latitude=latitude,
                              longitude=longitude,
                              timezone=time_zone,
                              diaspora=diaspora,
                              havdalah_offset=havdalah,
                              candle_lighting_offset=candle_lighting)
     sensor.hass = self.hass
     with patch('homeassistant.util.dt.now', return_value=test_time):
         run_coroutine_threadsafe(sensor.async_update(),
                                  self.hass.loop).result()
         assert sensor.state == result