HASwitchPlate / openHASP-custom-component

Home Assistant custom component for openHASP
https://www.openhasp.com
MIT License
49 stars 9 forks source link

Option for .json pages file containing an array of objects #67

Closed scribblrsam closed 2 years ago

scribblrsam commented 2 years ago

How does this look for a first pass based upon the descussion in the main openHASP project?

Outstanding:

Example pages.json file:


  {
    "page": 0,
    "id": 1,
    "obj": "btn",
    "action": "p1",
    "x": 0,
    "y": 200,
    "w": 80,
    "h": 40,
    "bg_color": "#2C3E50",
    "text": "1",
    "text_color": "#FFFFFF",
    "radius": 0,
    "border_side": 0,
    "text_font": 32
  },
  "comment here, no object needed",
  {
    "page": 0,
    "id": 2,
    "obj": "btn",
    "action": "p2",
    "x": 80,
    "y": 200,
    "w": 80,
    "h": 40,
    "bg_color": "#2C3E50",
    "text": "2",
    "text_color": "#FFFFFF",
    "radius": 0,
    "border_side": 0,
    "text_font": 32
  },
  {
    "page": 0,
    "id": 3,
    "obj": "btn",
    "action": "p3",
    "x": 160,
    "y": 200,
    "w": 80,
    "h": 40,
    "bg_color": "#2C3E50",
    "text": "3",
    "text_color": "#FFFFFF",
    "radius": 0,
    "border_side": 0,
    "text_font": 32
  },
  {
    "page": 0,
    "id": 4,
    "obj": "btn",
    "action": "p4",
    "x": 240,
    "y": 200,
    "w": 80,
    "h": 40,
    "bg_color": "#2C3E50",
    "text": "4",
    "text_color": "#FFFFFF",
    "radius": 0,
    "border_side": 0,
    "text_font": 32
  }
]
scribblrsam commented 2 years ago

I'd like to add a json-schema check but thought that could be another PR if you agree.

I also noticed that the doc string for async_load_page says it clears the page but as far as i can see it just overwrites. Is this intentional?

dgomes commented 2 years ago

I'd like to add a json-schema check but thought that could be another PR if you agree.

OK!

I also noticed that the doc string for async_load_page says it clears the page but as far as i can see it just overwrites. Is this intentional?

I think it something that changed meanwhile and was never updated in documentation

nagyrobi commented 2 years ago

One question, if the same filename is present as both json and jsonl, which one has priority?

scribblrsam commented 2 years ago

I think it something that changed meanwhile and was never updated in documentation

I'll edit the docstring, unless you want to put the clear back in?

scribblrsam commented 2 years ago

One question, if the same filename is present as both json and jsonl, which one has priority?

@nagyrobi - I dont think this is an case that exists the component requires a valid path to a file. You would need to specify a file ending in .json for this PR to make a difference. All other extenstions including .jsonl are processed as before

dgomes commented 2 years ago

I think it something that changed meanwhile and was never updated in documentation

I'll edit the docstring, unless you want to put the clear back in?

I'm fine with any solution @nagyrobi and @fvanroie what do you think ?

nagyrobi commented 2 years ago

I think it something that changed meanwhile and was never updated in documentation

I'll edit the docstring, unless you want to put the clear back in?

I'm fine with any solution @nagyrobi and @fvanroie what do you think ?

Fine by me.

fvanroie commented 2 years ago

I'm fine with any solution @nagyrobi and @fvanroie what do you think ?

        """Clear current pages and load new ones."""

jsonl commands create an object if it doesn't exist and update the object if it already exists. However, you can not change the obj type once the object has been created.

To clear everything and recreate all objects, you need to call clearpage all first.

scribblrsam commented 2 years ago

Personally, I think that a clearpage all first would be a good idea, this ensures that any objects which are deleted from the pages file are removed without the need to reboot.

On Thu, 26 Aug 2021 at 15:26, fvanroie @.***> wrote:

I'm fine with any solution @nagyrobi https://github.com/nagyrobi and @fvanroie https://github.com/fvanroie what do you think ?

    """Clear current pages and load new ones."""

jsonl https://haswitchplate.github.io/openHASP-docs/0.6.1/commands/#jsonl commands create an object if it doesn't exist and update the object if it already exists. However, you can not change the obj type once the object has been created.

To clear everything and recreate all objects, you need to call clearpage all https://haswitchplate.github.io/openHASP-docs/0.6.1/commands/#clearpage first.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/HASwitchPlate/openHASP-custom-component/pull/67#issuecomment-906462066, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB35DFCPAPBRYOFX2UAREGLT6ZFK7ANCNFSM5CZ7ECMQ .

nagyrobi commented 2 years ago

Personally, I think that a clearpage all first would be a good idea

There are cases when this is not desired to be done automatically. When you want to clear all, use a command service call and clear the pages separately first, and start parsing jsonls after that.

fvanroie commented 2 years ago

So have a load_pages and reload_pages?

nagyrobi commented 2 years ago

No need. It's fine the way it is now, no need to change anything. If you want to clear pages in advance, use the apropriate clearpage command in HA automation sequence, before loading of the page.

nagyrobi commented 2 years ago

We already have these services: https://haswitchplate.github.io/openHASP-docs/0.6.1/integrations/home-assistant/howto/#services

scribblrsam commented 2 years ago

There are cases when this is not desired to be done automatically

I'll just update the docstring for that function for clarity! Sorry, I didn't mean for that to spiral, it just confused me when reading it.

dgomes commented 2 years ago

All good! Thanks! 🎉

fvanroie commented 2 years ago

openHASP (ArduinoJSON really) optimizes the jsonl stream for fast decoding.

One future optimization is to append a payload buffer with more <object>\n strings up until 1000 characters and then send it via MQTT. There is a small overhead with incoming mqtt data, so more jsonl objects in the same payload will be faster than individual messages...