veebch / hometime

A physical progress bar based on Google Calendar events
GNU General Public License v3.0
45 stars 6 forks source link

False Working Hours #17

Closed holmesha closed 1 year ago

holmesha commented 1 year ago

Occasionally I get a "False" reading to the working hours/working variable and the display won't show anything. My understanding was that when connected to the google calendar API that the working hours are set by the events on the calendar rather than the set hours in the config or clockin/out times so I'm not understanding how events could be outside working hours in that case. I did make sure the clockin/out times in the config file were definitely before / after any calendar events, and the current time is within the working hours set by the events. I've tried to debug, but I can't quite seem to find the issue. Any ideas would be much appreciated!

veebch commented 1 year ago

I've not encountered this one.

You're right, as soon as you are using google, the hardcoded times are ignored. Have you got an example so that I can try to reproduce the error?

holmesha commented 1 year ago

I actually THINK I might have a fix depending on how you want the display to work. I was struggling to get the events within the working hours somehow so instead of changing the events, I tried to force it to check the config clockin/out hours regardless of when events happen on the calendar. However this does change the end of the progress bar to end at the clockout time instead of the last event, which I actually like since I want it to end at the same time daily regardless of meetings, etc. SEEMS to work, but would love your opinion. I commented out the old lines so you can see the changes I made to the code:

if googlecalbool is True: # overwrite clockin/clockout times if Google Calendar is to be used
                if googleindex == 1:
                    print('Updating from Google Calendar')
                    try:
                        appointment_times = get_today_appointment_times(calendar, api_key, config.TIMEZONE)
                        appointment_times = sorted_appointments(appointment_times)
                        print(appointment_times)
                        #clockin = timetohour(appointment_times[0])
                        #print("clockin:",clockin)
                        #clockout = timetohour(appointment_times[len(appointment_times)-1])
                        eventbool = eventnow(hoursin, appointment_times[::2]) # only the even elements (starttimes)
                    except:
                        print('Scheduling issues')
                        appointment_times = []
                        #clockin = 6
                        #clockout = 18
                        eventbool = False
            clockin = float(schedule[dayname][0]['clockin'])
            clockout = float(schedule[dayname][0]['clockout'])
            #else:
            #    clockin = float(schedule[dayname][0]['clockin'])
            #    clockout = float(schedule[dayname][0]['clockout'])
veebch commented 1 year ago

It's a good point. I'm not sure what would be more useful. The full reliance on google calendar was a way to make me use the google calendar more.

A nice alternative might be to run a webserver on the pico, that lets you set the working hours via a webpage. That would involve the least tinkering with the code for people wanting to just build one and get it up and running with minimal effort.

It should be simple to add an explicit IGNORE_HARDCODED boolean to the config file that forces the schedule to be entirely determined by google calendar when True, otherwise it uses the schedule in the code and only uses google calendar entries for the times specified.

holmesha commented 1 year ago

Oh I love the google calendar for the events, I just had to find a way to fix the start and end times so my events always fall in between.

I am always late to meetings since I have so many back to back and when the light bar starts glowing now everyone else even knows what that means lol!

veebch commented 1 year ago

I've added the ability to hardcode working hours and still use the Google Calendar.

It seems to work ok, so closing for now.