#NEWLINE# def test_track_sunset( self ) : #NEWLINE# #INDENT# 'Test track sunset decorator.' #NEWLINE# latitude = 32.87336 #NEWLINE# longitude = 117.22743 #NEWLINE# self . hass . config . latitude = latitude #NEWLINE# self . hass . config . longitude = longitude #NEWLINE# sun . setup ( self . hass , { #NEWLINE# #INDENT# sun . DOMAIN : { #NEWLINE# #INDENT# sun . CONF_ELEVATION : 0 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# astral = Astral ( ) #NEWLINE# utc_now = dt_util . utcnow ( ) #NEWLINE# mod = ( - 1 ) #NEWLINE# while True : #NEWLINE# #INDENT# next_setting = astral . sunset_utc ( ( utc_now + timedelta ( days = mod ) ) , latitude , longitude ) #NEWLINE# if ( next_setting > utc_now ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# mod += 1 #NEWLINE# #UNINDENT# runs = [ ] #NEWLINE# decor = track_sunset ( ) #NEWLINE# decor ( ( lambda x : runs . append ( 1 ) ) ) #NEWLINE# offset_runs = [ ] #NEWLINE# offset = timedelta ( minutes = 30 ) #NEWLINE# decor = track_sunset ( offset ) #NEWLINE# decor ( ( lambda x : offset_runs . append ( 1 ) ) ) #NEWLINE# self . _send_time_changed ( ( next_setting - offset ) ) #NEWLINE# self . hass . pool . block_till_done ( ) #NEWLINE# self . assertEqual ( 0 , len ( runs ) ) #NEWLINE# self . assertEqual ( 0 , len ( offset_runs ) ) #NEWLINE# self . _send_time_changed ( next_setting ) #NEWLINE# self . hass . pool . block_till_done ( ) #NEWLINE# self . assertEqual ( 1 , len ( runs ) ) #NEWLINE# self . assertEqual ( 0 , len ( offset_runs ) ) #NEWLINE# self . _send_time_changed ( ( next_setting + offset ) ) #NEWLINE# self . hass . pool . block_till_done ( ) #NEWLINE# self . assertEqual ( 2 , len ( runs ) ) #NEWLINE# self . assertEqual ( 1 , len ( offset_runs ) )