PTST / O365-HomeAssistant

Office 365 integration for Home Assistant
MIT License
69 stars 13 forks source link

start and end offset are ignored #61

Open ThisBytes5 opened 4 years ago

ThisBytes5 commented 4 years ago

I have the following configuration:

- device_id: WorkFromHome end_offset: 24 name: Work From Home start_offset: -24 track: true search: "WFH"

Today is may 5th, at 22:56 EDT

I've added the following _LOGGER calls to calendar.py def o365_get_events(self, start_date, end_date): query = self.calendar.new_query("start").greater_equal(start_date) query.chain("and").on_attribute("end").less_equal(end_date) if self.search is not None: query.chain("and").on_attribute("subject").contains(self.search) _LOGGER.warning("HERE") _LOGGER.warning(query)

The results of the _Logger calls are as follows:

2020-05-05 22:56:33 WARNING (MainThread) [custom_components.o365.calendar] HERE 2020-05-05 22:56:33 WARNING (MainThread) [custom_components.o365.calendar] Filter: start/dateTime ge '2020-05-05T04:00:00+00:00' and end/dateTime le '2020-05-06T04:00:00+00:00' and contains(subject, 'WFH')

Start and end times are still midnight even though they should be May 4th at 22:56 and May 6th at 22:56

I believe the issue is in the below snippet of code, and I don't believe the :

@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): results = self.o365_get_events( dt.start_of_local_day(), dt.start_of_local_day() + timedelta(days=1) )

However, I haven't changed it as I'm not a 100% sure, and don't know if it will affect other parts of the component. I do have a WFH event in my calendar, recurring each day so it should be finding the event.

I also wonder if this is correct:

async def async_update(self): self.data.update() event = copy.deepcopy(self.data.event) if event is None: self._event = event return

This returns no event, then exits the method and doesn't attempt to the rest of the method.

I'm not a HA developer (yet) and as such don't fully understand everything going on here, but it does appear to me that the only time my search phrase is looked for my offsets are ignored.

Let me know if I can provide anything else you may need to help resolve this issue.

ThisBytes5 commented 4 years ago

Also just to mention, my sensor for the WFH is always off, even though it's searching the whole day it still does not find my event, unless it's an All day event. So sort of confused by that as well.

ThisBytes5 commented 4 years ago

Do you need anything else from me for this one?

PTST commented 4 years ago

No, i just need time to look into this. hopefully in the next couple of days. πŸ™‚

ThisBytes5 commented 4 years ago

Thank you, wasn't trying to be pushy, just wanted to make sure you didn't need anything from me. I truly appreciate the time you put into this, it's been very helpful now that I am working from home, and I'm sure if I ever have to go back to the office I'll find other uses for it!

gijbelsy commented 4 years ago

I think the problem to this resides in the following piece of code:

async def async_update(self, hass):
        results = await hass.async_add_executor_job(self.o365_get_events,
            dt.start_of_local_day(), dt.start_of_local_day() + timedelta(days=1)
        )

the start_of_local_day() reports in UTC time format, and doesn't take time-zones into account. Referring to the issue listed here: https://github.com/home-assistant/core/issues/10477 This should be dt_util.start_of_local_day(dt_util.as_local(now)) where the timezone information is passed to the function.

Can this be tested and fixed in the code if applicable?

filikun commented 4 years ago

I think I have the same Issue. Installed two days ago and it showed upp all fine with data and alla and then just disappeared

I have this calendar.liverpool that is showing me all upcoming Liverpool FC games. And this is all I get from it.

offset_reached: false data: friendly_name: Liverpool

The funny thing is that the new calendar page in Home Assistant is showing all the games correctly.

Here is my config for that calendar

- cal_id: XXXX entities: - device_id: Liverpool end_offset: 24 name: Liverpool start_offset: 0 track: true

Edit: For some reason I can't get the code indentation to work properly.

gijbelsy commented 4 years ago

@PTST: Any updates on this ?

ghost commented 4 years ago

I have been asking about the offsets earlier and still I can't wrap my head around it (could be because of the bug?).

`- cal_id: xxx entities:

I always add an appointment with subject "Hotel" at 18:00 every time I travel. I use this to set HA to travel mode.

I have made a sensor that looks for Hotel in the message field. `sensor:

This does not work that well because it set HA to travel mode to early. If offset works like I think it works using `sensor:

Am I thinking correctly?

Br

PTST commented 4 years ago

I have implemented a partial fix for the offsets not being used which will be included in the next release.

This fix is only applicable for the calendar data shown under the data key. I have not messed with the current event data that is shown at the toplevel of the data. Simply because i'm not quite sure of the ramifications of messing with this data, especially in regards to calendar cards and the like.

I really would love som input on this.

And finally sorry about the long response time on this issue, life simply got in the way πŸ™‚

ghost commented 4 years ago

Thank you for looking into this. Is the fix included in v2.1.8?

JanEsders commented 3 years ago

Is there any update on this?

ThisBytes5 commented 3 years ago

I really would love som input on this.

Did you get the help you needed? I would be more then happy to help, what do I need to do?

maxalbani commented 3 years ago

Start and End Offsets still don't work. The data attribute of the calendar entity always shows only the current day. I would like to use a template sensor that shows the next task on the calendar, but this cannot be done. @PTST Is it possible to fix?