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
async def getZmanim(self, ctx): db = await aiosqlite.connect("haGaon.db") cursor = await db.cursor() await cursor.execute( f"SELECT * FROM main WHERE user_id = {ctx.message.author.id}") result = await cursor.fetchone() if result is None: await create_embed(ctx, "Run setLocation first!!") elif result is not None: dias = result[4] == "True" location = hdate.Location( longitude=float(result[2]), latitude=float(result[1]), timezone=result[3], diaspora=dias, ) await create_embed( ctx, str(hdate.Zmanim(location=location, hebrew=False))) await cursor.close() await db.close()
async def async_update(self): """Update the state of the sensor.""" import hdate now = dt_util.as_local(dt_util.now()) _LOGGER.debug("Now: %s Timezone = %s", now, now.tzinfo) today = now.date() sunset = dt_util.as_local( get_astral_event_date(self.hass, SUN_EVENT_SUNSET, today)) _LOGGER.debug("Now: %s Sunset: %s", now, sunset) location = hdate.Location(latitude=self.latitude, longitude=self.longitude, timezone=self.timezone, diaspora=self.diaspora) def make_zmanim(date): """Create a Zmanim object.""" return hdate.Zmanim( date=date, location=location, candle_lighting_offset=self.candle_lighting_offset, havdalah_offset=self.havdalah_offset, hebrew=self._hebrew) date = hdate.HDate(today, diaspora=self.diaspora, hebrew=self._hebrew) lagging_date = date # Advance Hebrew date if sunset has passed. # Not all sensors should advance immediately when the Hebrew date # officially changes (i.e. after sunset), hence lagging_date. if now > sunset: date = date.next_day today_times = make_zmanim(today) if today_times.havdalah and now > today_times.havdalah: lagging_date = lagging_date.next_day # Terminology note: by convention in py-libhdate library, "upcoming" # refers to "current" or "upcoming" dates. if self.type == 'date': self._state = date.hebrew_date elif self.type == 'weekly_portion': # Compute the weekly portion based on the upcoming shabbat. self._state = lagging_date.upcoming_shabbat.parasha elif self.type == 'holiday_name': self._state = date.holiday_description elif self.type == 'holyness': self._state = date.holiday_type elif self.type == 'upcoming_shabbat_candle_lighting': times = make_zmanim( lagging_date.upcoming_shabbat.previous_day.gdate) self._state = times.candle_lighting elif self.type == 'upcoming_candle_lighting': times = make_zmanim(lagging_date.upcoming_shabbat_or_yom_tov. first_day.previous_day.gdate) self._state = times.candle_lighting elif self.type == 'upcoming_shabbat_havdalah': times = make_zmanim(lagging_date.upcoming_shabbat.gdate) self._state = times.havdalah elif self.type == 'upcoming_havdalah': times = make_zmanim( lagging_date.upcoming_shabbat_or_yom_tov.last_day.gdate) self._state = times.havdalah elif self.type == 'issur_melacha_in_effect': self._state = make_zmanim(now).issur_melacha_in_effect else: times = make_zmanim(today).zmanim self._state = times[self.type].time() _LOGGER.debug("New value: %s", self._state)
async def async_update(self): """Update the state of the sensor.""" import hdate now = dt_util.as_local(dt_util.now()) _LOGGER.debug("Now: %s Timezone = %s", now, now.tzinfo) today = now.date() sunset = dt_util.as_local( get_astral_event_date(self.hass, SUN_EVENT_SUNSET, today)) _LOGGER.debug("Now: %s Sunset: %s", now, sunset) if now > sunset: today += timedelta(1) date = hdate.HDate(today, diaspora=self.diaspora, hebrew=self._hebrew) location = hdate.Location(latitude=self.latitude, longitude=self.longitude, timezone=self.timezone, diaspora=self.diaspora) def make_zmanim(date): """Create a Zmanim object.""" return hdate.Zmanim( date=date, location=location, candle_lighting_offset=self.candle_lighting_offset, havdalah_offset=self.havdalah_offset, hebrew=self._hebrew) if self.type == 'date': self._state = date.hebrew_date elif self.type == 'weekly_portion': # Compute the weekly portion based on the upcoming shabbat. self._state = date.upcoming_shabbat.parasha elif self.type == 'holiday_name': self._state = date.holiday_description elif self.type == 'holyness': self._state = date.holiday_type elif self.type == 'upcoming_shabbat_candle_lighting': times = make_zmanim(date.upcoming_shabbat.previous_day.gdate) self._state = times.candle_lighting elif self.type == 'upcoming_candle_lighting': times = make_zmanim( date.upcoming_shabbat_or_yom_tov.first_day.previous_day.gdate) self._state = times.candle_lighting elif self.type == 'upcoming_shabbat_havdalah': times = make_zmanim(date.upcoming_shabbat.gdate) self._state = times.havdalah elif self.type == 'upcoming_havdalah': times = make_zmanim( date.upcoming_shabbat_or_yom_tov.last_day.gdate) self._state = times.havdalah elif self.type == 'issur_melacha_in_effect': self._state = make_zmanim(now).issur_melacha_in_effect else: times = make_zmanim(today).zmanim self._state = times[self.type].time() _LOGGER.debug("New value: %s", self._state)