Skip to content

Commit

Permalink
When constructing device name, avoid null parts of it,
Browse files Browse the repository at this point in the history
Changed the logic of errors from not found endpoints
  • Loading branch information
elad-bar committed May 7, 2024
1 parent b1cc440 commit 543c61f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 2.0.0b6

- When constructing device name, avoid null parts of it [#113](https://github.com/elad-bar/ha-hpprinter/issues/113)
- Changed the logic of errors from not found endpoints [#120](https://github.com/elad-bar/ha-hpprinter/issues/120)
- On initial load / setting up integration - one of the endpoints must return valid response, otherwise the integration will fail to load.
- After the integration loaded, it will update data periodically,
- 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)
- If printer goes offline, all data will be set as Unknown.

## 2.0.0b5

- Support no prefetch mode
Expand Down
6 changes: 6 additions & 0 deletions custom_components/hpprinter/managers/ha_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ def create_consumable_device(
device_name_parts.append(cartridge_color)
device_name_parts.append(cartridge_type.capitalize())

device_name_parts = [
device_name_part
for device_name_part in device_name_parts
if device_name_part is not None
]

device_unique_id = slugify(f"{self.entry_id}.{device_key}")

cartridge_device_name = " ".join(device_name_parts)
Expand Down
21 changes: 15 additions & 6 deletions custom_components/hpprinter/managers/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,21 @@ async def _get_request(
_LOGGER.debug(f"Request to {url}")

except ClientResponseError as cre:
if not ignore_error:
exc_type, exc_obj, tb = sys.exc_info()
line_number = tb.tb_lineno
_LOGGER.error(
f"Failed to get response from {endpoint}, Error: {cre}, Line: {line_number}"
)
if cre.status == 404:
if not ignore_error:
exc_type, exc_obj, tb = sys.exc_info()
line_number = tb.tb_lineno
_LOGGER.debug(
f"Failed to get response from {endpoint}, Error: {cre}, Line: {line_number}"
)

else:
if not ignore_error:
exc_type, exc_obj, tb = sys.exc_info()
line_number = tb.tb_lineno
_LOGGER.error(
f"Failed to get response from {endpoint}, Error: {cre}, Line: {line_number}"
)

except Exception as ex:
if not ignore_error:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hpprinter/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/elad-bar/ha-hpprinter/issues",
"requirements": ["xmltodict~=0.13.0", "flatten_json", "defusedxml"],
"version": "2.0.0b5"
"version": "2.0.0b6"
}

0 comments on commit 543c61f

Please sign in to comment.