hasl-sensor / integration

Swedish Public Transport Sensor (HASL). Formerly named HomeAssistant SL Sensor
https://hasl.sorlov.com
Apache License 2.0
36 stars 8 forks source link

Sensor checking too often - (checkminutesdiff) #17

Closed FredHags closed 2 years ago

FredHags commented 2 years ago

Hi,

Setting seconds between checks doesn't work.

The function checkminutesdiff seems to have values (d1, d2) in the wrong order. So the result is always above threshold.

I have changed the code to:

`
def getminutesdiff(self, d1, d2):

    d1 = datetime.strptime(d1, "%Y-%m-%d %H:%M:%S")
    d2 = datetime.strptime(d2, "%Y-%m-%d %H:%M:%S")
    diff = (d1 - d2).total_seconds()
    logger.debug(f"[get_minutes_diff] diff {diff}, d1 {d1}, d2 {d2}")
    return diff

`

which seems to be working.