Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions homeassistant/components/jewish_calendar/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ def make_zmanim(date):
self._state = times.havdalah
elif self.type == 'issur_melacha_in_effect':
self._state = make_zmanim(now).issur_melacha_in_effect
elif self.type == 'omer_count':
self._state = date.omer_day
else:
times = make_zmanim(today).zmanim
self._state = times[self.type].time()
Expand Down
53 changes: 53 additions & 0 deletions tests/components/jewish_calendar/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,56 @@ def test_issur_melacha_sensor(self, now, candle_lighting, havdalah,
sensor.async_update(),
self.hass.loop).result()
assert sensor.state == result

omer_params = [
make_nyc_test_params(dt(2019, 4, 21, 0, 0), 1),
make_jerusalem_test_params(dt(2019, 4, 21, 0, 0), 1),
make_nyc_test_params(dt(2019, 4, 21, 23, 0), 2),
make_jerusalem_test_params(dt(2019, 4, 21, 23, 0), 2),
make_nyc_test_params(dt(2019, 5, 23, 0, 0), 33),
make_jerusalem_test_params(dt(2019, 5, 23, 0, 0), 33),
make_nyc_test_params(dt(2019, 6, 8, 0, 0), 49),
make_jerusalem_test_params(dt(2019, 6, 8, 0, 0), 49),
make_nyc_test_params(dt(2019, 6, 9, 0, 0), 0),
make_jerusalem_test_params(dt(2019, 6, 9, 0, 0), 0),
make_nyc_test_params(dt(2019, 1, 1, 0, 0), 0),
make_jerusalem_test_params(dt(2019, 1, 1, 0, 0), 0),
]
omer_test_ids = [
"nyc_first_day_of_omer",
"israel_first_day_of_omer",
"nyc_first_day_of_omer_after_tzeit",
"israel_first_day_of_omer_after_tzeit",
"nyc_lag_baomer",
"israel_lag_baomer",
"nyc_last_day_of_omer",
"israel_last_day_of_omer",
"nyc_shavuot_no_omer",
"israel_shavuot_no_omer",
"nyc_jan_1st_no_omer",
"israel_jan_1st_no_omer",
]

@pytest.mark.parametrize(["now", "candle_lighting", "havdalah", "diaspora",
"tzname", "latitude", "longitude", "result"],
omer_params, ids=omer_test_ids)
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(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests will be more robust if we set up the component and platform via setup_component or async_setup_component, let the platform add an entity, mock time passing to have an update then assert that the entity state is correct by getting it from the core state machine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a great idea. Do you have an example for something of that type?

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare Jul 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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