Closed cooperaj closed 3 years ago
Ah I see the issue. I think you're on an tarrif with no current end date, whereas I'm assuming there's always one. I'll rectify this hopefully tonight.
Think i've cracked the empty response to curl -u "sk_live_muhkey:" "https://api.octopus.energy/v1/accounts/A-MUHACC"
as curl -u "sk_live_muhkey:" "https://api.octopus.energy/v1/accounts/A-MUHACC/"
brings back everything I expect (note the closing slash). I expect curl does not follow the redirect but the python library does.
I think this would still hit the issue you've described as the 'valid_to' field is null in my response.
from homeassistant.util.dt import (utcnow, as_utc, parse_datetime)
import datetime as dt
def get_active_agreement(agreements):
now = utcnow()
for agreement in agreements:
valid_from = as_utc(parse_datetime(agreement["valid_from"]))
if agreement["valid_to"] is not None:
valid_to = as_utc(parse_datetime(agreement["valid_to"]))
else:
valid_to = now + dt.timedelta(seconds=1)
if valid_from <= now and valid_to >= now:
return agreement
return None
Python is not my thing but this appears to work.
Yup that's the area. I've updated to handle it slightly differently to how you did it, just because I don't want to make any assumptions. Closing issue as I've applied a fix, but feel free to reopen if my fix is somehow still broken
Ah, that's the path I took originally but I think won't work. The valid_to field will always exist, but the value may either be None or a string. I think (unless my knowledge of Python is way off) the altered code will have the same issue as reported.
I think it should be fine, but to be on the safe side I've added the additional check you had as well.
After setting up the integration I get no new entities. My logs contains
Running a manual curl query at the url that provides the 'point' dict (in
async_get_account
) I get a blank response. I rancurl -u "sk_live_muhkey:" "https://api.octopus.energy/v1/accounts/A-MUHACC"
and get back nothing. Looking at the API documentation I can't even seen a GET /v1/accounts endpoint. There is a POST one but that is for partner organisations only.