From 30f227df079e274ceb44ce2b5e37c658e3d0a7a2 Mon Sep 17 00:00:00 2001 From: Elad Bar Date: Wed, 6 May 2020 13:15:30 +0300 Subject: [PATCH] Fix #57 - Log is filling with errors --- CHANGELOG.md | 4 ++++ custom_components/hpprinter/managers/HPDeviceData.py | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0141d9a..13d7632 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 2020-05-06 +**Fixed bugs:** + +- Fix Log is filling with errors [\#57](https://github.com/elad-bar/ha-hpprinter/issues/57) + **Implemented enhancements:** - More descriptive error message when unable to access printer's API at setup or changing options diff --git a/custom_components/hpprinter/managers/HPDeviceData.py b/custom_components/hpprinter/managers/HPDeviceData.py index f2dd165..632b422 100644 --- a/custom_components/hpprinter/managers/HPDeviceData.py +++ b/custom_components/hpprinter/managers/HPDeviceData.py @@ -413,7 +413,10 @@ def set_printer_consumable_data(self, printer_consumable_data): @staticmethod def clean_parameter(data_item, data_key, default_value="N/A"): - result = data_item.get(data_key, {}) + if data_item is None: + result = default_value + else: + result = data_item.get(data_key, {}) if not isinstance(result, str): result = result.get("#text", 0)