Skip to content

Commit 543c61f

Browse files
committed
When constructing device name, avoid null parts of it,
Changed the logic of errors from not found endpoints
1 parent b1cc440 commit 543c61f

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## 2.0.0b6
4+
5+
- When constructing device name, avoid null parts of it [#113](https://github.com/elad-bar/ha-hpprinter/issues/113)
6+
- Changed the logic of errors from not found endpoints [#120](https://github.com/elad-bar/ha-hpprinter/issues/120)
7+
- On initial load / setting up integration - one of the endpoints must return valid response, otherwise the integration will fail to load.
8+
- After the integration loaded, it will update data periodically,
9+
- If one of the endpoints will return 404 (not found) - the data related to it will get reset, DEBUG message will be logged (instead of ERROR)
10+
- If printer goes offline, all data will be set as Unknown.
11+
312
## 2.0.0b5
413

514
- Support no prefetch mode

custom_components/hpprinter/managers/ha_coordinator.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ def create_consumable_device(
160160
device_name_parts.append(cartridge_color)
161161
device_name_parts.append(cartridge_type.capitalize())
162162

163+
device_name_parts = [
164+
device_name_part
165+
for device_name_part in device_name_parts
166+
if device_name_part is not None
167+
]
168+
163169
device_unique_id = slugify(f"{self.entry_id}.{device_key}")
164170

165171
cartridge_device_name = " ".join(device_name_parts)

custom_components/hpprinter/managers/rest_api.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,21 @@ async def _get_request(
346346
_LOGGER.debug(f"Request to {url}")
347347

348348
except ClientResponseError as cre:
349-
if not ignore_error:
350-
exc_type, exc_obj, tb = sys.exc_info()
351-
line_number = tb.tb_lineno
352-
_LOGGER.error(
353-
f"Failed to get response from {endpoint}, Error: {cre}, Line: {line_number}"
354-
)
349+
if cre.status == 404:
350+
if not ignore_error:
351+
exc_type, exc_obj, tb = sys.exc_info()
352+
line_number = tb.tb_lineno
353+
_LOGGER.debug(
354+
f"Failed to get response from {endpoint}, Error: {cre}, Line: {line_number}"
355+
)
356+
357+
else:
358+
if not ignore_error:
359+
exc_type, exc_obj, tb = sys.exc_info()
360+
line_number = tb.tb_lineno
361+
_LOGGER.error(
362+
f"Failed to get response from {endpoint}, Error: {cre}, Line: {line_number}"
363+
)
355364

356365
except Exception as ex:
357366
if not ignore_error:

custom_components/hpprinter/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"iot_class": "local_polling",
1010
"issue_tracker": "https://github.com/elad-bar/ha-hpprinter/issues",
1111
"requirements": ["xmltodict~=0.13.0", "flatten_json", "defusedxml"],
12-
"version": "2.0.0b5"
12+
"version": "2.0.0b6"
1313
}

0 commit comments

Comments
 (0)