Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0aef0e7

Browse files
committed
Tankerkoenig:
- bump to 2.0.5 - change log level of diverse logs from error to notice
1 parent ee85891 commit 0aef0e7

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

tankerkoenig/__init__.py

100755100644
Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838

3939
class TankerKoenig(SmartPlugin):
40-
PLUGIN_VERSION = "2.0.4"
40+
PLUGIN_VERSION = "2.0.5"
4141

4242
_base_url = 'https://creativecommons.tankerkoenig.de/json'
4343
_detail_url_suffix = 'detail.php'
@@ -182,17 +182,17 @@ def get_petrol_stations(self, lat: float = None, lon: float = None, price: str =
182182

183183
# check if value for price
184184
if price not in ['e5', 'e10', 'diesel', 'all']:
185-
self.logger.error(f"Plugin '{self.get_fullname()}': Used value={price} for 'price' at 'get_petrol_stations' not allowed. Set to default 'all'.")
185+
self.logger.notice(f"Plugin '{self.get_fullname()}': Used value={price} for 'price' at 'get_petrol_stations' not allowed. Set to default 'all'.")
186186
price = 'all'
187187

188188
# check if value for sort
189189
if sort not in ['price']:
190-
self.logger.error(f"Plugin '{self.get_fullname()}': Used value={sort} for 'sort' at 'get_petrol_stations' not allowed. Set to default 'price'.")
190+
self.logger.notice(f"Plugin '{self.get_fullname()}': Used value={sort} for 'sort' at 'get_petrol_stations' not allowed. Set to default 'price'.")
191191
sort = 'price'
192192

193193
# limit radius to 25km
194194
if float(rad) > 25:
195-
self.logger.error(f"Plugin '{self.get_fullname()}': Used value={rad} for 'rad' at 'get_petrol_stations' not allowed. Set to max allowed value '25km'.")
195+
self.logger.notice(f"Plugin '{self.get_fullname()}': Used value={rad} for 'rad' at 'get_petrol_stations' not allowed. Set to max allowed value '25km'.")
196196
rad = 25
197197

198198
result_stations = []
@@ -267,13 +267,12 @@ def get_petrol_station_prices(self, station_ids: list) -> dict:
267267
"""
268268
_station_id_prices = self._request_station_prices(station_ids)
269269
if _station_id_prices is None:
270-
self.logger.error(
271-
f"get_petrol_station_prices: self._request_station_prices(station_ids) returned invalid result")
272-
return None
270+
self.logger.notice(f"get_petrol_station_prices: self._request_station_prices(station_ids) returned invalid result")
271+
return {}
273272
_price_dict = _station_id_prices.get('prices', None)
274273
for station_id in station_ids:
275274
if station_id not in _price_dict:
276-
self.logger.error(f"Plugin '{self.get_fullname()}': No result for station with id {station_id}. Check manually!")
275+
self.logger.notice(f"Plugin '{self.get_fullname()}': No result for station with id {station_id}. Check manually!")
277276

278277
if _price_dict and isinstance(_price_dict, dict):
279278
for station_id in _price_dict:
@@ -324,11 +323,13 @@ def set_item_status_values(self):
324323
self.logger.debug(f"set_item_status_values: handle item {item} type {item.type()}")
325324
station_id = self.item_dict[item]['station_id']
326325
tankerkoenig_attr = self.item_dict[item]['tankerkoenig_attr']
327-
if self.station_prices.get(station_id, None) is not None:
326+
327+
if self.station_prices is not None and self.station_prices.get(station_id, None) is not None:
328328
value = self.station_prices.get(station_id, None).get(tankerkoenig_attr, None)
329329
else:
330-
self.logger.error(
331-
f"set_item_status_values: station_id with {station_id} does not exist in station_prices.")
330+
self.logger.notice(f"set_item_status_values: station_id with {station_id} does not exist in station_prices.")
331+
continue
332+
332333
self.logger.debug(f"set_item_status_values: station_id={station_id}, tankerkoenig_attr={tankerkoenig_attr}, value={value}")
333334
if value:
334335
item(value, self.get_shortname())
@@ -344,8 +345,9 @@ def set_item_detail_values(self):
344345
if self.station_details.get(station_id, None) is not None:
345346
value = self.station_details.get(station_id, None).get(tankerkoenig_attr, None)
346347
else:
347-
self.logger.error(
348-
f"set_item_status_values: station_id with {station_id} does not exist in station_details.")
348+
self.logger.notice(f"set_item_status_values: station_id with {station_id} does not exist in station_details.")
349+
continue
350+
349351
self.logger.debug(f"set_item_detail_values: station_id={station_id}, tankerkoenig_attr={tankerkoenig_attr}, value={value}")
350352
if value:
351353
item(value, self.get_shortname())
@@ -393,14 +395,14 @@ def _request_stations(self, lat: float = None, lon: float = None, price: str = '
393395
try:
394396
response = self._session.get(url)
395397
except Exception as e:
396-
self.logger.error(f"Plugin '{self.get_fullname()}': Exception when sending GET request for _request_petrol_stations: {e}")
397-
return
398+
self.logger.notice(f"Plugin '{self.get_fullname()}': Exception when sending GET request for _request_petrol_stations: {e}")
399+
return {}
398400

399401
try:
400402
return response.json()
401403
except Exception as e:
402-
self.logger.error(f"Plugin '{self.get_fullname()}': Exception when handling GET response to JSON for _request_petrol_stations: {e}")
403-
return
404+
self.logger.notice(f"Plugin '{self.get_fullname()}': Exception when handling GET response to JSON for _request_petrol_stations: {e}")
405+
return {}
404406

405407
def _request_station_detail(self, station_id: str) -> dict:
406408
"""
@@ -458,18 +460,21 @@ def _request_station_detail(self, station_id: str) -> dict:
458460
@param station_id: Internal ID of petrol station to retrieve information for
459461
"""
460462

463+
response = None
461464
url = self._build_url(f"{self._detail_url_suffix}?id={station_id}&apikey={self._apikey}")
462465
try:
463466
response = self._session.get(url)
464467
except Exception as e:
465-
self.logger.error(f"Plugin '{self.get_fullname()}': Exception when sending GET request for get_petrol_station_detail: {e}, response was {response}")
466-
return
468+
self.logger.notice(f"Plugin '{self.get_fullname()}': Exception when sending GET request for get_petrol_station_detail: {e}, response was {response}")
469+
return {}
470+
471+
self.logger.debug(f"{response=}")
467472

468473
try:
469474
return response.json()
470475
except Exception as e:
471-
self.logger.error(f"Plugin '{self.get_fullname()}': Exception when handling GET response to JSON for get_petrol_station_detail: {e}")
472-
return
476+
self.logger.notice(f"Plugin '{self.get_fullname()}': Exception when handling GET response to JSON for get_petrol_station_detail: {e}")
477+
return {}
473478

474479
def _request_station_prices(self, station_ids: list):
475480
"""
@@ -516,13 +521,13 @@ def _request_station_prices(self, station_ids: list):
516521
try:
517522
response = self._session.get(url)
518523
except Exception as e:
519-
self.logger.error(f"Plugin '{self.get_fullname()}': Exception when sending GET request for _request_station_prices: {e}")
524+
self.logger.notice(f"Plugin '{self.get_fullname()}': Exception when sending GET request for _request_station_prices: {e}")
520525
return
521526

522527
try:
523528
return response.json()
524529
except Exception as e:
525-
self.logger.error(f"Plugin '{self.get_fullname()}': Exception when handling GET response to JSON for _request_station_prices: {e}")
530+
self.logger.notice(f"Plugin '{self.get_fullname()}': Exception when handling GET response to JSON for _request_station_prices: {e}")
526531
return
527532

528533
###################################################

tankerkoenig/plugin.yaml

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugin:
1212
documentation: http://smarthomeng.de/user/plugins_doc/config/tankerkoenig.html
1313
support: https://knx-user-forum.de/forum/supportforen/smarthome-py/938924-benzinpreis-plugin
1414
keywords: petrol station, fuel prices, petrol prices
15-
version: 2.0.4 # Plugin version
15+
version: 2.0.5 # Plugin version
1616
sh_minversion: '1.9' # minimum shNG version to use this plugin
1717
# sh_maxversion: # maximum shNG version to use this plugin (leave empty if latest)
1818
# py_minversion: # minimum Python version to use for this plugin

0 commit comments

Comments
 (0)