def set_blind_position(self, *args): current_elevation = elevation(self.locationInfo.observer) current_azimuth = azimuth(self.locationInfo.observer) self.log( "current_elevation: {}, open_elevation: {}, close_elevation: {}". format(current_elevation, self.open_elevation, self.close_elevation)) self.log( "current_azimuth: {}, start_azimuth: {}, end_azimuth: {}".format( current_azimuth, self.start_azimuth, self.end_azimuth)) for cover in self.covers: if self.start_azimuth <= current_azimuth <= self.end_azimuth: position = max( 0, min( 100, self.offset + ((current_elevation - self.close_elevation) / (self.open_elevation - self.close_elevation) * 100), ), ) self.log("setting {} to {}".format(cover, position)) self.call_service("cover/set_cover_position", entity_id=cover, position=position) else: self.log("not setting blinds, outside azimuth range")
async def sun_position(self): """Calculate where the sun is in the sky.""" astral_now = now(tzinfo=self._tzinfo) sun_elevation = elevation(observer=self._siteinfo.observer, dateandtime=astral_now) sun_azimuth = azimuth(observer=self._siteinfo.observer, dateandtime=astral_now) results = [{ 'topic': 'sun/position', 'elevation': round(sun_elevation, 1), 'azimuth': round(sun_azimuth, 1) }] return results
async def generate_azimuth_datetimes( self, search: datetime, range_stop: int, hours: bool = False, minutes: bool = False) -> Dict[float, datetime]: """ Generate for a given datetime and direction a dict of azimuth/datetime values """ datetimes = [ search + timedelta(hours=(1 if hours else 0) * index, minutes=(1 if minutes else 0) * index) for index in range(range_stop) ] return { azimuth(self.location_info.observer, _datetime): _datetime for _datetime in datetimes }
def test_Azimuth_Above85Degrees(): d = datetime.datetime(2001, 6, 21, 13, 11, 0) assert sun.azimuth(Observer(86, 77.2), d) == pytest.approx(276.2148, abs=0.001)
def test_Azimuth(new_delhi): d = datetime.datetime(2001, 6, 21, 13, 11, 0) assert sun.azimuth(new_delhi, d) == pytest.approx(292.766381632981)
def test_SolarAzimuth_NoDate(london): assert sun.azimuth(london) == pytest.approx(166.9676, abs=0.001)
def test_SolarAzimuth(dt, angle, london): assert sun.azimuth(london.observer, dt) == pytest.approx(angle, abs=0.001)