@@ -119,27 +119,53 @@ async def async_update(self):
119
119
self .api .get_standing_orders , self ._account_id
120
120
)
121
121
122
- if "items" in transactions :
123
- self ._transactions = transactions ["items" ]
124
- if "items" in payments :
125
- self ._payments = payments ["items" ]
126
- if "items" in standing_orders :
127
- self ._standing_orders = standing_orders ["items" ]
128
- if "available" in account :
122
+ if (
123
+ "available" in account
124
+ and "balance" in account
125
+ and "name" in account
126
+ and "accountNumber" in account
127
+ and "accountType" in account
128
+ and "creditLimit" in account
129
+ ):
130
+ self .credit_limit = account ["creditLimit" ]
129
131
self ._available = float (account ["available" ])
130
- if "balance" in account :
131
132
self ._balance = float (account ["balance" ])
132
- if "name" in account :
133
133
self ._account_name = account ["name" ]
134
- if "accountNumber" in account :
135
134
self ._account_number = account ["accountNumber" ]
136
- if "accountType" in account :
137
135
self ._account_type = account ["accountType" ]
138
- if "creditLimit" in account :
139
- self .credit_limit = account ["creditLimit" ]
140
- self ._last_updated = datetime .now ()
136
+ self ._last_updated = datetime .now ()
137
+ _LOGGER .debug (f"Updating account information: { self ._attr_name } " )
138
+ else :
139
+ _LOGGER .warn (
140
+ f"Error updating account information { self ._attr_name } . Account: { str (account )} "
141
+ )
141
142
142
- _LOGGER .debug (f"Updating Sbanken Sensors: { self ._attr_name } " )
143
+ if "items" in transactions :
144
+ self ._transactions = transactions ["items" ]
145
+ self ._last_updated = datetime .now ()
146
+ _LOGGER .debug (f"Updating transactions: { self ._attr_name } " )
147
+ else :
148
+ _LOGGER .warn (
149
+ f"Error updating transactions { self ._attr_name } . Transactions: { str (transactions )} "
150
+ )
151
+
152
+ if "items" in payments :
153
+ self ._payments = payments ["items" ]
154
+ self ._last_updated = datetime .now ()
155
+ _LOGGER .debug (f"Updating payments: { self ._attr_name } " )
156
+ else :
157
+ _LOGGER .warn (
158
+ f"Error updating payments { self ._attr_name } . Payments: { str (payments )} "
159
+ )
160
+
161
+ if "items" in standing_orders :
162
+ self ._standing_orders = standing_orders ["items" ]
163
+ self ._last_updated = datetime .now ()
164
+ _LOGGER .debug (f"Updating standing orders: { self ._attr_name } " )
165
+ else :
166
+ _LOGGER .warn (
167
+ f"Error updating standing orders { self ._attr_name } . Standing orders: { str (standing_orders )} "
168
+ )
143
169
144
170
145
171
class CustomerInformationSensor (Entity ):
@@ -165,6 +191,7 @@ def __init__(
165
191
self ._phone_numbers = None
166
192
self ._first_name = ""
167
193
self ._last_name = ""
194
+ self ._last_updated = datetime .now ()
168
195
169
196
@property
170
197
def device_info (self ):
@@ -194,6 +221,7 @@ def extra_state_attributes(self):
194
221
"postalAddress" : self ._postal_address ,
195
222
"streetAddress" : self ._street_address ,
196
223
"phoneNumbers" : self ._phone_numbers ,
224
+ ATTR_LAST_UPDATE : self ._last_updated ,
197
225
}
198
226
199
227
async def async_update (self ):
@@ -204,21 +232,28 @@ async def async_update(self):
204
232
customer_info = await self .hass .async_add_executor_job (
205
233
self .api .get_customer_information
206
234
)
207
- if "customerId" in customer_info :
235
+
236
+ if (
237
+ "customerId" in customer_info
238
+ and "emailAddress" in customer_info
239
+ and "dateOfBirth" in customer_info
240
+ and "postalAddress" in customer_info
241
+ and "streetAddress" in customer_info
242
+ and "phoneNumbers" in customer_info
243
+ and "firstName" in customer_info
244
+ and "lastName" in customer_info
245
+ ):
208
246
self ._customer_id = customer_info ["customerId" ]
209
- if "emailAddress" in customer_info :
210
247
self ._email_address = customer_info ["emailAddress" ]
211
- if "dateOfBirth" in customer_info :
212
248
self ._date_of_birth = customer_info ["dateOfBirth" ]
213
- if "postalAddress" in customer_info :
214
249
self ._postal_address = customer_info ["postalAddress" ]
215
- if "streetAddress" in customer_info :
216
250
self ._street_address = customer_info ["streetAddress" ]
217
- if "phoneNumbers" in customer_info :
218
251
self ._phone_numbers = customer_info ["phoneNumbers" ]
219
- if "firstName" in customer_info :
220
252
self ._first_name = customer_info ["firstName" ]
221
- if "lastName" in customer_info :
222
253
self ._last_name = customer_info ["lastName" ]
223
-
224
- _LOGGER .debug (f"Updating Sbanken Sensors: { self ._attr_name } " )
254
+ self ._last_updated = datetime .now ()
255
+ _LOGGER .debug (f"Updating customer information: { self ._attr_name } " )
256
+ else :
257
+ _LOGGER .warn (
258
+ f"Error updating customer information: { self ._attr_name } . Data{ str (customer_info )} "
259
+ )
0 commit comments