9
9
from homeassistant import config_entries
10
10
from homeassistant import core
11
11
from homeassistant .helpers import config_entry_oauth2_flow
12
+ from homeassistant .helpers import issue_registry as ir
12
13
13
14
from .const import DAIKIN_DEVICES
14
15
from .const import DOMAIN
@@ -84,10 +85,16 @@ async def doBearerRequest(self, resourceUrl, options=None):
84
85
_LOGGER .error ("REQUEST FAILED: %s" , e )
85
86
return []
86
87
87
- self .rate_limits ["minute" ] = res .headers .get ("X-RateLimit-Limit-minute" , 0 )
88
- self .rate_limits ["day" ] = res .headers .get ("X-RateLimit-Limit-day" , 0 )
89
- self .rate_limits ["remaining_minutes" ] = res .headers .get ("X-RateLimit-Remaining-minute" , 0 )
90
- self .rate_limits ["remaining_day" ] = res .headers .get ("X-RateLimit-Remaining-day" , 0 )
88
+ self .rate_limits ["minute" ] = int (res .headers .get ("X-RateLimit-Limit-minute" , 0 ))
89
+ self .rate_limits ["day" ] = int (res .headers .get ("X-RateLimit-Limit-day" , 0 ))
90
+ self .rate_limits ["remaining_minutes" ] = int (res .headers .get ("X-RateLimit-Remaining-minute" , 0 ))
91
+ self .rate_limits ["remaining_day" ] = int (res .headers .get ("X-RateLimit-Remaining-day" , 0 ))
92
+
93
+ if self .rate_limits ["remaining_minutes" ] > 0 :
94
+ ir .async_delete_issue (self .hass , DOMAIN , "minute_rate_limit" )
95
+
96
+ if self .rate_limits ["remaining_day" ] > 0 :
97
+ ir .async_delete_issue (self .hass , DOMAIN , "day_rate_limit" )
91
98
92
99
_LOGGER .debug ("BEARER RESPONSE CODE: %s LIMIT: %s" , res .status_code , self .rate_limits )
93
100
@@ -98,9 +105,33 @@ async def doBearerRequest(self, resourceUrl, options=None):
98
105
_LOGGER .error ("RETRIEVE JSON FAILED: %s" , res .text )
99
106
return False
100
107
elif res .status_code == 429 :
101
- raise Exception (
102
- "Rate limit: Remaining minute " + str (self .rate_limits ["remaining_minutes" ]) + " day " + str (self .rate_limits ["remaining_day" ])
103
- )
108
+ if self .rate_limits ["remaining_minutes" ] == 0 :
109
+ ir .async_create_issue (
110
+ self .hass ,
111
+ DOMAIN ,
112
+ "minute_rate_limit" ,
113
+ is_fixable = False ,
114
+ is_persistent = True ,
115
+ severity = ir .IssueSeverity .ERROR ,
116
+ learn_more_url = "https://developer.cloud.daikineurope.com/docs/b0dffcaa-7b51-428a-bdff-a7c8a64195c0/rate_limitation" ,
117
+ translation_key = "minute_rate_limit" ,
118
+ )
119
+
120
+ if self .rate_limits ["remaining_day" ] == 0 :
121
+ ir .async_create_issue (
122
+ self .hass ,
123
+ DOMAIN ,
124
+ "day_rate_limit" ,
125
+ is_fixable = False ,
126
+ is_persistent = True ,
127
+ severity = ir .IssueSeverity .ERROR ,
128
+ learn_more_url = "https://developer.cloud.daikineurope.com/docs/b0dffcaa-7b51-428a-bdff-a7c8a64195c0/rate_limitation" ,
129
+ translation_key = "day_rate_limit" ,
130
+ )
131
+ if options is not None and "method" in options and options ["method" ] == "PATCH" :
132
+ return False
133
+ else :
134
+ return []
104
135
elif res .status_code == 204 :
105
136
self ._last_patch_call = datetime .now ()
106
137
return True
0 commit comments