Skip to content

Commit

Permalink
Take timezone into consideration when calulating Zmanim. Partial fix …
Browse files Browse the repository at this point in the history
  • Loading branch information
tsvi authored and balloob committed Oct 4, 2018
1 parent b61a250 commit c997671
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
9 changes: 6 additions & 3 deletions homeassistant/components/sensor/jewish_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ async def async_setup_platform(
dev = []
for sensor_type in config[CONF_SENSORS]:
dev.append(JewishCalSensor(
name, language, sensor_type, latitude, longitude, diaspora))
name, language, sensor_type, latitude, longitude,
hass.config.time_zone, diaspora))
async_add_entities(dev, True)


class JewishCalSensor(Entity):
"""Representation of an Jewish calendar sensor."""

def __init__(
self, name, language, sensor_type, latitude, longitude, diaspora):
self, name, language, sensor_type, latitude, longitude, timezone,
diaspora):
"""Initialize the Jewish calendar sensor."""
self.client_name = name
self._name = SENSOR_TYPES[sensor_type][0]
Expand All @@ -81,6 +83,7 @@ def __init__(
self._state = None
self.latitude = latitude
self.longitude = longitude
self.timezone = timezone
self.diaspora = diaspora
_LOGGER.debug("Sensor %s initialized", self.type)

Expand Down Expand Up @@ -131,7 +134,7 @@ async def async_update(self):
else:
times = hdate.Zmanim(
date=today, latitude=self.latitude, longitude=self.longitude,
hebrew=self._hebrew).zmanim
timezone=self.timezone, hebrew=self._hebrew).zmanim
self._state = times[self.type].time()

_LOGGER.debug("New value: %s", self._state)
37 changes: 31 additions & 6 deletions tests/components/sensor/test_jewish_calendar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""The tests for the Jewish calendar sensor platform."""
import unittest
from datetime import time
from datetime import datetime as dt
from unittest.mock import patch

Expand Down Expand Up @@ -64,7 +65,7 @@ def test_jewish_calendar_sensor_date_output(self):
sensor = JewishCalSensor(
name='test', language='english', sensor_type='date',
latitude=self.TEST_LATITUDE, longitude=self.TEST_LONGITUDE,
diaspora=False)
timezone="UTC", diaspora=False)
with patch('homeassistant.util.dt.now', return_value=test_time):
run_coroutine_threadsafe(
sensor.async_update(),
Expand All @@ -77,7 +78,7 @@ def test_jewish_calendar_sensor_date_output_hebrew(self):
sensor = JewishCalSensor(
name='test', language='hebrew', sensor_type='date',
latitude=self.TEST_LATITUDE, longitude=self.TEST_LONGITUDE,
diaspora=False)
timezone="UTC", diaspora=False)
with patch('homeassistant.util.dt.now', return_value=test_time):
run_coroutine_threadsafe(
sensor.async_update(), self.hass.loop).result()
Expand All @@ -89,7 +90,7 @@ def test_jewish_calendar_sensor_holiday_name(self):
sensor = JewishCalSensor(
name='test', language='hebrew', sensor_type='holiday_name',
latitude=self.TEST_LATITUDE, longitude=self.TEST_LONGITUDE,
diaspora=False)
timezone="UTC", diaspora=False)
with patch('homeassistant.util.dt.now', return_value=test_time):
run_coroutine_threadsafe(
sensor.async_update(), self.hass.loop).result()
Expand All @@ -101,7 +102,7 @@ def test_jewish_calendar_sensor_holiday_name_english(self):
sensor = JewishCalSensor(
name='test', language='english', sensor_type='holiday_name',
latitude=self.TEST_LATITUDE, longitude=self.TEST_LONGITUDE,
diaspora=False)
timezone="UTC", diaspora=False)
with patch('homeassistant.util.dt.now', return_value=test_time):
run_coroutine_threadsafe(
sensor.async_update(), self.hass.loop).result()
Expand All @@ -113,7 +114,7 @@ def test_jewish_calendar_sensor_holyness(self):
sensor = JewishCalSensor(
name='test', language='hebrew', sensor_type='holyness',
latitude=self.TEST_LATITUDE, longitude=self.TEST_LONGITUDE,
diaspora=False)
timezone="UTC", diaspora=False)
with patch('homeassistant.util.dt.now', return_value=test_time):
run_coroutine_threadsafe(
sensor.async_update(), self.hass.loop).result()
Expand All @@ -125,8 +126,32 @@ def test_jewish_calendar_sensor_torah_reading(self):
sensor = JewishCalSensor(
name='test', language='hebrew', sensor_type='weekly_portion',
latitude=self.TEST_LATITUDE, longitude=self.TEST_LONGITUDE,
diaspora=False)
timezone="UTC", diaspora=False)
with patch('homeassistant.util.dt.now', return_value=test_time):
run_coroutine_threadsafe(
sensor.async_update(), self.hass.loop).result()
self.assertEqual(sensor.state, "פרשת נצבים")

def test_jewish_calendar_sensor_first_stars_ny(self):
"""Test Jewish calendar sensor date output in hebrew."""
test_time = dt(2018, 9, 8)
sensor = JewishCalSensor(
name='test', language='hebrew', sensor_type='first_stars',
latitude=40.7128, longitude=-74.0060,
timezone="America/New_York", diaspora=False)
with patch('homeassistant.util.dt.now', return_value=test_time):
run_coroutine_threadsafe(
sensor.async_update(), self.hass.loop).result()
self.assertEqual(sensor.state, time(19, 48))

def test_jewish_calendar_sensor_first_stars_jerusalem(self):
"""Test Jewish calendar sensor date output in hebrew."""
test_time = dt(2018, 9, 8)
sensor = JewishCalSensor(
name='test', language='hebrew', sensor_type='first_stars',
latitude=self.TEST_LATITUDE, longitude=self.TEST_LONGITUDE,
timezone="Asia/Jerusalem", diaspora=False)
with patch('homeassistant.util.dt.now', return_value=test_time):
run_coroutine_threadsafe(
sensor.async_update(), self.hass.loop).result()
self.assertEqual(sensor.state, time(19, 21))

0 comments on commit c997671

Please sign in to comment.