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

[Feature Request] Make next / prev / up / home icons in title bar configurable entities. #633

Closed
esclear opened this issue Dec 26, 2022 · 34 comments
Milestone

Comments

@esclear
Copy link
Contributor

esclear commented Dec 26, 2022

FEATURE DESCRIPTION

I would like to have the option to make the next / prev / up / home icons in the top left and top right corners of the screen configurable entities.
Then, one would have the option of navigating, switching outputs, triggering automations, etc.

This would be somewhat similar to statusIcon1 and statusIcon2 for the screensaver

ADDITIONAL CONTEXT

This might be a duplicate of #403, though I think this request may be a bit broader and #403 seems to be limited to ioBroker.

PANEL / FIRMWARE VERION

nspanel-lovelace-ui v3.7.3, tasmota 12.3.1 on NSPanel EU.

@esclear esclear changed the title [Feature Request] Make next / prev / up / home icons in title bar configurable. [Feature Request] Make next / prev / up / home icons in title bar configurable entities. Dec 26, 2022
@joBr99
Copy link
Owner

joBr99 commented Dec 27, 2022

interesting idea, however this is a pretty significat change and it's not going to land on the roadmap in the near future

@esclear
Copy link
Contributor Author

esclear commented Dec 27, 2022

Aww, that's unfortunate (but understandable) :/

I don't know much about how the Nextion UI works, but I assume that the icons are already some form of buttons.
This is one of the cases where I can see myself making a PR to scratch my own itch, if that would be acceptable for you. Though I would probably need some support.

How is the homeButton currently controlled?
I looked at the HMI protocol, but I didn't find any mention of it there.

@joBr99
Copy link
Owner

joBr99 commented Dec 27, 2022

Initially there was only one "horizontal" level for the pages. (controlled with bPrev/bNext)

With the addion of navigate there was bUp added, the apperace of the buttons is controlled though the second value of entiyUpd Command. (entityUpd~test~1|1)

0 -> disabled
1 -> bPrev/bNext
2 -> bUp/bHome

In general you can categorize the buttons in the HMI Project into "static" and more "dynamic" ones.

The static ones are doing what's defined in them and the apperance is defined in the Project.

The button for bNext is for example sending this: (simplified, there is some logic for bNext/bHome)

tSend.txt="event,buttonPress2,cardMedia,bNext"

The buttons used on cardGrid and on the buttom row of cardMedia (since last version) are based on the format build for cardEntities. This allows to reuse code to generate entities for cardGrid/cardEntities and cardMedia.

{type}~{internalNameEntity}~{icon}~{iconColor}~{displayNameEntity}~{optionalValue}

displayNameEntity and the optionalValue isn't really needed for the usage as button; however the paramter needs to be there to stick with the format.

I will look into implementing this in the HMI Project (replacing the 1|1 prameter with the 12 parameters needed for the two buttons).

However that's only the HMI side of things, there are also some todo's on the python side.

@joBr99
Copy link
Owner

joBr99 commented Dec 27, 2022

do you think it's importent to be able to open popup/detail pages from thoose button in the nav bar?

@esclear
Copy link
Contributor Author

esclear commented Dec 27, 2022

This hasn't come up for the use cases I imagine.
However, I think it would be a valid assumption that this works more or less like a "normal" entity item (such as one from a cardGrid)

@joBr99
Copy link
Owner

joBr99 commented Dec 28, 2022

https://github.com/joBr99/nspanel-lovelace-ui/blob/main/HMI/README.md#cardentities-page

Serial Protocol has been changed.

Also Navigation in the backend has been changed to use new format.

l = self.generate_entities_item(Entity(

Should be possible to implement a config option to overwrite the navigation buttons from there.

joBr99 added a commit that referenced this issue Jan 4, 2023
@joBr99
Copy link
Owner

joBr99 commented Jan 4, 2023

Should be working like this:

    cards:
      - type: cardGrid
        title: Wohnzimmer
        navItem1:
          entity: light.bad_lights
        navItem2:
          entity: light.bad_lights
        entities:
          - entity: navigate.cardGrid_szenen
            icon: palette

@joBr99 joBr99 added this to the 3.8.X milestone Jan 4, 2023
@joBr99 joBr99 closed this as completed Jan 4, 2023
@esclear
Copy link
Contributor Author

esclear commented Jan 4, 2023

Cool, thanks a lot!

Can this be tested with the latest / current Nextion firmware / configuration, as described in https://docs.nspanel.pky.eu/faq/#how-to-upgrade-from-a-release-to-the-current-development-version ?
I tried that out, but it renders incorrectly (with no navItems configured).

@joBr99
Copy link
Owner

joBr99 commented Jan 4, 2023

Will have a look, but if there's an error it's on the python side.

@esclear
Copy link
Contributor Author

esclear commented Jan 4, 2023

I am seeing two errors in my appdaemon logs:

2023-01-04 19:23:46.370830 WARNING nspanel: ------------------------------------------------------------
2023-01-04 19:23:46.371767 WARNING nspanel: Unexpected error in worker for App nspanel:
2023-01-04 19:23:46.372541 WARNING nspanel: Worker Ags: {}
2023-01-04 19:23:46.373207 WARNING nspanel: ------------------------------------------------------------
2023-01-04 19:23:46.380825 WARNING nspanel: Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/appdaemon/app_management.py", line 165, in initialize_app
    await utils.run_in_executor(self, init)
  File "/usr/local/lib/python3.9/site-packages/appdaemon/utils.py", line 337, in run_in_executor
    response = future.result()
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/conf/apps/hacs/nspanel-lovelace-ui/nspanel-lovelace-ui.py", line 22, in initialize
    mqttsend = LuiMqttSender(self, topic_send)
TypeError: __init__() missing 1 required positional argument: 'topic_send'

This is likely not the cause of the problem, however this one may be:

2023-01-04 19:24:46.659018 WARNING Error: ------------------------------------------------------------
2023-01-04 19:24:46.660006 WARNING Error: Unexpected error loading module: /conf/apps/hacs/nspanel-lovelace-ui/nspanel-lovelace-ui.py:
2023-01-04 19:24:46.660796 WARNING Error: ------------------------------------------------------------
2023-01-04 19:24:46.669622 WARNING Error: Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/appdaemon/app_management.py", line 993, in check_app_updates
    await utils.run_in_executor(self, self.read_app, mod["name"], mod["reload"])
  File "/usr/local/lib/python3.9/site-packages/appdaemon/utils.py", line 337, in run_in_executor
    response = future.result()
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/appdaemon/app_management.py", line 784, in read_app
    self.modules[module_name] = importlib.import_module(module_name)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/conf/apps/hacs/nspanel-lovelace-ui/nspanel-lovelace-ui.py", line 3, in <module>
    from luibackend.config import LuiBackendConfig
  File "/conf/apps/hacs/nspanel-lovelace-ui/luibackend/config.py", line 1, in <module>
    from itertools import pairwise
ImportError: cannot import name 'pairwise' from 'itertools' (unknown location)

@joBr99
Copy link
Owner

joBr99 commented Jan 4, 2023

did you restart appdaemon after redownloading the app?

@esclear
Copy link
Contributor Author

esclear commented Jan 4, 2023

I did, yes. It seems that the problem is that the appdaemon container comes with Python 3.9 installed, but itertools.pairwise was added in Python 3.10.

@joBr99
Copy link
Owner

joBr99 commented Jan 4, 2023

oh shoot ... appdaemon on homeassistant supervisor is alrady bundled with 3.10 ; appdaemon standalone is on 3.9

@esclear
Copy link
Contributor Author

esclear commented Jan 4, 2023

An alternative might be using itertools.combinations( sequence, 2).
Although I think that the generated sequence might be slightly different.

That's wrong, I thought that pairwise did something different.
But the itertools documentation has something equivalent.

@joBr99
Copy link
Owner

joBr99 commented Jan 4, 2023

it's used to go though the cards and add "pointers" to the previous and the next card, so the sequence has to be AB BC CD

@esclear
Copy link
Contributor Author

esclear commented Jan 4, 2023

Wouldn't it have to be something like AC BD CE then?
Or rather EB AC BD CE DA to wrap around?
(I haven't looked at the code yet).

@joBr99
Copy link
Owner

joBr99 commented Jan 4, 2023

It's a loop going over each card.

Inside of the loop it needs to access the previous and the next card's uuid to set it to the prev and next attribute of the current card.

@esclear
Copy link
Contributor Author

esclear commented Jan 4, 2023

Yes, so if I'm in card B, I'd want the ids of card A, the previous, and card C, the next one, don't I?

@esclear
Copy link
Contributor Author

esclear commented Jan 4, 2023

Ah, I see. The previous id for the next card is set when setting the next id for the current card. That works.

@joBr99
Copy link
Owner

joBr99 commented Jan 4, 2023

yep, there are probably thousands of ways to do this, end result should look like this:

cardA:
  self.uuid = A
  self.uuid_next = B
  self.uuid_prev = C
  
 cardB:
  self.uuid = B
  self.uuid_next = C
  self.uuid_prev = A
  
 cardC:
  self.uuid = C
  self.uuid_next = A
  self.uuid_prev = B

during rendering of the card it's going to use uuid_prev and uuid_next for the entities in the corner of the card

@esclear
Copy link
Contributor Author

esclear commented Jan 4, 2023

I wrote an alternative implementation, that works in python 3.9 (and also older versions), which I could provide in a PR.

I'm currently facing some other issues, but I don't know what may have caused them:

2023-01-04 20:11:42.852882 WARNING HASS: Code: 500, error: 500 Internal Server Error  Server got itself in trouble
--
2023-01-04 20:11:42.852058 WARNING HASS: Error calling Home Assistant service default/template/render

I'm not sure whether these are related by the upgrade to HA 2023.01 or to this projects' HEAD.

@joBr99
Copy link
Owner

joBr99 commented Jan 4, 2023

do that

I would guess this error could be caused by a render_template call, do you have an idea on which actions thoose warnings appear?

@esclear
Copy link
Contributor Author

esclear commented Jan 4, 2023

That appears when restarting AppDaemon. So, uuh … I'm not sure 🤷🏻.

@joBr99
Copy link
Owner

joBr99 commented Jan 4, 2023

Ok, I've the same warnings in my log and I'm still on 2022.12.1

@esclear
Copy link
Contributor Author

esclear commented Jan 4, 2023

In the HA log, I see:

2023-01-04 20:19:49.950 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 81, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 136, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/api/__init__.py", line 364, in post
    tpl = template.Template(data["template"], request.app["hass"])
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 338, in __init__
    raise TypeError("Expected template to be a string")
TypeError: Expected template to be a string

@joBr99
Copy link
Owner

joBr99 commented Jan 4, 2023

Took me some time to figure it out, but it's most likely caused by defaultCard = apis.ha_api.render_template(defaultCard) in config.py

@esclear
Copy link
Contributor Author

esclear commented Jan 4, 2023

Ah, yes. this is None in my case.
Huh, even though I have set a default card in my configuration 👀

@esclear
Copy link
Contributor Author

esclear commented Jan 4, 2023

When I set this manually, I get:

2023-01-04 20:42:09.336493 WARNING nspanel: ------------------------------------------------------------
2023-01-04 20:42:09.336882 WARNING nspanel: Unexpected error running initialize() for nspanel
2023-01-04 20:42:09.337163 WARNING nspanel: ------------------------------------------------------------
2023-01-04 20:42:09.342083 WARNING nspanel: Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/appdaemon/app_management.py", line 165, in initialize_app
    await utils.run_in_executor(self, init)
  File "/usr/local/lib/python3.9/site-packages/appdaemon/utils.py", line 337, in run_in_executor
    response = future.result()
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/conf/apps/hacs/nspanel-lovelace-ui/nspanel-lovelace-ui.py", line 27, in initialize
    controller = LuiController(cfg, mqttsend.send_mqtt_msg)
  File "/conf/apps/hacs/nspanel-lovelace-ui/luibackend/controller.py", line 16, in __init__
    self._previous_cards.append(self._config.get_default_card())
  File "/conf/apps/hacs/nspanel-lovelace-ui/luibackend/config.py", line 234, in get_default_card
    defaultCard = self.search_card(defaultCard)
AttributeError: 'LuiBackendConfig' object has no attribute 'search_card'

@joBr99
Copy link
Owner

joBr99 commented Jan 4, 2023

going to refactor searchCard to search_card and fix that call to the HA api with none

@joBr99
Copy link
Owner

joBr99 commented Jan 4, 2023

should be fixed

tested with and without defaultCard configured

@esdcmc
Copy link

esdcmc commented Jan 7, 2023

now that the home button has disappeared: it is unclear what should be added in apps.yaml to get it back

@joBr99
Copy link
Owner

joBr99 commented Jan 7, 2023

You have to configure it on your cards; as noted in the breaking changes of the release notes:

bHome config option to display Home Button has been removed, use overwrite of navigation buttons instead #633 @joBr99

    cards:
      - type: cardGrid
        title: Home
        key: home
        entities:
          - entity: light.bad

    hiddenCards:
      - type: cardGrid
        title: Wohnzimmer
        navItem2:
          entity: navigate.home
          icon: mdi:home
        entities:
          - entity: light.kitchen

@esdcmc
Copy link

esdcmc commented Jan 7, 2023

thanks it does work again now (I will just have to add instruction on all cards).

Sorry description on "the breaking changes of the release notes" confused me as this 633# is about something not working in Python and could not find a clear example of revised apps.yaml.

Maybe it's just me
Thanks a lot anyway

@joBr99
Copy link
Owner

joBr99 commented Jan 8, 2023

added an example in the docs & a link in the release notes

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

No branches or pull requests

3 participants