Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic reloading broken on recently added displays. #140

Merged
merged 3 commits into from
Aug 19, 2024

Conversation

xNUTx
Copy link
Contributor

@xNUTx xNUTx commented Aug 8, 2024

The display stops or refuses to dynamically update (from HA) and throws an error in the logs because (most likely) num_pages contains a string, while page contains an int, resulting in a python type error.

…r in the logs because (most likely) num_pages contains a string, while page contains an int, resulting in a python type error
@dgomes
Copy link
Collaborator

dgomes commented Aug 8, 2024

Could you please provide a log of the error ? I would prefer to trace to error to the source then to fix where we find the symptom

@xNUTx
Copy link
Contributor Author

xNUTx commented Aug 8, 2024

Exception in lwt_message_received when handling msg on 'hasp/seeeddisplay1/LWT': 'online' Traceback (most recent call last): File "/config/custom_components/openhasp/__init__.py", line 478, in lwt_message_received await self.async_load_page(self._pages_jsonl) File "/config/custom_components/openhasp/__init__.py", line 673, in async_load_page await self.refresh() File "/config/custom_components/openhasp/__init__.py", line 628, in refresh await self.async_change_page(self._page) File "/config/custom_components/openhasp/__init__.py", line 559, in async_change_page if page <= 0 or page > num_pages: ^^^^^^^^^^^^^^^^ TypeError: '>' not supported between instances of 'int' and 'str'

I reintroduced the bug but added a comment with the actual fix. the line numbers beyond 559 are +1 instead of the actual lines in the trace.

@FreeBear-nc
Copy link
Contributor

Page is already being tested against zero (so should already be a number). Does it really need to be cast to an int for the test against num_pages ?

@xNUTx
Copy link
Contributor Author

xNUTx commented Aug 15, 2024

As you can see in the error log, it seems to be able to have more then just an int, so the change helps to fix this.

I was not sure where this string content comes from to fix the source issue, which may be better to fix instead. Also I am unsure if it was the 'page' or the 'num_pages' variable carrying the string... but if you say 'page' is already checked for number content elsewhere, I think it must have been 'num_pages'.

See https://github.com/HASwitchPlate/openHASP-custom-component/blob/86bca7ecd77ccb163084d66dc2724a34b23bdb40/custom_components/openhasp/__init__.py#L539C1-L561C23

It shows 'page' can hold a string called 'all'. There is no type cast on 'num_pages' when it is filled.

@xNUTx
Copy link
Contributor Author

xNUTx commented Aug 15, 2024

Skipping through the code in the component, I can conclude BOTH 'page' and 'num_pages' hold a string initially.

self._statusupdate = {HASP_NUM_PAGES: entry.data[CONF_PAGES]}

HASP_NUM_PAGES is set with the discovered number of pages here:

self.config_data[CONF_PAGES] = _discovered.get(DISCOVERED_PAGES)

We can actually conclude this is pretty much guaranteed an int as HASP_NUM_PAGES in self._statusupdate is set using the discovered 'CONF_PAGES'.

So it is 'page' that can hold the string 'all' which does not allow a 'larger then' int comparison. That is the one which needs a workaround in that check.

@xNUTx
Copy link
Contributor Author

xNUTx commented Aug 15, 2024

Updated the code to check 'page' for the type int instead of casting both to it.

This should satisfy the check in every possible way and not throw exceptions.

Copy link
Collaborator

@dgomes dgomes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fvanroie fvanroie merged commit 847825d into HASwitchPlate:main Aug 19, 2024
2 checks passed
@xNUTx
Copy link
Contributor Author

xNUTx commented Sep 5, 2024

Logger: homeassistant.util.logging
Bron: util/logging.py:95
Eerst voorgekomen: 17:33:32 (6 gebeurtenissen)
Laatst gelogd: 17:34:09

Exception in lwt_message_received when handling msg on 'hasp/seeeddisplay3/LWT': 'online' Traceback (most recent call last): File "/config/custom_components/openhasp/__init__.py", line 478, in lwt_message_received await self.async_load_page(self._pages_jsonl) File "/config/custom_components/openhasp/__init__.py", line 671, in async_load_page await self.refresh() File "/config/custom_components/openhasp/__init__.py", line 626, in refresh await self.async_change_page(self._page) File "/config/custom_components/openhasp/__init__.py", line 559, in async_change_page if isinstance(page, int) and (page <= 0 or page > num_pages): ^^^^^^^^^^^^^^^^ TypeError: '>' not supported between instances of 'int' and 'str'
Exception in lwt_message_received when handling msg on 'hasp/seeeddisplay1/LWT': 'online' Traceback (most recent call last): File "/config/custom_components/openhasp/__init__.py", line 478, in lwt_message_received await self.async_load_page(self._pages_jsonl) File "/config/custom_components/openhasp/__init__.py", line 671, in async_load_page await self.refresh() File "/config/custom_components/openhasp/__init__.py", line 626, in refresh await self.async_change_page(self._page) File "/config/custom_components/openhasp/__init__.py", line 559, in async_change_page if isinstance(page, int) and (page <= 0 or page > num_pages): ^^^^^^^^^^^^^^^^ TypeError: '>' not supported between instances of 'int' and 'str'
Exception in lwt_message_received when handling msg on 'hasp/seeeddisplay2/LWT': 'online' Traceback (most recent call last): File "/config/custom_components/openhasp/__init__.py", line 478, in lwt_message_received await self.async_load_page(self._pages_jsonl) File "/config/custom_components/openhasp/__init__.py", line 671, in async_load_page await self.refresh() File "/config/custom_components/openhasp/__init__.py", line 626, in refresh await self.async_change_page(self._page) File "/config/custom_components/openhasp/__init__.py", line 559, in async_change_page if isinstance(page, int) and (page <= 0 or page > num_pages): ^^^^^^^^^^^^^^^^ TypeError: '>' not supported between instances of 'int' and 'str'

The fix seems to not be complete. Somehow num_pages can hold a string as well... 🤔

xNUTx added a commit to xNUTx/openHASP-custom-component that referenced this pull request Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants