Skip to content

Commit

Permalink
potential fix for custom scan interval #3
Browse files Browse the repository at this point in the history
  • Loading branch information
FaserF committed Sep 13, 2022
1 parent cff38f4 commit 251dc78
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion custom_components/foodsharing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async def async_setup_entry(
config = hass.data[DOMAIN][entry.entry_id]
async def async_update_data():
"""Fetch data from Foodsharing."""
scan_interval=timedelta(minutes=config[CONF_SCAN_INTERVAL])
async with async_timeout.timeout(scan_interval - 1):
await hass.async_add_executor_job(lambda: data.update())

Expand All @@ -49,7 +50,7 @@ async def async_update_data():
_LOGGER,
name=f"{entry.entry_id} Foodsharing state",
update_method=async_update_data,
update_interval=timedelta(seconds=config[CONF_SCAN_INTERVAL]),
update_interval=timedelta(minutes=config[CONF_SCAN_INTERVAL]),
)

return True
Expand Down
2 changes: 1 addition & 1 deletion custom_components/foodsharing/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def async_step_user(self, user_input=None):
vol.Required(CONF_DISTANCE, default=7): cv.positive_int,
vol.Required(CONF_EMAIL, default="[email protected]"): str,
vol.Required(CONF_PASSWORD, default="mySecretPassword"): str,
vol.Required(CONF_SCAN_INTERVAL, default=180): cv.positive_int,
vol.Required(CONF_SCAN_INTERVAL, default=2): cv.positive_int,
},
)

Expand Down
3 changes: 2 additions & 1 deletion custom_components/foodsharing/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"longitude": "Longitude",
"distance": "Distance in kilometers (km)",
"email": "E-Mail Adress from your foodsharing account",
"password": "Password from your foodsharing account"
"password": "Password from your foodsharing account",
"scan_interval": "Scan interval in minutes"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion custom_components/foodsharing/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"longitude": "Longitude",
"distance": "Entfernung in Kilometern (km)",
"email": "E-Mail Adresse des foodsharing accounts",
"password": "Passwort des foodsharing accounts"
"password": "Passwort des foodsharing accounts",
"scan_interval": "Scan Intervall in Minuten"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion custom_components/foodsharing/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"longitude": "Longitude",
"distance": "Distance in kilometers (km)",
"email": "E-Mail Adress from your foodsharing account",
"password": "Password from your foodsharing account"
"password": "Password from your foodsharing account",
"scan_interval": "Scan interval in minutes"
}
}
},
Expand Down

0 comments on commit 251dc78

Please sign in to comment.