Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unavailable sensor fix #33

Closed
wants to merge 2 commits into from

Conversation

djbadders
Copy link

I found the issue causing the sensors to become unavailable was due to some very choppy performance with the Octopus APIs moving form a call time of 1-3 seconds to 30 seconds or greater at times. This longer call duration then exceeded to timeout that was defined for the HA poll of 30 secs and therefore left the sensors unavailable. Fix is simple increase HA async task timeout to 60 seconds. Also changed the polling to every 2 mins and all is good.

@@ -23,7 +23,7 @@ def __init__(self, hass, *, api_key, account_id, off_peak_start, off_peak_end):
# Name of the data. For logging purposes.
name="Octopus Intelligent",
# Polling interval. Will only be polled if there are subscribers.
update_interval=timedelta(seconds=300),
update_interval=timedelta(seconds=120),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Much appreciated.

I'm a bit reluctant to increase the amount of requests we make to octopus. Given the recent noise on this and the fact most were happy with 300s before, I'm going to revert this change but keep the timeout increase.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into that and they allow 10 requests a min, so well within that with the 2 min poll; the issue is their sometimes long responses. Maybe they have locking issues, not sure. 2 mins is working fine for me.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is true that some users jump to conclusions and incorrectly assume that any API failures are a result of rate limiting. On the other hand, response times of 30+ seconds may be a sign of server overload. I note that the proposed increased timeout of 60 seconds is 50% of the proposed reduced polling interval of 120 seconds. Think about it: If the servers took 60 seconds to reply to a request, hitting it with another request just 60 seconds later “feels a bit mean.” (Although Octopus should get their act together on server capacity and introduce real bitting rate limits if that’s an issue for them.)

My 2 cents would be for this “Unavailable sensor fix” PR to focus on increasing the timeout only, which is what fixes the issue. The polling interval in my opinion should be configurable instead of hardcoded (hass config flow).

@@ -48,7 +48,7 @@ async def _async_update_data(self):
try:
# Note: asyncio.TimeoutError and aiohttp.ClientError are already
# handled by the data update coordinator.
async with async_timeout.timeout(30):
async with async_timeout.timeout(60):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about something along the following lines (may need amending):

Suggested change
async with async_timeout.timeout(60):
timeout = max(30, min(300, update_interval / 2))
async with async_timeout.timeout(timeout):

Where update_interval is the value from the __init__ method (maybe self.update_interval, not sure), which used to be 5 minutes and this PR currently proposes amending. The intention being: The timeout should be half the update interval, capped at a minimum of 30s and a maximum of 300s (5 minutes).

Rationale: Given that this integration runs 24/7 and automations depend on it, as a user I would rather face request timeouts as crazy long as, say, 5 minutes rather than facing “unavailable” errors.

If the update interval was configurable by the user as suggested in another comment, the 30s minimum timeout would imply a minimum polling interval of 60s.

@@ -23,7 +23,7 @@ def __init__(self, hass, *, api_key, account_id, off_peak_start, off_peak_end):
# Name of the data. For logging purposes.
name="Octopus Intelligent",
# Polling interval. Will only be polled if there are subscribers.
update_interval=timedelta(seconds=300),
update_interval=timedelta(seconds=120),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is true that some users jump to conclusions and incorrectly assume that any API failures are a result of rate limiting. On the other hand, response times of 30+ seconds may be a sign of server overload. I note that the proposed increased timeout of 60 seconds is 50% of the proposed reduced polling interval of 120 seconds. Think about it: If the servers took 60 seconds to reply to a request, hitting it with another request just 60 seconds later “feels a bit mean.” (Although Octopus should get their act together on server capacity and introduce real bitting rate limits if that’s an issue for them.)

My 2 cents would be for this “Unavailable sensor fix” PR to focus on increasing the timeout only, which is what fixes the issue. The polling interval in my opinion should be configurable instead of hardcoded (hass config flow).

@pdcastro pdcastro mentioned this pull request Feb 2, 2024
@megakid
Copy link
Owner

megakid commented Feb 4, 2024

I've just updated the timeout value and published a new release. Thanks

@megakid megakid closed this Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants