Skip to content
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a4433fd
Move jewish calendar to its own platform
tsvi Aug 22, 2019
ee155a5
Fix tests for Jewish Calendar platform
tsvi Aug 26, 2019
5e1c8dc
Get sensors to update during test
tsvi Aug 27, 2019
6b9c0af
Use hass.config.set_time_zone instead of directly calling set_default…
tsvi Aug 27, 2019
3bbf625
Cleanup log messages
tsvi Aug 27, 2019
65d29c4
Rename result from weekly_portion to parshat_hashavua
tsvi Aug 27, 2019
a467dbd
Fix english/hebrew tests
tsvi Aug 27, 2019
a766b72
Fix updating of issue melacha binary sensor
tsvi Aug 27, 2019
d97a599
Fix docstrings of binary sensor
tsvi Aug 27, 2019
f2d3bc5
Reset timezones before and after each test
tsvi Aug 27, 2019
9a66823
Use correct entity_id for day of the omer tests
tsvi Aug 27, 2019
156daab
Fix omer tests
tsvi Aug 28, 2019
42ede7a
Cleanup and rearrange tests
tsvi Aug 28, 2019
ff4cc58
Remove the old issur_melacha_in_effect sensor
tsvi Aug 28, 2019
4d65727
Rename variables to make the code clearer
tsvi Aug 28, 2019
096199c
Use dt_util.set_default_time_zone instead of hass.config.set_time_zon…
tsvi Aug 28, 2019
27b1aac
Remove should_poll set to false (accidental copy/paste)
tsvi Aug 28, 2019
ca03279
Remove _LOGGER messaging during init and impossible cases
tsvi Aug 28, 2019
73ddbba
Move binary tests to standalone test functions
tsvi Aug 28, 2019
acd6ddb
Collect entities before calling add_entities
tsvi Aug 28, 2019
6b72775
Fix pylint errors
tsvi Aug 28, 2019
9677156
Simplify logic in binary sensor until a future a PR adds more sensors
tsvi Aug 28, 2019
779065c
Rename test_id holyness to holiday_type
tsvi Aug 28, 2019
be0ec18
Fix time zone for binary sensor tests
tsvi Aug 28, 2019
1ccca66
Don't use unnecessary alter_time in sensors
tsvi Aug 28, 2019
3960547
Simply set hass.config.time_zone instead of murking around with globa…
tsvi Aug 29, 2019
77508c6
Use async_fire_time_changed instead of directly calling async_update_…
tsvi Aug 29, 2019
7c92dd6
Removing debug messaging during init of integration
tsvi Aug 29, 2019
a71ed76
Capitalize constants
tsvi Aug 29, 2019
7329208
Collect all Entities before calling async_add_entities
tsvi Aug 29, 2019
26fb77f
Revert "Don't use unnecessary alter_time in sensors"
tsvi Aug 31, 2019
05797b9
Use test time instead of utc_now
tsvi Aug 31, 2019
781adb8
Remove superfluous testing
tsvi Sep 3, 2019
b0a12a6
Fix triggering of time changed
tsvi Sep 3, 2019
e39e624
Fix failing tests due to side-effects
tsvi Sep 3, 2019
879e2f6
Use dt_util.as_utc instead of reimplementing it's functionality
tsvi Sep 3, 2019
611b668
Use dict[key] for default values
tsvi Sep 3, 2019
726914c
Move 3rd party imports to the top of the module
tsvi Sep 3, 2019
d0ad1c8
Fix imports
tsvi Sep 3, 2019
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
109 changes: 109 additions & 0 deletions homeassistant/components/jewish_calendar/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,110 @@
"""The jewish_calendar component."""
import logging

import voluptuous as vol

Comment thread
tsvi marked this conversation as resolved.
Outdated
import hdate

from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
from homeassistant.helpers.discovery import async_load_platform
import homeassistant.helpers.config_validation as cv


_LOGGER = logging.getLogger(__name__)

DOMAIN = "jewish_calendar"

SENSOR_TYPES = {
"binary": {
"issur_melacha_in_effect": ["Issur Melacha in Effect", "mdi:power-plug-off"]
},
"data": {
"date": ["Date", "mdi:judaism"],
"weekly_portion": ["Parshat Hashavua", "mdi:book-open-variant"],
"holiday_name": ["Holiday name", "mdi:calendar-star"],
"holiday_type": ["Holiday type", "mdi:counter"],
"omer_count": ["Day of the Omer", "mdi:counter"],
},
"time": {
"first_light": ["Alot Hashachar", "mdi:weather-sunset-up"],
"gra_end_shma": ['Latest time for Shm"a GR"A', "mdi:calendar-clock"],
"mga_end_shma": ['Latest time for Shm"a MG"A', "mdi:calendar-clock"],
"plag_mincha": ["Plag Hamincha", "mdi:weather-sunset-down"],
"first_stars": ["T'set Hakochavim", "mdi:weather-night"],
"upcoming_shabbat_candle_lighting": [
"Upcoming Shabbat Candle Lighting",
"mdi:candle",
],
"upcoming_shabbat_havdalah": ["Upcoming Shabbat Havdalah", "mdi:weather-night"],
"upcoming_candle_lighting": ["Upcoming Candle Lighting", "mdi:candle"],
"upcoming_havdalah": ["Upcoming Havdalah", "mdi:weather-night"],
},
}

CONF_DIASPORA = "diaspora"
CONF_LANGUAGE = "language"
CONF_CANDLE_LIGHT_MINUTES = "candle_lighting_minutes_before_sunset"
CONF_HAVDALAH_OFFSET_MINUTES = "havdalah_minutes_after_sunset"

CANDLE_LIGHT_DEFAULT = 18

DEFAULT_NAME = "Jewish Calendar"

CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
{
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_DIASPORA, default=False): cv.boolean,
vol.Inclusive(CONF_LATITUDE, "coordinates"): cv.latitude,
vol.Inclusive(CONF_LONGITUDE, "coordinates"): cv.longitude,
vol.Optional(CONF_LANGUAGE, default="english"): vol.In(
["hebrew", "english"]
),
vol.Optional(
CONF_CANDLE_LIGHT_MINUTES, default=CANDLE_LIGHT_DEFAULT
): int,
# Default of 0 means use 8.5 degrees / 'three_stars' time.
vol.Optional(CONF_HAVDALAH_OFFSET_MINUTES, default=0): int,
}
)
},
extra=vol.ALLOW_EXTRA,
)


async def async_setup(hass, config):
"""Set up the Jewish Calendar component."""
name = config[DOMAIN][CONF_NAME]
language = config[DOMAIN][CONF_LANGUAGE]

latitude = config[DOMAIN].get(CONF_LATITUDE, hass.config.latitude)
longitude = config[DOMAIN].get(CONF_LONGITUDE, hass.config.longitude)
diaspora = config[DOMAIN][CONF_DIASPORA]

candle_lighting_offset = config[DOMAIN][CONF_CANDLE_LIGHT_MINUTES]
havdalah_offset = config[DOMAIN][CONF_HAVDALAH_OFFSET_MINUTES]

location = hdate.Location(
latitude=latitude,
longitude=longitude,
timezone=hass.config.time_zone,
diaspora=diaspora,
)

hass.data[DOMAIN] = {
"location": location,
"name": name,
"language": language,
"candle_lighting_offset": candle_lighting_offset,
"havdalah_offset": havdalah_offset,
"diaspora": diaspora,
}

hass.async_create_task(async_load_platform(hass, "sensor", DOMAIN, {}, config))

hass.async_create_task(
async_load_platform(hass, "binary_sensor", DOMAIN, {}, config)
)

return True
66 changes: 66 additions & 0 deletions homeassistant/components/jewish_calendar/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""Support for Jewish Calendar binary sensors."""
import logging

from homeassistant.components.binary_sensor import BinarySensorDevice
import homeassistant.util.dt as dt_util

from . import DOMAIN, SENSOR_TYPES

import hdate
Comment thread
tsvi marked this conversation as resolved.
Outdated

_LOGGER = logging.getLogger(__name__)


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Jewish Calendar binary sensor devices."""
if discovery_info is None:
return

async_add_entities(
[
JewishCalendarBinarySensor(hass.data[DOMAIN], sensor, sensor_info)
for sensor, sensor_info in SENSOR_TYPES["binary"].items()
]
)


class JewishCalendarBinarySensor(BinarySensorDevice):
"""Representation of an Jewish Calendar binary sensor."""

def __init__(self, data, sensor, sensor_info):
"""Initialize the binary sensor."""
self._location = data["location"]
self._type = sensor
self._name = f"{data['name']} {sensor_info[0]}"
self._icon = sensor_info[1]
self._hebrew = data["language"] == "hebrew"
self._candle_lighting_offset = data["candle_lighting_offset"]
self._havdalah_offset = data["havdalah_offset"]
self._state = False

@property
def icon(self):
"""Return the icon of the entity."""
return self._icon

@property
def name(self):
"""Return the name of the entity."""
return self._name

@property
def is_on(self):
"""Return true if sensor is on."""
return self._state

async def async_update(self):
"""Update the state of the sensor."""
zmanim = hdate.Zmanim(
date=dt_util.now(),
location=self._location,
candle_lighting_offset=self._candle_lighting_offset,
havdalah_offset=self._havdalah_offset,
hebrew=self._hebrew,
)

self._state = zmanim.issur_melacha_in_effect
Loading